Self Shadowing of Terrain - Which method to use?

Started by
7 comments, last by filousnt 14 years, 10 months ago
Hi, I have been struggling with the terrain shadowing nearly for 2 months now. I tried different modifications of shadow mapping. The first one was the normal, unmodified algorithm. It resulted with horrible aliasing artifacts and it was actually the subject of this topic I started: http://www.gamedev.net/community/forums/topic.asp?topic_id=536074 After this one, I tried the PSSM(Parallel Split Shadow Mapping). The results were much worser than the regular SM. Especially, the terrain parts in the last split got very low SM texture resolution, resulting in serious aliasing. The last method was an invention of mine: The terrain is partitioned using QuadTree, so I assigned every single node which is visible in the current frame a shadow map, whose resolution changes with the square of the distance between the camera and the terrain node. (Actually there is a single 1024x1024 shadow map, I just modify the render target's viewport size according to this scheme.) My own method worked very good and made me really proud for a very short time: The aliasing, while reduced significantly in a long distance from the terrain surface, gets unacceptably bad when one gets very close to the surface. I recently came to realize that maybe shadow mapping is not the correct answer for the self-shadowing terrain question. It is OK, when one only let the other objects like cars, houses, trees etc. to cast shadows, but when it came to the terrain itself, it fails. The reason is IMHO, the huge size of the terrain, especially when the user comes near to the terrain surface. In this case at the shadow edges, the resolution of the shadow map gets too low compared to the frequency of the pixels on the screen and aliasing becomes unavoidable. So now I am in search of a new method for terrain shadowing. I have two aims: 1-The terrain will shadow itself obviously, 2-The terrain must shadow other objects on it, too. For example a car in the behind of a high mountain must enter its shadow. (So, static pre-computed shadows are out of question.) I know that shadow volumes can do this, but I am not sure whether it is a good idea to use them with terrain. I tried google, but I couldn't find a satisfactory result. So, which method or methods would you suggest me in this case? Thanks in advance
Advertisement
Hi,

I think shadow mapping & PCF is a good choice for self shadowing of terrains.

Depth-bias based artifacts can be avoided by PCF + blurring the shadow. But you may need a large shadow map such as a 1024x1024 one. With this, your shadow is saved from artifacts and looks more realistic, but this technique may cause decreasing the performance a bit.

Also, I found a way to solve depth bias problem. You can look at the details here

I'm using this technique to generate blurred sun shadows and works nice.

Hope this helps.
There's no "hard", and "the impossible" takes just a little time.
Quote:I think shadow mapping & PCF is a good choice for self shadowing of terrains.


Do you ever tried shadow mapping with terrain before? As I have told, I am using this method but can't get good results. I think my problem is more related to aliasing rather than shadow biasing. I took some screenshots from my program, which show how the glitches occuring progressively. The shots were taken while the shadow mapping with my own method was running and without using PCF.
1- This shows the terrain and the shadows from a long distance. Almost everything seems to be in order in this picture.
http://img199.imageshack.us/img199/342/pic1dgr.jpg

2-This picture shows a part of the terrain, where I got one of the most disturbing glitches overall. The red ellipse shows the area where it will appear. The distance is the same with the first picture, the camera has just rotated a bit. Still no aliasing.
http://img199.imageshack.us/img199/4774/pic2jkm.jpg

3-I am getting nearer to the area, the problem begins to appear in the red ellipse. (And in other parts of the picture, too.) But still not very disturbing.
http://img268.imageshack.us/img268/4967/pic3drz.jpg

4-More closer. Glitches are clearly visible.
http://img241.imageshack.us/img241/7690/pic4a.jpg

5-Very close to the small hills, indicated by the red ellipse in the previous pictures. Now the problem is crystal clear. Shadow edges get very jagged, like long saw teeth in some places. The shadow map resolution is 1024x1024 for this terrain node.(The whole terrain is partitioned into 256 such nodes, so the resolution is pretty high for this one.)
http://img35.imageshack.us/img35/4724/pic5u.jpg

I tried different kinds of shadow biases, constant ones and polygon slope scale bias. They won't work, the shadows just get larger or smaller according to the bias values, the glitches go on as they are. PCF is not effective, too, it makes the shadow edges to get blurred, meaning I will just have the same jaggies and saw teeth with their edges blurred. I don't think that I am doing something wrong in my shadow mapping code, checked it many times. Maybe there is something very obvious which I am missing and I will be very glad if someone would tell me, but except that, I think shadow mapping is just not suitable for terrain self-shadowing. I still need suggestions and help on this one.
This is a normal problem with shadow mapping...You can't just expect to use one 1024*1024 shadow map for large areas and expect it to look good.

You need some method to split the view frustum up into several shadow maps, like parallel split-frustum shadow mapping or cascading shadow maps.

There is another option: you can either use VSM or do a post-process blur on the shadow (requires two terrain passes or deferred pipeline.) If you blur the shadow enough the aliasing wont be so apparent.

