Browse Source

pressing N,n changes lighting to pseudocolored normals (#2478)

Alec Jacobson 5 months ago
parent
commit
bf9bdb9c70

+ 6 - 0
include/igl/opengl/MeshGL.cpp

@@ -314,6 +314,7 @@ R"(#version 150
   uniform float texture_factor;
   uniform float matcap_factor;
   uniform float double_sided;
+  uniform bool pseudocolor_with_normals;
 
   uniform sampler2D shadow_tex;
   in vec4 position_shadow;
@@ -327,6 +328,11 @@ R"(#version 150
       outColor = vec4(0.56,0.85,0.77,1.);
       return;
     }
+    if(pseudocolor_with_normals)
+    {
+      outColor = vec4(normalize(normal_eye) * 0.5 + 0.5, 1.0);
+      return;
+    }
     // If is_directional_light then assume normalized
     vec3 direction_to_light_eye = light_position_eye;
     if(! is_directional_light)

+ 3 - 0
include/igl/opengl/ViewerCore.cpp

@@ -177,6 +177,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
   GLint texture_factori       = glGetUniformLocation(data.meshgl.shader_mesh,"texture_factor");
   GLint matcap_factori        = glGetUniformLocation(data.meshgl.shader_mesh,"matcap_factor");
   GLint double_sidedi         = glGetUniformLocation(data.meshgl.shader_mesh,"double_sided");
+  GLint pseudocolor_with_normalsi = glGetUniformLocation(data.meshgl.shader_mesh,"pseudocolor_with_normals");
 
   const bool eff_is_directional_light = is_directional_light || is_shadow_mapping;
   glUniform1f(specular_exponenti, data.shininess);
@@ -214,6 +215,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
       glUniform1f(texture_factori, is_set(data.show_texture) ? 1.0f : 0.0f);
       glUniform1f(matcap_factori, is_set(data.use_matcap) ? 1.0f : 0.0f);
       glUniform1f(double_sidedi, data.double_sided ? 1.0f : 0.0f);
+      glUniform1i(pseudocolor_with_normalsi, data.pseudocolor_with_normals);
       data.meshgl.draw_mesh(true);
       glUniform1f(matcap_factori, 0.0f);
       glUniform1f(texture_factori, 0.0f);
@@ -228,6 +230,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
         data.line_color[1],
         data.line_color[2],
         data.line_color[3]);
+      glUniform1i(pseudocolor_with_normalsi, false);
       data.meshgl.draw_mesh(false);
       glUniform4f(fixed_colori, 0.0f, 0.0f, 0.0f, 0.0f);
     }

+ 2 - 0
include/igl/opengl/ViewerData.cpp

@@ -25,6 +25,7 @@ IGL_INLINE igl::opengl::ViewerData::ViewerData()
   face_based        (false),
   double_sided      (false),
   invert_normals    (false),
+  pseudocolor_with_normals(false),
   is_visible        (~unsigned(0)),
   show_custom_labels(0),
   show_face_labels  (0),
@@ -503,6 +504,7 @@ IGL_INLINE void igl::opengl::ViewerData::clear()
   face_based = false;
   double_sided = false;
   invert_normals = false;
+  pseudocolor_with_normals = false;
   show_texture = false;
   use_matcap = false;
 }

+ 4 - 0
include/igl/opengl/ViewerData.h

@@ -302,6 +302,9 @@ public:
   /// Invert mesh normals
   bool invert_normals;
 
+  /// Skip lighting and color with RGB = 0.5*N-0.5
+  bool pseudocolor_with_normals;
+
   /// Visualization options
   /// Each option is a binary mask specifying on which viewport each option is set.
   /// When using a single viewport, standard boolean can still be used for simplicity.
@@ -401,6 +404,7 @@ namespace igl
       SERIALIZE_MEMBER(show_custom_labels);
       SERIALIZE_MEMBER(show_texture);
       SERIALIZE_MEMBER(double_sided);
+      SERIALIZE_MEMBER(pseudocolor_with_normals);
       SERIALIZE_MEMBER(point_size);
       SERIALIZE_MEMBER(line_width);
       SERIALIZE_MEMBER(line_color);

+ 6 - 0
include/igl/opengl/glfw/Viewer.cpp

@@ -558,6 +558,12 @@ namespace glfw
         core().toggle(data().show_lines);
         return true;
       }
+      case 'N':
+      case 'n':
+      {
+        data().pseudocolor_with_normals = !data().pseudocolor_with_normals;
+        return true;
+      }
       case 'O':
       case 'o':
       {