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/squares.frag

43 lines
752 B
GLSL
Raw Normal View History

2016-02-01 14:03:21 +01:00
#version 330
out vec4 fragColor;
uniform vec2 res;
uniform float time;
const float sharpness = 500;
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 square(vec2 m, float a, float r, vec2 p) {
2016-02-02 08:23:02 +01:00
vec2 diff = abs((m - p) * rot(r));
float d = max(diff.x, diff.y);
2016-02-01 14:03:21 +01:00
2016-02-02 08:23:02 +01:00
return clamp((a - 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 a = atan(p.x, p.y);
2016-02-01 14:03:21 +01:00
2016-02-02 08:23:02 +01:00
float x = mod(p.x, 0.1);
float y = mod(p.y, 0.1);
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 <= 50; i++) {
float c = square(vec2(0.5, 0) * rot(time/500/i), 0.1 + 0.005*i, time/500/i + time/(100*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
}