turning on and off shadow casting

Hello,

I am working on a project that is creating/extending the basic level editor that ships with Panda.

At the moment, I am trying to implement the ability to set a light as a ShadowCaster, dynamically, in the level editor.

The issue being run into is that when setShadowCaster(True) is called on a given light, in the editor, nothing happens.

In a separate application, I tested using a light as a ShadowCaster and found that it works fine, as long as the light is set as a shadow caster when the application is started.

If I setShadowCaster(False) while the application is running, the shadows cease to be dynamic and become static shadows (kind of nice for creating “baked” shadows in the application actually).

Also, after doing this, I attempted to setShadowCaster(True), again, and no changes occurred.

Is there a way to make the light cast shadows dynamically, again, after turning its shadow casting off?

Thanks for your help.

-Kent

Hi, welcome to the forums!

The problem is that the setShadowCaster call is independent from the Shader Generator, which generates not only the shaders but also the shadow buffers for the shadow receivers.

As a workaround, you can introduce some kind of state change to the scene graph that forces the shaders to be regenerated and the buffers to be created/destroyed.

Thanks for your quick reply, rdb.

What is an efficient means of invoking a state change that would force shaders to be regenerated?

The first thing that came to mind was to call setShaderOff, when the shadow casting is turned off, for each object that has a shadow. Then, when the shadow casting is turned back on, just call setShaderAuto for each object.

This solution works in a test application, as it will remove shadow casting and reinstate it. Seems like there would be a better way to do this, though.

-Kent

That seems like a fine workaround to me. I haven’t been able to think of a cleaner way to fix this, yet.

Hmm, okay.

If it sounds good to you, I will go with that for now.

Thanks for your help.

-Kent