I know there are a lot of topics asking about multiple lights, but I just have one simple question that I can't seem to find the answer to.
So in order to support multiple lights, I loop over the lights, and add together the intensities of each light source (and things like color etc..)
Now the only thing I'm having trouble with, is how to handle the dot product. I tried adding the dot products, but that just makes the two light sources sort of merge into each other, and when they are far apart the object is completely dark.
How do I handle the angle/dot product for multiple lights? (I'm not sure if code is needed to answer the question, if so I'll upload my shader code).
Thanks in advance!
2 replies to this topic
Sponsor:
#3 Crossbones+ - Reputation: 5188
Posted 16 October 2012 - 04:44 PM
The dot product is part of the lighting model.
Each lighting model should be done separately and then added together.
Taking a very basic Lambertian diffuse component on 2 lights, the proper way to combine them would be:
((Light0Color * max( Light0DotNormal, 0.0 )) + (Light1Color * max( Light1DotNormal, 0.0 ))) * DiffuseMaterial.
Simple pseudo-code would be:
L. Spiro
Each lighting model should be done separately and then added together.
Taking a very basic Lambertian diffuse component on 2 lights, the proper way to combine them would be:
((Light0Color * max( Light0DotNormal, 0.0 )) + (Light1Color * max( Light1DotNormal, 0.0 ))) * DiffuseMaterial.
Simple pseudo-code would be:
vec4 diffuseLight = vec4( 0.0, 0.0, 0.0, 0.0 );
for ( int I = 0; I < lights; I++ ) {
diffuseLight += lightingModel( I ); // Performs L·N as part of the lighting model for light index I.
}
finalColor.xyz = diffuseMaterial.xyz * diffuseLight.xyz;
L. Spiro
Edited by L. Spiro, 16 October 2012 - 04:45 PM.
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums






