Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is a clockwise face in openGL

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?

like image 681
Dan Webster Avatar asked Feb 23 '13 14:02

Dan Webster


People also ask

Is OpenGL clockwise or counterclockwise?

Basically, your reasoning is slightly off when you say that OpenGL uses counter-clockwise by default. But for what? It is to determine what polygons are front - facing so that the polygons not visible are culled (not rendered).

How does face culling work?

Back-face culling is a method in computer graphics programming which determines whether a polygon of a graphical object is visible. If not visible, the polygon is "culled" from rendering process, which increases efficiency by reducing the number of polygons that the hardware has to draw.

What is the purpose of back face culling?

Backface culling is an important part of how a 3D engine performs visibility checks. Its purpose is to detect polygons that are invisible in a particular scene – that is, polygons that face away from the viewer.

Does OpenGL automatically cull?

By default, OpenGL expects counter-clockwise winding order for triangles that are facing forwards. With backface culling enabled, triangles facing the other direction will be automatically culled. This occurs before rasterization.


2 Answers

This is one triangle viewed from opposite sides:

clockwise vs counterclockwise

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:

ccw textured box

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.

like image 192
fsw Avatar answered Sep 22 '22 23:09

fsw


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.

like image 34
Bartek Banachewicz Avatar answered Sep 22 '22 23:09

Bartek Banachewicz