Last active
November 23, 2017 10:07
-
-
Save gam0022/ca204f51361abbc81de838cd51856888 to your computer and use it in GitHub Desktop.
レイマーチングの法線をdFdxとdFdyで導出する ref: https://qiita.com/gam0022/items/1878150981494fd66abe
This file contains 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
vec3 getNormal(vec3 p) { | |
vec3 dx = dFdx(p); | |
vec3 dy = dFdy(p); | |
return normalize(cross(dx, dy)); | |
} |
This file contains 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
const float EPS = 0.001; | |
vec3 getNormal(vec3 p) { | |
return normalize(vec3( | |
sceneDist(p + vec3(EPS, 0.0, 0.0)) - sceneDist(p + vec3(-EPS, 0.0, 0.0)), | |
sceneDist(p + vec3(0.0, EPS, 0.0)) - sceneDist(p + vec3( 0.0, -EPS, 0.0)), | |
sceneDist(p + vec3(0.0, 0.0, EPS)) - sceneDist(p + vec3( 0.0, 0.0, -EPS)) | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment