diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index 4e39e0d413..cd53b02246 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -204,7 +204,7 @@ ConfigVariableBool color_scale_via_lighting "it. See also alpha-scale-via-texture.")); ConfigVariableBool alpha_scale_via_texture -("alpha-scale-via-texture", false, +("alpha-scale-via-texture", true, PRC_DESC("When this is true, Panda will try to implement " "ColorScaleAttribs that affect alpha by " "creating an additional Texture layer over the geometry " diff --git a/panda/src/display/graphicsStateGuardian.I b/panda/src/display/graphicsStateGuardian.I index 4d7d0273a2..a834d61444 100644 --- a/panda/src/display/graphicsStateGuardian.I +++ b/panda/src/display/graphicsStateGuardian.I @@ -599,7 +599,8 @@ get_alpha_scale_via_texture() const { INLINE bool GraphicsStateGuardian:: get_alpha_scale_via_texture(const TextureAttrib *tex_attrib) const { return _alpha_scale_via_texture && - (tex_attrib->get_num_on_stages() < get_max_texture_stages()); + (tex_attrib == (const TextureAttrib *)NULL || + tex_attrib->get_num_on_stages() < get_max_texture_stages()); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 9d660c9ec2..cf06f63288 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -1568,6 +1568,12 @@ do_issue_color() { //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: do_issue_color_scale() { + // If the previous color scale had set a special texture, clear the + // texture now. + if (_has_texture_alpha_scale) { + _state._texture = 0; + } + const ColorScaleAttrib *attrib = _target._color_scale; _color_scale_enabled = attrib->has_scale(); _current_color_scale = attrib->get_scale(); @@ -1588,8 +1594,11 @@ do_issue_color_scale() { determine_light_color_scale(); } + if (_alpha_scale_via_texture && !_has_scene_graph_color && attrib->has_alpha_scale()) { + // This color scale will set a special texture--so again, clear + // the texture. _state._texture = 0; _state._tex_matrix = 0; @@ -1933,13 +1942,15 @@ end_bind_clip_planes() { //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: determine_effective_texture() { + nassertv(_target._texture != (TextureAttrib *)NULL && + _target._tex_gen != (TexGenAttrib *)NULL); _effective_texture = _target._texture->filter_to_max(_max_texture_stages); _effective_tex_gen = _target._tex_gen; - + if (_has_texture_alpha_scale) { PT(TextureStage) stage = get_alpha_scale_texture_stage(); PT(Texture) texture = TexturePool::get_alpha_scale_map(); - + _effective_texture = DCAST(TextureAttrib, _effective_texture->add_on_stage(stage, texture)); _effective_tex_gen = DCAST(TexGenAttrib, _effective_tex_gen->add_stage (stage, TexGenAttrib::M_constant, TexCoord3f(_current_color_scale[3], 0.0f, 0.0f)));