Skip to content

Instantly share code, notes, and snippets.

@ahsquared
Last active March 23, 2017 13:59
Show Gist options
  • Save ahsquared/ba4bc5b873943903f66e43380940092d to your computer and use it in GitHub Desktop.
Save ahsquared/ba4bc5b873943903f66e43380940092d to your computer and use it in GitHub Desktop.
Hex packing shader for shadertoy
float hex(vec2 p) {
p.x *= 0.57735*2.0;
p.y += mod(floor(p.x), 2.0)*0.5;
p = abs((mod(p, 1.0) - 0.5));
return abs(max(p.x*1.5 + p.y, p.y*2.0) - 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 pos = fragCoord.xy;
vec2 p = pos/20.0;
float r = (1.0 -0.7)*0.5;
fragColor = vec4(smoothstep(0.0, r + 0.05, hex(p)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment