PointPrimitiveCollectionVS.glsl 6.0 KB

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