Last active
May 3, 2019 07:46
-
-
Save heestand-xyz/439934762b696b7b69938301d2eda833 to your computer and use it in GitHub Desktop.
Frag - Hexagon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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