• Advertisement
Sign in to follow this  

3DMark06, Cascaded Shadow Maps (CSM)

This topic is 4388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody! Just read the 3DMark06 White Paper about Cascaded Shadow Maps... Link to pdf "This method works by dividing the view frustum in to 5 sections along the z-axis. Each section gets shadowed by a standard uniform 2048x2048 shadowmap." So if i get this right.., the shadow maps are placed from the near clip plane to the far clip plane along the z-axis (where each map is covering a larger area?), according to this image?? csm Did i understand this right? Has anyone implemented this? /Mike [Edited by - vx7johmi on January 19, 2006 8:09:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
I haven't seen the paper that you refer to, so I can't help you, but it sounded interesting so could you please link it ;)

Also.. 5 2048 maps? Won't that eat up about 2048*2048*4*5 = 80 MB VRAM? That's a lot of graphics memory :)

Thanks!
/Simon

Share this post


Link to post
Share on other sites
they 'only' use 16MB of video memory for CSM shadow maps, but another 24MB for the pointlights it seams ..

but how are they rendering there scene, when they are reusing the same texture everytime. They have to rerender every shadowmap, every frame, and can't store the ones in the distance .. strange. I doubt if that is better than LiSPSM.


Share this post


Link to post
Share on other sites
Quote:
but how are they rendering there scene, when they are reusing the same texture everytime.


Render SM1, render relevant shadow term result to main scene, render SM2, render relevant shadow term result to main scene, etc.

Share this post


Link to post
Share on other sites
I thought one of the tricks of trade here is to update the shadow maps for example every 2 or 3 frame. This way you do not really kill so much bandwidth, but you have five maps lying around in memory.
If they use 16-bit depth buffers, it is not that much ... it should be 5 x 8 MB, which is 40 MB ... an amount that fits into a 512 MB graphics card easily.
To scale the whole approach you just decrease the shadow distance and only use two maps on slower hardware .. this is then 16 MB.

[Edited by - wolf on January 20, 2006 9:51:49 AM]

Share this post


Link to post
Share on other sites
[q]they 'only' use 16MB of video memory for CSM shadow maps, but another 24MB for the pointlights it seams .. [/q]
Oh then they use the video memory of the second shadow map several times maybe? I mean you can skip rendering the third, fourth and/or fifth shadow map anyway based on viewing distance, but having them lying around for a few frames seems to be nice to me.

Share this post


Link to post
Share on other sites
Did anyone implement this? I have it up and running.
I would be curious, how you select the shadow map based on viewing distance in the pixel shader in an efficient way :-)

Share this post


Link to post
Share on other sites
I am sorry I can't. The game is not announced.
But I am willing to talk about any aspect of the implementation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just a couple of quick questions Wolfgang:

- Do you partition the frustum in the way that the original poster suggested?
- How do you "focus" the shadow maps on their specific region to be as tight and also as fast as possible?

PS: Love your books :)

Share this post


Link to post
Share on other sites
That was me above... forgot to login :|

Some more questions :)

- Also... are there no problems with "dueling frusta" cases? As far as I understand this approcah, performance could be much worse if the light and the camera are looking at each other as you render everything ~5 times. If they are perpendicular you only have to render it ~1 more time (as each SM covers 1/5th of your frustum).

- Do put all 5 SMs into the pixel shader and then decide which one to choose? May I ask what is your criteria as pixel shader instrucions are quite expensive :)

Share this post


Link to post
Share on other sites
I sketched my implementation on the thread http://www.gamedev.net/community/forums/topic.asp?topic_id=372261, but didn't get any feedback, so I'll repeat it here (still hoping for feedback or a much better implementation ;-). It's a simple yet robust way of first creating a shadow texture with black/white color information that can be used in lighting shaders later on.

