PDA

View Full Version : shader front/back face and ccw ,cw



giuseppe500
04-29-2011, 07:20 AM
I created a front/back shader and I use two pass one front and one back with the correct culling.
The problem is that i find some models(sketchup) that i suppose have both ccw meshes and cw meshes.
In this case I get wrong results.
Is possible to convert all faces in cw or in ccw?
How?
thanks.
ps.
I think that the trick is the sign of the normal, may be?
If the normal is positive then i'm in a cw(or ccw , i don't know) else if the normal is negative in ccw.
Then in my importer i have a method that creates the triangles, i can test if the normal is negative ,then rebuilt the indexes else ok and i does nothing else that create the triangle wit the existing indexes.
But how i test if the normal go outside (positive?) or inside (negative?) with the opengl axis system.

sorry for my english

thanks

BionicBytes
04-29-2011, 03:53 PM
I think the answer is to pick a convention and ensure all faces use the same.

_x57_
05-02-2011, 05:21 AM
Depending on your shader you may use the glsl built-in variable gl_FrontFacing and reduce to a one-pass shader.

You can swap the OpenGL interpretation of front and back with glFrontFace(GL_CW) or GL_CCW.