Skip to content

Instantly share code, notes, and snippets.

@hb3p8
Created August 2, 2018 13:06
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 hb3p8/f28372a4d537fa9c910f820463a84931 to your computer and use it in GitHub Desktop.
Save hb3p8/f28372a4d537fa9c910f820463a84931 to your computer and use it in GitHub Desktop.
float const depthGL = read_imagef (depthImage, depthSampler, (int2) (x, y)).x; // in range [0,1]
float2 const pixel = (float2) ( (x + 0.5f) / (float) imageSizeX,
(y + 0.5f) / (float) imageSizeY); // in range [0,1]
float4 point_NDC = (float4) ( 2.0f * pixel.x - 1.0f, // in range [-1,1]
2.0f * pixel.y - 1.0f, // in range [-1,1]
2.0f * depthGL - 1.0f, // in range [-1,1]
1.0f);
point_NDC.z -= 1.25e-6f; // apply constant polygon offset for OpenGL depth
float4 const point_WORLD = matVecMult (trsf_NDC_WORLD, point_NDC);
float const rayTime = depthGL < 1.f ? length (point_WORLD.xyz / point_WORLD.w - ray.Origin.xyz) : BIGFLOAT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment