Sign in to follow this  
vajuras

Shadow mapping in a Large Enviroment

Recommended Posts

vajuras    139
Hi I am trying to figure out can I use just 1 shadowmap for a large virtual scene or do I need 4 shadowmaps (4 light sources - 1 light source for each direction the character can face). Basically right now I have everything working with one directional light source. I am using orthogonal projection for this so that everything in the distance can be nicely stored into the depth map. My dilemma, like I explained before, this is a large scene (think something like World Of Warcraft or Oblivion). I was hoping I could just use one shadowmap and maybe rotate the light source to face same direction my character is facing. Problem is- all the objects in my scene rotate as well of course and you see all the shadows rotate. I cannot find any examples of a full working system really. I have tried looking at the NeL engine to see how they overcome this problem but got lost in piles of source code. Honestly all I need to know is can this be done with 1 shadowmap and if so, how am I supposed to get this working? According to my sources I need a shadowmap for each light source. And right now it appears I need 4 lights (North, South, East, and West). I saw an earlier post on this topic about a year or two ago and I think YannL replied its best to use 4 just wanted to double check Thanks

Share this post


Link to post
Share on other sites
godmodder    828
Hello,

I'm not exactly sure about what you're really trying to do, but I think you might be looking for something like Perspective Shadowmapping. There are quite a few techniques available, but none of them solve all the problems. PSM is considered very hard to implement and doesn't provide very good quality in the end. LiSPSM and TSM provide better bang for the buck, but they too have their issue's, and sometimes this means UNACCEPTABLE artifacts. I don't think shadowmapping with just one shadowmap is going to cut it with large environments like you're describing. I would give PSSM's a shot. It's surprisingly fast these days and there are 2 demo's available with full source for both Direct3D and OpenGL (I made the last one).

Go check it out: --> http://hax.fi/asko/PSSM.html

Hope I've been able to help,
Jeroen

Share this post


Link to post
Share on other sites
vajuras    139
Thanks I'm aware of LispSM, Parellel Split, etc. Right now I'm not interested in cleaning up the shadows per se. I just want to make sure I'm on the right track (use 4 shadowmaps for a large virtual enviroment). I'm kind of confused because my friend that worked on True Crime (its like GTA) claims they did it with just one shadowmap. And I thought that game had a huge, virtual enviroment. Maybe he was mistaken

Share this post


Link to post
Share on other sites
Drilian    1067
There are problems rendering a large world's shadows with a single shadow map. It's next to impossible to get a good shadowing setup. Perspective/Trapezoidal/etc shadow maps CAN look good, but only under the most ideal circumstances. Every single-shadowmap setup that I've ever seen has some sort of singularity, in which it looks either no better or, in many cases, much WORSE than not using the technique at all.

