I’m trying to combine OpenGL standard lighting with some quick’n dirty diffuse bump mapping effects. There is one thing that doesn’t work like I planned so I reduced the problem to this:
Given:
-OpenGL Standard Lighting
-1 enabled point light with ambient=diffuse, no specular
-one object
-no global ambient lighting
Method: Render the object as usual
Method: Render in 2 passes
1st:
light’s diffuse set to zero
2nd:
enable blending (GL_FUNC_ADD, GL_ONE, GL_ONE)
restore light’s diffuse color
set light’s ambient color to zero
Shouldn’t the output be the same? In Method 1 diffuse and ambient are added per vertex. Method 2 does it in the frame buffer. Why is the output of Method 2 much brighter than method 1?
I understand that computations in the framebuffer and in texture environments are done with lower precision but where is the mathematical reason for the framebuffer method to be a lot brighter?
Edit:
Err…after thinking about it: The reason is, that the (abient + diffuse) sum is clamped to 0…1 when given to the texture stage as primary color? So when abient=0.7 and diffuse=0.7 it is set to 1.0. So the first method writes 1.0texture to the framebuffer while second 1.4texture what is indeed a lot brighter. Did I get it right?
Pass two is:
clamp(ambient)*texture + clamp(diffuse)*texture
Note you will only get this problem in fixed function. When you use a shader you can do pass 1 without the clamp. (as long as you use a float interpolator to pass the color)