PointPrimitiveCollectionVS.js 6.6 KB

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