Archived

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

Alpha Textured Quad Sort Order

This topic is 5619 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 drawing a whole bunch of textured quads with alpha channels and I know I have to sort them from back to front. I''ve searched the forum and found people saying, "Yes, you need to sort the quads from back to front before drawing" but I''ve never seen anyone explaining the criteria or method used for this sort. Can someone expand on it for me?

Share this post


Link to post
Share on other sites
ok...try this...

1. select all the quads inside the camera frustum (do a frustum culling).
2. calculate center point of each quad. The center point is the center of the axis aligned box that can tight fit the quad.
3. calculate the distance between the center point of each quad to the camera position in world space. Save this as ''depth'' against each quad.
4. do a qsort on the list and sort all the quads based on the depth.
5. render the sorted list

(well the price you pay for this is that you cannot sort the quads based on the texture here, so a large number of texture state changes if the quads have different textures...)

does this help??

Share this post


Link to post
Share on other sites
Thanks for the reply. Don''t I need to worry about transforming the center points into camera space before doing the distance check?

I''m hoping to render 100 quads each using a seperate texture. Hope this doesn''t cause me grief!

Share this post


Link to post
Share on other sites
Some additions to the above:


A. Don''t go down to per-poly/per-quad sorts until you need to - if you have any form of higher level groupings of polys such as meshes, or objects etc, then first sort those bounding volumes. That will reduce the number of swaps the sort needs to peform.

B. Many things don''t actually require per-polygon alpha sorting, flag the ones which don''t and sort their objects rather than their polys.

C. A trick which will work for some meshes and help avoid any need for sorting:
- set culling to CW
- render mesh with alpha blending on and culling on
- set culling to CCW
- render mesh again

D. Rather than the distance from the camera to the quad centre, better is the distance along the camera vector which the centre falls (the projection of the object centre onto the camera vector). You can get this by taking the dot product of the normalised camera direction and the centre point of the object.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
I agree with ''S1CA'' on those points... calculating the distance along the camera look at vector is the better option... i just wanted to keep it simple...

Also you don''t need to transform the quad to camera space. If you do, then consider the transformed position of the quad as a vector and take the length; that will be distance. Or else you can project the transformed point on to the Z axis and take the distance, which is easily done by just taking the Z value of the quad center.

quote:

I''m hoping to render 100 quads each using a seperate texture. Hope this doesn''t cause me grief!



Please start worrying ab''t texture state changes...

Share this post


Link to post
Share on other sites