This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
glslview/examples/supersnail.frag

38 lines
622 B
GLSL
Raw Normal View History

#version 130
2016-02-01 14:03:21 +01:00
out vec4 fragColor;
uniform vec2 res;
uniform float time;
const float sharpness = 300;
mat2 rot(float a) {
2016-02-02 08:23:02 +01:00
return mat2(
cos(a), -sin(a),
sin(a), cos(a)
);
2016-02-01 14:03:21 +01:00
}
float circle(vec2 m, float r, vec2 p) {
2016-02-02 08:23:02 +01:00
vec2 diff = m - p;
float d = sqrt(dot(diff, diff));
2016-02-01 14:03:21 +01:00
2016-02-02 08:23:02 +01:00
return clamp((r - d)*sharpness, 0.0, 1.0);
2016-02-01 14:03:21 +01:00
}
void main(void) {
2016-02-02 08:23:02 +01:00
vec2 m = res/2;
float s = min(m.x, m.y);
vec2 p = (gl_FragCoord.xy - m) / s;
2016-02-01 14:03:21 +01:00
2016-02-02 08:23:02 +01:00
float scene = 0;
2016-02-01 14:03:21 +01:00
2016-02-02 08:23:02 +01:00
for (int i = 1; i <= 100; i++) {
float c = circle(vec2(0.5, 0) * rot(time/200/i), 0.1 + 0.002*i, p);
scene = abs(scene - c);
}
2016-02-01 14:03:21 +01:00
2016-02-02 08:23:02 +01:00
fragColor = vec4(vec3(1, 1, 1) * scene, 1);
2016-02-01 14:03:21 +01:00
}