Browse Source

fix flashing-white lod fades

David Rose 17 years ago
parent
commit
0798221a5b

+ 5 - 0
panda/src/pgraph/config_pgraph.cxx

@@ -283,6 +283,11 @@ ConfigVariableInt lod_fade_bin_draw_order
  PRC_DESC("The default bin draw order to assign the fading part of a "
  PRC_DESC("The default bin draw order to assign the fading part of a "
           "FadeLODNode transition."));
           "FadeLODNode transition."));
 
 
+ConfigVariableInt lod_fade_state_override
+("lod-fade-state-override", 1000,
+ PRC_DESC("The default override value to assign to the fade attribs "
+          "in order to effect a FadeLODNode transition."));
+
 ConfigVariableBool verify_lods
 ConfigVariableBool verify_lods
 ("verify-lods", false,
 ("verify-lods", false,
  PRC_DESC("When this is true, LODNodes will test when they are rendered to "
  PRC_DESC("When this is true, LODNodes will test when they are rendered to "

+ 1 - 0
panda/src/pgraph/config_pgraph.h

@@ -58,6 +58,7 @@ extern ConfigVariableBool polylight_info;
 extern ConfigVariableDouble lod_fade_time;
 extern ConfigVariableDouble lod_fade_time;
 extern ConfigVariableString lod_fade_bin_name;
 extern ConfigVariableString lod_fade_bin_name;
 extern ConfigVariableInt lod_fade_bin_draw_order;
 extern ConfigVariableInt lod_fade_bin_draw_order;
+extern ConfigVariableInt lod_fade_state_override;
 extern ConfigVariableBool verify_lods;
 extern ConfigVariableBool verify_lods;
 
 
 extern ConfigVariableBool show_vertex_animation;
 extern ConfigVariableBool show_vertex_animation;

+ 13 - 0
panda/src/pgraph/fadeLodNode.I

@@ -57,4 +57,17 @@ get_fade_bin_draw_order() const {
   return _fade_bin_draw_order;
   return _fade_bin_draw_order;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: FadeLODNode::get_fade_state_override
+//       Access: Published
+//  Description: Returns the override value that is applied to the
+//               state changes necessary to apply the fade effect.
+//               This should be larger than any attrib overrides on
+//               the fading geometry.
+////////////////////////////////////////////////////////////////////
+INLINE int FadeLODNode::
+get_fade_state_override() const {
+  return _fade_state_override;
+}
+
 
 

+ 37 - 15
panda/src/pgraph/fadeLodNode.cxx

@@ -20,6 +20,7 @@
 #include "colorScaleAttrib.h"
 #include "colorScaleAttrib.h"
 #include "depthWriteAttrib.h"
 #include "depthWriteAttrib.h"
 #include "transparencyAttrib.h"
 #include "transparencyAttrib.h"
+#include "cullBinAttrib.h"
 
 
 TypeHandle FadeLODNode::_type_handle;
 TypeHandle FadeLODNode::_type_handle;
 
 
@@ -37,6 +38,7 @@ FadeLODNode(const string &name) :
   _fade_time = lod_fade_time;
   _fade_time = lod_fade_time;
   _fade_bin_name = lod_fade_bin_name;
   _fade_bin_name = lod_fade_bin_name;
   _fade_bin_draw_order = lod_fade_bin_draw_order;
   _fade_bin_draw_order = lod_fade_bin_draw_order;
+  _fade_state_override = lod_fade_state_override;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -51,6 +53,7 @@ FadeLODNode(const FadeLODNode &copy) :
   _fade_time = copy._fade_time;
   _fade_time = copy._fade_time;
   _fade_bin_name = copy._fade_bin_name;
   _fade_bin_name = copy._fade_bin_name;
   _fade_bin_draw_order = copy._fade_bin_draw_order;
   _fade_bin_draw_order = copy._fade_bin_draw_order;
+  _fade_state_override = copy._fade_state_override;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -278,26 +281,43 @@ set_fade_bin(const string &name, int draw_order) {
   _fade_2_old_state.clear();
   _fade_2_old_state.clear();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: FadeLODNode::set_fade_state_override
+//       Access: Published
+//  Description: Specifies the override value that is applied to the
+//               state changes necessary to apply the fade effect.
+//               This should be larger than any attrib overrides on
+//               the fading geometry.
+////////////////////////////////////////////////////////////////////
+void FadeLODNode::
+set_fade_state_override(int override) {
+  _fade_state_override = override;
+  _fade_1_old_state.clear();
+  _fade_1_new_state.clear();
+  _fade_2_old_state.clear();
+  _fade_2_new_state.clear();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FadeLODNode::get_fade_1_old_state
 //     Function: FadeLODNode::get_fade_1_old_state
-//       Access: Protected, Static
+//       Access: Protected
 //  Description: Returns a RenderState for rendering the old element
 //  Description: Returns a RenderState for rendering the old element
 //               during first half of fade.
 //               during first half of fade.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) FadeLODNode::
 CPT(RenderState) FadeLODNode::
 get_fade_1_old_state() {
 get_fade_1_old_state() {
-  static CPT(RenderState) state = (const RenderState *)NULL;
-  if (state == (const RenderState *)NULL) {
-    state = RenderState::make
-      (DepthOffsetAttrib::make());
+  if (_fade_1_old_state == (const RenderState *)NULL) {
+    _fade_1_old_state = RenderState::make
+      (DepthOffsetAttrib::make(),
+       _fade_state_override);
   }
   }
 
 
-  return state;
+  return _fade_1_old_state;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FadeLODNode::get_fade_1_new_state
 //     Function: FadeLODNode::get_fade_1_new_state
-//       Access: Protected, Static
+//       Access: Protected
 //  Description: Returns a RenderState for rendering the new element
 //  Description: Returns a RenderState for rendering the new element
 //               during first half of fade.
 //               during first half of fade.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -307,7 +327,8 @@ get_fade_1_new_state(float in_alpha) {
     _fade_1_new_state = RenderState::make
     _fade_1_new_state = RenderState::make
       (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
       (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
        CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
        CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
-       DepthOffsetAttrib::make());
+       DepthOffsetAttrib::make(),
+       _fade_state_override);
   }
   }
 
 
   LVecBase4f alpha_scale(1.0f, 1.0f, 1.0f, in_alpha);
   LVecBase4f alpha_scale(1.0f, 1.0f, 1.0f, in_alpha);
@@ -327,7 +348,8 @@ get_fade_2_old_state(float out_alpha) {
     _fade_2_old_state = RenderState::make
     _fade_2_old_state = RenderState::make
       (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
       (TransparencyAttrib::make(TransparencyAttrib::M_alpha),
        DepthWriteAttrib::make(DepthWriteAttrib::M_off),
        DepthWriteAttrib::make(DepthWriteAttrib::M_off),
-       CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order));
+       CullBinAttrib::make(_fade_bin_name, _fade_bin_draw_order),
+       _fade_state_override);
   }
   }
 
 
   LVecBase4f alpha_scale(1.0f, 1.0f, 1.0f, out_alpha);
   LVecBase4f alpha_scale(1.0f, 1.0f, 1.0f, out_alpha);
@@ -337,19 +359,19 @@ get_fade_2_old_state(float out_alpha) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FadeLODNode::get_fade_2_new_state
 //     Function: FadeLODNode::get_fade_2_new_state
-//       Access: Protected, Static
+//       Access: Protected
 //  Description: Returns a RenderState for rendering the new element
 //  Description: Returns a RenderState for rendering the new element
 //               during second half of fade.
 //               during second half of fade.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) FadeLODNode::
 CPT(RenderState) FadeLODNode::
 get_fade_2_new_state() {
 get_fade_2_new_state() {
-  static CPT(RenderState) state = (const RenderState *)NULL;
-  if (state == (const RenderState *)NULL) {
-    state = RenderState::make
-      (DepthOffsetAttrib::make());
+  if (_fade_2_new_state == (const RenderState *)NULL) {
+    _fade_2_new_state = RenderState::make
+      (DepthOffsetAttrib::make(),
+       _fade_state_override);
   }
   }
 
 
-  return state;
+  return _fade_2_new_state;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 8 - 2
panda/src/pgraph/fadeLodNode.h

@@ -42,18 +42,24 @@ PUBLISHED:
   INLINE const string &get_fade_bin_name() const;
   INLINE const string &get_fade_bin_name() const;
   INLINE int get_fade_bin_draw_order() const;
   INLINE int get_fade_bin_draw_order() const;
 
 
+  void set_fade_state_override(int override);
+  INLINE int get_fade_state_override() const;
+
 private:
 private:
-  static CPT(RenderState) get_fade_1_old_state();
+  CPT(RenderState) get_fade_1_old_state();
   CPT(RenderState) get_fade_1_new_state(float in_alpha);
   CPT(RenderState) get_fade_1_new_state(float in_alpha);
   CPT(RenderState) get_fade_2_old_state(float out_alpha);
   CPT(RenderState) get_fade_2_old_state(float out_alpha);
-  static CPT(RenderState) get_fade_2_new_state();
+  CPT(RenderState) get_fade_2_new_state();
 
 
 private:
 private:
   float _fade_time;
   float _fade_time;
   string _fade_bin_name;
   string _fade_bin_name;
   int _fade_bin_draw_order;
   int _fade_bin_draw_order;
+  int _fade_state_override;
 
 
   CPT(RenderState) _fade_1_new_state;
   CPT(RenderState) _fade_1_new_state;
+  CPT(RenderState) _fade_1_old_state;
+  CPT(RenderState) _fade_2_new_state;
   CPT(RenderState) _fade_2_old_state;
   CPT(RenderState) _fade_2_old_state;
   
   
 public:
 public: