OpenGL Standard Lighting Question

Hi,

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

  1. Method: Render the object as usual

  2. 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?

Thanks a lot.

Markus

Is the object you are rendering textured? If so, what you see is expected as multiple passes can exceed the standard 0…1 range.

Yes, it is textured. Could you explain why this makes a difference, please?

I set the texture environment to GL_MODULATE. I don’t see where the math is different as:

ambienttexture+diffusetexture=(ambient+diffuse)*texture

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?

There’s also the light model’s ambient light color. Make sure you set the global ambient to zero for the second pass.

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, …)

Yes you are correct.

Pass one is:
clamp(ambient+diffuse)*texture

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)

Originally posted by memfr0b:
[b]There’s also the light model’s ambient light color. Make sure you set the global ambient to zero for the second pass.

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, …)[/b]
Good point. Forgot to write that I already took care about that. Danke aus Pankow :slight_smile:

Thank you both for your replies.