Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const calculateNormal = (x, z) => {
- // Find vertex neighbors
- let a = getHeight(x - 1, z).height;
- let b = getHeight(x + 1, z).height;
- let c = getHeight(x, z - 1).height;
- let d = getHeight(x, z + 1).height;
- // Compute the cross product
- let u = a - b;
- let v = 2;
- let w = c - d;
- // Normalize
- let m = Math.sqrt(u * u + v * v + w * w);
- u /= m;
- v /= m;
- w /= m;
- return [u, v, w];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement