Skip to content

Instantly share code, notes, and snippets.

@igalata
Last active October 9, 2017 14:10
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 igalata/6a916fd095a13b1723e998371496873c to your computer and use it in GitHub Desktop.
Save igalata/6a916fd095a13b1723e998371496873c to your computer and use it in GitHub Desktop.
// Author:
// Title:
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
bool insideTriangle(vec2 uv) {
vec2 a = normalize(vec2(0.0, 0.0) - uv);
vec2 b = normalize(vec2(0.5, 1.0) - uv);
vec2 c = normalize(vec2(1.0, 0.0) - uv);
return dot(a, b) + dot(b, c) + dot(a, c) < -1.0;
}
void main() {
vec2 uv = gl_FragCoord.xy/u_resolution.xy;
float red = uv.y;
float green = (1.0 - uv.x) * (1.0 - uv.y);
float blue = uv.x * (1.0 - uv.y);
gl_FragColor = insideTriangle(uv) ? vec4(red, green, blue, 1.0) : vec4(1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment