In back face culling you may either use the face normals to see if the face is pointing away from the camera of you may do some technique with if the triangle is drawn clock wise or counter clock wise.
I am confused about this technique with the clockwise. It seems like with this method, the ordering of the vertex data that gets sent to the graphics card decides whether it is facing towards or away from the camera. I don't see how this makes sense because the camera can be looking in any direction, it's as if the vertex data would have to change based on the camera position and that is obviously not done on the CPU.
How can I understand this?
This is one triangle viewed from opposite sides:
3 points in 3D space are defining a triangle. In addition, if those points are ordered (like here) they are also determining two sides (faces) of a triangle : clockwise and counter-clockwise (they are determined by the order clock put inside a face would point its vertices)
In above example triangle is textured counter-clockwise
Now imagine this triangle is an element of a dice:
If you roll the dice (or rotate camera around it) our triangle from CCW becomes CW and we don't want it to be textured any more.
This dice would be in fact built out of 12 such triangles and if we order them properly we will be texturing only 6 that are facing camera at a time.
I'll show you this on an example quad:
(0,0)-------(1,0)
| |
| X |
| |
(0,1)-------(1,1)
Let's assume we are starting at (0,0)
. Now, if you wind-up (pass) the vertices in "clockwise" order, the next ones would be (1,0)
, (1,1)
and (0,1)
. (1,0)
lays more or less on 2 o'clock, (1,1)
is 4, and so on.
Thus the data in GPU memory: 0,0, 1,0, 1,1, 0,1
.
When you correlate the windup direction with your setting, you can easily distinguish what's "front" and "back" - to imagine that better, you could draw it on something transparent, then look from the other side - the wind-up direction would be reversed.
So the specification of wind-up direction is merely to tell the GPU which side is front, and which one is back, as it cannot do it by itself - both sides of a triangle are equally good, and the normal vector of given polygon can either be N
or -N
. However, GPU can verify which of them is aligned with proper wind-up order.
Chapter 2 of The (Old) Red Book has some nice explanation regarding OpenGL specific stuff, that's still pretty relevant today.
That's exactly the point: the vertices order doesn't have to do with camera orientation initially, when you create/draw the face! Note that a camera is merely a transform, not something by itself recognized by openGL.
So, when rendering, after you'll have 'watched' through the camera, openGL simply checks (if culling is enabled) the new order of the face vertices, now according to the new orientation (after all transformations have been applied), to display the face or not.
来源:https://stackoverflow.com/questions/15041517/what-is-a-clockwise-face-in-opengl