shadow caster

in samples/shadows/advanced.py

Put a shader on the Light camera.

lci = NodePath(PandaNode(“Light Camera Initializer”))
lci.setShader(loader.loadShader(‘caster.sha’))
self.LCam.node().setInitialState(lci.getState())

the ‘caster.sha’ is not work

is now in latest version,the cammera has a default shadow caster? how can I change it ?

When you say that the shader doesn’t work, what do you mean? Does Panda simply continue on as though the shader weren’t there, or is the shader doing something, just not what you expect?

I’m guessing that Panda is ignoring the shader, as I think that I recall that happening to me, too. If so, try giving the shader a priority value–that is, change the “setShader” line to something like this:

lci.setShader(loader.loadShader('caster.sha'), 1)

(Note the “, 1”.)

Put a shader on the Light camera.

lci = NodePath(PandaNode(“Light Camera Initializer”))
lci.setShader(loader.loadShader(‘caster.sha’),1)
self.LCam.node().setInitialState(lci.getState())

Panda simply continue on as though the shader(‘caster.sha’) weren’t there.
I change the shader:

void fshader(in float4 l_pos : TEXCOORD0,
out float4 o_color : COLOR)
{
float z = (l_pos.z / l_pos.w) * 0.5 + 0.5;
z=1; //for test
o_color = float4(z, z, z, 1);
}

nothing changed, it seemed panda has a default shadow caster.

This is something that the sample explains very poorly.

The colour texture is completely unnecessary, and the same goes for the caster.sha shader, which only writes the depth value to the colour buffer. The sample actually also binds a depth texture to the depth buffer and uses that as the shadow map, so the caster.sha fragment shader is useless (since it doesn’t affect what is written to the depth buffer).

The only purpose the shader may have served in the past might have been to write depth to a colour texture so it can be used as depth map for hardware that does not support rendering to depth textures. However, virtually all hardware supports that (especially hardware that supports shaders to begin with), so it’s really not relevant.

We should just remove the whole bit about colour textures and caster.sha from the sample program. Also, without colour buffer, color write can be disabled entirely when rendering from the shadow camera’s perspective, which makes it faster.

Wait, come to think of it: are you using Panda’s automatic shader generator? (i.e., do you have “.setShaderAuto()” in your code?)

If so, that may be overriding the shader assignment above. If you’re calling “setShaderAuto” on the “render” NodePath, perhaps try moving it such that it’s on or above all NodePaths that you want it to affect, but not above your light-camera’s NodePath.

For example, let’s say that you have level geometry in a NodePath named “levelGeometry”, and both that and your light-camera are parented to “render”. In that case, instead of calling “render.setShaderAuto()”, you might call “levelGeometry.setShaderAuto()”.

One more question: what version of Panda are you using?

I’m pretty sure that I have code such as yours working in my own project, so it does seem to be possible.

[edit] Rdb’s comment above may obviate all of this, but in case you still want to apply a shader to your camera, I’ll leave it intact.

Again, aside from any animation or perturbation you might be doing in a vertex shader, it doesn’t matter whether you apply no shader, the auto shader, caster.sha or most other shaders when rendering from the camera’s point of view. It won’t make a difference for what’s written to the depth buffer.

Indeed, but not knowing the original poster’s intentions for “caster.sha”, I don’t want to assume that they don’t want to apply vertex offsets, or write to a texture instead of the depth buffer, or something else besides. They probably aren’t, given that they seem to be using the code given in the tutorial, but I’d rather not assume so, while nevertheless acknowledging what you indicated about the shader being otherwise superfluous.