Если угол конуса превышает 90 градусов, угловое затухание моего прожектора работает неправильно. От 0,1 до 90 затухание плавное от центра конуса к краям, но от 90 до 179,9 края становятся все резче и резче.
Вот мой код затухания:
uniform vec3 lightPosition; // Light's position
uniform vec3 lightDirection; // Light's direction
uniform float lightAngleCos: // Cosine of the half of the cone angle
uniform float lightRange: // Light's range
// Get the light vector
vec3 pixelToLight = lightPosition - position.xyz;
vec3 normPTL = normalize(pixelToLight);
// Get the dot product between the light direction and the light vector
float rho = dot(normPTL, -lightDirection);
if(rho > lightAngleCos)
{
float dif = 1.0 - lightAngleCos;
float angularAttenuation = clamp((rho - lightAngleCos) / dif, 0.0, 1.0);
float radialAttenuation = 1.0 - clamp(length(pixelToLight) / (lightRange), 0.0, 1.0);
float attenuation = angularAttenuation * radialAttenuation;
// Apply attenuation
out_color = color * attenuation;
}
lightDirection
, от света или к свету (по вашим расчетам кажется, что к свету, но это было бы странно, так что просто для уверенности)? - person Christian Rau   schedule 05.07.2013