Browse Source

display: ignore material if no lights are applied

This fixes materials suddenly showing up when a color scale is applied and color-scale-via-lighting is set.

Fixes #404
rdb 7 years ago
parent
commit
51414466da
2 changed files with 23 additions and 1 deletions
  1. 22 1
      panda/src/display/standardMunger.cxx
  2. 1 0
      panda/src/display/standardMunger.h

+ 22 - 1
panda/src/display/standardMunger.cxx

@@ -36,7 +36,8 @@ StandardMunger(GraphicsStateGuardianBase *gsg, const RenderState *state,
   _munge_color(false),
   _munge_color_scale(false),
   _auto_shader(false),
-  _shader_skinning(false)
+  _shader_skinning(false),
+  _remove_material(false)
 {
   const ShaderAttrib *shader_attrib;
   state->get_attrib_def(shader_attrib);
@@ -94,6 +95,19 @@ StandardMunger(GraphicsStateGuardianBase *gsg, const RenderState *state,
       // effort to detect this contrived situation and handle it correctly.
     }
   }
+
+  // If we have no lights but do have a material, we will need to remove it so
+  // that it won't appear when we enable color scale via lighting.
+  const LightAttrib *light_attrib;
+  const MaterialAttrib *material_attrib;
+  if (get_gsg()->get_color_scale_via_lighting() &&
+      (!state->get_attrib(light_attrib) || !light_attrib->has_any_on_light()) &&
+      state->get_attrib(material_attrib) &&
+      material_attrib->get_material() != nullptr &&
+      shader_attrib->get_shader() == nullptr) {
+    _remove_material = true;
+    _should_munge_state = true;
+  }
 }
 
 /**
@@ -291,6 +305,9 @@ compare_to_impl(const GeomMunger *other) const {
   if (_auto_shader != om->_auto_shader) {
     return (int)_auto_shader - (int)om->_auto_shader;
   }
+  if (_remove_material != om->_remove_material) {
+    return (int)_remove_material - (int)om->_remove_material;
+  }
 
   return StateMunger::compare_to_impl(other);
 }
@@ -344,5 +361,9 @@ munge_state_impl(const RenderState *state) {
     munged_state = munged_state->remove_attrib(ColorScaleAttrib::get_class_slot());
   }
 
+  if (_remove_material) {
+    munged_state = munged_state->remove_attrib(MaterialAttrib::get_class_slot());
+  }
+
   return munged_state;
 }

+ 1 - 0
panda/src/display/standardMunger.h

@@ -55,6 +55,7 @@ private:
   bool _munge_color_scale;
   bool _auto_shader;
   bool _shader_skinning;
+  bool _remove_material;
 
   LColor _color;
   LVecBase4 _color_scale;