Skip to content

Instantly share code, notes, and snippets.

@heestand-xyz
Last active May 3, 2019 07:46
Show Gist options
  • Save heestand-xyz/439934762b696b7b69938301d2eda833 to your computer and use it in GitHub Desktop.
Save heestand-xyz/439934762b696b7b69938301d2eda833 to your computer and use it in GitHub Desktop.
Frag - Hexagon
let hexagon = MetalPIX(res: particleRes, uniforms: [
MetalUniform(name: "resx", value: LiveFloat(particleRes.width)),
MetalUniform(name: "resy", value: LiveFloat(particleRes.height))
], code:
"""
int x = int(u * in.resx);
int y = int(v * in.resy);
int i = y * int(in.resx) + x;
float f = float(i) / (in.resx * in.resy);
int hexi = int(f * 6);
float hexf1 = float(hexi) / 6 + 1.0 / 12;
float hexf2 = float(hexi + 1) / 6 + 1.0 / 12;
float2 p1 = float2(cos(hexf1*pi*2), sin(hexf1*pi*2));
float2 p2 = float2(cos(hexf2*pi*2), sin(hexf2*pi*2));
float hexif = (f * 6) - floor(f * 6);
float2 p = p1 * (1.0 - hexif) + p2 * hexif;
pix = float4(p.x/2+0.5,p.y/2+0.5,0,1);
"""
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment