Multiple Lights, adding dot product?

Started by
1 comment, last by L. Spiro 11 years, 6 months ago
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!
Advertisement
What I'm doing in the engine I'm working on is calculating each different type of light value seperately... so like GI and diffuse...

Then I just add then together at the end in this form (lighta * basecolor) + (lightb * basecolor);
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:
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement