Sign in to follow this  
MARS_999

Shadows in a RTS game

Recommended Posts

I am thinking about how I should do shadows in my RTS. From what I have read some people think stencil shadows volumes are better than PSM... Any commments on this? My issue is I would like to minimize having to make multipass rendering to do shadows due to the size of the terrain. Also if the terrain image is lets say 257x257 and you have a shadow map of equal size won't the shadow be very blocky due to the size is per vertex? And if you increase the shadowmap size to 1024x1024 on a terrain of 257x257 aren't you still going to have somewhat of a pixelated shadow? Next topic on this idea is how about self shadowing hills and such? What is the best way to do that? Can you use a PSM or stencil shadow volume to self shadow the terrain? I just need some direction on what is correct way to go about this without much headache... Thanks for any help.

Share this post


Link to post
Share on other sites
Stencil shadows are pixel accurate, but they are very slow to compute compared to shadow maps. However, in the situation you're describing, the jaggies of the shadow map would be pretty much intolerable. Most terrain shadow algorithms do not use shadow maps or stencil shadows for this reason. There are a few articles on the terrain section of gamedev, and a few threads in the forums about terrain self-shadowing, which is how you would put shadows on the terrain. However, for making shadows for objects placed on the terrain, like a tree, player, etc, you could still use stencil shadows or shadow volumes. But for performance, you would have to be careful about what lights can cast shadows, and from what range they are active. It would probably not be advisable to use the sun as the shadow caster for these objects.

Share this post


Link to post
Share on other sites
I'd really consider using a shadow map approach, for a few reasons:
Shadow rendering time would be constant, for any amount of objects on screen (could be a lot if its a rts?).
It's pretty easy to implement.
If done well there will be minimal jaggies - you can use perspective shadow mapping so the 'frustrum' of the light fits tightly around the view frustrum - basically so space on the shadow map is not wasted.

Share this post


Link to post
Share on other sites
Quote:
Original post by stevenmarky
I'd really consider using a shadow map approach, for a few reasons:
Shadow rendering time would be constant, for any amount of objects on screen (could be a lot if its a rts?).
It's pretty easy to implement.
If done well there will be minimal jaggies - you can use perspective shadow mapping so the 'frustrum' of the light fits tightly around the view frustrum - basically so space on the shadow map is not wasted.


Exactly, in a RTS you can have 100's of units moving around and I need some kind of method to deal with that. And I still want to self shadow the terrain which I don't think you can do with PSM maybe I am wrong?

Share this post


Link to post
Share on other sites
yes, you can do it with shadow maps, but it would be a rather unwieldy approach (involving saving the depth values of every vertex and such), you should either use the strider algorithm which is outlined in the game programming seciton of the articles iirc, or stencil shadows. As for units, i dont think the size of the terrain has anything to do with the size of the shadow map, unless of course you want per vertex resolution and the light is right above the map... First of all, if its a rts, why dont you just do a little blob shadow projected onto the terrain below? and second, if you MUST do a more accurate technique, why not just render each unit to a shadow map then apply it to the terrain? (depending on how many units you expect to be onscreen at any time, it would probably be acceptable)

hope that helps
-Dan

Share this post


Link to post
Share on other sites
Well, to determine if a vertex should have the shadow map applied (if you were to attempt self shadowing) you need to check to see if it is deeper (from the light) than the shadow map depth
-Dan

Share this post


Link to post
Share on other sites
and again I say, errm... when you render with the shadow map you'll compare the outgoing fragment with the correct value in the shadow map to work out if its shadowed or not.
Again, this happens per fragment, not per vertex...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ok, but you dont need them, shadow maps basically give you self shadowing for free (well, not free but it just 'works' because of how the system works)

Share this post


Link to post
Share on other sites
Eh? i didnt know this, i thought that was the main folly of shadow maps was the lack of self shadowing, any papers on it? im interested lol

thanks
-Dan

Share this post


Link to post
Share on other sites
Quote:
Original post by Ademan555
Eh? i didnt know this, i thought that was the main folly of shadow maps was the lack of self shadowing, any papers on it? im interested lol

thanks
-Dan


ditto SM AFAIK dont' allow you to self shadow...

Share this post


Link to post
Share on other sites
this shows a reasonable example of an object casting a shadow onto its self.

The area of intrest is the left side of the object in the middle of the scene. Note the shadow line running across it.
This image is taken from a bod standard shadow mapping implimentation (the only change is I'm writing the z value to a rgba texture, which can be seen top left, and then pulling it back and comparing myself instead of copying the z-buffer and doing a proper shadow lookup), so no fancy code here.

Share this post


Link to post
Share on other sites

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