View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Multiple Lights, adding dot product?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1OmarShehata  Members

Posted 16 October 2012 - 12:01 PM

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).

### #2Butabee  Members

Posted 16 October 2012 - 03:51 PM

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);

### #3L. Spiro  Members

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:
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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.