sam_hawker

02-22-2017, 05:05 AM

In the absence of floating-point precision issues all faces can be classified as (a) front faces, (b) back faces and (c) faces which are viewed edge-on and therefore have zero area. Suppose I have a closed mesh and render all front faces in one pass and all back faces in a second pass. Any edge-on faces have zero area and should therefore not be rendered in either pass. In theory, for every pixel the number of front faces rendered should equal the number of back faces rendered. If I do this in OpenGL using GL_CULL_FACE then unfortunately this is not always the case for pixels close to triangle edges.

As far as I can tell, if a back face and a front face share an edge then any pixel which happens to land exactly on that edge should be considered either inside both triangles or outside both triangles. Presumably my problem therefore only occurs when I have a front face and a back face connected by one or more edge-on faces? In that case there is an edge on my back face which is theoretically co-linear with one on my front face when projected onto the viewing window. But I guess that because the projected extents of those edges are different they can become separated slightly due to a lack of precision?

Are there any practical ways to achieve the behaviour I am looking for? Failing that, is there a good way to quickly identify the affected pixels? I could count the number of front and back faces rendered in each pixel but for a sufficiently complex mesh I could (theoretically at least) have this kind of inconsistency occurring multiple times for a single pixel such that the count came out correct and I need to be able to identify these pixels too.

As far as I can tell, if a back face and a front face share an edge then any pixel which happens to land exactly on that edge should be considered either inside both triangles or outside both triangles. Presumably my problem therefore only occurs when I have a front face and a back face connected by one or more edge-on faces? In that case there is an edge on my back face which is theoretically co-linear with one on my front face when projected onto the viewing window. But I guess that because the projected extents of those edges are different they can become separated slightly due to a lack of precision?

Are there any practical ways to achieve the behaviour I am looking for? Failing that, is there a good way to quickly identify the affected pixels? I could count the number of front and back faces rendered in each pixel but for a sufficiently complex mesh I could (theoretically at least) have this kind of inconsistency occurring multiple times for a single pixel such that the count came out correct and I need to be able to identify these pixels too.