Sign in to follow this  

Shadow Maps or Shadow Volumes?

This topic is 3295 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

I'm writing a space game. Well, i'm trying to do it :) I've implemented a simple shadow support, using shadow map tecnique, but it's a bit imprecise and needs spotlights. The sun is a pointlight and it could be a problem (i think to rotate the spotlight always to point direct to the camera to give the impression of a omnidiretional light, but...) I've just discovered that there's another tecnique, called "shadow volume" that is more precise, but also more time-consuming. Now i need a suggestion: is it usable into a game or is too heavy? Should i use volumes or maps? Thank you!

Share this post


Link to post
Share on other sites
The field of shadowing in real-time graphics is open to endless debate across the entire spectrum really. It can be very hard to match up your typical scene against performance characteristics and quality trade-offs.

I'd recommend you dig through the depths of Ysaneya's Developer Journal (hosted on this site) as there are lots of technical discussions on shadows for a space-based game that you might find useful.

Also, remember you can use a hybrid solution - there is no rule stating you must choose one single shadowing algorithm for all cases [wink]

As an observation, the soft-shadowing techniques that tend to be a big part of any shadow mapping algorithm probably aren't of such interest to you. In space there will be less (or no) interreflection or atmospheric scattering thus you'll usually (always?) get sharp edged shadowing...


hth
Jack

Share this post


Link to post
Share on other sites
As jollyjeffers says, there are many shadowing solutions, you just need to find the best one for your situation.
To your question about the usability of shadow volumes in games I would have to say a qualified yes. The thing about shadow volumes is that their efficiency if bound to the complexity of geometry, so if your space-crafts have a lot of vertices, you could/will see some poor performance. Shadow volumes do give nice crisp shadows though, which look good in space!
There are a few techniques you can use to speed up shadow volumes, one of which is to use low-res models when calculating the capped shadow volume.
Steele.

Share this post


Link to post
Share on other sites
If you're interested, i wrote a tutorial about 21 pages about shadow volume...ZPass, ZFail, pro and what does not work in technique.

http://xvincentx.netsons.org/programBlog/?p=189

Share this post


Link to post
Share on other sites
The eternal question :)

I started with shadow volumes and then moved to shadow maps because shadow volumes required a great amount of polygons on my dynamic meshes, and it's harder to implement with soft edges. You can see the rough shadow volume edges on this screenshot:



Shadow mapping needs less vertex processing time but it requires some additional filters to look decent:



If you choose shadow volumes, they will work fine with all kinds of lighting but it will be really slow with high poly models.
If you go with shadow mapping, and you need a point light as the sun, you'll need to render the depth into a cube texture, and that means 6 additional renders per scene. But it looks good, and it's not THAT expensive. This screenshot was rendered using shadow mapping with a cube texture and taking 4 samples to soft the shadow edges:



