optimizing for multiple shadow maps

Started by
9 comments, last by zedz 15 years, 1 month ago
Hey guys, I have started to set up my code to use multiple shadow maps and lights but I do not want to draw the whole scene for every shadow map. Is it possible to do something so I can prevent this?? thanks
Advertisement
Frustum culling. Also you should only draw shadow casters, beside the usual optimizations (draw flat, etc). I also don't bind textures and pass texture coordinates to polygons that don't have alpha on its texture.
Quote:Original post by biraneto
Frustum culling.


Currently my whole scene is in one large OBJ file. And everything I have read abut frustum culling tells me I will need to test my objects to see if they intersect, obviously it will and this will just cost me time. Or am I missing something??
Sorry... I thought your scene was something like an open area with trees, etc. Frustum culling is only usefull if you are not looking the whole thing all the time.
Quote:Original post by biraneto
Sorry... I thought your scene was something like an open area with trees, etc. Frustum culling is only usefull if you are not looking the whole thing all the time.


Well, when using multiple shadowmaps, then they're hopefully not all 'looking'/covering at the entire scene :)
So frustum culling would be good when rendering into the shadowmaps.
| Stein Nygård - http://steinware.dk |
Quote:Original post by stein
Quote:Original post by biraneto
Sorry... I thought your scene was something like an open area with trees, etc. Frustum culling is only usefull if you are not looking the whole thing all the time.


Well, when using multiple shadowmaps, then they're hopefully not all 'looking'/covering at the entire scene :)
So frustum culling would be good when rendering into the shadowmaps.


I more the likly will add frustum culling later, but right now it would be pointless, so I am looking for other ways to optimize drawing the shadows to the scene.
Quote:Original post by cherryyosh
I more the likly will add frustum culling later, but right now it would be pointless, so I am looking for other ways to optimize drawing the shadows to the scene.


If it's pointless to add frustum culling, then why do you want to optimize?
What's the problem at hand?
| Stein Nygård - http://steinware.dk |
How about this: you have/copy the depth-buffer of your scene as/to a texture.
You draw a fullscreen quad per shadowmap, in multiply-mode blending.
Knowing your MVP matrix, x:y position at pixel, and depth - you get a vec3 of where the texel is in world-space. You fetch info from shadowmap: whether/how-much this vec3 is shadowed. Return that result in gl_FragColor. Scene color gets blended (darkened) where there are shadows.

Needs shaders and maybe some funky math. Haven't tried to code it, but it's been used in Crysis.

I bet it can even speed-up rendering, by keeping cache locality and for a lot of similar reasons.
I've got parallel-split shadow map code that renders the scene multiple times, so I've also approached the issue of optimizing for multiple shadow maps.

For me, the biggest performance win was in the elimination of material state changes while in depth-only rendering mode. Most surfaces are opaque, which means that their material doesn't matter during shadow map rendering. This means you can merge the geometry of all opaque surfaces into a single large element buffer and render in one pass using a trivial shader. After that, any alpha masked materials are rendered one-by-one.

I actually keep two sets of element buffers: one for color mode and another for depth-only mode. The result is a drastic reduction in batch count, program switching, and texture binding.
* Depending on your hardware, rendering all shadow maps simultaneously into a texture array in a single pass using geometry shaders can give large speedups.

* Many GPUs have a special highly optimized depth-only rasterization mode, which gets enabled under certain circumstances (read NVidias GPU programming guide).

* CSM/PSSM have a multitude of other, more obscure optimization possibilities, due to the mathematical relationship between the individual maps (ie. they aren't arbitrarily positioned).

* Frustum culling is vital, especially in CSM/PSSM.

* Use smaller shadow maps with a filterable shadow representation (VSM, ESM, ACDF SM) rather than the standard depth value with large maps and PCF.

* Some more aggressive forms of occlusion culling can be used for CSM/PSSM based systems.

This topic is closed to new replies.

Advertisement