Archived

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

polygon sorting

This topic is 5651 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 have a function which every frame sorts back to front some polygons(everything which has alpha - trees,grass,...).It does: 1)Loop through all polygons and compute distance from camera: dst=sqrt(pow(objPos.x-camPos.x, 2.0f)-pow(objPos.z-camPos.z, 2.0f)); 2)do a qsort based on the distance 3)refill the index buffer 4)render BUT it''s too slow. Doesn''t anybody know another more efficient way to do the same?

Share this post


Link to post
Share on other sites
You can optimize by sorting only the polygon which are in the view frustum..
What kinda algorithm that u use to sort the polygons ??
There are many ways to do so.. maybe you can search them out yourself.. my fave is the ray tracing method..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you could possibly get rid of the sqrt and sort based on squared distance...

Share this post


Link to post
Share on other sites
If all your objects are simple, concave objects (e.g. cones, spheres, cubes, walls etc.) then you can use the technique that my engine uses:

Instead of sorting the order of every polygon, sort the order of each object from back to front. This means there is alot less sorting to do, because each object is usually composed of many (maybe 1000s) of polygons. Then, for each object you render, you must render it twice - the first time render with front-face culling, so that only the back of your object gets rendered, the second time render with back-face culling so that only the front of your object gets rendered.

Even if your objects are too complex to use this method (e.g. some are convex) then you can still first sort by object, then sort by polygon. This is faster because each polygon only has to be sorted against polygons within the same object. This method assumes that none of your objects intersect each other.

If your objects intersect each other, then I cannot really think of any better method. Unless, you keep track of which objects that are intersecting, and in the times when they intersect, you "pretend" that the 2 objects are really just 1 object, and continue to use the method above.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you sorting individual polygons or models? Sorting by model can help. If the model geometry is pretty simple and you are backface culling then you needn''t sort individual polys within the model.

You could also try pre-sorting the models, make one list sorted by X and one by Z (in 3d world space, where Y is up). Given your orientation pick the list that best matches your needs, if looking along +Z ascend the Z sorted list, if looking along -X descend the X list. Finding your camera position within the list gives you the start point within the list to ascend or descend.

This all assumes the camera is essentialy moving in the flat XZ plane.

Whilst not an exact sort, especially when transparencies are placed very close to each other, this does work (I used it sucessfully to sort grass sprites in a commercial game).

Share this post


Link to post
Share on other sites
if your polygons are pretty much static, and form concave surfaces, try building a BSP tree. A simple tree can really boost performance by only rendering polygons within the view frustum..



Its my duty, to please that booty ! - John Shaft

Share this post


Link to post
Share on other sites