Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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.

  • You cannot reply to this topic
2 replies to this topic

#1 OmarShehata   Members   -  Reputation: 205

Like
0Likes
Like

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

Thanks in advance!

Sponsor:

#2 Butabee   Members   -  Reputation: 274

Like
1Likes
Like

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

#3 L. Spiro   Crossbones+   -  Reputation: 17891

Like
2Likes
Like

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.



PARTNERS