Browse Source

ShaderGenerator: fix updating color of combine stages with CS_constant

This also changes the function of TextureStage::uses_color(), which no longer incorporate TextureStage::involves_color_scale()

Fixes: #177
rdb 8 years ago
parent
commit
0db3d27247

+ 1 - 1
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -4438,7 +4438,7 @@ set_texture_blend_mode(int i, const TextureStage *stage) {
     set_texture_stage_state(i, D3DTSS_RESULTARG, D3DTA_CURRENT);
   }
 
-  if (stage->uses_color()) {
+  if (stage->uses_color() || stage->involves_color_scale()) {
     // Set up the constant color for this stage.
 
     D3DCOLOR constant_color;

+ 1 - 2
panda/src/gobj/textureStage.I

@@ -658,8 +658,7 @@ update_color_flags() {
        _combine_alpha_source2 == CS_constant_color_scale)));
 
   _uses_color =
-    (_involves_color_scale ||
-     _mode == M_blend ||
+    (_mode == M_blend ||
      (_mode == M_combine &&
       (_combine_rgb_source0 == CS_constant ||
        _combine_rgb_source1 == CS_constant ||

+ 9 - 5
panda/src/pgraphnodes/shaderGenerator.cxx

@@ -424,6 +424,11 @@ analyze_renderstate(ShaderKey &key, const RenderState *rs) {
       info._stage = stage;
     }
 
+    // Does this stage need a texcolor_# input?
+    if (stage->uses_color()) {
+      info._flags |= ShaderKey::TF_uses_color;
+    }
+
     key._textures.push_back(info);
     key._texture_flags |= info._flags;
   }
@@ -827,7 +832,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
       text << "\t uniform float4x4 texmat_" << i << ",\n";
     }
 
-    if (tex._mode == TextureStage::M_blend) {
+    if (tex._flags & ShaderKey::TF_uses_color) {
       text << "\t uniform float4 texcolor_" << i << ",\n";
     }
   }
@@ -1562,10 +1567,9 @@ combine_source_as_string(CPT(TextureStage) stage, short num, bool alpha, bool si
     case TextureStage::CS_texture:
       csource << "tex" << texindex;
       break;
-    case TextureStage::CS_constant: {
-      LVecBase4 c = stage->get_color();
-      csource << "float4(" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] << ")";
-      break; }
+    case TextureStage::CS_constant:
+      csource << "texcolor_" << texindex;
+      break;
     case TextureStage::CS_primary_color:
       csource << "primary_color";
       break;

+ 1 - 0
panda/src/pgraphnodes/shaderGenerator.h

@@ -110,6 +110,7 @@ protected:
       TF_map_height = 64,
       TF_map_glow = 128,
       TF_map_gloss = 256,
+      TF_uses_color = 512,
     };
 
     ColorAttrib::Type _color_type;