From the series of screenshots you posted, it looks to me as if the big problem is when you zoom close-up into the scene. In that case, I recommend you take a look at a Shadow map texel focusing method described in Wimmer, Scherzer. Robust Shadow Mapping with Light Space Perspective Shadow Maps, which is available in ShaderX4. This method can be used even if you're not doing LiSPSM (and they work nicely in conjunction with TSM), and I would expect it to fix exactly these kind of problems where you zoom in to a close-up detail on the landscape.

NVidia has a slightly similar (but cheaper) technique to do shadow map focusing, see HardwareShadowMap demo in nVidia SDK 9.52.

A year or so ago I investigated a few methods of extending the refocusing method described by Wimmer and Scherzer. The idea was that at the expense of a bit more CPU power, I would calculate a very tight polyhedron for the shadow map projection, after which a 2D fitting inside a parallelogram would be performed to maximize the shadow map texel use. These last steps are optional, just doing a simple refocusing using the formula described in the article produces results very similar to the following screenshots:


Standard dumb shadowmapping. No refocusing. Click for a close-up.
The 2D overlay shows the shadowmap. The minimal tightened polyhedron that the viewer can actually see is drawn in bright blue. You can see that 98% of the texel area is just wasted on invisible parts of the scene.


The same view, but with refocusing based on Wimmer and Scherzer's polyhedron. Click for a close-up.
The idea is very simple, we've just zoomed the shadowmap to cover only the part of the scene that matters to the viewer. (In my application, I'm fitting a minimal parallelogram around the convex hull of the 2D projection of the shadow map polyhedron, so the shape of the projection looks a bit different in the images, but don't mind that.)

From the screenshots you posted, it looks like you aren't doing this kind of focusing, so you should really investigate it. You have to remember though, that it doesn't help too much with the dueling frusta issue. For that, Cascaded Shadow Mapping seems to be the currently most prominent solution. For acne or peter panning, a shadowmapping scheme which allows you to filter, like Variance Shadow Maps or Exponential Shadow Maps might be worth the investigation. Note that this refocusing scheme, CSM and VSM could all be used together, they're separate ideas that don't contradict. (VSM and ESM are mutually exclusive though)
Hi,

You could try calculating static shadows for self-shadowing for the terrain (which could be slow and precise the first time) and then just use small shadow maps for the various objects.

I.e., if there is, say, a car on the landscape that needs to have a shadow cast on it, calculate a tight rectangle around it and then do shadowmapping just for that area (using frustum culling for the terrain of course).


-G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Matt Aufderheide:

I tried PSSM as I said. The 1024x1024 shadow map is used just for a single terrain node in those screenshots, not for the whole terrain. I am using some kind of adaptive shadow mapping, modifying the shadow map size for every terrain node, based on their distance from the camera.(More closer to the camera, the bigger shadow map.)

clb:

Your suggestions seem very logical to me, in my case those glitchy hills covering only a small portion of the shadow map and a large shadow map resolution gets wasted. Focusing only to the needed area was something I thought before but I failed to implement it. The first link you gave leads to an article in a book and I can't view it, in the NVIDIA site there is only the download link for the source code. Do you have any article or whitepaper explaining the theory of the shadow map focusing method?

Geometrian:

I think I will follow a mixed shadowing scheme as you describe, if I couldn't manage to correct shadow mapping. Recently I found an interesting article, which shows terrain shadowing with a so-called shadow height map: http://cg-korea.or.kr/Journal/2008/14-1/%5B2%5DReal-time%20Soft%20Shadowing%20of%20Dynamic%20Height%20Map.pdf This looks good, but my terrain has Geomipmapping and geomorphing implemented into it, making this method unefficient for me.(In every frame, recalculate the shadow height map for the 1025x1025 vertex grid, draw it into a texture, a huge performance hit.)
I'm sorry, I tried to look the paper up from Google, but can't really find if it's available anywhere for free. I think your best bet is to try to get your hand on ShaderX4 somewhere. I'll look a bit closer later on when I get home, but can't guarantee anything.
Quote:Original post by Geometrian
Hi,

You could try calculating static shadows for self-shadowing for the terrain (which could be slow and precise the first time) and then just use small shadow maps for the various objects.

I.e., if there is, say, a car on the landscape that needs to have a shadow cast on it, calculate a tight rectangle around it and then do shadowmapping just for that area (using frustum culling for the terrain of course).


-G


this solution seems wise. you can precalculate self-shadows for terrains :

- if your sun is static in the sky,
http://www.gamedev.net/reference/articles/article1817.asp
http://research.cs.queensu.ca/home/jstewart/papers/tvcg97.html

- if not,
http://ati.amd.com/developer/gdc/2007/Oat-Ambient_Aperture_Lighting-SI3D07.pdf

This topic is closed to new replies.

Advertisement