1. Divide the view frustum into five adjacent (but not overlapping) frustums along the viewer's z-Axis.
2. For each frustum - starting with the most distant one - do:
2.1. Clear screen z-buffer (but don't clear the color)
2.2. Create a standard shadow map for the current frustum
2.3. Apply this shadow map to the scene for the current frustum (this means to create a projection matrix with the z extends of the current frustum. This solves the "which shadow map for which objects and where" problem) such that a black and white image for shadowed and non-shadows regions is drawn. The color information for frustums closer to the viewer overlap that of more distant ones (kind of painter algorithm).
3. Use the screen as a texture and render the scene using real materials and that shadow information


Share this post


Link to post
Share on other sites
I wouldn't say my implementation is better than everyone else's implementation. It is just one way that works. I have the impression that other people have much more sophisticated implementations like yours.
I have up to four shadow maps and each has its own view frustum. The near and far clipping plane of each light/shadow map view frustum just slices the view frustum in four parts.
The transition between two shadow maps is difficult, but by overlapping them a bit you only see the transition when you know where to look for as long as they are proberly tuned.
Frustum culling takes care, that we render into each shadow map only the objects that are in the shadow map frustum.
I might change this a bit in the future, but this is how it is done in the moment.

- Wolf

Share this post


Link to post
Share on other sites
but if you're allocation 4 shadow maps of 2K x 2K you already 'waste' quite a lot video memory no? Isn't it more effecient to reuse the shadow maps, and render to a RGBA texture the black and white afterwards, which is then used during the shading part. The RGBA texture is in view space (so can be blurred) and can also contain shadow information of other point lights perhaps. Like this you can easily render multiple lights which cast shadow in a single pass. Which is nice. (I presume this is the technique you are using krausest)

I still have a question regarding the subdivision. Do you take the center of all frustum the current camera position, and extend the frustum in all directions, or only in the view direction. View direction would off course be more efficient, but object lying behind you which cast shadow are culled like this ..

Share this post


Link to post
Share on other sites
camera direction is viewed from right to left the pyrimid (im using using 3 SM frustums)
http://uk.geocities.com/sloppyturds/CC/2005_04_26A.jpg
u do need someover lap between the frustums
dont center them on the camera or else nearlt half the SM is going to waste

Share this post


Link to post
Share on other sites
Guoshima you are absolutely right :-).

<<<
The RGBA texture is in view space (so can be blurred) and can also contain shadow information of other point lights perhaps.
<<<
You mean in screenspace? Yep that is cool. Did anyone else do it this way?

I have one other question: how do you project in the shadow map ... or in other words, how do you construct the frustums? Any reference?
I did it on my own, but would love to see how others did it.

- Wolf

[Edited by - wolf on February 11, 2006 12:06:47 AM]

Share this post


Link to post
Share on other sites
<<<
- Also... are there no problems with "dueling frusta" cases? As far as I understand this approcah, performance could be much worse if the light and the camera are looking at each other as you render everything ~5 times. If they are perpendicular you only have to render it ~1 more time (as each SM covers 1/5th of your frustum).

- Do put all 5 SMs into the pixel shader and then decide which one to choose? May I ask what is your criteria as pixel shader instrucions are quite expensive :)
<<<
Dueling frusta might be 1.5 km aways on the fifth map ... so you do not really see it.
You choose shadow maps based on view distance ...
if(viewdistance < StartSecondShadowMap)
DrawIntoShadowMap1;
if(viewdistance > StartSecondShadowMap && viewdistance < StartThirdShadowMap)
DrawIntoShadowMap2;

Works quite well as long as the dynamic branches in the pixel shader do not kill you :-). In case they kill you can try a texture atlas.
But I like the idea of rendering everything into a screenspace texture more ...

Share this post


Link to post
Share on other sites
zedeck:
<<<
dont center them on the camera or else nearlt half the SM is going to waste
<<<
so where do you center the light frustum then ... do you have a threshold value to move the frustum a bit in front?

Anonymus poster:
currently I look at the view frustum and calculate the light view frustum as an orthographic projection that gets its min values from the view frustum. I end up with a quad as the far and near plane. I wonder if this is the best way to do it. I would think that having an orthographic frustum that follows exactly the view frustum would be better.

Share this post


