Sorting front-to-back

Started by
2 comments, last by Dawoodoz 13 years, 7 months ago
I'm trying to find a way to sort my meshes in a front-to-back order.

I was thinking about calculating the distance from the meshes position to eye position.

But, imagine I have a scene with a house and a table inside the house. The distance from the table position to the eye might be lower than the distance from the house to the eye because the house position is based on the center of the house and the table might be in a room nearer to the eye position. So the house will be drawn first and will run on the pixel shader, and then the house will be drawn over the table... So I wasted time running the pixel shader in table's pixels that wont be visible...

Well, how can I make it work better? or is it ok to have some errors in sorting?
Advertisement
DX Documentation says that performing rendering process from front to back increases ZBuffer performance. It doesn't say anything the problem that you described.

I was thinking the same thing and I couldn't find any solution. So, what I do is sorting by .z component of view-space position of bonding-box' center point. It works well and no performance issue(s) occured until now.
There's no "hard", and "the impossible" takes just a little time.
Quote:Original post by Aqua Costa
Well, how can I make it work better? or is it ok to have some errors in sorting?


It's perfectly OK to not have perfect sorting, especially in cases like the one you describe. Sorting perfectly in such cases can easily be more expensive than drawing those few extra pixels.
If you have a case where the entire screen is unnecessarily redrawn multiple times, then you might want to look at ways to sort better, if you notice your game slowing down. For these small things you don't need to worry about it.
Subtract a bounding sphere's radius from the distance so that the house exterior is rendered before the items inside.
DrawDistance = MidpointDistance - Radius
Use progressive sorting that has a deadline in case that it takes quadratic time to sort everything when changing scene.

This topic is closed to new replies.

Advertisement