Realtime shadow mapping

Posted By: Excessus

Realtime shadow mapping - 10/24/06 11:10

Hi,



This is a shot from my realtime shadowmapping shader. Some info:

-The cube in the top left is the lightsource.
-All objects can cast and recieve shadows.
-The shadows aren't smooth yet, I'm planning to add a smoothing method I have come up with. If it doesn't work or produces other problems I will implement percentage-closer filtering.
-Requires vs 1.1 and ps 2.0.
-No plugins.
Posted By: broozar

Re: Realtime shadow mapping - 10/24/06 11:17

thumbs up how does it work? does the light source have to have special parameters? or the block (like _litAndShodow)? can we set if a surface can receive shadows? is it hardware independent (nvidia/ati/volari/s3)?
Posted By: Machinery_Frank

Re: Realtime shadow mapping - 10/24/06 11:18

Great work, Excessus. Please talk with JCL about this topic. Maybe he can add your excellent shaders into the upcoming shader template package?

Regards,
Frank
Posted By: ello

Re: Realtime shadow mapping - 10/24/06 11:22

good job! maybe you use the light/depth information for adding a blur .. what about multiple lights?
Posted By: Excessus

Re: Realtime shadow mapping - 10/24/06 11:46

Thanks for your comments.

Quote:

how does it work?



1) The scene is rendered from the lightsource with a shader that outputs the depth.
2) The scene is then rendered with the normal camera and the depth texture is projected from the lightsource onto the scene. I then check the depth in the depth texture to the distance from pixel to the lightsource. If the pixel's distance to the light is greater than the depth stored in the depth texture, it is in shadow.

Quote:

does the light source have to have special parameters? or the block (like _litAndShodow)?



The light source is basicly a view, so you can set it's position, angle, arc, etc. The occluder/reciever doesn't need anything, it just needs to be a mesh.

Right now the scene is only rendered once from the camera but I'm planning to change it so that the camera is first rendered with the normal shaders, and then with a shader that only draws the shadows (with the other areas transparent) and overlay that on the first render. That way, you can still use your normal shaders.

This also allows to use a simple screenspace blur on the shadow texture. However this will result in dark halos around the silhouette of the model. I will try to prevent that by using the differntial of the neighbouring pixels on the shadow map (Don't blur if neighbouring pixels are much 'deeper'). If that doesn't work I will use percentage closer filtering: check how many points near this pixel are in shadow to decide shadow darkness. The drawback of PCF is that a smoother shadow will require more samples (thus slower rendering).

Quote:

can we set if a surface can receive shadows?



Everything casts and recieves shadows by default. You can use a different material in the depth-pass that doesn't render the object so that it is 'ignored'.

Quote:

Please talk with JCL about this topic. Maybe he can add your excellent shaders into the upcoming shader template package?



When the shader is done, I'll talk to JCL about this.

Quote:

what about multiple lights?



Not yet supported, I'll have to think about the implications of adding another light but it should be possible.

I think implementing this shader in your project could be as easy as including a script and passing a vector pointer to a function. You can then set that vector to any position and angle you want. You will probably also have to add two lines of code to all your materials for switching to a depth material when rendering from the lightsource.
Posted By: EX Citer

Re: Realtime shadow mapping - 10/24/06 12:44

Interesting... If you do multiple lights, could you try to make the shadow the more transparent the closer they are to the light. It would be good if a second light source is within the shadow of another lightsource it would lighten up around the light the closer the "part" of the shadow is.
Posted By: frazzle

Re: Realtime shadow mapping - 10/24/06 18:46

This looks very intriguing and interesting !!
It looks like the effect you create is very realistic
Het goede oude Hollandse verstand, wa zouden we zonder

Mooie werk Excessus

Cheers

Frazzle
Posted By: lostclimate

Re: Realtime shadow mapping - 01/20/07 16:33

how are you getting the z-buffer info? are they allowing access to it in a6.54?
Posted By: Excessus

Re: Realtime shadow mapping - 01/20/07 17:56

Even if you could get access to the zbuffer (and I think this would be possible in a dll), it would be useless. You need the depth as seen from the light's position, not the camera's. On top of that, the bit depth would be a problem. I'm using a floating point texture and bit depth is already a major problem (huge artifacts on large scenes).

To get the depth, the scene is rendered with a shader that outputs the (linearized) depth of the pixels. You can use a render event to set the material to this depth-material when the current view is the light-view.
Posted By: lostclimate

Re: Realtime shadow mapping - 01/21/07 02:58

have no idea what you just said, so ill just leave you with, got it
Posted By: Germanunkol

Re: Realtime shadow mapping - 01/21/07 08:10

Hey, this does look great!
Since this is a different method than 3dgs uses for it's shadows, if the camera was moved in between the light source and the shadow, it would not get weird results?
Doesn't the fps drop or something? I mean, I have no idea about all this, to be honest, never done anything like it. But what you say up there... rendering the view twice etc... sounds like it would take quite some time...

Good luck with this!
© 2024 lite-C Forums