From 7514345d8f731affc1fe0f2b1f38822103fdaac5 Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 6 Jun 2017 09:16:18 -0400 Subject: [PATCH] utils: added translation and box shape --- utilities/shapes.glsl | 8 ++++++++ utilities/translation.glsl | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 utilities/translation.glsl diff --git a/utilities/shapes.glsl b/utilities/shapes.glsl index dd4d343..6cc6ffa 100644 --- a/utilities/shapes.glsl +++ b/utilities/shapes.glsl @@ -5,6 +5,14 @@ vec3 circle(in vec2 _st, in float _radius, vec3 color){ dot(dist,dist)*4.0); } +vec3 box(vec2 width, vec2 height) { + height = vec2(0.5) - height*0.5; + vec2 he = height+0.001; + vec2 uv = smoothstep(height, he, width); + uv *= smoothstep(height, he, vec2(1.0)-width); + return vec3(uv.x*uv.y); +} + // Inspired by (but modified) // http://thndl.com/square-shaped-shaders.html #define TAU 6.28318530718 diff --git a/utilities/translation.glsl b/utilities/translation.glsl new file mode 100644 index 0000000..63d2c71 --- /dev/null +++ b/utilities/translation.glsl @@ -0,0 +1,8 @@ +mat2 rotate2d(float a) { + float c = cos(a); + return mat2(c, -sin(a), sin(a), c); +} + +mat2 scale(vec2 s) { + return mat2(s.x, 0., 0., s.y); +}