Skip to content

Instantly share code, notes, and snippets.

@pyalot
Created March 3, 2015 13:28
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 pyalot/711c7b0a228f125096ff to your computer and use it in GitHub Desktop.
Save pyalot/711c7b0a228f125096ff to your computer and use it in GitHub Desktop.
anti-aliased checker-sphere procedural glsl pattern
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