• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Sorting Polys for Blending

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

## Recommended Posts

How do I sort polygons so it will blend perfectly. Is it...like :: Draw all non-blending polys on screen Enable Depth Testing Draw all blending polys on screen from farthest to nearest ? is it true ? How do I sort the polys (from diffrent camera position) ? Thanks in advance

##### Share on other sites
Yeah, that should work.

Sort the polys by their z depth in camera space. You''ll likely need to use some variant of a billboarding technique or transform the polys yourself.

Depending on what the polys are, you may be able to skip it, tho. I have had no problem with blending in the wrong order unless I really look hard. But then, I''m just blending smoke and fire, so they''re generally not very order dependent.

##### Share on other sites
No, it won''t work. Do it like that:

Enable Depth Testing
Enable depth writes
Draw all non-blending polys on screen
Disable depth writes
Draw all blending polys on screen from farthest to nearest
- AH

##### Share on other sites
How do I sort polys from farthest to nearest ? Should I get the Projection and Modelview Matrix, multiply it and get the transformed coordinates for every vertics. And calculate the distance of each vertex to the camera position ?

I''m rather dumb about this thing, can someone tell me how to do this. Because polygons are 3 dimensional objects and one vertex could be the farthest vertex and the other could be the nearest vertex ? Should I make an average distance of every triangle (from its Vertics) to the camera ?

Oh well.. any good link for a nice tutorial ?

##### Share on other sites
There are several different methods, you could just take the average of the 3 vertices. Or the nearest one to the camera. Or the farthest. It won''t make much difference, if your faces are small. Just be sure to be consistent (eg. don''t just take the first vertex of a face, you''ll get unconsistent ordering and things will flicker).

- AH

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 10
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634148
• Total Posts
3015794
×