Jump to content
  • Advertisement


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


Sorting transparent polys

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

Hi. I am trying to figure out how to sort the transparent poly, so they can be ordered back to front, to ensure that they are rendered nicely. If someone knows any documents of any kind describe the problems here i would like some pointers to it. Trying to formulate my questions, I wound up describing how I think the things work, so I kind of need to know if I have it all wrong and/or there are any better ways to do what i am trying to do. 1. The Z now the value i need to sort after has to be some Z value in eye-coordinates. In the following I will just assume using an average Z for the poly, allthough i am aware that this will cause artifacts in some rare cases. Q: How does one calculate this Z value? My suggestion would be this: given our Perspective Matrix: [ x11 x12 x13 x14 ] M = [ x21 x22 x23 x24 ] [ x31 x32 x33 x34 ] [ x41 x42 x43 x44 ] And the point of which we want the Eye Z of: P = [ p1,p2,p3,1 ] Now the Z value transformed to eye coordinates should be Ztrans = x31 * p1 + x32 * p2 + x33 * p3 + x34 * 1 under the assumption that the bottom row of the matrix is 0,0,0,1. If its not, we divide the value obtained above by the w value calculated by: Wtrans = x41 * p1 + x42 * p2 + x43 * p3 + x44 * 1 Is All this correct? And are there any faster way to obtain this value? And what about correctly sorting the polys, so we can draw two polys that cut through each other? how is this considered?? And is it doable on an average machine today, if one wants real-time rendering? 2. Seeing that i need to sort all transparent polys, i seem to think that i need an intermediary array, into where i can queue up transparent polys for rendering, after the non-transparent parts have been rendered. So for each triangle i need to store: the material the point the normal the texture coords now since there is no way of telling which order my polys are going to be rendered in, i cannot guarantee that following polys have the same texture. Hence the need for me to set up material after rendering of each primitive. Thus follows, that instead of storing all the stuff above it would be just as good for me to store an pointer to a vertex-array, and an index into that array. that would give me less data to sort. Is this the right way to do it? Any ideas on how to do it in a better more general way? Thanks for reading! Jonas

Share this post

Link to post
Share on other sites
Several solutions exist, here''s just my opinion:

You are on the right track. Arrange your data in a way that you pass all primitives to be rendered to a clever holy data structure that sorts these primitives by material for solid primitives (see keyword shade tree) and z for transparent surfaces. Personally I dont care about triangles that cut though each other, I just make sure that complete meshes are properly depth sorted, but that depends on your scenery. The distance mesh<->origin to camera is a easy to compute and anyway needed for various tasks, the depth sort of all transparent primitives might be too expensive and should only be done if rough transformations before indicated the need.

- thomas

Share this post

Link to post
Share on other sites
Another way to think of the Z value:

A dot product projection...

vector u = point_to_get_z_for - camera_position;
vector v = Normalise( camera_direction );
float z = DotProduct( u, v );

You''re projecting the point onto the view direction vector (i.e. how far along that vector the point lies).

The normalisation would obviously only be done once for a scene.

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!