Jump to content
  • Advertisement
Sign in to follow this  
daniel_i_l

depthtest only one side

This topic is 4482 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 found a great way (in my opinion) to render tree shadows - I drew a black picture of the tree on the ground and then disabled depth testing, that means that the terrain wont cut through the trees: Image hosting by Photobucket The problem is that also the bottom of the trees go through the terrain and so if the trees are on a hill, the shadows on the far side of the hill can be seen from the front of the hill: Image hosting by Photobucket How can this be fixed? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
you may need to use the stencil buffer, so that stuff only gets drawn where shadows actually are drawn.

I never got it to work in my engine thou.. but it didn't matter since it was a RTS :D

Share this post


Link to post
Share on other sites
Anyone? And isn't there a way to do it without the stencil buffer? For example, is it possible to color the texture on only one side, or make the side oppisite the normal not show up?
Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sort the terrain polygons and tree shadows by depth (distance from camera)
draw far objects first
this way, if a hill is in front of some shadows, it gets drawn on top of them.

Share this post


Link to post
Share on other sites
Quote:
Original post by daniel_i_l
Anyone? And isn't there a way to do it without the stencil buffer? For example, is it possible to color the texture on only one side, or make the side oppisite the normal not show up?
Thanks.

No, it's not possible. That's what happens when you disable the depth buffer. You have a couple of other options, but I don't think you're going to like them.

As the AP above mentioned, you can simply sort *all* polygons (the trees and the terrain) yourself. This might fix your problem, but it won't be perfect where the shadow polygons intersect the terrain. Sorting by polygon means using a point on the polygon (usually the midpoint) to determine which one to draw first. In an overlapping situation, this is a never-win situation. Even if you did implement it, the performance cost of sorting would be too slow and there is no way you could render the same number of polygons that you have now at the same FPS.

As for the other option, I presume you are drawing your shadows "straight out" -- as in the quad's vertices all have the same Y value? You could adjust the Y vertex of the shadow polygon by checking the height value of the terrain at that X,Z location, so the shadow polygon would never intersect the terrain. If you implemented this, you should re-enable depth testing, and then render: terrain -> tree shadows -> trees. That should hopefully give you the same effect you're looking for.

The only downfall with this method is if a tree is on flat ground but its shadow is on a hill -- the shadow polygon will be rendered floating above the ground. It might look bad, it might not. Depends on how close the camera gets to the ground, I guess.

You can work around that problem by either planning the locations of your trees well so that never happens, or splitting the shadow polygon into multiple pieces so it has less of a chance of being rendered at a noticable angle.

Share this post


Link to post
Share on other sites
So if I render the terrain and shadows seperatly there's no way to fix the problem if depth-testing is disabled? I don't want to enable the testing and split the shadows up cause thats exactly what I was trying to avoid with this method.
Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by bpoint
Even if you did implement it, the performance cost of sorting would be too slow and there is no way you could render the same number of polygons that you have now at the same FPS.


Hello Im the AP

Regarding Sorting,
you can do it, but you have to be clever, otherwise its going to be prohibitively expensive

I'd like to point out, that assuming your terrain is a heightfield, that the polygons in it are *Already Sorted* - the 2d grid structure itself contains order information. While details of distance to camera are not accounted, the rows and columns themselves have an order, and simply ensuring on a row by row basis that rows in front render first, should be enough to cover the overlapping hill problem.
So depending on what direction your camera is facing, you can simply transverse the heightfield in forward or reverse ordered triangle list, to change their effective rendering order. (there are special cases where you might need to do it in two sections with different fwd/rev order, but thats the general idea)

Additionally, since a heightfield is grid based, each tree can be located and tracked as being placed on a cell of this grid. by rendering each tree immediatly after we render its associated heightmap cell, we can apply the 'free' sorting of the heightmap to the trees as well.

Share this post


Link to post
Share on other sites
Thanks, and about the sorting you proposed - if I'm rendering the terrain as a quadtree were the rendering function is a recusive function that splits into 4 and does the render function on each part (which are split into 4) untill the function gets a "leaf" node which it renders. So to do the sorting would it work if every time I split a node into 4, I pass the new nodes to the render function in front to back order?
Thanks.

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!