IntersectDepth.glsl 1.0 KB

1234567891011121314151617181920212223
  1. // See IntersectionUtils.glsl for the definitions of Ray, Intersections,
  2. // setIntersectionPair, INF_HIT, NO_HIT
  3. /* intersectDepth defines (set in Scene/VoxelRenderResources.js)
  4. #define DEPTH_INTERSECTION_INDEX ###
  5. */
  6. uniform mat4 u_transformPositionViewToUv;
  7. void intersectDepth(in vec2 screenCoord, in Ray ray, inout Intersections ix) {
  8. float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, screenCoord));
  9. if (logDepthOrDepth != 0.0) {
  10. // Calculate how far the ray must travel before it hits the depth buffer.
  11. vec4 eyeCoordinateDepth = czm_screenToEyeCoordinates(screenCoord, logDepthOrDepth);
  12. eyeCoordinateDepth /= eyeCoordinateDepth.w;
  13. vec3 depthPositionUv = vec3(u_transformPositionViewToUv * eyeCoordinateDepth);
  14. float t = dot(depthPositionUv - ray.pos, ray.dir);
  15. setIntersectionPair(ix, DEPTH_INTERSECTION_INDEX, vec2(t, +INF_HIT));
  16. } else {
  17. // There's no depth at this location.
  18. setIntersectionPair(ix, DEPTH_INTERSECTION_INDEX, vec2(NO_HIT));
  19. }
  20. }