Sign in to follow this  

Detecting a shadow z-depth collision under terrain polygons

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

I may have been looking in the wrong places for this answer, but I cannot find anything that answers this question, if you have an answer that would be great!

 

I have just implemented shadow maps into my game.  They seem to work fine, however I have the issue where the z-depth calculation still considered a polygon of my terrain not shadowed when the light vector is positioned below the terrain, and I am looking to see if there is a simple solution to this.

 

For example, if the light vector in the world is placed underneath the terrain, and light upward towards the terrain, the z-depth buffer still collides with the polygon exactly, thus flagging the location is not shaded, as in normal lighting calculations.

 

My question is, is there a simply way to calculate that the ray is colliding with the polygon underneath it like in the shader?  Is there a way to tell if the light vector calculation hit a counter clockwise, or clockwise polygon?

 

One answer I was thinking was to make a large outside rendered box on the edge of the rendered world below the terrain, that way the light vector will collide with a polygon underneath the terrain at all times.  However this is a problem since this does not help with terrain on the edge that just ends, it would be tough to render a vertical wall slice for each polygon terrain just for these calculations.

 

Another method I was thinking of was re-render the entire terrain but at a slightly lower height, that way it would hit the lower terrain before the upper terrain, but that would be massively un-optimized and not a perfect solution. 

 

Again thanks for any help!

Share this post


Link to post
Share on other sites

I'm not sure if this is the answer you are looking for but typically, when doing the lighting calculations you'll do a dot product between the light direction and the surface normal and if the surface isn't facing the light, the light doesn't affect the surface (or pixel / sample). In this case, the shadow calculations aren't necessary even. So, shadow map needs to be calculated for light facing pixels only. 

 

Typically you should use triangle culling to eliminate triangles which are not facing the viewer, unless the object requires 2 sided rendering. The triangle culling should solve the problem of light under ground. Well, I'm not sure why to place a light source underground in the first place :)

 

I'm not sure if I understand the question 100% correctly, you want an underground light not to light the terrain or to light the terrain?

 

Cheers!

Share this post


Link to post
Share on other sites

Thanks, when I woke up this morning I had that realization that the dot product of the normal was what i was looking for, I have been doing to many crazy matrix calculation in my head I ignored the simpler solution :)

 

The issue with underground lighting is that even if the light is above the horizontal plane, there are still exposed polygons past the edges of the world where the light still shines underneath, the terrain at the edges of the world are not "capped" since there is no reason to since the player can never see in that direction.  So for my orthogonal shadow map, I render the scene starting outside the entire terrain world, and look in.  Hope that makes sense!

Share this post


Link to post
Share on other sites

Yeah ok I figure - some kind of capping would be needed for the lower light angles. The dot product won't fix all the issues either since triangles can face the under horizon light source. Rendering the geometry 2-sided would fix that. 

 

Cheers!

Share this post


Link to post
Share on other sites

This topic is 1194 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.

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