Skip to main content
gamedev.net
🔒 Locked

painter's algorithm not working

Started by fsb_ Apr 18, 2001 at 11:11 PM 6 replies 500+ views
Original Post
fsb_
fsb_
im trying to render a simple cube composed of 12 triangles. i get the average z of each polygon, then sort these values and draw the polygons in that order. im am not using backface culling (because i want to see if the sort algo works, and if the backfaces were gone, then i couldnt do that.) i wind up with a considerable number of weird occurances where the wrong polygon is drawn first. i have also tried sorting by the minumum z or maximum z of the polygon. is painter''s algo capable of handling a cube? if so, what am i doing wrong? if not, what is a good way to do visibility determination. by good i mean simple (im not too concerned with speed just yet.) it must also be able to handle chancing objects (so bsps are out.) thanx. fsb_
LilBudyWizer
LilBudyWizer
If the sign of the dot product of the view vector and the polygons normal is negative then it faces away from you.
Keys to success: Ability, ambition and opportunity.
fsb_
fsb_
yes. i am aware of that. the idea was to not use backface culling yet untill i know that the painter''s algo is working!


thanks for trying anyway though.
Mikey
Mikey
That''s the problem with Z-sorting your triangles based on a single point. Whichever point you choose to sort by, you''re more than likely going to end up with ordering errors. Even if you could find a method that works for a cube, in the more general case you will stil get errors (eg if 2 triangles intersect, you''ll get errors whichever way you order them).

The only way to be really sure about the ordering is to use a z-buffer, but I take it you don''t want to do it that way or you wouldn''t be trying the painter''s algorithm?

Another option could be to split triangles that intersect along all axes to form mutually exclusive triangles. Or if you''re objects are always convex, you could pre-order the faces. I seem to remember a theory from a long time ago that said that convex objects could always be preordered so that rendering the faces in that order would always be correct. Can''t remember any algorithms for calcualting the order though (and I think it relies on backface culling as well).

Sorry I don''t have any more useful suggestions ...

Mike.
fleejay
fleejay
How about considering the highest or lowest z-value instead of the average one??

---

Fleejay
---Fleejay
Mikey
Mikey
As he mentioned in the original post, he''s already tried min and max z values and still gets the errors.

In the case when triangles are non-intersecting, I think sorting by min z will always work (correct me if I''m wrong). But in the case of intersecting triangles you can''t find any point to sort by which will always be correct. In the case of a cube, all triangles intersect other traingles at the edges (i.e will give the same z value). So depending on how the sort works (<= or <) you will end up rendering either one or the other first. If it looks correct from one side, then it will look incorrect from the other.
fsb_
fsb_
problem solved: i just wrote a z-buffer instead.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.