智慧水务管理系统 - 精河县供水工程综合管理平台

PointPrimitiveCollectionVS.glsl 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. uniform float u_maxTotalPointSize;
  2. in vec4 positionHighAndSize;
  3. in vec4 positionLowAndOutline;
  4. in vec4 compressedAttribute0; // color, outlineColor, pick color
  5. in vec4 compressedAttribute1; // show, translucency by distance, some free space
  6. in vec4 scaleByDistance; // near, nearScale, far, farScale
  7. in vec4 distanceDisplayConditionAndDisableDepthAndSplitDirection; // near, far, disableDepthTestDistance, splitDirection
  8. out vec4 v_color;
  9. out vec4 v_outlineColor;
  10. out float v_innerPercent;
  11. out float v_pixelDistance;
  12. out vec4 v_pickColor;
  13. out float v_splitDirection;
  14. const float SHIFT_LEFT8 = 256.0;
  15. const float SHIFT_RIGHT8 = 1.0 / 256.0;
  16. void main()
  17. {
  18. // Modifying this shader may also require modifications to PointPrimitive._computeScreenSpacePosition
  19. // unpack attributes
  20. vec3 positionHigh = positionHighAndSize.xyz;
  21. vec3 positionLow = positionLowAndOutline.xyz;
  22. float outlineWidthBothSides = 2.0 * positionLowAndOutline.w;
  23. float totalSize = positionHighAndSize.w + outlineWidthBothSides;
  24. float outlinePercent = outlineWidthBothSides / totalSize;
  25. // Scale in response to browser-zoom.
  26. totalSize *= czm_pixelRatio;
  27. float temp = compressedAttribute1.x * SHIFT_RIGHT8;
  28. float show = floor(temp);
  29. #ifdef EYE_DISTANCE_TRANSLUCENCY
  30. vec4 translucencyByDistance;
  31. translucencyByDistance.x = compressedAttribute1.z;
  32. translucencyByDistance.z = compressedAttribute1.w;
  33. translucencyByDistance.y = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;
  34. temp = compressedAttribute1.y * SHIFT_RIGHT8;
  35. translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;
  36. #endif
  37. ///////////////////////////////////////////////////////////////////////////
  38. vec4 color = czm_decodeRGB8(compressedAttribute0.x);
  39. vec4 outlineColor = czm_decodeRGB8(compressedAttribute0.y);
  40. vec4 pickColor = czm_decodeRGB8(compressedAttribute0.z);
  41. vec4 alphaPacked = czm_decodeRGB8(compressedAttribute0.w);
  42. color.a = alphaPacked.x;
  43. outlineColor.a = alphaPacked.y;
  44. pickColor.a = alphaPacked.z;
  45. ///////////////////////////////////////////////////////////////////////////
  46. vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  47. vec4 positionEC = czm_modelViewRelativeToEye * p;
  48. ///////////////////////////////////////////////////////////////////////////
  49. #if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)
  50. float lengthSq;
  51. if (czm_sceneMode == czm_sceneMode2D)
  52. {
  53. // 2D camera distance is a special case
  54. // treat all billboards as flattened to the z=0.0 plane
  55. lengthSq = czm_eyeHeight2D.y;
  56. }
  57. else
  58. {
  59. lengthSq = dot(positionEC.xyz, positionEC.xyz);
  60. }
  61. #endif
  62. #ifdef EYE_DISTANCE_SCALING
  63. totalSize *= czm_nearFarScalar(scaleByDistance, lengthSq);
  64. #endif
  65. if (totalSize > 0.0) {
  66. // Add padding for anti-aliasing on both sides.
  67. totalSize += 3.0;
  68. }
  69. // Clamp to max point size.
  70. totalSize = min(totalSize, u_maxTotalPointSize);
  71. // If size is too small, push vertex behind near plane for clipping.
  72. // Note that context.minimumAliasedPointSize "will be at most 1.0".
  73. if (totalSize < 1.0)
  74. {
  75. positionEC.xyz = vec3(0.0);
  76. totalSize = 1.0;
  77. }
  78. float translucency = 1.0;
  79. #ifdef EYE_DISTANCE_TRANSLUCENCY
  80. translucency = czm_nearFarScalar(translucencyByDistance, lengthSq);
  81. // push vertex behind near plane for clipping
  82. if (translucency < 0.004)
  83. {
  84. positionEC.xyz = vec3(0.0);
  85. }
  86. #endif
  87. #ifdef DISTANCE_DISPLAY_CONDITION
  88. float nearSq = distanceDisplayConditionAndDisableDepthAndSplitDirection.x;
  89. float farSq = distanceDisplayConditionAndDisableDepthAndSplitDirection.y;
  90. if (lengthSq < nearSq || lengthSq > farSq) {
  91. // push vertex behind camera to force it to be clipped
  92. positionEC.xyz = vec3(0.0, 0.0, 1.0);
  93. }
  94. #endif
  95. gl_Position = czm_projection * positionEC;
  96. czm_vertexLogDepth();
  97. #ifdef DISABLE_DEPTH_DISTANCE
  98. float disableDepthTestDistance = distanceDisplayConditionAndDisableDepthAndSplitDirection.z;
  99. if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)
  100. {
  101. disableDepthTestDistance = czm_minimumDisableDepthTestDistance;
  102. }
  103. if (disableDepthTestDistance != 0.0)
  104. {
  105. // Don't try to "multiply both sides" by w. Greater/less-than comparisons won't work for negative values of w.
  106. float zclip = gl_Position.z / gl_Position.w;
  107. bool clipped = (zclip < -1.0 || zclip > 1.0);
  108. if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))
  109. {
  110. // Position z on the near plane.
  111. gl_Position.z = -gl_Position.w;
  112. #ifdef LOG_DEPTH
  113. czm_vertexLogDepth(vec4(czm_currentFrustum.x));
  114. #endif
  115. }
  116. }
  117. #endif
  118. v_color = color;
  119. v_color.a *= translucency * show;
  120. v_outlineColor = outlineColor;
  121. v_outlineColor.a *= translucency * show;
  122. v_innerPercent = 1.0 - outlinePercent;
  123. v_pixelDistance = 2.0 / totalSize;
  124. gl_PointSize = totalSize * show;
  125. gl_Position *= show;
  126. v_pickColor = pickColor;
  127. v_splitDirection = distanceDisplayConditionAndDisableDepthAndSplitDirection.w;
  128. }