Created
March 3, 2015 13:28
-
-
Save pyalot/711c7b0a228f125096ff to your computer and use it in GitHub Desktop.
anti-aliased checker-sphere procedural glsl pattern
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
float checkerSphere(){ | |
vec3 normal = normalize(vNormal); | |
float c = (acos(normal.y)/PI)*20.0; | |
float dc = fwidth(c); | |
c = mod(c, 2.0); | |
c = smoothstep(0.5-dc, 0.5+dc, c) - smoothstep(1.5-dc, 1.5+dc, c); | |
vec2 dir = normalize(normal.xz); | |
float t = (atan(dir.x, dir.y)/TAU)*40.0; | |
float dt = fwidth(t); | |
t = mod(t, 2.0); | |
t = smoothstep(0.5-dt, 0.5+dt, t) - smoothstep(1.5-dt, 1.5+dt, t); | |
t = mix(t, 1.0-t, c); | |
t = t*0.1+0.5; | |
return t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment