Browse Source

compilation issues, expose lighting factor in viewer, pass on ao tutorial example

Former-commit-id: 7f2d9ced69126469ed1068fdc00b1d8c4e4ee0bb
Alec Jacobson 11 years ago
parent
commit
5a5c4b9d32

+ 8 - 7
include/igl/unproject.cpp

@@ -61,10 +61,11 @@ IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::unproject(
 #endif
 
 
-Eigen::Vector3f igl::unproject(const Eigen::Vector3f& win,
-                          const Eigen::Matrix4f& model,
-                          const Eigen::Matrix4f& proj,
-                          const Eigen::Vector4f& viewport)
+Eigen::Vector3f igl::unproject(
+  const Eigen::Vector3f& win,
+  const Eigen::Matrix4f& model,
+  const Eigen::Matrix4f& proj,
+  const Eigen::Vector4f& viewport)
 {
   Eigen::Matrix4f Inverse = (proj * model).inverse();
 
@@ -80,10 +81,10 @@ Eigen::Vector3f igl::unproject(const Eigen::Vector3f& win,
   return obj.head(3);
 }
 
+#ifdef IGL_STATIC_LIBRARY
+
 #ifndef IGL_NO_OPENGL
 #ifndef IGL_OPENGL_4
-
-#ifdef IGL_STATIC_LIBRARY
 // Explicit template instanciation
 template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
 template int igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
@@ -92,6 +93,6 @@ template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<
 template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
 template int igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
 #endif
-
 #endif
+
 #endif

+ 18 - 18
include/igl/unproject.h

@@ -33,24 +33,24 @@ namespace igl
   IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
     const Eigen::PlainObjectBase<Derivedwin> & win);
 
-// Eigen reimplementation of gluUnproject
-// Inputs:
-//   win  screen space x, y, and z coordinates
-// Returns:
-//   the unprojected x, y, and z coordinates
-// Returns return value of gluUnProject call
-IGL_INLINE Eigen::Vector3f unproject(const Eigen::Vector3f& win,
-                                     const Eigen::Matrix4f& model,
-                                     const Eigen::Matrix4f& proj,
-                                     const Eigen::Vector4f& viewport);
-
-template <typename Derivedwin, typename Derivedobj>
-IGL_INLINE int unproject(
-  const Eigen::PlainObjectBase<Derivedwin> & win,
-  Eigen::PlainObjectBase<Derivedobj> & obj);
-template <typename Derivedwin>
-IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
-  const Eigen::PlainObjectBase<Derivedwin> & win);
+  // Eigen reimplementation of gluUnproject
+  // Inputs:
+  //   win  screen space x, y, and z coordinates
+  // Returns:
+  //   the unprojected x, y, and z coordinates
+  // Returns return value of gluUnProject call
+  IGL_INLINE Eigen::Vector3f unproject(
+    const Eigen::Vector3f& win,
+    const Eigen::Matrix4f& model,
+    const Eigen::Matrix4f& proj,
+    const Eigen::Vector4f& viewport);
+  template <typename Derivedwin, typename Derivedobj>
+  IGL_INLINE int unproject(
+    const Eigen::PlainObjectBase<Derivedwin> & win,
+    Eigen::PlainObjectBase<Derivedobj> & obj);
+  template <typename Derivedwin>
+  IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
+    const Eigen::PlainObjectBase<Derivedwin> & win);
 }
 
 

+ 4 - 2
include/igl/viewer/Viewer.cpp

@@ -641,6 +641,7 @@ namespace igl
 
     // Default lights settings
     options.light_position << 0.0f, -0.30f, -5.0f;
+    options.lighting_factor = 1.0f; //on
 
     // Default trackball
     options.trackball_angle << 0.0f, 0.0f, 0.0f, 1.0f;
@@ -1688,7 +1689,7 @@ namespace igl
     "dot_prod_specular = max (dot_prod_specular, 0.0);"
     "float specular_factor = pow (dot_prod_specular, specular_exponent);"
     "vec3 Is = Ls * Ksi * specular_factor;"    // specular intensity
-    "vec4 color = vec4(lighting_factor * (Is + Id) + Ia, 1.0);"
+    "vec4 color = vec4(lighting_factor * (Is + Id) + Ia, 1.0) + vec4((1.0-lighting_factor) * Kdi,1.0);"
     "outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color;"
     "if (fixed_color != vec4(0.0)) outColor = fixed_color;"
     "}";
@@ -1832,7 +1833,7 @@ namespace igl
     glUniform1f(specular_exponenti, options.shininess);
     Vector3f rev_light = -1.*options.light_position;
     glUniform3fv(light_position_worldi, 1, rev_light.data());
-    glUniform1f(lighting_factori, 1.0f); // enables lighting
+    glUniform1f(lighting_factori, options.lighting_factor); // enables lighting
     glUniform4f(fixed_colori, 0.0, 0.0, 0.0, 0.0);
 
     if (data.V.rows()>0)
@@ -2081,6 +2082,7 @@ namespace igl
     xmlSerializer->Add(background_color, "background_color");
     xmlSerializer->Add(line_color, "line_color");
     xmlSerializer->Add(light_position, "light_position");
