Masterchoc

Untitled

Dec 13th, 2017
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const calculateNormal = (x, z) => {
  2.     // Find vertex neighbors
  3.     let a = getHeight(x - 1, z).height;
  4.     let b = getHeight(x + 1, z).height;
  5.     let c = getHeight(x, z - 1).height;
  6.     let d = getHeight(x, z + 1).height;
  7.  
  8.     // Compute the cross product
  9.     let u = a - b;
  10.     let v = 2;
  11.     let w = c - d;
  12.  
  13.     // Normalize
  14.     let m = Math.sqrt(u * u + v * v + w * w);
  15.     u /= m;
  16.     v /= m;
  17.     w /= m;
  18.  
  19.     return [u, v, w];
  20. };
RAW Paste Data