Vector3DTileClampedPolylinesFS.glsl 1.8 KB

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