Sign in to follow this  

What Shadowing techinque should I use?

This topic is 4836 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 have per pixel lighting up and running on my terrain. I want to add shadows, and not sure what method to use with per pixel lighting? I have the light position moving around in circle to simulate the sun. So the lighting is dynamic and the shadows would need to be also? I have looked at horizon mapping. Not sure if that will work or not? Thanks

Share this post


Link to post
Share on other sites
Well, in your situation you're basically left with two possibilities: shadow volumes (stencil shadows) or shadow maps. I'm a big fan of the latter, so I'd obviously recommend shadow maps. But shadow volumes might also be an option to consider. It primarily depends on the type of geometry you use (size, face count, detail level) and on the type of shader effects you're applying to it.

I'd suggest researching both methods, and trying out both. Then you'll quickly discover the advantages and drawbacks of each one, applied to your specific situation.

Share this post


Link to post
Share on other sites
Terrain would mean lots and lots of polys, I assume, so I don't think a stencil based approach would be a good idea. Edge finding and such would probably take a very long time.

Shadow maps are probably much more efficient...but I believe they don't work with point lights, and it sounds like that's what you're using.


I don't have real suggestions, unfortunately, but it doesn't seem to me like either of Yann's ideas are feasible. But I could be wrong; disagreeing with Yann is usually not a good idea [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
Terrain would mean lots and lots of polys, I assume, so I don't think a stencil based approach would be a good idea. Edge finding and such would probably take a very long time.

Depends. That's generally not the bottleneck (much can be either precomputed, or done on the GPU), but fillrate might very well be. Shadow maps will most likely be much more efficient. But it really depends on the situation.

Quote:
Original post by Promit
Shadow maps are probably much more efficient...but I believe they don't work with point lights, and it sounds like that's what you're using.

SMs work with pretty much every type of light source you can imagine: point lights, spot lights, directional lights, in a modified form even area lights. The sun is best modelled as a directional light, btw, which makes it even easier due to the orthographic projection.

Quote:
Original post by Promit
I don't have real suggestions, unfortunately, but it doesn't seem to me like either of Yann's ideas are feasible. But I could be wrong; disagreeing with Yann is usually not a good idea [grin]

Heh, feel free :)

But shadowmaps are very feasable on large and complex geometry, in fact, that's one of their strong points. You might need some form of advanced shadow mapping algorithm though (PSM, TSM, LSSM, etc). But it really depends on the scale and precision you want/need, so Mars needs to be a little more precise about his requirements.

Share this post


Link to post
Share on other sites
Well, if shadow maps work with point lighting, that should be perfect. I know they work with directional...he mentioned moving the sun, so I assumed it was point, but I suppose it could simply be a rotating directional.


I wouldn't want to use stencil shadows on terrain though. Lots of polys to find edges with, extra passes to be done, the shadow hull probably won't be simple, etc.


So best thing to do is probably to research one of the shadow mapping algorithms Yann mentioned.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
Well, if shadow maps work with point lighting, that should be perfect.

