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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #ifdef QUANTIZATION_BITS12
  2. in vec4 compressed0;
  3. in float compressed1;
  4. #else
  5. in vec4 position3DAndHeight;
  6. in vec4 textureCoordAndEncodedNormals;
  7. #endif
  8. #ifdef GEODETIC_SURFACE_NORMALS
  9. in vec3 geodeticSurfaceNormal;
  10. #endif
  11. #ifdef EXAGGERATION
  12. uniform vec2 u_verticalExaggerationAndRelativeHeight;
  13. #endif
  14. uniform vec3 u_center3D;
  15. uniform mat4 u_modifiedModelView;
  16. uniform mat4 u_modifiedModelViewProjection;
  17. uniform vec4 u_tileRectangle;
  18. // Uniforms for 2D Mercator projection
  19. uniform vec2 u_southAndNorthLatitude;
  20. uniform vec2 u_southMercatorYAndOneOverHeight;
  21. out vec3 v_positionMC;
  22. out vec3 v_positionEC;
  23. out vec3 v_textureCoordinates;
  24. out vec3 v_normalMC;
  25. out vec3 v_normalEC;
  26. #ifdef APPLY_MATERIAL
  27. out float v_slope;
  28. out float v_aspect;
  29. out float v_height;
  30. #endif
  31. #if defined(FOG) || defined(GROUND_ATMOSPHERE) || defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT)
  32. out float v_distance;
  33. #endif
  34. #if defined(FOG) || defined(GROUND_ATMOSPHERE)
  35. out vec3 v_atmosphereRayleighColor;
  36. out vec3 v_atmosphereMieColor;
  37. out float v_atmosphereOpacity;
  38. #endif
  39. #ifdef ENABLE_CLIPPING_POLYGONS
  40. uniform highp sampler2D u_clippingExtents;
  41. out vec2 v_clippingPosition;
  42. flat out int v_regionIndex;
  43. #endif
  44. // These functions are generated at runtime.
  45. vec4 getPosition(vec3 position, float height, vec2 textureCoordinates);
  46. float get2DYPositionFraction(vec2 textureCoordinates);
  47. vec4 getPosition3DMode(vec3 position, float height, vec2 textureCoordinates)
  48. {
  49. return u_modifiedModelViewProjection * vec4(position, 1.0);
  50. }
  51. float get2DMercatorYPositionFraction(vec2 textureCoordinates)
  52. {
  53. // The width of a tile at level 11, in radians and assuming a single root tile, is
  54. // 2.0 * czm_pi / pow(2.0, 11.0)
  55. // We want to just linearly interpolate the 2D position from the texture coordinates
  56. // when we're at this level or higher. The constant below is the expression
  57. // above evaluated and then rounded up at the 4th significant digit.
  58. const float maxTileWidth = 0.003068;
  59. float positionFraction = textureCoordinates.y;
  60. float southLatitude = u_southAndNorthLatitude.x;
  61. float northLatitude = u_southAndNorthLatitude.y;
  62. if (northLatitude - southLatitude > maxTileWidth)
  63. {
  64. float southMercatorY = u_southMercatorYAndOneOverHeight.x;
  65. float oneOverMercatorHeight = u_southMercatorYAndOneOverHeight.y;
  66. float currentLatitude = mix(southLatitude, northLatitude, textureCoordinates.y);
  67. currentLatitude = clamp(currentLatitude, -czm_webMercatorMaxLatitude, czm_webMercatorMaxLatitude);
  68. positionFraction = czm_latitudeToWebMercatorFraction(currentLatitude, southMercatorY, oneOverMercatorHeight);
  69. }
  70. return positionFraction;
  71. }
  72. float get2DGeographicYPositionFraction(vec2 textureCoordinates)
  73. {
  74. return textureCoordinates.y;
  75. }
  76. vec4 getPositionPlanarEarth(vec3 position, float height, vec2 textureCoordinates)
  77. {
  78. float yPositionFraction = get2DYPositionFraction(textureCoordinates);
  79. vec4 rtcPosition2D = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);
  80. return u_modifiedModelViewProjection * rtcPosition2D;
  81. }
  82. vec4 getPosition2DMode(vec3 position, float height, vec2 textureCoordinates)
  83. {
  84. return getPositionPlanarEarth(position, 0.0, textureCoordinates);
  85. }
  86. vec4 getPositionColumbusViewMode(vec3 position, float height, vec2 textureCoordinates)
  87. {
  88. return getPositionPlanarEarth(position, height, textureCoordinates);
  89. }
  90. vec4 getPositionMorphingMode(vec3 position, float height, vec2 textureCoordinates)
  91. {
  92. // We do not do RTC while morphing, so there is potential for jitter.
  93. // This is unlikely to be noticeable, though.
  94. vec3 position3DWC = position + u_center3D;
  95. float yPositionFraction = get2DYPositionFraction(textureCoordinates);
  96. vec4 position2DWC = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);
  97. vec4 morphPosition = czm_columbusViewMorph(position2DWC, vec4(position3DWC, 1.0), czm_morphTime);
  98. vec4 morphPositionEC = czm_modelView * morphPosition;
  99. return czm_projection * morphPositionEC;
  100. }
  101. #ifdef QUANTIZATION_BITS12
  102. uniform vec2 u_minMaxHeight;
  103. uniform mat4 u_scaleAndBias;
  104. #endif
  105. void main()
  106. {
  107. #ifdef QUANTIZATION_BITS12
  108. vec2 xy = czm_decompressTextureCoordinates(compressed0.x);
  109. vec2 zh = czm_decompressTextureCoordinates(compressed0.y);
  110. vec3 position = vec3(xy, zh.x);
  111. float height = zh.y;
  112. vec2 textureCoordinates = czm_decompressTextureCoordinates(compressed0.z);
  113. height = height * (u_minMaxHeight.y - u_minMaxHeight.x) + u_minMaxHeight.x;
  114. position = (u_scaleAndBias * vec4(position, 1.0)).xyz;
  115. #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y) || defined(APPLY_MATERIAL)
  116. float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;
  117. float encodedNormal = compressed1;
  118. #elif defined(INCLUDE_WEB_MERCATOR_Y)
  119. float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;
  120. float encodedNormal = 0.0;
  121. #elif defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)
  122. float webMercatorT = textureCoordinates.y;
  123. float encodedNormal = compressed0.w;
  124. #else
  125. float webMercatorT = textureCoordinates.y;
  126. float encodedNormal = 0.0;
  127. #endif
  128. #else
  129. // A single float per element
  130. vec3 position = position3DAndHeight.xyz;
  131. float height = position3DAndHeight.w;
  132. vec2 textureCoordinates = textureCoordAndEncodedNormals.xy;
  133. #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)) && defined(INCLUDE_WEB_MERCATOR_Y)
  134. float webMercatorT = textureCoordAndEncodedNormals.z;
  135. float encodedNormal = textureCoordAndEncodedNormals.w;
  136. #elif defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)
  137. float webMercatorT = textureCoordinates.y;
  138. float encodedNormal = textureCoordAndEncodedNormals.z;
  139. #elif defined(INCLUDE_WEB_MERCATOR_Y)
  140. float webMercatorT = textureCoordAndEncodedNormals.z;
  141. float encodedNormal = 0.0;
  142. #else
  143. float webMercatorT = textureCoordinates.y;
  144. float encodedNormal = 0.0;
  145. #endif
  146. #endif
  147. vec3 position3DWC = position + u_center3D;
  148. #ifdef GEODETIC_SURFACE_NORMALS
  149. vec3 ellipsoidNormal = geodeticSurfaceNormal;
  150. #else
  151. vec3 ellipsoidNormal = normalize(position3DWC);
  152. #endif
  153. #if defined(EXAGGERATION) && defined(GEODETIC_SURFACE_NORMALS)
  154. float exaggeration = u_verticalExaggerationAndRelativeHeight.x;
  155. float relativeHeight = u_verticalExaggerationAndRelativeHeight.y;
  156. float newHeight = (height - relativeHeight) * exaggeration + relativeHeight;
  157. // stop from going through center of earth
  158. float minRadius = min(min(czm_ellipsoidRadii.x, czm_ellipsoidRadii.y), czm_ellipsoidRadii.z);
  159. newHeight = max(newHeight, -minRadius);
  160. vec3 offset = ellipsoidNormal * (newHeight - height);
  161. position += offset;
  162. position3DWC += offset;
  163. height = newHeight;
  164. #endif
  165. gl_Position = getPosition(position, height, textureCoordinates);
  166. v_positionEC = (u_modifiedModelView * vec4(position, 1.0)).xyz;
  167. v_positionMC = position3DWC; // position in model coordinates
  168. v_textureCoordinates = vec3(textureCoordinates, webMercatorT);
  169. #if defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL) || defined(APPLY_MATERIAL)
  170. vec3 normalMC = czm_octDecode(encodedNormal);
  171. #if defined(EXAGGERATION) && defined(GEODETIC_SURFACE_NORMALS)
  172. vec3 projection = dot(normalMC, ellipsoidNormal) * ellipsoidNormal;
  173. vec3 rejection = normalMC - projection;
  174. normalMC = normalize(projection + rejection * exaggeration);
  175. #endif
  176. v_normalMC = normalMC;
  177. v_normalEC = czm_normal3D * v_normalMC;
  178. #endif
  179. #ifdef ENABLE_CLIPPING_POLYGONS
  180. vec2 sphericalLatLong = czm_approximateSphericalCoordinates(position3DWC);
  181. sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);
  182. vec2 minDistance = vec2(czm_infinity);
  183. v_clippingPosition = vec2(czm_infinity);
  184. v_regionIndex = -1;
  185. for (int regionIndex = 0; regionIndex < CLIPPING_POLYGON_REGIONS_LENGTH; regionIndex++) {
  186. vec4 extents = unpackClippingExtents(u_clippingExtents, regionIndex);
  187. vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;
  188. vec2 clamped = clamp(rectUv, vec2(0.0), vec2(1.0));
  189. vec2 distance = abs(rectUv - clamped) * extents.wz;
  190. float threshold = 0.01;
  191. if (minDistance.x > distance.x || minDistance.y > distance.y) {
  192. minDistance = distance;
  193. v_clippingPosition = rectUv;
  194. if (rectUv.x > threshold && rectUv.y > threshold && rectUv.x < 1.0 - threshold && rectUv.y < 1.0 - threshold) {
  195. v_regionIndex = regionIndex;
  196. }
  197. }
  198. }
  199. #endif
  200. #if defined(FOG) || (defined(GROUND_ATMOSPHERE) && !defined(PER_FRAGMENT_GROUND_ATMOSPHERE))
  201. bool dynamicLighting = false;
  202. #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_DAYNIGHT_SHADING) || defined(ENABLE_VERTEX_LIGHTING))
  203. dynamicLighting = true;
  204. #endif
  205. #if defined(DYNAMIC_ATMOSPHERE_LIGHTING_FROM_SUN)
  206. vec3 atmosphereLightDirection = czm_sunDirectionWC;
  207. #else
  208. vec3 atmosphereLightDirection = czm_lightDirectionWC;
  209. #endif
  210. vec3 lightDirection = czm_branchFreeTernary(dynamicLighting, atmosphereLightDirection, normalize(position3DWC));
  211. computeAtmosphereScattering(
  212. position3DWC,
  213. lightDirection,
  214. v_atmosphereRayleighColor,
  215. v_atmosphereMieColor,
  216. v_atmosphereOpacity
  217. );
  218. #endif
  219. #if defined(FOG) || defined(GROUND_ATMOSPHERE) || defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT)
  220. v_distance = length((czm_modelView3D * vec4(position3DWC, 1.0)).xyz);
  221. #endif
  222. #ifdef APPLY_MATERIAL
  223. float northPoleZ = czm_ellipsoidRadii.z;
  224. vec3 northPolePositionMC = vec3(0.0, 0.0, northPoleZ);
  225. vec3 vectorEastMC = normalize(cross(northPolePositionMC - v_positionMC, ellipsoidNormal));
  226. float dotProd = abs(dot(ellipsoidNormal, v_normalMC));
  227. v_slope = acos(dotProd);
  228. vec3 normalRejected = ellipsoidNormal * dotProd;
  229. vec3 normalProjected = v_normalMC - normalRejected;
  230. vec3 aspectVector = normalize(normalProjected);
  231. v_aspect = acos(dot(aspectVector, vectorEastMC));
  232. float determ = dot(cross(vectorEastMC, aspectVector), ellipsoidNormal);
  233. v_aspect = czm_branchFreeTernary(determ < 0.0, 2.0 * czm_pi - v_aspect, v_aspect);
  234. v_height = height;
  235. #endif
  236. }