Jump to content
  • Advertisement
Sign in to follow this  

Self shadowing polygon seems

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

Hello everyone, I recently implemented shadow mapping in my engine and im trying to get it too look just right. When I added a sphere to the scene I noticed there where seams in the self shadowing along the polygons of the underlying mesh and it was not the smooth self shadowing I was expecting for a sphere. I didn’t really notice this before because I was using more complex models with more dense geometry. here is a picture of what i'm talking about


Im not sure why this would be the case I would think there should be a nice smooth line on the part of the sphere that is in shadow. it must be a problem with something in my shaders here is how I do the shadowing.

Vert Shader:

ProjShadow = TextureMatrix * WorldMatrix * in_Position;

Frag Shader:

float depth = textureProj(ShadowMap, ProjShadow).x;
float R = ProjShadow.p / ProjShadow.q;
R += 0.0005;
float shadowValue = (R <= depth) ? 1.0 : 0.0;

If anyone knows what I am doing wrong and could help me out I would really appreciate it.

Thanks, David Edited by Davidtse

Share this post

Link to post
Share on other sites
This kind of self shadowing (when the polygons are backfacing relatively to the light) shouldn't be handled with shadow mapping. This should be handled by the standard lighting, which you doesn't seem to have yet.

Simply put: even if there is no shadowing at all, this kind of self shadowing is handled by the simplest lighting models "by default".

Nevertheless, there will be this self shadowing artefact accidentally with shadow mapping. This can be handled usually in two ways: if your meshes are closed, then simply don't render backfacing triangles to the shadow map.
Adding a shadow bias value. Which you seem to do (R += 0.0005), maybe it's just not a good value. Maybe you need a negative value.
If you add this bias, you won't see the self shadowing. Because as I said earlier, you need to handle that with your lighting model.

EDIT: I say "you shouldn't" because you won't be able to solve this kind of self shadowing with shadow mapping (you'll always have this non smooth pattern) and you have to use lighting anyway. Edited by szecs

Share this post

Link to post
Share on other sites

How do you create the shadow map?

And well... you should use a "normal" shading, like phong shading, which will be smooth. Edited by csisy

Share this post

Link to post
Share on other sites
A note to my previous post:
There was a bit misleading info, it was long ago when I did shadow mapping.
This part:
if your meshes are closed, then simply don't render backfacing triangles to the shadow map.[/quote]
can be true, but it's usually done the other way around: only backfacing triangles are rendered to the shadow map, so that there won't be artefacts on the light-facing triangles (where sometimes it's rendered shadowed, sometimes not shadowed, usually producing a striped pattern).

And another sidenote: shadows are usually "ambient shadows". Meaning the shadows are rendered (I'm not talking about the shadow map generation) with the ambient lighting component applied only to the scene. This is more realistic than adding a black, or faint black shadow overlay.

This also means that the light-backfacing self-shadowing artefacts may not be visible at all, because the shadowed and non-shadowed surfaces look the same (you won't see the striped pattern).

BUT: artefacts will be present on smooth surfaces on the border of light and shadow, so you always have to apply bias with shadow mapping.

So to sum it up: apply an appropriate bias value.

I hope that my post makes sense....

Share this post

Link to post
Share on other sites
OK I thought that this may just be a problem with shadow maps. I just thought when things are rendered to the shadow map the geometry would not effect the shadows. So bassicly you are saying that the self shadowing of the sphere is dependent on how dense the mesh is? I have the bias set to fix alot of the acne on the shadows already and already backface cull when rendering to the shadow map. I do have blinn-phong lighting implemented(not enabled in the screenshot), I was just wondering why the self shadowing was based on the polygons of the mesh. The regular Lighting does cover up and fix most of the self shadowing on the sphere but I can still see some of the sharp self shadowing from the shadow maps under the lighting. I dont think the problem is the bias because the line is the along the polygon edges and any bias value I put only effects the line but its always long the lines of the polygons of the mesh.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!