Dark lighting with multiple lights

I am working on using multiple lights. When I add more than one light the dark parts of the lighting become darker. What am I doing wrong? Here is the important part of my shader:

#version 120
uniform vec4 ulight1;
uniform vec4 ulight2;
uniform vec4 ulight3;
uniform vec4 ulight4;

varying vec4 v_color;
varying vec3 v_position;
varying vec3 v_normal;


vec3 ambient = vec3(0.2,0.2,0.2);
vec3 lightcolor = vec3(0.6,0.6,0.6);

vec3 phong() {
	vec3 nn = normalize(v_normal);
	vec3 dtl1 = ulight1.xyz-(v_position);
	vec3 dtl2 = ulight2.xyz-(v_position);
	vec3 dtl3 = ulight3.xyz-(v_position);
	vec3 dtl4 = ulight4.xyz-(v_position);
	float dis1 = length(dtl1);
	float dis2 = length(dtl2);
	float dis3 = length(dtl3);
	float dis4 = length(dtl4);
	float att1 = (1.0 / (1.0 + (dis1 * dis1)));
	float att2 = (1.0 / (1.0 + (dis2 * dis2)));
	float att3 = (1.0 / (1.0 + (dis3 * dis3)));
	float att4 = (1.0 / (1.0 + (dis4 * dis4)));
	float d1 = max(dot(nn,normalize(dtl1)),0.0);
	float d2 = max(dot(nn,normalize(dtl2)),0.0);
	float d3 = max(dot(nn,normalize(dtl3)),0.0);
	float d4 = max(dot(nn,normalize(dtl4)),0.0);
	vec3 lw1 = att1*(ambient+lightcolor*d1)*ulight1.w; // w of 0 = no light
	vec3 lw2 = att2*(ambient+lightcolor*d2)*ulight2.w;
	vec3 lw3 = att3*(ambient+lightcolor*d3)*ulight3.w;
	vec3 lw4 = att4*(ambient+lightcolor*d4)*ulight4.w;
	float ff = (-((ulight1.w+ulight2.w+ulight3.w+ulight4.w)-1))/2;// Increase ambient when no light
	vec3 final = vec3(ambient+ff);
	return lw1+lw2+lw3+lw4+final; //add together lights
}

Here are some screenshots.

One Light:

http://s15.postimage.org/w1riye2dz/before.png

Two Lights:

http://s15.postimage.org/vayssm00n/after.png

I think that the lights are further away from the “darkening” side you speak of.

As I see it, I’m standing in the z axis looking at the y axis right? if we look from the left this is what I imagine is happening:

y axis
|
| [light/s]
| >0 (camera)
| [surface]<-- dark side________
|____________________________________________________________________________________ z axis
|

I don’t know If you get what I mean. If I’m right, that’s a normal behavior, but if I’m wrong, then we’ll need to wait for anyone with more experience :slight_smile:
Could you provide the coords of the lights and that surface-object-thing? :slight_smile:

This chunk of code is my suspect.


float ff = (-((ulight1.w+ulight2.w+ulight3.w+ulight4.w)-1))/2;// Increase ambient when no light

If ulight1.w + ulight2.w + ulight3.w + ulight4.w > 1, then ff’s result will be a negative number, rather than a positive. Check these values if you can.

Oops. Removing that fixed it. That code was old and unnecessary anyway.