And finally, remember that most of current graphics cards supports hardware acceleration for shadowing. Most ATI cards and nVidia cards supports hardware shadow mapping (http://developer.nvidia.com/object/hwshadowmap_paper.html) and it could be implemented on cube textures with a few tricks. nVidia cards with UltraShadow technology will also speed up shadow volume rendering (http://www.nvidia.com/object/feature_ultrashadow2.html). The speed gain by using hardware shadows goes from 150% to 300% approx.

Hope this helps. Good luck!

Share this post


Link to post
Share on other sites
Quote:
Original post by XVincentX
If you're interested, i wrote a tutorial about 21 pages about shadow volume...ZPass, ZFail, pro and what does not work in technique.

http://xvincentx.netsons.org/programBlog/?p=189


This would seem quite interesting... Is there an English version available?

Share this post


Link to post
Share on other sites
Quote:
Original post by Rompa
Quote:
Original post by XVincentX
If you're interested, i wrote a tutorial about 21 pages about shadow volume...ZPass, ZFail, pro and what does not work in technique.

http://xvincentx.netsons.org/programBlog/?p=189


This would seem quite interesting... Is there an English version available?



Sorry, but for now it's aviable only in Italiano. Translation is in planning

Share this post


Link to post
Share on other sites
Quote:
Original post by PdGyoutube video


Looking good! What kind of shadow mapping technique are you using on that video?

(Just remember that if you want to use Variance Shadow Mapping you wont be able to use hardware acceleration...)

Congrats!

Share this post


Link to post
Share on other sites
Quote:
Original post by jpventoso
(Just remember that if you want to use Variance Shadow Mapping you wont be able to use hardware acceleration...)


Well with VSM you get hardware-accelerated anisotropic filtering and mip-mapping, of course.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rompa
Quote:
Original post by XVincentX
If you're interested, i wrote a tutorial about 21 pages about shadow volume...ZPass, ZFail, pro and what does not work in technique.

http://xvincentx.netsons.org/programBlog/?p=189


This would seem quite interesting... Is there an English version available?


Here, I did one ages ago:
Real time shadow with multiple lights

Share this post


Link to post
Share on other sites
Quote:
Original post by jpventoso
Quote:
Original post by PdGyoutube video


Looking good! What kind of shadow mapping technique are you using on that video?

(Just remember that if you want to use Variance Shadow Mapping you wont be able to use hardware acceleration...)

Congrats!


The procedure is:

- i render the scene once moving the camera in the light position, and obtain a depth buffer
- i render the scene one more moving the camere in it's position.
- i compare the two depth buffer. If the results are different for one pixel, then that pixel is in shadow.
- i'll obtain so a map, called "shadow map".
- i'll project the map from the light source, that should be a spotlight. Is not possible to use point light or directional light (and this is a problem...)

The big issues of this method are:

- only spotlight. Sun is a pointlight.. for a good result you should emulate it using a cube. So you need to render the scene 6 times, not two.
- the resolution of the map is low.. so you'll see a lot of aliasing on the shadow.
- the precision of depth buffer is low, so the light should be NEAR the target to obtain detailed shadows. If you put the light very far, the depth buffer is not able to distinguish a lighted point from a dark point. And the sun is VERY far...

Share this post


Link to post
Share on other sites
Quote:
- only spotlight. Sun is a pointlight.. for a good result you should emulate it using a cube. So you need to render the scene 6 times, not two.


D3D10 (i do not know if you're using D3D9 or 10) gives to you new features to make CubeMap saving a lot of performances (only a Draw call instead of 6).
Quote:


- the precision of depth buffer is low, so the light should be NEAR the target to obtain detailed shadows. If you put the light very far, the depth buffer is not able to distinguish a lighted point from a dark point. And the sun is VERY far...


Trapezoidal Shadow Mapping may help you in this issue.

Share this post


Link to post
Share on other sites
Quote:
Original post by PdG
- i'll obtain so a map, called "shadow map".


Just a heads up...it's common to refer to the depth buffer from light's point of view as the "shadow map". Just thought I'd let you know so you can avoid communication problems.

Quote:
Original post by PdG
- only spotlight. Sun is a pointlight.. for a good result you should emulate it using a cube. So you need to render the scene 6 times, not two.


Are you sure you need to model the sun as a pointlight? Do you actually move sufficient distances in your game world such that the direction from sun->camera/ship changes significantly? Even if you do move enough that using a directional light would be insufficient, I would guess that for most cases it would be sufficient to model the sun as a spotlight that's aimed squarely at your view frustum. You would only need to switch to a pointlight/cubemap for areas where the view frustum is very close to the sun. And when you are using a cubemap, make sure you agressively cull both shadow casters as well as faces of the cubemap. For each cubemap face figure out the resulting view frustum, and only render that cubemap face if that volume is visible. If you then cull your shadow casters using those frustums, you'll avoid a lot of draw calls.

Quote:
Original post by PdG
- the resolution of the map is low.. so you'll see a lot of aliasing on the shadow.


Make sure you look into filtering techniques like Percentage Closer Filtering. ATI and Nvidia have extensions that allow you to accelerate 2x2 PCF in hardware, otherwise it can be done in the shader.

Quote:
Original post by PdG
- the precision of depth buffer is low, so the light should be NEAR the target to obtain detailed shadows. If you put the light very far, the depth buffer is not able to distinguish a lighted point from a dark point. And the sun is VERY far...


When you're rendering shadow occluders to the shadow map, make sure you scale your depth values to the minimum and maximum possible values. You can get these values by tightly fitting the shadow projection to your main view frustum, or to the closest and furthest occluders rendered to the shadow map.

Share this post


Link to post
Share on other sites
That's right, with VSM you achieve hardware accelerated filtering and mip. I forgot that :) I used both techniques (VSM and hardware acceleration through tex2Dproj) and the second is a lot faster but less accurate... But VSM works only if your entire scene is dynamic (I'm using lightmaps for static objects so VSM doesn't fit into my engine).

If your camera doesn't travel high distances, you may want to threat the sun as a directional light. Then, you can use an orthogonal projection to generate the shadow map texture.

Share this post


Link to post
Share on other sites

This topic is 3295 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this