Interestingly, I started a topic on the same idea a few years ago (with almost the same title: Shadow mapping in large environments

The Gist of it is, a single shadow map doesn't give you optimal-enough resolution. We came up with a way to generate a more optimal shadow projection, but it ended up requiring a logarithmic projection, which gets ugly real fast.

Today, I would suggest something simpler:

Use Cascading Shadow Maps.

Now, that doesn't give you a SINGLE shadow map, but it is, I think, the best (and one of the easiest) ways to handle large-scale shadowing. It's what games like Crysis are using.

Share this post


Link to post
Share on other sites
vajuras    139
Hi Drilian yes I was thinking of your original post when I wrote this.

From reading your post, it sounds like it should be possible that I can do this with one shadowmap (even though everything will look messed up)?

Right now my light source is sort of positioned overhead right behind my character. Perhaps I messed up a matrix somewhere because right now I cant even get to the point where I can produce a shadowmap in any direction the character faces. For instance, I have two mushrooms in my scene. If I look to the right, I would like to be able to generate a shadowmap for that direction. However, if I rotate my light source to face that direction, my shadows on the mushrooms also rotates. When I get home I can try to FRAPS it into a video right fast.

So my problem is perhaps I messed up the basic implementation. I'm not really at the point whereas I need to cleanup the shadows per se. Right now, I am having trouble rotating my light source w/o distorting the existing shadows the viewer was looking at.

I just checked some article on Lost Planet and it appears they used different shadowmaps to breakup the view frustum. My problem is I havent made it to that point yet because it appears I might have errored in my LightViewProj matrix.

Share this post


Link to post
Share on other sites
Drilian    1067
The trick with most directional light shadowing methods is that you have to rerender the shadows essentially every frame. It's not really that you have shadow maps for what's to the left and right, it's that you keep the shadow map positioned over the view's area and move it as the view moves.

After you move it, you of course have to re-do the shadow map render.

Share this post


Link to post
Share on other sites
vajuras    139
Interesting, been playing around with the NVidia SDK 9.5 example from their browser. In their world, you can move around the entire scene. The shadowmap appears to update as you move around, etc. And when you rotate the view, the shadows when in ortho view do 'swim' a bit like my engine does. But when I switch their browser to LispSM the shadows dont swim when I rotate the light source. LispSM doesnt appear to be too difficult to implement hopefully tonight when I get home I'll plug it in.

Yeah right now I update my shadowmap every frame and everything is fine when I walk around. But where I'm having probs is when I try to rotate my light source to face the same direction as the character. I am seeing the shadow swim with the light source. So let's say I circle around my mushroom, what happens as I rotate around it I see my shadows swim around. But from looking at this demo, it appears once I switch to LispSM or something that should fix. Guess I'll see when I get time to implement.

Thanks for all of your advice

edit- Bah nevermind, you cannot move the light source around in their PSM demo. It is a fixed light source apparently just like all the other examples. And when I tell it to let the light source move I see the shadows swim with it. What I wanted was a way to always have my objects maintain their same depth / shadow as I move around the scene and remain the scene no matter what angle the light source is facing

Share this post


Link to post
Share on other sites
cyber_wiz_2007    124
PSSM or cascaded shadows look fine, however the shadow can't be blurred correctly using the normal techniques such as a poisson disk because the shadow is discontinuous.

I would try a static shadow mask. This involves rendering a massive shadow map for all of the static objects in the scene once at the start of the program. The shadow mask is then reused throughout the program frames as a normal shadow map - without the render-to-texture stage. The trick is to combine the shadow mask with a dynamic shadow map for the character - preferebaly allowing the shadows to blend seamlessly (i.e. you dont see a character shadow when the character is behind a wall to the light).

you could use a shader code of the form:-

float3 shadow_mask = tex2D( mask_sampler, coords1 );
float3 dynamic_shadow = tex2D( shadow_sampler, coords2 );

float shad1 = shadow_mask > length( pos- light_pos ) ? 1.0f, 0.0f;
flaot shad2 = dynamic_shadow > length( pos - light_pos ) ? 1.0f, 0.0f;

float shadow = shad1 * shad2; //



if the pixel is in shadow the variable 'shadow' is zero, therefore color is the shadow or ambient color ...

Share this post


Link to post
Share on other sites
Todo    451
Quote:
Original post by vajuras
I just checked some article on Lost Planet and it appears they used different shadowmaps to breakup the view frustum. My problem is I havent made it to that point yet because it appears I might have errored in my LightViewProj matrix.


That technique is what Drilian meant by Cascading Shadow Maps or CSM.

Share this post


Link to post
Share on other sites
AndyTX    806
Somewhat off-topic, but does anyone have a link to a paper on cascading shadow maps? I've seen all of the PSSM work (and it certainly is a good idea - probably the best current solution really), but I've been unable to find detailed information on exactly how cascading shadow maps differs from it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Cascading Shadow Maps rock. Period. There are issues but right now they are the best solution. Static shadows are so 2002 :-). I watch the Crysis Engine Editor video nearly daily as inspiration to code. If you're going to invest the time, make it look GREAT.

Share this post


Link to post
Share on other sites
wolf    852
AndyTX: Cascaded Shadow Maps in ShaderX5 :-) ... then there are articles by Brandon Loyd ... the parallel split shadow maps are not that efficient. I do not know anything about Brandon's implementation.

Share this post


Link to post
Share on other sites
vajuras    139
I see I'll have to order shaderX5 now :)

Okay below is the depth map from the light source. Below is the overhead view I wanted because since I'm using orthogonal projection I can see actors, etc far into the distance. My dilemma is that I can see a lot of objects into the distance however not to the left / right / behind the toon. If I try to rotate the light source so that it will always face direction character is facing then the existing shadows will also rotate which looks hella wrong. Which goes back to my original question. Am I just simply supposed to 'never' rotate my sunlight to face the direction my character is facing? It seems to me it is okay to 'movve' the sunlight along with the character but never rotate it to face the direction he is facing.



