Jump to content
  • Advertisement
Sign in to follow this  
Gumgo

Easily/automatically flip normals?

This topic is 3197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!