Skip to content

Instantly share code, notes, and snippets.

@thomas-holmes
Created April 12, 2019 15:36
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 thomas-holmes/ed9c952ac1ed0649c66b8b2a8ea51530 to your computer and use it in GitHub Desktop.
Save thomas-holmes/ed9c952ac1ed0649c66b8b2a8ea51530 to your computer and use it in GitHub Desktop.
Some shader fooling. Copied a bunch of it from tuts/samples
#define PI 3.14159265359
#define TWO_PI 6.28318530718
//POLYGON FUNCTION
float polygon(vec2 uv, vec2 pos, float size, float blur, int sides){
uv = uv-pos;
//Angle and radius of polygon
float angle = atan(uv.x,uv.y)+PI;
float rad = TWO_PI/float(sides);
float dist = cos(floor(0.5+angle/rad)*rad-angle)*length(uv);
float poly = smoothstep(size, size-blur, dist);
poly -= smoothstep(size*0.9, size*0.9-blur, dist);
return poly;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord.xy/iResolution.xy;
uv.x = uv.x;
uv.x *= iResolution.x / iResolution.y;
// Time varying pixel color
vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
// Output to screen
fragColor = vec4(col,1.0);
vec2 tri1 = vec2(0.5, 0.5);
vec2 rot = vec2(sin(iTime), cos(iTime))/10.0;
uv += rot;
fragColor += polygon(uv, tri1, 0.1, 0.001, 3);
fragColor += polygon(uv, tri1 + vec2(0.5, 0), 0.1, 0.001, 3);
fragColor += polygon(uv, tri1 + vec2(0.4, 0), 0.1, 0.001, 3);
fragColor += polygon(uv, tri1 + vec2(0.9, 0.2), 0.1, 0.001, 3);
fragColor += polygon(uv, tri1 + vec2(-0.2, -0.3), 0.1, 0.001, 3);
fragColor += polygon(uv, tri1 + vec2(-0.35, 0.4), 0.1, 0.001, 3);
fragColor += polygon(uv, tri1 + vec2(0.5, 0.5), 0.1, 0.001, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment