axmol/core/renderer/shaders/layer_radialGradient.frag

39 lines
667 B
GLSL
Raw Normal View History

#version 310 es
precision highp float;
precision highp int;
2019-11-23 20:27:39 +08:00
layout(location = 0) in vec4 v_position;
2019-11-23 20:27:39 +08:00
layout(std140) uniform fs_ub {
vec4 u_startColor;
vec4 u_endColor;
vec2 u_center;
float u_radius;
float u_expand;
};
2019-11-23 20:27:39 +08:00
layout(location = 0) out vec4 FragColor;
2019-11-23 20:27:39 +08:00
void main()
{
float d = distance(v_position.xy, u_center) / u_radius;
if (d <= 1.0)
{
if (d <= u_expand)
{
FragColor = u_startColor;
2019-11-23 20:27:39 +08:00
}
else
{
FragColor = mix(u_startColor, u_endColor, (d - u_expand) / (1.0 - u_expand));
2019-11-23 20:27:39 +08:00
}
}
else
{
FragColor = vec4(0.0, 0.0, 0.0, 0.0);
2019-11-23 20:27:39 +08:00
}
}