summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-02-03 15:41:24 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-02-03 15:41:24 +0100
commit85cf1849350c5a570d41191b643695b527c906a9 (patch)
tree4633acf0067e93cd289a6c93ce18d4de2b58fd53
parentd5375d5308b3483f5dc8da89943d5a98f67818d5 (diff)
downloadglslview-85cf1849350c5a570d41191b643695b527c906a9.tar
glslview-85cf1849350c5a570d41191b643695b527c906a9.zip
examples/symmetry: more cleanup
-rw-r--r--examples/symmetry.frag44
1 files changed, 34 insertions, 10 deletions
diff --git a/examples/symmetry.frag b/examples/symmetry.frag
index 90bd71a..26f4651 100644
--- a/examples/symmetry.frag
+++ b/examples/symmetry.frag
@@ -14,31 +14,55 @@ const float sharpness = 300;
const float PI = 3.14159265358979323846;
-mat2 rot(float a) {
- return mat2(
- cos(a), -sin(a),
- sin(a), cos(a)
+mat3 rot(float a) {
+ return mat3(
+ cos(a), -sin(a), 0,
+ sin(a), cos(a), 0,
+ 0, 0, 1
);
}
-float square(vec2 m, float a, float r, vec2 p) {
- vec2 diff = abs((m - p) * rot(r));
- float d = max(diff.x, diff.y);
+mat3 scale(float s) {
+ return mat3(
+ s, 0, 0,
+ 0, s, 0,
+ 0, 0, 1
+ );
+}
- return clamp((a - d)*sharpness, 0.0, 1.0);
+mat3 trans(float x, float y) {
+ return mat3(
+ 1, 0, x,
+ 0, 1, y,
+ 0, 0, 1
+ );
}
+float square(vec3 p) {
+ float d = max(abs(p.x), abs(p.y));
+
+ return clamp((1 - 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;
+ vec3 p = vec3((gl_FragCoord.xy - m) / s, 1);
float scene = 0;
int n = param0 + 32;
float k = param1;
+
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 + 0.02 * param2, -PI/2*(k*i/n + time/1500), p * (1 + 0.03*param2));
+ mat3 t = scale(0.3 + 0.02 * param2)
+ * rot(-PI/2*(k*i/n + time/1500))
+ * trans(0.5, 0.0)
+ * rot(2*PI*i/n)
+ * scale(1 / (1 + 0.03 * param2));
+
+ float c = square(p * inverse(t));
scene = abs(scene - c);
}