Below is the image that is above the scene that my friend told me I should do (I need to make sure light source can see everything the player can see). This seems like a lot fo work to me if I go this route because it doesnt seem like I am benefiting much from the orthogonal projection? I will have to work to clip everything the character see in every possible direction. Looking at the shadowmaps from Lost Planet from the article I read I dont think their light source is top down like this....



So- I guess what I'm trying to ask is it okay to position my light source at whatever angle I choose as long as it can see all the objects encompassed by the view frustum? Right now the images above are obviously not optimized to only see the 3 objects but I was trying to get a feel how this would work with a huge scene populated by a lot of objects.

I want to use the position used in image #1 which can see objectsfar into the distance. it takes full advantage of the orthogonal projection. However, when my character moves left/right/back the shadowmap generated from that angle is no longer valid / needed and if I try to generate a new shadowmap for the new view direction I see the existing shadows sort of rotate along with the light source (because they rotate around in my depth map).

What I cant figure out is why doesnt anyone else have this problem and what did I do wrong....


In any case I'll go ahead and move forward with an algorithm. until I get the shaderx5 book, I'll probably have to go with LispPM since it looks easy to implement. Will also have to build a better orthogonal proj matrix that tightly encompasses the objects. hoping this mystery will unravel itself. once the wife goes to sleep maybe I'll have time to FRAPS this right fast I'll try to make the video filesize real small

Share this post


Link to post
Share on other sites
vajuras    139
Okay this is the link to the film (please right click to Save Target As). When I rotate my orthogonal light source I get this sort of effect. I show it in the test scene + the shadowmap itself. Was wondering if I'm doing something wrong. The .wmv file is only 3mb or you can look at the pics above.

Share this post


Link to post
Share on other sites
Drilian    1067
It looks like you have the light locked in place relative to the camera. My guess is, you're transforming the stuff in the shadow map by the view transform, when you should only be moving it with the world transform. (or maybe you're transforming the light direction by the view matrix? I'm not sure which it is, it's late)

Just a guess, I could be wrong. It's something along those lines.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
One important consideration (between the lines of praising cascaded and other prespective corrected techniques) - the prespective corrected shadowmaps require update every (or almost) frame, and this effectively add another heap of vertices to process, etc.
Add here 'large environments'. Add reflection. Add sophisticated motion blur. Z-pass. All this things shrink your potential budget for vertices per scene down.
So, for distant part of the scene I would consider using shadowing methods that don't require updated every frame...

Share this post


Link to post
Share on other sites
vajuras    139
Yeah I hooked up the light source to the view matrix to demonstrate what happens if I try to rotate it (shadows swim along with the light source). I suppose thats how a shadow camera is supposed to work and I've been probably worried over nothing it appears. I just expected orthogonal lights to work a bit differently I guess. Like, allow me to look in 'all' directions at once not just a single direction. Guess this makes perfect sense now that all of this is soaking in. Once I build the enclosing volume for all the objects that exist within the light frustum I think everything will work and everything will become a lot clearer

Now I need to try to get my hands on that shader x5 book I could not find an CSM implementation online.... I hope it includes good examples hehe. Was tempted to look at Parellel Split as well I wonder if CSM is much simpler then that? Does CSM naturally work with orthogonal light sources? Will have to remember to ask my friend to bring that book tomorrow

Thanks

Share this post


Link to post
Share on other sites
Schrompf    1035
To bring a different perspective to the topic: there are solution to do shadow mapping in one pass with one shadow map. It's just... it has issues, just like any other technique. Mine is presented here: http://www.gamedev.net/community/forums/topic.asp?topic_id=405955 Haven't made it to produce a english paper on it, yet, but it works quite nicely here.

In our case we're mostly cpu bound, even with heavy shaders. That's why I don't want to afford rendering the scene x times as required by CSM or PSSM. If you don't have this limits, CSM might be the way to go for you.

To summarize:

Perspective Shadow Mapping: depends on the angle between view direction and light direction. Has dead points.

Light Space Perspective Shadow Mapping: as above, but without the dead points. Scales back to uniform shadow mapping the closer your view direction gets to the light direction.

Cascaded Shadow Mapping / Parallel Split Shadow Mapping: perfect shadows everywhere due to multiple shadow maps or passes for different distances. To my knowledge the shadow maps itsself are projected uniformly, so it's simple to implement as well.

