Pixel-Composer/shaders/sh_fd_repulse/sh_fd_repulse.fsh

27 lines
588 B
Text
Raw Normal View History

2024-11-22 09:43:50 +01:00
#define TAU 6.283185307179586
2023-02-14 02:48:33 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float strength;
2024-11-22 09:43:50 +01:00
uniform vec2 center;
uniform float radius;
uniform float spokes;
uniform float rotate;
2023-02-14 02:48:33 +01:00
void main() {
2024-11-22 09:43:50 +01:00
vec2 pos = v_vTexcoord - center;
float rad = length(pos);
float dist = rad * strength;
float drad = smoothstep(radius * strength, 0., dist);
2023-02-14 02:48:33 +01:00
float angle = atan(pos.y, pos.x);
2024-11-22 09:43:50 +01:00
if(spokes != 0.) {
float sp = TAU / spokes;
angle = floor(angle / sp) * sp + sp * .5 + rotate;
}
2023-02-14 02:48:33 +01:00
2024-11-22 09:43:50 +01:00
gl_FragColor = vec4(cos(angle) * dist * drad, sin(angle) * dist * drad, 0., 1.);
2023-02-14 02:48:33 +01:00
}