I’m trying to replicate fixed functionality directional lighting in a vertex shader. I am also trying to make it behave as if GL_COLOR_MATERIAL was enabled with GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE. I was having trouble making the output match the fixed functionality exactly and I suspect that the problem was my use of gl_FrontLightModelProduct.sceneColor in the output color calculation.
The Orange Book states that gl_FrontLightModelProduct.sceneColor is equivalent to:
gl_FrontMaterial.emission + gl_FrontMaterial.ambient * gl_LightModel.ambient
So I have two questions:
-
I’ve observed that with GL_COLOR_MATERIAL glEnabled, gl_FrontMaterial.ambient does not track the vertex color. Instead I have to implement this in my shader by using gl_Color instead of gl_FrontMaterial.ambient (same goes for .diffuse). GL_COLOR_MATERIAL does not look like it has any effect on the materials available to the vertex shader. I guess this seems reasonable… is this correct or am I missing something?
-
Does this mean I can’t use gl_FrontLightModelProduct.sceneColor, and instead must always calculate it with “gl_FrontMaterial.emission + gl_Color * gl_LightModel.ambient” (or in my case, material emission is [0,0,0,0] so I can just drop that component from the equation)?
Using gl_Color instead of the material’s ambient and diffuse colors, and also not using gl_FLMP.sceneColor, produces precisely the same output as the fixed functionality – so it seems right. I just want to double check to make sure I’m not missing something. The Orange Book didn’t mention either of these things, I kind of had to wing it so confidence is low.
Thanks,
Jason