## IsCulled function question

Help
ggg
2006-04-13
2013-04-17
• ggg - 2006-04-13

Hi
After frustum back-face culling might directly use the z-component of the surface normal.
It is said the triangle is clipped when the normal is negtive.
But the following vincent code made me confused.I do not exactly know how you calculate the "sign"!
Would you like to give me a detail answer.Thanks!

IsCulled():

if (((x0 & 0xff000000) == 0 || (x0 & 0xff000000) == 0xff000000) &&
((y0 & 0xff000000) == 0 || (y0 & 0xff000000) == 0xff000000) &&
((z0 & 0xff000000) == 0 || (z0 & 0xff000000) == 0xff000000)) {
sign =
+ Round(x0) * (MulLong(Round(y1), Round(z2)) - MulLong(Round(z1), Round(y2)))
- Round(y0) * (MulLong(Round(x1), Round(z2)) - MulLong(Round(z1), Round(x2)))
+ Round(z0) * (MulLong(Round(x1), Round(y2)) - MulLong(Round(y1), Round(x2)));
} else {
sign =
+ Round(x0 >> 6) * (MulLong(Round(y1), Round(z2)) - MulLong(Round(z1), Round(y2)))
- Round(y0 >> 6) * (MulLong(Round(x1), Round(z2)) - MulLong(Round(z1), Round(x2)))
+ Round(z0 >> 6) * (MulLong(Round(x1), Round(y2)) - MulLong(Round(y1), Round(x2)));
}

Thanks and regards

• Hans-Martin Will - 2006-04-13

First you might want to check the latest version of the code (I posted an update 2 days ago).

Second, no, you cannot use the normal for culling; the normals set through the API are only used for lighting calculations, and with smooth shading, for example, it is not even clear what "the" surface normal would be (because you have 3 different ones in the corner). Therefore you need to calculate the orientation of surface normal in homogenous coordinates from the vertex coordinates, which is exactly what this determinant is doing.

You might want to read the corresponding section of the OpenGL spec. to get the details.

- HM

• ggg - 2006-04-19

Hi HM

It is said in the OpenGL1.5 spec:
"This determination is made by examining the sign of the area computed by equation 2.6 of section 2.14.1 .

If it is a polygon, then the selection is based on the sign of the (clipped or unclipped) polygon's signed area computed in window
coordinates."

So the polygon's signed area computed in window coordinates.
Is the "sign" equal to the surface normal you discribed?

I wonder how the flowing code come from:

sign =
+ (x0 >> 12) * (static_cast<I64>(y1 >> 12) * (z2 >> 12) - static_cast<I64>(z1 >> 12) * (y2 >> 12))
- (y0 >> 12) * (static_cast<I64>(x1 >> 12) * (z2 >> 12) - static_cast<I64>(z1 >> 12) * (x2 >> 12))
+ (z0 >> 12) * (static_cast<I64>(x1 >> 12) * (y2 >> 12) - static_cast<I64>(y1 >> 12) * (x2 >> 12));

sign =
+ x0 * (static_cast<I64>(y1) * z2 - static_cast<I64>(z1) * y2)
- y0 * (static_cast<I64>(x1) * z2 - static_cast<I64>(z1) * x2)
+ z0 * (static_cast<I64>(x1) * y2 - static_cast<I64>(y1) * x2);

You use the clip coordinates not the windows coordinate which the spec describe.
Maybe I should pick up a graphic book to read but I can not find the idea of your code!:(
Would you like to explain your code using clip coordinates in detail?
I just learn computor graphic not long ago.

Regards

• ggg - 2006-04-20

OK now!I have work out the formula!:)

No, thanks