MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ ray_at_depth()

glm::vec3 MayaFlux::Kinesis::ray_at_depth ( double  window_x,
double  window_y,
uint32_t  width,
uint32_t  height,
float  ndc_depth,
const ViewTransform vt 
)
inline

Recover the world-space position at a known depth for a given pixel.

Unprojects a window pixel and a Vulkan NDC depth value [0, 1] back into world space by inverting the full view-projection transform. This is the inverse of what the vertex shader does: given the depth the GPU wrote into the depth attachment at (window_x, window_y), return the world position that produced it.

The depth value must be in Vulkan's [0, 1] range (not OpenGL's [-1, 1]). Pass 0.0 to recover the near-plane position, 1.0 for the far plane. A value sampled from the depth attachment is valid directly.

Parameters
window_xX in window space [0, width] (top-left origin).
window_yY in window space [0, height] (top-left origin).
widthWindow width in pixels.
heightWindow height in pixels.
ndc_depthDepth in [0, 1] (Vulkan convention).
vtActive ViewTransform (view + projection matrices).
Returns
World-space position corresponding to the pixel at that depth.

Definition at line 198 of file HitTest.hpp.

203{
204 float ndc_x = (static_cast<float>(window_x) / static_cast<float>(width)) * 2.0F - 1.0F;
205 float ndc_y = 1.0F - (static_cast<float>(window_y) / static_cast<float>(height)) * 2.0F;
206
207 glm::mat4 inv_vp = glm::inverse(vt.projection * vt.view);
208 glm::vec4 h = inv_vp * glm::vec4(ndc_x, ndc_y, ndc_depth, 1.0F);
209 return glm::vec3(h) / h.w;
210}
uint32_t width
Definition Decoder.cpp:59
uint32_t h
Definition InkPress.cpp:28

References h, MayaFlux::Kinesis::ViewTransform::projection, MayaFlux::Kinesis::ViewTransform::view, and width.