##
I got results with directional light but I can’t see what is wrong with spot light.Do you know?thanks!

vertex shader—

uniform mat4x4 modelview;

uniform mat4x4 projection;

in vec3 a_vertex;

in vec3 a_normal;

in vec2 a_textureCoord0;

varying out vec2 textureCoord0;

varying out vec4 color;

//estruturas

struct tLight{

uniform vec4 position;

uniform vec4 ambient;

uniform vec4 diffuse;

uniform vec4 specular;

vec4 spotDirection;

float spotCutoff;

float spotCosCutoff;

float spotExpoent;

float constantAttenuation;

float linearAttenuation;

float quadraticAttenuation;

};

struct tMaterial{

uniform vec4 ambient;

uniform vec4 diffuse;

uniform vec4 specular;

uniform vec4 emissive;

uniform float shininess;

};

uniform struct tLight light0;

uniform struct tMaterial material;

void main(){

//vetor que armazenará os resultados finais da luz, inicialmente sem luz

vec4 finalColor = light0.ambient + material.ambient;

//transformando normal nas coordenadas do word -> eye

mat3x3 normalMatrix = mat3x3(modelview);

vec3 normal = normalMatrix * a_normal;

```
//transformação da posição do word -> eye
vec4 position = modelview * vec4(a_vertex,1.0);
vec3 lightPosition = (modelview * light0.position).xyz;
//vetores
vec3 lightVector = (lightPosition - position.xyz).xyz;
float dist = length(lightVector);
vec3 eye = -(position.xyz);
//cálculo do angulo do termo diffuso, modelo de luz (phong)
float lambertTerm = max(dot(normalize(normal),normalize(lightVector.xyz)),0.0);
//cálculo da atenuação
float attenuation = 1.0;
//se cos(ângulo) > 0 então superfíce está recebendo luz
if(lambertTerm > 0.0){
//a luz na superfície está dentro do cone spot ?
float spotEffect = dot(normalize(-lightVector),normalize(light0.spotDirection.xyz));
if(spotEffect > light0.spotCosCutoff){
//computa termo diffuso
finalColor += light0.diffuse * material.diffuse * lambertTerm;
//cálculos speculares
vec3 HV = eye + lightVector;
float NdotHV = max(dot(normalize(normal),normalize(HV)),0.0);
//computa termo specular
finalColor += light0.specular * material.specular * pow(NdotHV,material.shininess);
//computa atenuação
attenuation = spotEffect/(light0.constantAttenuation +
light0.linearAttenuation * dist +
light0.quadraticAttenuation * dist * dist);
}
}
finalColor *= attenuation;
color = finalColor;
gl_Position = projection * position;
textureCoord0 = a_textureCoord0;
```

## }

## frag shader

uniform sampler2D texture0;

in vec2 textureCoord0;

in vec4 color;

void main(){

vec4 texColor = texture2D(texture0,textureCoord0.st);

gl_FragColor = texColor * color;

}