Nameless Shadow Mapping: my version of it. Works by distorting the shadow map texture coords like a lens effect that makes closer objects larger on the shadow map, thus improving the resolution for them. Works for all view angles and light angles, works with a single shadow map and a single pass, the difference is just some additional vertex shader instructions. But its improvement potential is limited and there's an unsolved problem with certain viewing angles where parts of very the distant scene end up outside the shadow map. Demo available in the thread linked above, but without source.

Hope it helps.

Bye, Thomas

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by Schrompf
...


What is exactly the differense of your method and other perspective corrected single-pass ones?
The function of 'scene pyramid' -> 'shadowmap square' transformation?
And why it is better, then?
Just interested.

Share this post


Link to post
Share on other sites
krausest    146
> And why it is better, then?
Hi Schrompf, did you fix your algorithm such that it's guaranteed that no portion of the scene is warped outside the shadow map? (Otherwise I wouldn't consider it an alternative.)

Share this post


Link to post
Share on other sites
AndyTX    806
Quote:
Original post by wolf
AndyTX: Cascaded Shadow Maps in ShaderX5 :-) ... then there are articles by Brandon Loyd ... the parallel split shadow maps are not that efficient. I do not know anything about Brandon's implementation.

Alright I'll check that out, thank you!

PSSMs seem fairly efficient to me (and the demo seems reasonable and runs stupidly-fast on my G80). I think PSSM/CSM+VSM would look amazingly good... I'll hopefully prototype that when I get the chance. That said, interpolation across different shadow maps may not work properly, so blurring and hardware filtering would have to be done with care (although that would already be the case for PCF).

Share this post


Link to post
Share on other sites
godmodder    828
Hello,

CSM is essentially just an alternative approach to PSSM to make the technique view-independent. You just transform the splits of PSSM to center around a world position. This means that, although you don't have to render the shadowmap every frame, PSSM actually makes more efficient use of the shadowmap resolution, as you only divide your splits on the current view frustum. I'd say that if your light's don't move very fast and caching the shadowmaps is important, then go for CSM. If on the other hand you demand super high quality and you don't mind rerendering your shadowmap every frame, you should use PSSM. Keep in mind though that you're probably rendering at double speed, because you only need to draw the depth into a texture, so speed is quite good with PSSM. Today's cards can achieve amazing poly rates when used appropriatly.
About the filtering issue that cyber_wiz_2007 brought up: I had never even heard of it. I can use PCF/VSM on my PSSM's without any problem.

Jeroen

Share this post


Link to post
Share on other sites
krausest    146
Quote:
Original post by godmodder
I had never even heard of it. I can use PCF/VSM on my PSSM's without any problem.

Can you explain how your filtering works? A naive PCF just mixes adjacent pixels from the shadow map. Thus if you sample from different shadow maps the filter size isn't comparable. The results look much sharper for shadow maps closer to the viewer and you can see the shadow map boundaries, isn't that right?

Share this post


Link to post
Share on other sites
AndyTX    806
Quote:
Original post by krausest
Can you explain how your filtering works? A naive PCF just mixes adjacent pixels from the shadow map. Thus if you sample from different shadow maps the filter size isn't comparable.

That's true, but can't you compute the ratio of shadow texel sizes between levels and filter accordingly? Furthermore I'd expect hardware derivatives to work seamlessly, so filtering with VSMs should "just work". One would have to be a bit careful when blurring the different levels of the VSM (if desired), but that could be done using the above compute ratios, right?

godmodder: thanks for the overview. I think I'll implement one or both of PSSM/CSM when I get the chance, and see how they work with VSMs.

Share this post


Link to post
Share on other sites
cyber_wiz_2007    124
Quote:
Original post by krausest
Quote:
Original post by godmodder
I had never even heard of it. I can use PCF/VSM on my PSSM's without any problem.

Can you explain how your filtering works? A naive PCF just mixes adjacent pixels from the shadow map. Thus if you sample from different shadow maps the filter size isn't comparable. The results look much sharper for shadow maps closer to the viewer and you can see the shadow map boundaries, isn't that right?


Here is a screenshot from a PSSM demo modified to do a standard poisson disk at a shadowmap size of 1k *1k I think...


Image Hosted by ImageShack.us

the discontinuity at the split is usually invisible, however if only using 1 split it becomes very obvious. I have also got a screenshot of one using 4 splits with a visible discontinuity.

IMHO it does not matter much. I mean noones going to be looking too closely at the shadows, they'll just be playing the game!

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