Skip to content

Instantly share code, notes, and snippets.

@eddietree
Created April 20, 2018 23:42
Show Gist options
  • Save eddietree/69d2966fc9c99d2acd7e2f159e092d7c to your computer and use it in GitHub Desktop.
Save eddietree/69d2966fc9c99d2acd7e2f159e092d7c to your computer and use it in GitHub Desktop.
SDF normal
float3 calcNormal(in float3 pos) {
float3 eps = float3(0.001, 0.0, 0.0);
float3 nor = float3(
map(pos + eps.xyy).x - map(pos - eps.xyy).x,
map(pos + eps.yxy).x - map(pos - eps.yxy).x,
map(pos + eps.yyx).x - map(pos - eps.yyx).x);
return normalize(nor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment