PDA

View Full Version : shadow map problem



Poons
10-31-2005, 06:05 AM
hi,

i have implemented shadow maps. but unfortunetaly some wired artefacts appear at the shadow border.

i'm already using glPolygonOffset but the problem won't dissappear.

here is a screenshot of the problem.

http://stud3.tuwien.ac.at/~e9925247/artefacts.JPG

maybe some of you have any suggestions. any help is kindly appreciated!

Zulfiqar Malik
10-31-2005, 08:18 AM
Unfortunately, there is no simple way of getting rid of these artifacts in shadow maps. One solution is to render back faces (from the light POV) during the shadow map generation pass. Because backfaces are, by default, shaded dark during the lighting pass (since they are facing away from the light) therefore the artifacts will be hardly noticable.

Racoon
10-31-2005, 08:27 AM
Maybe, try to change projection matrix light view in order to shadow source was at full window. (you can to use gluPerspective ())

dorbie
10-31-2005, 11:23 AM
These shadow maps will always have artifacts like this because most of the problem is caused by polygon subdivision, you could alter the geometric subdivision to help some, and you could help a bit using offset to fix any artifacts due to zbuffer precision, the best solution for this geometry though is to only modulate the direct lighting contribution. This means that for diffuse L.N (or whatever you use) the lighting result will tend to zero near the shadow silhouette. Then you can add ambient & other terms.

Poons
10-31-2005, 02:29 PM
So this artefacts are "ok" and not a coding error.

rendering back faces only is not possible because i will have to deal with open meshes. that was one of my reasons to choose shadow maps and not shadow volumes.

@racoon: i have tried this now, but it effects the result only slightly.

@dorbie: do you suggest using some sort of shader for lighting?

a idea which came just to my mind:
would it help if i would alter the vertices slightly in direction of the normal and use this modified geometry for generating the shadow map?

Racoon
10-31-2005, 04:23 PM
Had you taken everything out the depth texture resolution limit? Not grudge! :)

Poons
11-01-2005, 12:56 AM
this is was i have done:
set the near plane right before the shadow source
set the far plane right after the shadow source
set the fov so that the shadow source fills the whole shadow map.
set the perspective with gluPerspective

is there anything i have missed?

SirKnight
11-01-2005, 05:58 AM
I have this paper that shows how you can make two depth maps, one for front facing and one for backfacing triangles, then contruct a new depth map which contain the depth values between the first two and use this as your shadow map. This requires twice the renderings but gets rid of the problems with shadow acne and biasing issues. Last year John Carmack talked about doing this and how it works great. I've been meaning to try it but havn't gotten around to it yet.

-SirKnight

Poons
11-01-2005, 08:08 AM
that sounds good. Do you have a link where this paper can be found or the name of the paper, so i can google for it?

as speed is not so much of an issue this could solve my problem :)

Racoon
11-01-2005, 08:28 AM
- is there anything i have missed?
- this is right.

But as far as know the shadow is must be ideal for this geometry and depth tex. resolution 512x512 (and higher).

Baggio
11-01-2005, 09:41 AM
Originally posted by SirKnight:
I have this paper that shows how you can make two depth maps, one for front facing and one for backfacing triangles, then contruct a new depth map which contain the depth values between the first two and use this as your shadow map. This requires twice the renderings but gets rid of the problems with shadow acne and biasing issues. Last year John Carmack talked about doing this and how it works great. I've been meaning to try it but havn't gotten around to it yet.

-SirKnightCan you please share that paper or at least the name of the paper so we can google it?

spasi
11-01-2005, 09:49 AM
Shadow Mapping Based on Dual Depth Layers (http://www.google.com/search?hl=en&q=Shadow+Mapping+Based+on+Dual+Depth+Layers&btnG=Google+Search)

SirKnight
11-01-2005, 10:04 AM
Yeah that's it. I'm not at home so I couldn't go look what the name of the paper was and I couldn't remember it at all. :) I meant to go searching for it but I got carried away with something. Glad to see someone found it though. :)

-SirKnight

zed
11-01-2005, 10:27 AM
Originally posted by dorbie:
This means that for diffuse L.N (or whatever you use) the lighting result will tend to zero near the shadow silhouette. Then you can add ambient & other terms.thats quite good (and simple though i never thought of it before)
something like clamp(angle+0.9,0,1) maybe with pow
personally i just render the backsides into the depthmap + add a slight bias to the projection matrix (seems to get rid of most precision errors)

Poons
11-01-2005, 01:42 PM
Originally posted by spasi:
Shadow Mapping Based on Dual Depth Layers (http://www.google.com/search?hl=en&q=Shadow+Mapping+Based+on+Dual+Depth+Layers&btnG=Google+Search) thanks for the link! i read thru the paper and it sounds good. but i have some problems understanding how i get the second depth map (the one that stores the second nearest depth values in regard to the eye). can someone clarify this step? would there be a way without using shaders?

SirKnight
11-01-2005, 04:45 PM
Something like this?

shadowMap1.Bind();
glCullFace( GL_BACK );
RenderSceneFromLightPov();

shadowMap2.Bind();
glCullFace( GL_FRONT );
RenderSceneFromLightPov();

-SirKnight

Poons
11-01-2005, 10:48 PM
i think that works fine with closed geometry. but with open objects errors can occur, IMO. assume this case:


| |\
Eye-> | | \
| |__\the first object would only appear in one of the two maps.

SirKnight
11-02-2005, 05:04 AM
Models with holes will always cause probems in more areas than just shadow mapping. You should have closed models anyway. :D

-SirKnight

alkiem
11-02-2005, 05:46 AM
I implemented this dual depth pass and used the stencil buffer to consider only averaging when there are front and back faces. Basically, i render back faces in the first pass with increasing the stencil buffer. And in the second pass, i render front faces, considering pixels only where there were back faces (using stencil test). But in such case, only front faces won't cast shadows so your open objects could be a problem.
May be there is some solution using stencil buffer in a similar way. For example (just an idea), render front faces and increase stencil in first pass and in second pass, render back faces and average depth when stencil test passes. This doesn't work correctly, there is a problem with the depth test since you render front faces first, but maybe it is a way to investigate.

SirKnight
11-02-2005, 08:22 AM
That's an interesting idea of using the stencil buffer for trying to correct depth maps with an open model. I'll have to think about this some more. :D

-SirKnight

Poons
11-02-2005, 09:04 AM
Originally posted by SirKnight:
Models with holes will always cause probems in more areas than just shadow mapping. You should have closed models anyway. :D

-SirKnightthat's true. but unfortunetely it's not in my power :( to choose the models.

i will think over alkiem approach.

SirKnight
11-02-2005, 12:31 PM
Is there a good reason why an artist would make a model that's not closed other than not being a very good artist? Models with holes don't make sense to me and seeing them just signals poor artistry. I don't know, maybe there's a good reason to have them sometimes, I can't think of any.

-SirKnight

zed
11-02-2005, 02:08 PM
Originally posted by SirKnight:
Is there a good reason why an artist would make a model that's not closed double sided polygons eg a polygon with a fence texture on it

SirKnight
11-02-2005, 04:03 PM
Double sided polys like for leafs, hmmm I forgot about those things.

Anyway I was mainly meant typical models like characters, chairs, etc...

Poons
11-03-2005, 01:41 AM
Originally posted by SirKnight:
Is there a good reason why an artist would make a model that's not closed
-SirKnightThe models i have to deal with come partially from architecture where they model walls just as simple polygons.