Link to post
Share on other sites
hmm i know CSM for a while now but i still don't really understand what it is that makes them so good. Ok they have less aliasing problems but at what costs? you have to render 5 times only for the shadow maps and they consume much memory. So what are the advantages of CSM in comparison to other shadow map techniques like TSMs(which,as far as i understood, result in less aliasing problems on spots that are farer away from the camera)?

regards,
m4gnus

Share this post


Link to post
Share on other sites
- The center position: I think a good idea would be to put the center of the frustra at 1/3 of the current size of the frustum, in the direction of camera. Like this you waste a lot less SM space. What offset sizes do you think between the different frustum sizes? I tried times 2, but then you get a frustum with 4 divisions such as this:



Is this is a good way to subdivide ? If you start with a shadow map of 32m x 32m, you can cover 'only' 256m / 3 * 2 = 170m .. which perhaps might even not be enough.

The thing I don't like about the multiple shadow maps is that you have to shade your scene also with the subdivided frustums, and this doesn't really work well with deferred shading and feels counterintuitive. You could select the shadow map to render depending on the distance (as wolf suggested I think), but then you have to give all the shadow maps to the shader, have a lot of texture memory swapping (shadow maps are rather big uncompressed textures), and it's always better to avoid branching I think. I tried it before and it works fine. I even increased the PCF when sampling the shadow maps closer to the camera.

I presume (not sure yet, cause I'm writing here as I am thinking :)), that you could do the following:

- cull scene with all object which will be shaded (shadow receiver objects)
- cull all possible object which can contribute shadows into a single visible array (shadow caster objects)
- devide the visible array into different frustra, 4 here
- repeat for each frustra (starting with furthest)
* render shadow caster objects from frustum in a shadow map
* render shadow receiver objects within this frustum, using shadow map to another RGBA texture in screenspace, and only store black and white and perhaps perform some PCF here
- now we have the complete projected shadow map into a single texture for the scene -> blur it.
- render the shadow receiver objects again (all of them), using the RGBA shadow map.

This seams like the easiest method, because you don't really have to modify your shading system to work with multiple frustra.

Someone else posted another very nice link to Variance Shadow Map. But I would only use the Variance Shadow Maps for point and spotlights, cause I think it would work best there.

All comments welcome of course

Share this post


Link to post
Share on other sites
to magnus:

that's what I though in the beginning as well, but have you already taken a good look at battlefield or battle for middle earth 2. The shadows are bad! With wrong directions you always manage to make them look really really ugly if you use a perspective correction. Perhaps if you would blur them somehow it could work. But I think with method I described above, you only have to render the objects once more, with a cheap shader, and it doesn't consume more texture memory than normal TSM, and it has far less special cases on quality level (at least I think :))

Share this post


Link to post
Share on other sites
it all depends on the scene/light height/geometry size/height etc but
pick a fixed minimum size, depending on geometry size etc
eg 4meters overlap, so with the original drawing that goes 1-5, between each frustum u have a 4meter overlap, eg frustum 2 may contain fully frustum 1 (if frsutum 1 is 2 meters wide), but by the time u reach frustum 5 (2^5=32meters wide) it only contains a small % of the previous frustum, the problrem with your drawing Guoshima is theres a lot of overlap which equals a lot of wastage

Quote:
that's what I though in the beginning as well, but have you already taken a good look at battlefield or battle for middle earth 2. The shadows are bad! With wrong directions you always manage to make them look really really ugly if you use a perspective correction.

theyre not uising CSM i assume then but some sort of perspective shadowmaps (from what ive seen its not possible for the various perspective SM methods to work great from all view angles, sometimes the best u can hope for is just the same as normal SMs )

Share this post


Link to post
Share on other sites
hmm .. I don't really understand how you subdivide your frustra then. Could you make a quick sketch or explain in a little bit more detail then pls. I have modified my preview a little bit. Each region has its own color, and overlaps the previous and next region.

Share this post


Link to post
Share on other sites
Image hosting by Photobucket

but like i said it all depends on the scene, one thing to watch out for are tall objects offscreen (eg pylons trees) casting shadows in the screen

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement