depth.shaderModule
- README.md1.5 KB
- module.wgsl3.0 KB
This package holds more than this page lists. See all of its files in its world.
README.md
depth
The one reading of a stored depth value. Scene depth is reversed — the near plane is 1.0 and the far plane 0.0 — so converting it back to a distance is not the textbook inversion, and this is where that inversion lives.
Pure math — no bindings. A Surface-domain shader and a post-process shader see different frameworks and cannot share a sampling function, but they share this, so both agree on what a depth value means.
#include "@builtin::shaderModules.depth"
zero_linear_depth_through(depth, view_proj, camera_position) is the reading
for a frame drawn by any camera: it takes the view-projection the frame was
drawn with and the position it was drawn from (engine.view_proj and
zero_camera_position() in a post-process shader, uniforms.view_proj and
uniforms.camera_pos in a surface shader, camera.viewData()'s viewProj and
position for a compute pass) and reads from them the camera's near and far
planes and whether it projects in perspective, where the stored value falls
with the reciprocal of the distance, or orthographically, where it falls in
step with the distance. A frame drawn at any near and far plane reads back the
same distance for the same surface.
zero_linear_depth(depth, near, far) and
zero_linear_depth_orthographic(depth, near, far) are the two inversions given
the planes themselves (camera.viewData()'s near and far are the planes the
viewport's frame was drawn with), for a shader that knows which projection drew
the depth.