PDA

View Full Version : How to demonstrate a T-junction problem with OpenGL



tonylic
02-07-2014, 10:22 AM
Hi All:

I'm working on demonstrate the classic T-junction problem. So I create several rectangles in two rows like this:


glColor3f(1.0f, 0.0f, 0.0f);//red
for(int i=-50; i<50; i+=10)
{
glBegin(GL_QUADS);
glNormal3f(-1, 0,1);
glVertex3f(i, 20.0f, 0.0f);
glNormal3f(-1, 0,1);
glVertex3f(i+10, 20.0f, 0.0f);
glNormal3f(-1, 0,1);
glVertex3f(i+10, 0.0f, 0.0f);
glNormal3f(-1, 0, 1);
glVertex3f(i, 0.0f, 0.0f);
glEnd();
}

glColor3f(0.0f, 1.0f, 0.0f);//green
for(int i=-50; i<50; i+=6)
{
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glVertex3f(i, 0.0f, 0.0f);
glNormal3f(0, 0, 1);
glVertex3f(i+6, 0.0f, 0.0f);
glNormal3f(0, 0, 1);
glVertex3f(i+6, -20.0f, 0.0f);
glNormal3f(0, 0, 1);
glVertex3f(i, -20.0f, 0.0f);
glEnd();
}
The first row rectangles are 10*20 with normal vector (-1, 0, 1) and second row rectangles are 6*20 with normal vector (0, 0, 1). They share edges but vertices are not in the same coordinate. And I put the camera on (0, 0, 80) and a light on (0,0,10). Then I rotate it, I found some zig-zag between the red and greed edges, is it a T-junction artifact? I'm not sure, if not, please give me some hints about how to create the T-junction artifact. Thanks!!!

tonylic
02-07-2014, 10:26 AM
It seems like I'm not able to upload picture result. Hope anyone could understand what I mean

Brokenmind
02-07-2014, 11:08 AM
It seems in this forum, you can only link external sources after you made some posts. I couldn't do so in my first post either ;)

I printed your coordinates and can find nothing suspicious, apart from the face normal:
1. You don't need to set it before every vertex. It stays as long as no new normal is set.
2. It should be orthogonal to your triangle, and in the first loop, it clearly isn't. But this is not likely to be the problem you are looking for.
If you want, you can send me a screenshot via PN and I'll include it here.

Anyway, these effects can happen: If faces touch each others' edges very precisely, the depth testing is sometimes not accurate enough to determine which is in front of the other (z-fighting). But did I understand you correctly, you want to create these artefacts on purpose?

Dark Photon
02-07-2014, 06:52 PM
Yes, you have T-junctions:



glVertex3f(i , 20, 0);
glVertex3f(i+10, 20, 0);
glVertex3f(i+10, 0, 0);
glVertex3f(i , 0, 0);

glVertex3f(i , 0, 0);
glVertex3f(i+6, 0, 0);
glVertex3f(i+6, -20, 0);
glVertex3f(i , -20, 0);


Notice that your stride for the top (red) is x=+10, while the stride for the bottom (green) is x=+6.

A T-junction occurs when you have a triangle vertex occurring in the middle of the edge of another. For instance, below "T" is the vertex that causes a T-junction.



*
| \
| \
| \
| \
| \
| \
| \
| \
*---------T--*
| /
| /
| /
| /
| /
| /
| /
| /
| /
| /
| /
*


The problem with T-junctions is that due to precision issues, the vertex on the edge is not exactly on the edge, and depending on the computation that's done, you can end up with stray pixels or samples between the two triangles that don't actually get coverage (i.e. aren't filled, or are filled twice).

Also re the posting images issue... Yes, new users aren't allowed to post images until they've posted a few times -- this is to cut down on spam. Just put some spaces in the URL or something to get it posted and we'll fix it up for you.