如何将点光源转换为 oval/ellipse?
How do I convert my point light into an oval/ellipse?
我希望通过具有可以具有不同 x 和 y 值的 vec2 半径将我当前的圆形光变成椭圆形。有没有什么方法可以根据我当前在片段着色器中的代码执行此操作?
uniform struct Light
{
vec4 colour;
vec3 position;
vec2 radius;
float intensity;
} allLights[MAX_LIGHTS];
vec4 calculateLight(Light light)
{
vec2 lightDir = fragmentPosition.xy - light.position.xy;
float lightDistance = length(lightDir);
if (lightDistance >= light.radius.x)
{
return vec4(0, 0, 0, 1); //outside of radius make it black
}
return light.intensity * (1 - lightDistance / light.radius.x) * light.colour;
}
用椭圆的半轴将向量分成光源,并检查向量的长度是否大于1.0:
if (length(lightDir / light.radius) >= 1.0)
return vec4(0, 0, 0, 1); //outside of radius make it black
return light.intensity * (1 - length(lightDir / light.radius)) * light.colour;
我希望通过具有可以具有不同 x 和 y 值的 vec2 半径将我当前的圆形光变成椭圆形。有没有什么方法可以根据我当前在片段着色器中的代码执行此操作?
uniform struct Light
{
vec4 colour;
vec3 position;
vec2 radius;
float intensity;
} allLights[MAX_LIGHTS];
vec4 calculateLight(Light light)
{
vec2 lightDir = fragmentPosition.xy - light.position.xy;
float lightDistance = length(lightDir);
if (lightDistance >= light.radius.x)
{
return vec4(0, 0, 0, 1); //outside of radius make it black
}
return light.intensity * (1 - lightDistance / light.radius.x) * light.colour;
}
用椭圆的半轴将向量分成光源,并检查向量的长度是否大于1.0:
if (length(lightDir / light.radius) >= 1.0)
return vec4(0, 0, 0, 1); //outside of radius make it black
return light.intensity * (1 - length(lightDir / light.radius)) * light.colour;