S

#### Shifty

##### Guest

Trying to make a 2d directional spotlight effect with a shader. Heres the SpotLight() function that does the lighting calc.

Fragment Shader: normal_map_lighting_test at line 80 : 'SpotLight'

Fragment Shader: normal_map_lighting_test at line 80 : ''

Yes! very informative thank you

Line 80 points to this line:

"vec3 NormalMap = texture2D(normalMap, v_vTexcoord).rgb;"

My expirence with GLSL debugging in GMS tells me that the actual error tends to occur on one of the lines immediately following the one stated in the compile error. However i just can't seem to see whats wrong.

Code:

```
vec3 SpotLight (in sampler2D normalMap, in vec3 LightPos, in vec4 LightColor, in vec3 ConeDirection) {
vec4 DiffuseColor = texture2D(gm_BaseTexture, v_vTexcoord);
vec3 NormalMap = texture2D(normalMap, v_vTexcoord).rgb;
NormalMap.g = 1.0 - NormalMap.g;
vec3 coneDirection = normalize(ConeDirection);
vec3 SurfaceToLight = normalize(LightPos);
float LightToSurfaceAngle = degrees(acos(dot(-SurfaceToLight, coneDirection)));
vec3 LightDir = vec3(LightPos.xy - (Fragcoord.xy / Resolution.xy), LightPos.z);
LightDir.x *= Resolution.x / Resolution.y;
float D = length(LightDir);
vec3 N = normalize(NormalMap * 2.0 - 1.0);
vec3 L = normalize(LightDir);
vec3 Diffuse = (LightColor.rgb * LightColor.a) * max(dot(N , L), 0.0);
vec3 Ambient = AmbientColor.rgb* AmbientColor.a;
if(LightToSurfaceAngle > ConeAngle)
{
Attenuation = 0.0;
} else {
float Attenuation = 1.0 / (Falloff.x + (Falloff.y*D) + (Falloff.z*D*D) );
}
vec3 Intensity = Ambient + Diffuse * Attenuation;
vec3 Color = DiffuseColor.rgb * Intensity;
return Color;
}
```

Heres the Main() of the shader so you can see how SpotLight() is being used.

Code:

```
void main()
{
LightPosition[0] = LightPos1;
LightPosition[1] = LightPos2;
vec4 DiffuseColor = texture2D(gm_BaseTexture, v_vTexcoord);
vec3 sum = vec3(0.0);
for(int i=0; i < NUMBER_LIGHTS; i++){
if (i == 0) {
sum += LightCalc(u_normals, LightPosition[i], LightColor);
}
else {
sum += SpotLight(u_normals, LightPosition[i], vec4(1.0, 0.3, 0.3, 1.0), ConeDirection);
}
}
gl_FragColor = vec4(sum, DiffuseColor.a);
}
```

Any advice on glsl es is welcome as well. Thanks for looking.