Vector3DTileClampedPolylinesFS.glsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. in vec4 v_startPlaneEC;
  2. in vec4 v_endPlaneEC;
  3. in vec4 v_rightPlaneEC;
  4. in float v_halfWidth;
  5. in vec3 v_volumeUpEC;
  6. uniform vec4 u_highlightColor;
  7. void main()
  8. {
  9. float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw)));
  10. // Discard for sky
  11. if (logDepthOrDepth == 0.0) {
  12. #ifdef DEBUG_SHOW_VOLUME
  13. out_FragColor = vec4(0.0, 0.0, 1.0, 0.5);
  14. return;
  15. #else // DEBUG_SHOW_VOLUME
  16. discard;
  17. #endif // DEBUG_SHOW_VOLUME
  18. }
  19. vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);
  20. eyeCoordinate /= eyeCoordinate.w;
  21. float halfMaxWidth = v_halfWidth * czm_metersPerPixel(eyeCoordinate);
  22. // Expand halfMaxWidth if direction to camera is almost perpendicular with the volume's up direction
  23. halfMaxWidth += halfMaxWidth * (1.0 - dot(-normalize(eyeCoordinate.xyz), v_volumeUpEC));
  24. // Check distance of the eye coordinate against the right-facing plane
  25. float widthwiseDistance = czm_planeDistance(v_rightPlaneEC, eyeCoordinate.xyz);
  26. // Check eye coordinate against the mitering planes
  27. float distanceFromStart = czm_planeDistance(v_startPlaneEC, eyeCoordinate.xyz);
  28. float distanceFromEnd = czm_planeDistance(v_endPlaneEC, eyeCoordinate.xyz);
  29. if (abs(widthwiseDistance) > halfMaxWidth || distanceFromStart < 0.0 || distanceFromEnd < 0.0) {
  30. #ifdef DEBUG_SHOW_VOLUME
  31. out_FragColor = vec4(logDepthOrDepth, 0.0, 0.0, 0.5);
  32. return;
  33. #else // DEBUG_SHOW_VOLUME
  34. discard;
  35. #endif // DEBUG_SHOW_VOLUME
  36. }
  37. out_FragColor = u_highlightColor;
  38. czm_writeDepthClamp();
  39. }