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

71 lines
1 KiB
GLSL
Raw Permalink Normal View History

#version 130
2016-02-02 05:35:00 +01:00
out vec4 fragColor;
uniform vec2 res;
uniform float time;
uniform int param0;
uniform int param1;
uniform int param2;
2016-02-03 10:13:49 +01:00
2016-02-02 05:35:00 +01:00
const float sharpness = 300;
const float PI = 3.14159265358979323846;
2016-02-03 15:41:24 +01:00
mat3 rot(float a) {
return mat3(
cos(a), -sin(a), 0,
sin(a), cos(a), 0,
0, 0, 1
2016-02-02 08:23:02 +01:00
);
2016-02-02 05:35:00 +01:00
}
2016-02-03 15:41:24 +01:00
mat3 scale(float s) {
return mat3(
s, 0, 0,
0, s, 0,
0, 0, 1
);
}
2016-02-02 05:35:00 +01:00
2016-02-03 15:41:24 +01:00
mat3 trans(float x, float y) {
return mat3(
1, 0, x,
0, 1, y,
0, 0, 1
);
2016-02-02 05:35:00 +01:00
}
2016-02-03 15:41:24 +01:00
float square(vec3 p) {
float d = max(abs(p.x), abs(p.y));
return clamp((1 - d)*sharpness, 0.0, 1.0);
}
2016-02-02 05:35:00 +01:00
void main(void) {
2016-02-02 08:23:02 +01:00
vec2 m = res/2;
float s = min(m.x, m.y);
2016-02-03 15:41:24 +01:00
vec3 p = vec3((gl_FragCoord.xy - m) / s, 1);
2016-02-02 05:35:00 +01:00
2016-02-02 08:23:02 +01:00
float scene = 0;
2016-02-02 05:35:00 +01:00
int n = param0 + 32;
float k = param1;
2016-02-03 15:41:24 +01:00
2016-02-02 08:23:02 +01:00
for (int i = 0; i < n; i++) {
mat3 t = scale(1 + 0.03 * param2)
* rot(-2*PI*i/n)
* trans(-0.5, 0.0)
* rot(PI/2*(k*i/n + time/1500))
* scale(1 / (0.3 + 0.02 * param2));
2016-02-03 15:41:24 +01:00
float c = square(p * t);
2016-02-02 08:23:02 +01:00
scene = abs(scene - c);
}
2016-02-02 05:35:00 +01:00
2016-02-02 08:23:02 +01:00
fragColor = vec4(vec3(1, 1, 1) * scene, 1);
2016-02-02 05:35:00 +01:00
}