Skip to content

Instantly share code, notes, and snippets.

@dannygarcia
Created June 28, 2017 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannygarcia/4f754e7e1502e586b78120a4e30e5e52 to your computer and use it in GitHub Desktop.
Save dannygarcia/4f754e7e1502e586b78120a4e30e5e52 to your computer and use it in GitHub Desktop.
Draws a square in a fragment shader (unoptimized implementation).
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec3 color = vec3(0.0);
float left = 1.0 - step(0.1,st.x) + step(0.2,st.x) + step(0.9,st.y) + 1.0-step(0.1,st.y);
float bottom = 1.0 - step(0.1,st.y) + step(0.2,st.y) + step(0.9,st.x) + 1.0-step(0.1,st.x);
float right = 1.0 - step(0.8,st.x) + step(0.9,st.x) + step(0.9,st.y) + 1.0-step(0.1,st.y);
float top = 1.0 - step(0.8,st.y) + step(0.9,st.y) + step(0.9,st.x) + 1.0-step(0.1,st.x);
float pct = left * bottom * right * top;
color = vec3(pct);
gl_FragColor = vec4(color,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment