PointPrimitiveCollectionVS.glsl 6.0 KB

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