Fixing a spotlight shader in glsl

Hello,

I’m having some troubles with my math that I would like a quick help on.
My goal is to have a spotlight that only has light from a customizable angle to another customizable angle, for example from 0 to 90 degrees.
Though my shader seens to be duplicating this angles, like if it is performing on both positive and negative side…

here is my shader code:

[quote]uniform float lightInt;
uniform vec2 lightLocation;
uniform vec3 lightColor;
uniform float lightType;

void main() {
float distance = length(lightLocation - gl_FragCoord.xy);
float attenuation = lightInt / distance;
vec4 color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3) * 10) * vec4(lightColor * lightInt, 1);

color = vec4(0, 0, 0, 0);
float h = distance;
float x = lightLocation.x - gl_FragCoord.x;

float angle = degrees(acos(x / h));
if (angle >= 0 && angle <= 90) {
	color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3) * 10) * vec4(lightColor * lightInt, 1);
}
gl_FragColor = color;

}
[/quote]
this is how it looks,

http://www.joaolourenco.net/light.png

I guess there is something wrong on the math… don’t know what though…

Thank you for your time, Joaogl.