How to override shader state using RenderState.make?

I’m struggling to override the shader state of a leaf node, it seems it keeps using the shader set on the parent node even with an explicit configuration.

I have a root node path on which a custom shader is configured using
root_np.setShader(my_custom_shader) but without any geometry

Attached to this root node I have several children node with the actual geometry, using the shader set on the parent, so far so good.

But, for debugging purpose, I need to add another node under the root node that does not use the configured shader but instead the fixed pipeline, or the autogenerated shader, it’s only to render the debug geom with a flat color.

If I try to use RenderState.make() to override the shader used, it won’t work and still uses the parent’s shader :

            sa = ShaderAttrib.make()
            sa.set_shader_auto(True, 10000)
            state = RenderState.make(ColorAttrib.make_flat(LColor(0, 1.0, 0, 1.0)), sa)
            np.node().set_state(state)

On the other hand, if I simple use np.set_shader_auto(True) it just works, what does set_shader_auto() do more ?

Have you tried passing in an override to the RenderState.make() call to override the state set on the parent node?

Just tried with this :

            state = RenderState.make(ColorAttrib.make_flat(LColor(0, 1.0, 0, 1.0)), sa, 1000)

but same problem, the ShaderAttrib used is still the parent’s one.

The problem was between the chair and the keyboard, I got confused by the weird behavior of ShaderAttrib::set_shader_auto(), it does not set the auto shader flag on the attire but return a new attrib with that flag set, and so I was still using the unconfigured attrib instead.

The correct code is :

            sa = ShaderAttrib.make().set_shader_auto(True)
            state = RenderState.make(ColorAttrib.make_flat(LColor(0, 1.0, 0, 1.0)), sa)
            np.node().set_state(state)