I'm trying to create a front/back material system.
I have this code for check if a face is in front or back to the camera:
i calculate the parameter in the vertex shader.
with(in pseudo code):
vec3 transformedNormal = uNMatrix * aVertexNormal;// in the vertex shader uNMatrix is the inverse word matrix
float Dir = dot(transformedNormal,CameraModelPosition);//in the pixelShader
//then i do this test in the fragment shader:
if(Dir > (CameraModelPosition.z)-DELTA){
Out.Color......= vector4(ColorFront.xyz,1.0);
}
else {
Out.color ...... = vector4(ColorBack.xyz,1.0);
}
and all works fine with big DELTAs , but how must be big the Delta? is correct the inserting of CameraModelPosition in the test of Dir?
my problem is solved if there is a mathematical formula for do this.
There is the FACE params in hlsl , i not remember fine, but is related to the winding order and that is bad for my problem.
i i specify that i'm not interested the winding order of the triangles , i would only know if a face is a front face or a back face to the camera.
I would use this for example in a two face (with front color and back color for example) , if i look at it when is in front of the camera position display a color(the front color) and if i rotate the camera of 180 degree show the back color
thanks.
Thanks.
