tags:

views:

114

answers:

1

I'm tinkering with an open source project that uses OpenGL for rendering in 3D. In the construction of the materials I see code like this:

// set ambient material reflectance
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mAmbient);

In other examples, this is used:

glMaterialfv(GL_FRONT, GL_AMBIENT, mAmbient);

So my question is, what is the difference here? Under what circumstances would it look different and, if my volume is enclosed with all normals pointing outwards, is there any performance difference?

+2  A: 

One sets the material for front and back faces, the other, just front faces. If you culling back faces, it's not going to really matter. If you're not culling back faces, well, you'll see the material on the front face only.

If you're enclosing a volume, you probably won't directly see the back faces - the only way you would is if the camera was inside the volume. If it's outside, then you'll never see the back faces, and there's little point to rendering them. (Which is why in many games, if you force the camera into an object, it'll look like all the polygons are 1 sided: that's back face culling) OpenGL just has the ability to set different properties for the front and the back faces of a triangle/quad/etc.

Thanatos
Ok makes sense. On the performance point, does back culling use fewer resources/improve peformance? And if back culling is already enabled (I think it is, but have to find that bit of the code) then does it matter whether I specify `GL_FRONT_AND_BACK` or just `GL_FRONT`?
Drew Noakes
From the standpoint of the final rendering, no - if back faces are culled (and thus not draw) it shouldn't matter what material is applied to them. It may, however, be faster to only call `GL_FRONT`, as OGL would then only have to change the part of its state related to the front faces, and not the back faces.
Thanatos