如何将点光源转换为椭圆形/椭圆形? [英] How do I convert my point light into an oval/ellipse?

查看:62
本文介绍了如何将点光源转换为椭圆形/椭圆形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过具有可以具有不同 x 和 y 值的 vec2 半径将我当前的圆形光变成椭圆.有没有办法根据我在片段着色器中的当前代码来做到这一点?

I am looking to turn my current circular light into an ellipse by having a vec2 radius which can have different x and y values. Is there any way to do this based on my current code in the fragment shader?

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:

Divide the vector to the light source with the semi-axis of the ellipse and check whether the length of the vector is greater than 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;

这篇关于如何将点光源转换为椭圆形/椭圆形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