Created
August 11, 2017 07:56
-
-
Save weargoggles/1201390ccf590e02aef6026389533955 to your computer and use it in GitHub Desktop.
shader book shapes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author @patriciogv - 2015 | |
// http://patriciogonzalezvivo.com | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform vec2 u_resolution; | |
uniform vec2 u_mouse; | |
uniform float u_time; | |
mat2 rot2(float angle) { | |
float ct = cos(angle); | |
float st = sin(angle); | |
return mat2(ct, st, -st, ct); | |
} | |
float circle(vec2 st, vec2 centre, float radius) { | |
float r = sqrt( | |
pow(st.x - centre.x, 2.0) | |
+ pow(st.y - centre.y, 2.0) | |
); | |
return 1.0 - smoothstep(radius - 0.002, radius + 0.005, r); | |
} | |
float rect(vec2 st, vec2 bl, vec2 sz) { | |
vec2 blc = smoothstep(bl - 0.002, bl + 0.002, st); | |
vec2 trc = 1.0 - smoothstep(bl + sz - 0.002, bl + sz + 0.002, st); | |
return blc.x * blc.y * trc.x * trc.y; | |
} | |
float square(vec2 st, vec2 bl, float l) { | |
return rect(st, bl, vec2(l)); | |
} | |
void main(){ | |
vec2 st = gl_FragCoord.xy/u_resolution.xy; | |
vec3 color = mix( | |
vec3(1.0), | |
vec3(0.500,0.065,0.079), | |
circle(st, vec2(0.500,0.250), 0.2) | |
); | |
color = mix( | |
color, | |
vec3(0.500,0.065,0.079), | |
circle(st, vec2(0.500,0.750), 0.2) | |
); | |
color = mix( | |
color, | |
vec3(0.3), | |
square(st, vec2(0.300,0.310), 0.4) | |
); | |
gl_FragColor = vec4(color, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment