basic: added color panes and moving lights; utilities: added shapes; weird: added piet (doesnt scale)

This commit is contained in:
2017-06-06 01:30:01 -04:00
parent 86e54bd373
commit aca017dec1
4 changed files with 71 additions and 0 deletions

12
basic/color_panes.glsl Normal file
View File

@@ -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);
}

14
basic/moving_lights.glsl Normal file
View File

@@ -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);
}

6
utilities/shapes.glsl Normal file
View File

@@ -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);
}

39
weird/piet.glsl Normal file
View File

@@ -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);
}