Sign in to follow this  

Sorting front-to-back

This topic is 2666 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'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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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