Shadow Mapping - How to make geomtery block shadow casting

Started by
15 comments, last by HurtLockeR 10 years, 8 months ago

If only the dynamic objects are casting real time shadows, you can build a unique shadow map for each, then have them project into the scene by rendering small boxes around the gynamic geo extruded/ stretched in the light direction (deferred shadow map style). You could then limit this extrusion by some arbitrary amount to avoid them reaching casting too far, based on your scene. Kind of hacky, but would work in most cases.

Advertisement


The problem however is that the floor above isn't in the shadow map

Yeah good point :)

Thanks for the ideas. Hope I can get somewhere smile.png

Would it be an idea/possible to have 2 shadow depth textures (D3DFMT_32F), and then in one I render the entire scene: static + dynamic models.

(Even though I don't want static models like bridges, houses, walls, etc. to cast shadows since I use lightmapping for those)

And then to the 2nd texture I only render all dynamic models.

Then in the 2nd pass shadow shader, I test against the 1st buffer but if the test passes I use the data from the 2nd?

I keep thinking some games must have used something like this (lightmapped scenes + dynamic shadows)? It sounds pretty simple to implementsad.png

A better approach is to use a G16R16F texture and store dynamic geometry into the red channel and static in the green channel. Then when you read it in you can compare the shadow to the static depth too, without needing to read extra textures (or wasting more memory).

Honestly though, if you're going to go through the trouble of rendering your static geometry into a shadow map anyway, you might as well use them in the shadow mapping stage and reserve your lightmaps for your indirect lighting. It will look a lot more consistent to have the same shadows on all objects (look at "The Last of Us", they do this).

Most of the time "the other guys" use some form of blending like I mentioned. Just pre-compute the lightmap shadows (no GI or indirect lighting, just shadows) to the alpha channel of your lightmap textures (or wherever) and use this as a mask for your shadows. Then you can check if your shadow is inside a lightmapped shadow and just remove it. Rendering all your static objects to a shadow map and not using them at all for shadows (just masking) is a bit redundant and negates the point of having lightmap shadows in the first place.

A better approach is to use a G16R16F texture and store dynamic geometry into the red channel and static in the green channel. Then when you read it in you can compare the shadow to the static depth too, without needing to read extra textures (or wasting more memory).

Honestly though, if you're going to go through the trouble of rendering your static geometry into a shadow map anyway, you might as well use them in the shadow mapping stage and reserve your lightmaps for your indirect lighting. It will look a lot more consistent to have the same shadows on all objects (look at "The Last of Us", they do this).

Most of the time "the other guys" use some form of blending like I mentioned. Just pre-compute the lightmap shadows (no GI or indirect lighting, just shadows) to the alpha channel of your lightmap textures (or wherever) and use this as a mask for your shadows. Then you can check if your shadow is inside a lightmapped shadow and just remove it. Rendering all your static objects to a shadow map and not using them at all for shadows (just masking) is a bit redundant and negates the point of having lightmap shadows in the first place.

http://miciwan.com/SIGGRAPH2013/Lighting%20Technology%20of%20The%20Last%20Of%20Us.pdf

There is presentation that explain how "Last of us" does their lights and shadows. Some levels only contains fully baked lightmap that contain main directional component of lighting and ambient color. These are used by gpu and sub resolution copy of screen space buffer about is handed to SPU. Then per pixel direction value is used as starting point for cone trace against dynamics objects that are approximated with spheres. This is how they get super soft dynamic directional and ambient occlusion shadows that blend perfectly with baked light maps. Quite hacky and complicated(at least implementation wise).

Yeah I finally got to look at the paper after my post, seems I jumped the gun on using it as a reference. I remember them mentioning this for Uncharted 2 though. At any rate I didn't see any lightmapped shadows in the Uncharted games, only lightmapped GI.

Still, the concept can work for the OP. smile.png The idea is to blend the lighting together to make it consistent, doesn't really matter how OP chooses to do it.

Hello Styves, kale_h,

Thanks for your suggestions! I decided to go with the lightmap blending option. This is the easiest to implement: just make sure the world light is in the same position as the lightmap lighting, and then blend the realtime dynamic shadows with the baked lightmaps in the shader.

This makes the realtime shadows and the lightmap shadows blend perfectly, and there's no need to depth pass the static models! Frame rate = happy.

This whole thing of blending lightmaps and realtime shadows is actually interesting since it could give you the best of both worlds until hardware will be fast enough to do global illumination + shadows on detailed levels, which is probably a few years off yet.

If you make the realtime shadows soft, then you can't really tell the difference between what's pre-lightmapped and what's real time.

Thanks again, next step will be to look into the Last of Us shadowing! (especially hard edged shadows close up and softer at a larger model distance).

This topic is closed to new replies.

Advertisement