Skip to content

Instantly share code, notes, and snippets.

@greggman
Created January 14, 2014 05:58
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 greggman/8413752 to your computer and use it in GitHub Desktop.
Save greggman/8413752 to your computer and use it in GitHub Desktop.
Compute the z buffer representations for a particular bit depth. Meant to be pasted into JavaScript console.
res = 24; near = 0.1; far = 3500000; end = 1 << res; rangeInv = 1.0 / (near - far); j = []; last = 0; for(i = end - 16; i < end; ++i) {cz = i; cz = cz * 2.0 / (end - 1) - 1; z = near*far*rangeInv*2/(cz+(near+far)*rangeInv); j.push(" " + i + " = " + z.toFixed(3) + (last == 0 ? "" : (" range: " + (z - last).toFixed(3)))); last = z; }; console.log(j.join("\n") + "\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment