Textures: Front Face Only

I’m a developer of CAD software. A customer has requested that texture mapping be restricted to the front faces of polygons. I can’t find that OpenGL supports an easy way to achieve that, like it does for lighting.

The solution I’ve thought of is: turn texturing on, cull back faces, render; turn texturing off, cull front faces, render again; swap. I really wish there were a simpler, faster approach. If you know of one, let me know. The answer has proved to be google-resistant, at least with the search terms I’ve thought of.

Also, if anyone can comment on whether my customer’s request seems like a common one (that is, consistent with what is available in other software), I’d appreciate it.

If you’re using shaders, you can always follow different paths in the fragment shader based on the built-in gl_FrontFacing variable.


Hmmm. Interesting. My first reaction is that it wouldn’t be worth the effort, and wouldn’t run much faster than my original two-pass method.

I have similar customer requirements, and the two pass method you described is what I’ve always used.

Me too. Go for two passes. If you don’t already, use VBOs for uploading vertex data. The two passes won’t be slower than a single pass method (if it existed). About the simplicity: managing frontface texturing in one pass and backface lighting in another seems much simpler than mixing both things up in one pass, don’t you agree?


I also use the two pass method in one of my programs which renders thousands of 2D cards. It simplifies things a lot, and is fast with culling.

That depends on where your bottleneck is. If you have an enormous amount of geometry yet use a simple fragment shader (as is quite common for CAD), it may well be possible that the cost of processing geometry twice is higher than adding a simple conditional to the fragment shader. It also depends on the hardware used.

As for simplicity, if you’re using just a single fragment shader adding “if(gl_FrontFacing) {…} else {…}” to it is probably as simple as it gets. Certainly worth a try.