Yes, point light shadow mapping is usually achieved by using either a cubemap or a dual paraboloid map instead of the common 2D depth texture. The map generation is a little slower, but it works pretty well in practice (you don't need to regenerate the shadowmap every frame either).

Quote:
Original post by Promit
I know they work with directional...he mentioned moving the sun, so I assumed it was point, but I suppose it could simply be a rotating directional.

Rotating directional is best for sunlight. It takes less resources than a point light, and gives you much more precision (since perspective depth aliasing, a common problem with SM, doesn't apply to orthographic projections).

Share this post


Link to post
Share on other sites
I second the opinion that shadowmaps would be a good choice in this situation. And, like Yann said, you can even avoid problems like depth perspective aliasing if you represent the sun as a directional light source, (which is what makes most sense anyway).

Still, shadowmaps aren't perfect. Most articles on the subject will also present you with the downsides of the algorithm as well. One of them is the dueling frusta problem. Which is in a situation where the camera is oriented towards the light-source, and you get blocky edges in the shadowmap. Does anyone know if this will be a big problem in a terrain-rendering situation like this?
I also imagine you'd need a pretty high-resolution shadowmap, for a light covering an area as big as that...

Share this post


Link to post
Share on other sites
It looks like shadow maps are the way to go. I don't need soft shadows, because when I look outside at a tree and the sun is out I don't see a nice fade effect on the shadow I see a hard outline of the tree, or whatever the shadow is. I don't want any jaggie edges if possible. But speed vs. quality I would like a happy medium. So no one here suggests horizon mapping? Thanks all.

Share this post


Link to post
Share on other sites
when rendering the directional shadowmap for a terrain

how would you do it

1. prerender the shadowmap at compile time for the entire terrain at a high resolution
or
2. render it when needed all x frames only for the culled scene with a lower resolution

Share this post


Link to post
Share on other sites
Well, if you were to only pre-render the shadowmap, that would make the shadows completely static. That might not be desirable. In that case you might as well have encoded the "shadows" in the diffuse texture map.

But since the directional light source will be representing the sun (or moon, or whatever), then that means that it doesn't have to be updated too often. The sun doesn't move that fast, anyway. Even though, regenerating the shadowmap is a relatively cheap render-pass, because you can disable everything except depth-writes. Shadowmaps are more scalable with the amount of geometry, compared to shadow volumes.

Share this post


Link to post
Share on other sites
Quote:
But since the directional light source will be representing the sun (or moon, or whatever), then that means that it doesn't have to be updated too often. The sun doesn't move that fast, anyway.


that's true only if you've got a completely static terrain with no moving entities on it. because the light doesn't move, doesn't mean you have to update your shadow maps less often... unless of course you render the dynamic object's shadows differently...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
I have per pixel lighting up and running on my terrain. I want to add shadows, and not sure what method to use with per pixel lighting? I have the light position moving around in circle to simulate the sun. So the lighting is dynamic and the shadows would need to be also? I have looked at horizon mapping. Not sure if that will work or not? Thanks


For the terrain itself I woudld definitly use horizon maps. Horizon mapping (or a varient) is a really good fit for shadows of terrains on itself, and it is one of the few ways to have a selfshadowing bumpmaps. It also works well for any surface where objects are occluded in a continious way, which includes height map techniques. It is also really cheap to compute, and can optionally give you a soft to the shadow (which you probablly want to soften the aliasing).

If you want the terrain to shadow other objects (or the object to shadow the terrain), you have to use a seperate technique for that: Id buffers, shadowmaps, or stencils are the most common techniques. My personal advice would be to use either shadow maps or ID buffers. ID buffers would allow the terrain to shadow the object, Shadow buffers would also cause an object to shadow itself. It is harder to get good results with shadow and/or id buffers) then with stencil shadows, but the performance characteristics of Stencil shadows are horrible, especially for outdoor scenes.


So short answer: Use horizon map to self shadow the terrain, use shadow maps or id maps for the other shadows.




Share this post


Link to post
Share on other sites
Re: shadowmap size problem for large terrain.
Read Carmack's idea on multiple-sized shadowmaps here: http://benryves.com/bin/jcqc2004keynotes.txt
Same idea by Jonathan Blow (look at the 2nd image): http://number-none.com/happycake/notes_8/index.html

Share this post


Link to post
Share on other sites
Quote:
Original post by sBibi
Quote:
But since the directional light source will be representing the sun (or moon, or whatever), then that means that it doesn't have to be updated too often. The sun doesn't move that fast, anyway.


that's true only if you've got a completely static terrain with no moving entities on it. because the light doesn't move, doesn't mean you have to update your shadow maps less often... unless of course you render the dynamic object's shadows differently...


Good point, I didn't think about that.

Anyway, I found this thread. You should definitely read through it.

Share this post


Link to post
Share on other sites
James Trotter> this thread happened a bit before the TSM paper came out, and would probably have converged to a similar approach if it had kept going..

Trapezoidal shadow maps: (there are a bunch of threads talking about it here in gpt) http://www.comp.nus.edu.sg/~tants/tsm.html

EDIT: sorry, didn't notice Yann already mentionned TSMs

Share this post


Link to post
Share on other sites
I just read John Carmacks paper on Doom3 and whats next. He talks about pBuffers and the render to texture Extensions and their performace issue and nightmare to work with... I though about using this method but now am unsure. I am now thinking about using glTexSubImage and updating my shadow map texture every other few degrees instead of continually. This would be for my terrain only. I would have to come up with something else for my objects on the terrain.... Not sure what everyone else has to say about this....

Share this post


Link to post
Share on other sites
IIRC in Carmacks keynote on doom3 ... he talks about shadowing in outdoor scenes. He said that even with buffers with resolution of like 2000 x 2000 you get nasty shadows for things like bushes and trees.

Share this post


Link to post
Share on other sites
Quote:
He said that even with buffers with resolution of like 2000 x 2000 you get nasty shadows for things like bushes and trees.


not with TSMs, and with shadow volumes, it's much worse... if you use alpha maps to render the bushes, you get solid bush shadows, without any leaves, and if you model the leaves geometrically to get proper shadows, and have a few bushes, you'll get an awful performance drop...

[Edited by - sBibi on September 15, 2004 8:43:44 PM]

Share this post


Link to post
Share on other sites

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