prosperon/shaders/circle.cg

42 lines
728 B
Plaintext
Raw Normal View History

2024-05-30 17:12:54 -05:00
@vs vert
in vec3 a_pos;
uniform float radius;
uniform vec2 coord;
uniform mat4 vp;
out vec2 coords;
out float rad;
void main() {
vec3 pos = a_pos;
pos.xy -= 0.5;
pos.xy *= 2;
coords = pos.xy;
pos *= radius;
pos.xy += coord;
rad = radius;
gl_Position = vp * vec4(pos,1);
}
@end
@fs frag
in vec2 coords;
in float rad;
uniform vec4 shade;
uniform float inner_r;
2024-05-30 17:12:54 -05:00
out vec4 color;
void main() {
float px = 1/rad;
float blur = 1.0+px;
2024-05-30 17:12:54 -05:00
float R = 1;
float R2 = 1-inner_r;
float dist = distance(vec2(0,0),coords);
float sm = 1 - smoothstep(R-px,R*blur,dist);
float sm2 = smoothstep(R2-px,R2*blur,dist);
2024-05-30 17:12:54 -05:00
float alpha = sm*sm2;
color = vec4(shade.xyz, alpha*shade.a);
2024-05-30 17:12:54 -05:00
}
@end
@program circle vert frag