Soft Shadows

Aha, I have discovered the reason. The shader doesn’t work with transparency (I had transparency set on my ground, for what reason I don’t remember).
By the way, is it possible to make it work transparency?

I have found another strange bug in the code by ynjh_jo. Look at the pictures:



How to solve it?

Sorry, I missed the alpha calc, you can fix it this way :

  o_color = float4( baseColor.rgb * k_intensity * lerp(l_smooth, 

saturate(k_ambient.x + shade), l_cutSmooth), baseColor.a );

About your last shots, it’s because I clamp the texture coordinates.
I should’ve used border color instead, don’t you agree ?

        Ldepthmap.setBorderColor(Vec4(1,1,1,1))
        Ldepthmap.setWrapU(Texture.WMBorderColor)
        Ldepthmap.setWrapV(Texture.WMBorderColor)

That cuts the shadow.

Oh, there is 1 more “bug”. I didn’t use Josh’s caster.sha, because I wanted to save a little time. Without using it, some geomnodes which have transforms will be incorrectly shadowed twice. If the transform is not on the geomnode, it’s fine.
caster.sha firstly floods all models color with white before processing the real shadowing process.

Thank you, ynjh_jo!
In fact, I expected your shader to look somehow similar to the Panda’s shadow sample. I found that your shader spreads the lit area everywhere. For comparison, here are the pictures:
– hard shadow from Josh

– your soft shadows

Cut soft shadow:

In Josh’s shader, this part creates the spotlight falloff :

  float3 circleoffs = float3(l_lightclip.xy / l_lightclip.w, 0);
  float falloff = saturate(1.0 - dot(circleoffs, circleoffs));

The final color calc looks like this :

  o_color = float4( baseColor.rgb * k_intensity * lerp(l_smooth, saturate(k_ambient.x + min( falloff, shade) ), l_cutSmooth) , baseColor.a );

Don’t forget l_lightclip out/in, and remove its float4 type definition.

Thank you, sir! Now it works.
I’ve spent the whole night trying to solve it myself, but couldn’t do it. You just said a few words, and everything works. You magician, probably :slight_smile:

If you spend some more nights to understand the whole shader thing, you’d find yourself doing it as simple as walking around. Only the first crawls might hurt you, and eventually you’d find that you don’t have to be magician to get what you want. Just keep doing it, and you’ll be there. I believe life is that simple.

One thing bothers me, you said your hardware doesn’t support shadow filter but the shader runs anyway. Do your models really get self shadowed ?
And your framerate is great. I’m wondering, how fast this runs on yours :
comp.nus.edu.sg/~tants/tsm.html
GLEW is not included though, so google for it.

This demo doesn’t work for me at all, since it requires some NVidia OpenGL extensions, which are not supported on my crappy ATI X1600 card.

I have just checked, yes, my models are self-shadowed, although base.win.getGsg().getSupportsShadowFilter() returns False. I checked it with Ralph model, his hand does cast the shadow on his own body.

I want the shadows to work with orthographic lens to imitate sunlight. It was successful with hard shadows from Josh, but not with soft shadows:

  • hard with orthographic lens:
  • soft with 8 samples with orthographic lens:
  • soft with 4 samples with orthographic lens:

    What would you recommend?

It’s the samples gap.

How to eliminate this problem? If I set to 0, then shadows become usual hard shadows, if I set it to 0.01, the shadows are even uglier, and of more then 0.01 - the shadows are seen double again.

Use interactive adjustment and set the increment as tiny as 0.0001 or tiny enough to see the changes, and keep adjusting it until it’s good for you.

I trying to adapt this shader to directional light (used to imitate sunlight). But it is supposed to cover large areas, and this makes it impossible to use one buffer for the shader (too high resolution is required). So, I will need to create multiple buffers, and combine them in shader, right? But how to do it? Could you, please, give a hint or a piece of advice about it?

On NV site there is an openGL cascading shadow tutorial. It does exactly what you want and it should have the maths to get you started and finished.

nice sample!!~

I am newbie here.
I tried to combine your shadow with glow filter sample.
But the coordinate of glow filter is inaccurate.

Is it about texture size?
Please ,give me a trick. =)

It is not possible to have both glow and shadows at the moment because that would require you to combine multiple shaders.
A possibility would be to assign your own shader to the objects you want to have glow which is a combined version of glow and shadows, after assigning the ShadowManager. But that requires you to know Cg.

You could do what I do and have the shadow camera follow the base camera around and then have the shadows fade out as they get further away - or use a simple drop shadow for distant objects.

Having said that I want to try using two shadow cameras, one that covers a small area to produce hires shadows and another that covers a larger area and produced low-res shadows - and then combine them. Shouldn’t be too hard to setup. I should have some time this weekend to give it a go.

Hi pro-rsoft

The sample program works fine on my machine, running Windows XP. Now I have a problem with the setShaderAuto and setShaderOff, with the sample program.

If ever I have one or all of the following lines in the example.py:
render.setShaderAuto()
render.setShaderOff()

the screen becomes:
picasaweb.google.com.tw/lh/photo … directlink

It looks like my concept is wrong in these two function calls.

I thought that setShaderOff is the state of Panda when panda starts by default. setShaderAuto will tell panda to turn on auto shader, setShaderOff will reverse it back to the default state, i.e. Panda will not generate shader for the nodepath.

Adding these two lines at the very beginning before soft shadow manager starts shall have no effect:
render.setShaderAuto()
render.setShaderOff()

So, is this problem happening on my machine only? If not, would you correct my fundamental understanding of these calls, or if it is any fixes to this problem ?

setShaderOff doesn’t clear shaders, it applies a special shader attrib to the node that tells not to use shaders whatsoever.

Since my shadows code internally sets a shader on all scene objects, it breaks if you call any of the setShader* functions.
It’s possible to still have your own shaders (or autoshaders) and use my shadows manager, but that does require an extra rendering pass. Read this thread for more:
discourse.panda3d.org/viewtopic.php?t=5442

I see. Looks like I should call clearShader instead of setShaderOff.

I tried to understand your code in creating the Off-screen buffer, addRenderTexture, and other lower level api. In the manual it does not mention much. Is there an existing document for these api for details or I can just search around the forums ?