Hello everyone I’m facing a problem with setting a fixed (position) spot light. I don’t know, how to do it, because when I try something, the light moves a bit when I’m moving my camera. I want to move the light at a position of a lamp in my scene
I’ve got following in my vertex shader file
bulbLight.position = (VMatrix * vec4(0.16f, 1.04f, 0.35f, 1.0f)).xyz;
bulbLight.spotDirection = normalize((VMatrix * vec4(0.0f, 0.0f, -1.0f, 1.0f)).xyz);
and then I’ve got a following function to evaluate a lighting of the bulb … vertPosition and vertNormal is from vertex shader file:
//vs file
vertNormal = normalize(normalMatrix * vec4(normal, 0.0f)).xyz;
vertPosition = (VMatrix * MMatrix * vec4(position, 1.0f)).xyz;
//fs file
vec4 evalBulbLight(Light bulb, Material mat, vec3 vertNormal, vec3 vertPosition) {
vec3 result = vec3(0.0f);
vec3 L = normalize(bulb.position - vertPosition);
vec3 N = normalize(vertNormal);
vec3 V = normalize(-vertPosition);
float spotFactor = max(dot(-L, normalize(bulb.spotDirection)), 0.0f);
if(bulb.spotCosCutoff > spotFactor) {
return vec4(0.0f, 0.0f, 0.0f, 1.0f);
}
result += bulb.ambient * mat.ambient;
result += max(dot(L,N), 0.0f) * bulb.diffuse * mat.diffuse;
result += pow(max(dot(reflect(-L, N), V), 0.0f), mat.shininess) * bulb.specular * mat.specular;
float dst = distance(bulb.position, vertPosition);
float attenuationFactor = 1.0f / ( bulb.constantAttenuation +
bulb.linearAttenuation * dst +
bulb.quadraticAttenuation * (dst * dst) );
result *= attenuationFactor;
result *= pow(spotFactor, bulb.spotExponent);
result *= bulb.intensity;
return vec4(result, 1.0f);
}
What I am doing wrong? Maybe I shouldn’t multiply vectors by viewmatrix? But I also try modelmatrix … or modelLampMatrix … but nothing worked Could you give me some hint? Thank you very much