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

45 lines
805 B
GLSL

#version 330
out vec4 fragColor;
uniform vec2 res;
uniform float time;
uniform int param_l;
uniform int param_m;
const float sharpness = 300;
const float PI = 3.14159265358979323846;
mat2 rot(float a) {
return mat2(
cos(a), -sin(a),
sin(a), cos(a)
);
}
float square(vec2 m, float a, float r, vec2 p) {
vec2 diff = abs((m - p) * rot(r));
float d = max(diff.x, diff.y);
return clamp((a - d)*sharpness, 0.0, 1.0);
}
void main(void) {
vec2 m = res/2;
float s = min(m.x, m.y);
vec2 p = (gl_FragCoord.xy - m) / s;
float scene = 0;
int n = param_l + 32;
float k = param_m;
for (int i = 0; i < n; i++) {
float c = square(vec2(0.5, 0) * rot(PI/2*(4.0*i/n)) * vec2(1, 1), 0.3, -PI/2*(k*i/n + time/1500), p);
scene = abs(scene - c);
}
fragColor = vec4(vec3(1, 1, 1) * scene, 1);
}