+    xmlSerializer->Add(lighting_factor, "lighting_factor");
     xmlSerializer->Add(trackball_angle, "trackball_angle");
     xmlSerializer->Add(model_zoom, "model_zoom");
     xmlSerializer->Add(model_translation, "model_translation");

+ 1 - 0
include/igl/viewer/Viewer.h

@@ -55,6 +55,7 @@ namespace igl
 
       // Lighting
       Eigen::Vector3f light_position;
+      float lighting_factor;
 
       // Trackball angle (quaternion)
       Eigen::Vector4f trackball_angle;

+ 32 - 15
tutorial/606_AmbientOcclusion/main.cpp

@@ -1,10 +1,9 @@
 #include <igl/readOFF.h>
 #include <igl/viewer/Viewer.h>
-#include <igl/local_basis.h>
-#include <igl/barycenter.h>
+#include <igl/per_vertex_normals.h>
 #include <igl/avg_edge_length.h>
 #include <igl/embree/ambient_occlusion.h>
-#include <algorithm>
+#include <iostream>
 
 using namespace Eigen;
 using namespace std;
@@ -18,20 +17,32 @@ VectorXd AO;
   // It allows to change the degree of the field when a number is pressed
 bool key_down(igl::Viewer& viewer, unsigned char key, int modifier)
 {
-  if (key == '1')
+  const RowVector3d color(0.9,0.85,0.9);
+  switch(key)
   {
-    // Show the mesh without the ambient occlusion factor
-    viewer.set_colors(Eigen::RowVector3d(1,1,1));
-  }
-
-  if (key == '2')
-  {
-    // Show the mesh with the ambient occlusion factor
-    MatrixXd C = MatrixXd::Constant(V.rows(),3,1);
-    for (unsigned i=0; i<C.rows();++i)
-      C.row(i) *= std::min<double>(AO(i)+0.2,1);
-    viewer.set_colors(C);
+    case '1':
+      // Show the mesh without the ambient occlusion factor
+      viewer.set_colors(color);
+      break;
+    case '2':
+    {
+      // Show the mesh with the ambient occlusion factor
+      MatrixXd C = color.replicate(V.rows(),1);
+      for (unsigned i=0; i<C.rows();++i)
+        C.row(i) *= AO(i);//std::min<double>(AO(i)+0.2,1);
+      viewer.set_colors(C);
+      break;
+    }
+    case '.':
+      viewer.options.lighting_factor += 0.1;
+      break;
+    case ',':
+      viewer.options.lighting_factor -= 0.1;
+      break;
+    default: break;
   }
+  viewer.options.lighting_factor = 
+    std::min(std::max(viewer.options.lighting_factor,0.f),1.f);
 
   return false;
 }
@@ -40,6 +51,11 @@ int main(int argc, char *argv[])
 {
   using namespace std;
   using namespace Eigen;
+  cout<<
+    "Press 1 to turn off Ambient Occlusion"<<endl<<
+    "Press 2 to turn on Ambient Occlusion"<<endl<<
+    "Press . to turn up lighting"<<endl<<
+    "Press , to turn down lighting"<<endl;
 
   // Load a mesh in OFF format
   igl::readOFF("../shared/fertility.off", V, F);
@@ -57,5 +73,6 @@ int main(int argc, char *argv[])
   viewer.callback_key_down = &key_down;
   key_down(viewer,'2',0);
   viewer.options.show_lines = false;
+  viewer.options.lighting_factor = 0.0f;
   viewer.launch();
 }

+ 9 - 0
tutorial/cmake/FindLIBIGL.cmake

@@ -43,6 +43,14 @@ if(LIBIGL_USE_STATIC_LIBRARY)
     set(LIBIGL_FOUND FALSE)
   endif(NOT LIBIGL_LIBRARY)
   set(LIBIGL_LIBRARIES ${LIBIGL_LIBRARIES}  ${LIBIGL_LIBRARY})
+
+  FIND_LIBRARY( LIBIGLEMBREE_LIBRARY NAMES iglembree PATHS ${LIBIGL_LIB_DIRS})
+  if(NOT LIBIGLEMBREE_LIBRARY)
+    set(LIBIGL_FOUND FALSE)
+  endif(NOT LIBIGLEMBREE_LIBRARY)
+  set(LIBIGL_LIBRARIES ${LIBIGL_LIBRARIES}  ${LIBIGLEMBREE_LIBRARY})
+  find_package(Embree REQUIRED)
+
   FIND_LIBRARY( LIBIGLMATLAB_LIBRARY NAMES iglmatlab PATHS ${LIBIGL_LIB_DIRS})
   if(NOT LIBIGLMATLAB_LIBRARY)
     set(LIBIGL_FOUND FALSE)
@@ -55,6 +63,7 @@ if(LIBIGL_USE_STATIC_LIBRARY)
   else(MATLAB_FOUND)
     set(LIBIGL_FOUND FALSE)
   endif(MATLAB_FOUND)
+
   FIND_LIBRARY( LIBIGLSVD3X3_LIBRARY NAMES iglsvd3x3 PATHS ${LIBIGL_LIB_DIRS})
   if(NOT LIBIGLSVD3X3_LIBRARY)
     set(LIBIGL_FOUND FALSE)