Skip to content

Instantly share code, notes, and snippets.

@quilime
Last active December 22, 2015 03:09
Show Gist options
  • Save quilime/6408177 to your computer and use it in GitHub Desktop.
Save quilime/6408177 to your computer and use it in GitHub Desktop.
GLSL Triangle function
// via "Einstienstien" - by Dave Hoskins, on Shadertoy
// http://glsl.heroku.com/e#10662.0
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 resolution;
float col = 0.0; // Start black.
vec2 uv;
void Tri(vec4 p)
{
vec4 unC1 = (floor(mod(p, 256.0)) / vec4(395.,395.,395.,256.));
vec4 unC2 = (floor(p / 256.0)) / vec4(256.0);
vec2 a = vec2(unC1.x+.18, unC2.x);
vec2 b = vec2(unC1.y+.18, unC2.y);
vec2 c = vec2(unC1.z+.18, unC2.z);
vec2 as = uv-a;
bool uv_ab = (b.x-a.x)*as.y-(b.y-a.y)*as.x > 0.0;
if ((c.x-a.x)*as.y-(c.y-a.y)*as.x > 0.0 == uv_ab) return;
if ((c.x-b.x)*(uv.y-b.y)-(c.y-b.y)*(uv.x-b.x) > 0.0 != uv_ab) return;
col = mix (col, unC1.w, unC2.w);
}
void main(void)
{
uv = gl_FragCoord.xy / resolution.xy;
Tri(vec4(30702., 34338.,40328., 14851.));
gl_FragColor = vec4(vec3(col), 1.0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment