Hi there pros, I hope this hasn't been asked before, I searched for any ways of saying z-fighting I could think of and got nothing anyways I am making a basic rendering type deal for my first program (we prolly all do ) and I am having a few difficulties with the z-fighting of my polygons. basically I sort the table of polygons (sides of a rectangle) based on their center position's offset from the center of the rectangle, this seems to work fine except when I translate the cube it stops working... a link to the script is here: http://dl.dropbox.com/u/84093549/Links/Render.love
drag the mouse with no buttons pressed to move the shape, try rotating it in its current position and then moving it and rotating it again... only certain sides have issues
any help would be greatly appreciated
Rendering z-fighting
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Rendering z-fighting
Are you checking for back face?
(This code is used for triangles, but will still work with squares. Not sure if there's a way to make one for 4-sided polygons.)
Your polygon points would be specified in clockwise order. With the colored face on the clockwise side. And the backface being nothing drawn at all.
Code: Select all
function backface(x1, y1, x2, y2, x3, y3)
return not ((y3-y1)/(x3-x1) - (y2-y1)/(x2-x1) <= 0) ~= ((x1 <= x3) == (x1 > x2))
end
Your polygon points would be specified in clockwise order. With the colored face on the clockwise side. And the backface being nothing drawn at all.
Re: Rendering z-fighting
well all I do is sort the table so the back faces are at the beginning of the table and the front ones at the end (I sort it by the z and x cds to determine what's in front), then I render them one after the other and the front ones are drawn over the back ones
Re: Rendering z-fighting
When you put the 6 faces into your table, you put them in back to front with no rotations, and then rely on the painter's algorithm. Then, when you rotate them around, the original back surface in put in front of the original front surface (because you rotated it around to see the back of it), but then the draw order is the backface, then the other faces, and then the front face. The "Z" fighting is because your algorithm does nothing to render the faces in the correct order. Jasoco's solution is probably the best, i.e., don't rely on Painter's Algorithm. Check to see what direction the surface is facing, and only draw the ones that are facing you.
Who is online
Users browsing this forum: Semrush [Bot] and 3 guests