Easily/automatically flip normals?

Started by
0 comments, last by Zakwayda 14 years, 4 months ago
I've read that a somewhat effective approach to rendering (convex) transparent objects correctly is to first (disable z-write, of course, and then) cull the front faces and draw the object, then cull the back faces and draw it:

if (d->blendMode != BM_NONE) {
	renderState.setCullFace( GL_FRONT );
	glDrawRangeElements( GL_TRIANGLES, 0, d->vertCount-1, d->triCount*3, GL_UNSIGNED_INT, BUFFER_OFFSET( d->iboOffset ) );
}
renderState.setCullFace( GL_BACK );
glDrawRangeElements( GL_TRIANGLES, 0, d->vertCount-1, d->triCount*3, GL_UNSIGNED_INT, BUFFER_OFFSET( d->iboOffset ) );
However, this simply flips which side of the polygon is drawn - it doesn't affect the normals, so lighting will be "backwards" on the inside faces. This is especially an issue with objects use glAlphaFunc because most of the object looks like a normal opaque object, but the lighting would just be screwy looking. I'm guessing there isn't any like... er, glFlipNormals( true ), or glMultNormals( -1 ), is there, heh heh? Assuming not, any ideas of how to (somewhat) easily do this so that I won't have to redesign too much of my renderer? (Also, if you notice something strikingly wrong in my glDrawRangeElements calls, let me know, cause they crash for some reason. It probably isn't a problem with those lines though.)
Advertisement
I believe OpenGL supports two-sided lighting; you can find an example here. (I've never tried it myself, so I can't guarantee that it would give the results you're looking for.)

Just as a side note, Direct3D doesn't offer support for two-sided lighting (via the FFP, at least), so that's something you'd probably need to consider if your renderer is cross-API.

This topic is closed to new replies.

Advertisement