Last active
July 28, 2017 04:07
-
-
Save serser/b315d3f785f4f0a57d991b7d884bf370 to your computer and use it in GitHub Desktop.
Book of Shaders
This file contains hidden or 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; | |
/* -- */ | |
float gap(float left, float right, float v){ | |
return step(0.0, v) - step(left, v) + step(right, v); | |
} | |
float gap(vec2 left, vec2 right, vec2 v){ | |
vec2 res = step(vec2(0.0), v) - step(left, v) + step(right, v); | |
return res.x + res.y; | |
} | |
void main(){ | |
vec2 st = gl_FragCoord.xy/u_resolution.xy; | |
vec3 color = vec3(0.0); | |
float pct = 0.0; | |
// full horiontal lines | |
pct = gap(0.8,0.84, st.y); | |
pct *= gap(0.6,0.64, st.y); | |
// full vertical lines | |
pct *= gap(0.2,0.24, st.x); | |
pct *= gap(0.66,0.7, st.x); | |
pct *= gap(0.9,0.94, st.x); | |
// partial lines | |
pct *= gap(vec2(0.1, 0.6), vec2(0.14,1.0), st); | |
pct *= gap(vec2(0.2, 0.2), vec2(1.0,0.24), st); | |
color = vec3(pct); | |
gl_FragColor = vec4(color,1.0); | |
} |
This file contains hidden or 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: Inigo Quiles | |
// Title: Expo | |
// Modified: Serser | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
#define PI 3.14159265359 | |
uniform vec2 u_resolution; | |
uniform vec2 u_mouse; | |
uniform float u_time; | |
float pow5(float y) { | |
return pow(y, 5.0); | |
} | |
float plot(vec2 st, float pct, float barrier){ | |
return smoothstep( pct-barrier, pct, st.y) - | |
smoothstep(pct, pct+barrier, st.y); | |
} | |
void main() { | |
vec2 st = gl_FragCoord.xy/u_resolution; | |
float y = pow(st.x,5.0); | |
float bar = pow(st.x, 4.0) * 5.0; // tan theta | |
bar = sqrt(1.0/(bar*bar +1.0)); //cos theta | |
bar = 0.01/bar; | |
//float y = st.x; | |
vec3 color = vec3(y); | |
// bar = 0.02; | |
float pct = plot(st,y, bar); | |
color =(1.0-pct)*color+pct*vec3(0.0,1.0,0.0); | |
gl_FragColor = vec4(color,1.0); | |
} |
This file contains hidden or 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
// https://thebookofshaders.com/glossary/?search=smoothstep | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
#define PI 3.14159265359 | |
uniform vec2 u_resolution; | |
uniform vec2 u_mouse; | |
uniform float u_time; | |
float plot(vec2 st, float pct, float barrier){ | |
return smoothstep( pct-barrier, pct, st.y) - | |
smoothstep( pct, pct+barrier, st.y); | |
} | |
float smoothstepderivative(float low, float high, float x){ | |
if (x>high || x <low) { | |
return 0.; | |
} | |
return 1.0/(high-low); | |
} | |
void main() { | |
vec2 st = gl_FragCoord.xy/u_resolution; | |
// Smooth interpolation between 0.1 and 0.9 | |
float y = smoothstep(0.1, 0.9, st.x); | |
vec3 color = vec3(y); | |
float bar = smoothstepderivative(0.1, 0.9, y); | |
bar = 0.01/sqrt(1.0/(bar*bar +1.0)); //cos | |
float pct = plot(st,y,bar); | |
color = (1.0-pct)*color+pct*vec3(0.0,1.0,0.0); | |
gl_FragColor = vec4(color,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment