Skip to content

Instantly share code, notes, and snippets.

@valler
Last active December 9, 2019 19:29
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 valler/ac7fdd9afd490cd2a08abc63739d77f1 to your computer and use it in GitHub Desktop.
Save valler/ac7fdd9afd490cd2a08abc63739d77f1 to your computer and use it in GitHub Desktop.
WebGL2 Minimal Shaders
// both triangles CCW
vec3 quad (int x)
{
vec3 p = step(vec3(1,2,3),vec3(x%3));
return mix(p, vec3(p.x-p.y,p.x,0), step(3.,float(x%6)));
}
// one triangle CW and one CCW
vec3 quad (int x)
{
vec3 p = step(vec3(1,2,3),vec3(x%3));
return mix(p,p.yxz,step(3.,float(x%6)));
}
// one triangle CW and one CCW
#version 300 es
void main()
{
vec4 p = step(vec4(1,2,3,0),vec4(x%3));
return mix(p,p.yxzw,step(3.,float(x%6)));
}
// one triangle CW and one CCW
#version 300 es
void main()
{
ivec3 p = clamp(ivec3(1,2,0)%(gl_VertexID%3+1),0,1);
int a = clamp(gl_VertexID%6-2,0,1);
gl_Position = vec4(p*(1-a)+p.yxz*a,1);
}
#version 300 es
void main () { gl_Position = step(vec4(1,2,3,0),vec4(gl_VertexID%3)); }
vec3 triangle (int x) { return step(vec3(1,2,3),vec3(x%3)); }
#version 300 es
void main() { gl_Position = vec4(clamp(ivec3(1,2,0)%(gl_VertexID%3+1),0,1),1); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment