Hello,
I’m trying to replicate fixed functionality for directional lighting in a fragment shader.
My opengl code uses glColor and glColorMaterial.
I have some double sided transparent faces (same color on the 2 sides).
It works well except when using gl_LightModel.ambient : in this case “transparent” faces are almost entirely opaque or opaque.
Here is the ambient calculation (fragment shader) :
vec4 Iamb = gl_LightModel.ambient * gl_FrontMaterial.ambient + gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
I have found this post Implementing GL_COLOR_MATERIAL in vertex shader. - OpenGL: Basic Coding - Khronos Forums :
the alpha component in the fixed function pipeline always comes from the diffuse part of the primary color’s lighting calculation (OpenGL 2.1 spec chapter 2.14 page 63)
So I added this in my code : Iamb.a = gl_FrontMaterial.diffuse.a;
And it works well.
I have also tried to add this at the end : gl_FragColor.a = gl_FrontMaterial.diffuse.a;
I gives another “good” result. (not the same as previously - the specular light is different not the transparency)
How to compute the alpha component to have the correct result (same as with the fixed functions) ?
Thanks.