Sign in to follow this  
sobeit

OpenGL problems with shadow mapping(frontface culling, depth texture)

Recommended Posts

I'm trying to implement Variance Shadow Mapping. As I searched around I found many sites mentioned that frontface culling could reduce self-shadowing artifacts, but I failed to generate shadow map whenever I turned on frontface culling, and I think it's reasonable, because all the front facing triangle would be culled out. I mean let's imagine your eyes are camera and there's a counter-clock winding(front facing) triangle in front of you, then you do a frontface culling and throw the triangle away, now how could you get the depth of the back face of that triangle? Could someone explain this to me?

 

another question is: when I render depth to texture, OpenGL would convert x and y from normal device coordinate to texture coordinate(from [-1, 1] to [0, 1]), does the same goes to z axis?

Share this post


Link to post
Share on other sites

 

then you do a frontface culling and throw the triangle away, now how could you get the depth of the back face of that triangle? Could someone explain this to me?

You do not disable culling, just redefine what is front face, wheather it clockwise or , counter clockwise.

Just switch the front face identification by winding, this will render the actual "backfaces" now front faces and not render the actual "frontfaces" now backfaces. Do not disable culling, reverse it for the front face, and keep culling backface. Rememeber that vertex attributes such as normals will be bogus by this, so stick to only position and rasterized depth and such.

Edited by JohnnyCode

Share this post


Link to post
Share on other sites

This article disusses various shadow mapping techniques and concludes that front-face culling is as good as any.

 

Front-face culling (with back-face culling disabled) renders the back-faces, which creates essentially the same shadows but eliminates some artifacts. However, as discussed in that article, if you have objects with no back-faces (billboards, alpha-blended foliage, etc. - objects with no back-faces), some objects will not cast shadows.

 

how could you get the depth of the back face of that triangle?

 

 

You don't. You render the back-faces to get the depth of the rear of the object (ONLY if it has rear-facing triangles.) Think of front-face culling / back-face rendering as, e.g., rendering the rear half of a sphere. You get the same shadow.

Edited by Buckeye

Share this post


Link to post
Share on other sites

Thank you guys, I think I got it. Front face culling would fail shadow map generation for flat objects with no thickness.

anyone know answers of my second question?

Edited by sobeit

Share this post


Link to post
Share on other sites

When the shadow map texture is being generated, the depth is (normally) set to pos.z/pos.w (homogeneous depth).

Thank you Buckeye

I wrote gl_FragCoord.z to texture and it ranges for 0 to 1.

Edited by sobeit

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