From aca017dec15306715b11341c2ae05f0be1690b1c Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 6 Jun 2017 01:30:01 -0400 Subject: [PATCH] basic: added color panes and moving lights; utilities: added shapes; weird: added piet (doesnt scale) --- basic/color_panes.glsl | 12 ++++++++++++ basic/moving_lights.glsl | 14 ++++++++++++++ utilities/shapes.glsl | 6 ++++++ weird/piet.glsl | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 basic/color_panes.glsl create mode 100644 basic/moving_lights.glsl create mode 100644 utilities/shapes.glsl create mode 100644 weird/piet.glsl diff --git a/basic/color_panes.glsl b/basic/color_panes.glsl new file mode 100644 index 0000000..508d2ae --- /dev/null +++ b/basic/color_panes.glsl @@ -0,0 +1,12 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; + +void main(){ + vec2 st = gl_FragCoord.xy/u_resolution.xy; + + gl_FragColor = vec4(floor(vec3(st, u_mouse.x/u_resolution.x)+0.5),1.0); +} diff --git a/basic/moving_lights.glsl b/basic/moving_lights.glsl new file mode 100644 index 0000000..96c7243 --- /dev/null +++ b/basic/moving_lights.glsl @@ -0,0 +1,14 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +void main(){ + vec2 p1 = vec2(0.8*abs(sin(u_time)), 0.8*abs(cos(u_time))); + vec2 p2 = u_mouse/u_resolution; + vec2 st = gl_FragCoord.xy/u_resolution; + gl_FragColor = vec4(vec3(pow(distance(st,vec2(p1))*0.5,distance(st,p2)*0.5)), 1.0); +} diff --git a/utilities/shapes.glsl b/utilities/shapes.glsl new file mode 100644 index 0000000..039c132 --- /dev/null +++ b/utilities/shapes.glsl @@ -0,0 +1,6 @@ +vec3 circle(in vec2 _st, in float _radius, vec3 color){ + vec2 dist = _st-vec2(0.5); + return color-smoothstep(_radius-(_radius*0.02), + _radius+(_radius*0.02), + dot(dist,dist)*4.0); +} diff --git a/weird/piet.glsl b/weird/piet.glsl new file mode 100644 index 0000000..16bf51d --- /dev/null +++ b/weird/piet.glsl @@ -0,0 +1,39 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +vec3 WHITE = vec3(1.); +vec3 RED = vec3(1.,0.,0.); +vec3 BLACK = vec3(0.); +vec3 YELLOW = vec3(1.,1.,0); +vec3 BLUE = vec3(0.,0.,1.); + +// hacky but worky +vec3 rect(float thickness, vec2 offset, vec2 size, vec3 border_color, vec3 bg_color) { + vec2 pos = gl_FragCoord.xy; + if (pos.x < offset.x || pos.y < offset.y || pos.x>size.x+thickness+offset.x || pos.y>size.y+thickness+offset.y) return WHITE; + bool in_left = pos.x >= offset.x && pos.x <= offset.x+thickness; + bool in_right = pos.x >= offset.x+size.x && pos.x <= offset.x+thickness+size.x; + bool in_bottom = pos.y >= offset.y && pos.y <= offset.y+thickness; + bool in_top = pos.y >= offset.y+size.y && pos.y <= offset.y+thickness+size.y; + if (in_left || in_right || in_bottom || in_top) return border_color; + return bg_color; +} + +vec3 piet_rect(vec2 offset, vec2 size, vec3 bg_color) { + return rect(5., offset, vec2(size), BLACK, bg_color); +} + +void main() { + vec3 rect1 = piet_rect(vec2(10., 210.), vec2(200.), RED); + vec3 rect2 = piet_rect(vec2(10.), vec2(200.), WHITE); + vec3 rect3 = piet_rect(vec2(-90., -5), vec2(100., 200.), BLUE); + vec3 rect4 = piet_rect(vec2(-10., 210), vec2(20., 20.), WHITE); + vec3 rect5 = piet_rect(vec2(210, -5.), vec2(50., 300), YELLOW); + + gl_FragColor = vec4(rect1*rect2*rect3*rect4*rect5,1.0); +}