diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 4ad0250ee3..5b7ffce964 100644 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/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; diff --git a/panda/src/gobj/textureStage.I b/panda/src/gobj/textureStage.I index b00d47d699..c73c2d5338 100644 --- a/panda/src/gobj/textureStage.I +++ b/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 || diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index b58ce1e777..0b4dc68a62 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/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; diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index ba2619bef7..dc68d90d66 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/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;