Sorting Renderables front to back

This topic is 3028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi there, I want to sort some 3d renderables front to back from the viewer every frame in a 3rd person RPG game engine. Each of the renderables is a large group of triangles and has a 3-d vector for its "center". The camera is a standard 3d camera with a view matrix. I read somewhere that the "easiest" way to sort these renderables is in view space because then I can just sort based on the z-component. If this is the case, how can I move them to view space for the purposes of the sort?

Share on other sites
Quote:
 If this is the case, how can I move them to view space for the purposes of the sort?
Just transform the object centers by the camera view matrix.

Since it's really only the z value that's of interest, you could also do the following:
float view_space_z = dot(object.center - camera.position, camera.forward);

Share on other sites
If you have a view matrix, then you just multiply the center by said matrix and it will be in view space. Alternatively, if you have a 3D camera, you can use the location and normalized forward vector directly without needing to transform the whole point. The distance is then d = dot(p,F) - dot(C,F), where 'p' is the test point, 'F' is the normalized forward vector, and 'C' is the camera location.

Are you sorting your renderables from front to back to reduce overdraw? Because sorting isn't technically necessary unless they're transparent. Plus large objects close together don't sort very well because they overlap, and the sort is based on a center point that doesn't represent the whole volume very well. Just some things to think about.

EDIT: Damn jyk and his ninjafoo :)

Share on other sites
Thanks guys, yeah the objects are a bunch of trees with leaves (the botanical variety ;)

1. 1
2. 2
frob
15
3. 3
4. 4
5. 5
Rutin
12

• 12
• 12
• 58
• 14
• 15
• Forum Statistics

• Total Topics
632119
• Total Posts
3004208

×