PDA

View Full Version : OpenGL Standard Lighting Question



muhkuh
12-02-2005, 02:07 AM
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

sqrt[-1]
12-02-2005, 03:04 AM
Is the object you are rendering textured? If so, what you see is expected as multiple passes can exceed the standard 0..1 range.

muhkuh
12-02-2005, 04:19 AM
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:

ambient*texture+diffuse*texture=(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.0*texture to the framebuffer while second 1.4*texture what is indeed a lot brighter. Did I get it right?

memfr0b
12-02-2005, 11:23 AM
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, ...)

sqrt[-1]
12-02-2005, 01:11 PM
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)

muhkuh
12-03-2005, 09:29 AM
Originally posted by memfr0b:
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, ...)Good point. Forgot to write that I already took care about that. Danke aus Pankow :-)

Thank you both for your replies.