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

ShadowVolumeAppearanceFS.glsl 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifdef TEXTURE_COORDINATES
  2. #ifdef SPHERICAL
  3. in vec4 v_sphericalExtents;
  4. #else // SPHERICAL
  5. in vec2 v_inversePlaneExtents;
  6. in vec4 v_westPlane;
  7. in vec4 v_southPlane;
  8. #endif // SPHERICAL
  9. in vec3 v_uvMinAndSphericalLongitudeRotation;
  10. in vec3 v_uMaxAndInverseDistance;
  11. in vec3 v_vMaxAndInverseDistance;
  12. #endif // TEXTURE_COORDINATES
  13. #ifdef PER_INSTANCE_COLOR
  14. in vec4 v_color;
  15. #endif
  16. #ifdef NORMAL_EC
  17. vec3 getEyeCoordinate3FromWindowCoordinate(vec2 fragCoord, float logDepthOrDepth) {
  18. vec4 eyeCoordinate = czm_windowToEyeCoordinates(fragCoord, logDepthOrDepth);
  19. return eyeCoordinate.xyz / eyeCoordinate.w;
  20. }
  21. vec3 vectorFromOffset(vec4 eyeCoordinate, vec2 positiveOffset) {
  22. vec2 glFragCoordXY = gl_FragCoord.xy;
  23. // Sample depths at both offset and negative offset
  24. float upOrRightLogDepth = czm_unpackDepth(texture(czm_globeDepthTexture, (glFragCoordXY + positiveOffset) / czm_viewport.zw));
  25. float downOrLeftLogDepth = czm_unpackDepth(texture(czm_globeDepthTexture, (glFragCoordXY - positiveOffset) / czm_viewport.zw));
  26. // Explicitly evaluate both paths
  27. // Necessary for multifrustum and for edges of the screen
  28. bvec2 upOrRightInBounds = lessThan(glFragCoordXY + positiveOffset, czm_viewport.zw);
  29. float useUpOrRight = float(upOrRightLogDepth > 0.0 && upOrRightInBounds.x && upOrRightInBounds.y);
  30. float useDownOrLeft = float(useUpOrRight == 0.0);
  31. vec3 upOrRightEC = getEyeCoordinate3FromWindowCoordinate(glFragCoordXY + positiveOffset, upOrRightLogDepth);
  32. vec3 downOrLeftEC = getEyeCoordinate3FromWindowCoordinate(glFragCoordXY - positiveOffset, downOrLeftLogDepth);
  33. return (upOrRightEC - (eyeCoordinate.xyz / eyeCoordinate.w)) * useUpOrRight + ((eyeCoordinate.xyz / eyeCoordinate.w) - downOrLeftEC) * useDownOrLeft;
  34. }
  35. #endif // NORMAL_EC
  36. void main(void)
  37. {
  38. #ifdef REQUIRES_EC
  39. float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw));
  40. vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);
  41. #endif
  42. #ifdef REQUIRES_WC
  43. vec4 worldCoordinate4 = czm_inverseView * eyeCoordinate;
  44. vec3 worldCoordinate = worldCoordinate4.xyz / worldCoordinate4.w;
  45. #endif
  46. #ifdef TEXTURE_COORDINATES
  47. vec2 uv;
  48. #ifdef SPHERICAL
  49. // Treat world coords as a sphere normal for spherical coordinates
  50. vec2 sphericalLatLong = czm_approximateSphericalCoordinates(worldCoordinate);
  51. sphericalLatLong.y += v_uvMinAndSphericalLongitudeRotation.z;
  52. sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);
  53. uv.x = (sphericalLatLong.y - v_sphericalExtents.y) * v_sphericalExtents.w;
  54. uv.y = (sphericalLatLong.x - v_sphericalExtents.x) * v_sphericalExtents.z;
  55. #else // SPHERICAL
  56. // Unpack planes and transform to eye space
  57. uv.x = czm_planeDistance(v_westPlane, eyeCoordinate.xyz / eyeCoordinate.w) * v_inversePlaneExtents.x;
  58. uv.y = czm_planeDistance(v_southPlane, eyeCoordinate.xyz / eyeCoordinate.w) * v_inversePlaneExtents.y;
  59. #endif // SPHERICAL
  60. #endif // TEXTURE_COORDINATES
  61. #ifdef CULL_FRAGMENTS
  62. // When classifying translucent geometry, logDepthOrDepth == 0.0
  63. // indicates a region that should not be classified, possibly due to there
  64. // being opaque pixels there in another buffer.
  65. if (uv.x <= 0.0 || 1.0 <= uv.x || uv.y <= 0.0 || 1.0 <= uv.y || logDepthOrDepth == 0.0) {
  66. discard;
  67. }
  68. #endif
  69. #ifdef PICK
  70. out_FragColor.a = 1.0; // Explicitly set the alpha, otherwise this may be discarded by ShaderSource.createPickFragmentShaderSource
  71. #ifdef CULL_FRAGMENTS
  72. czm_writeDepthClamp();
  73. #endif // CULL_FRAGMENTS
  74. #else // PICK
  75. #ifdef NORMAL_EC
  76. // Compute normal by sampling adjacent pixels in 2x2 block in screen space
  77. vec3 downUp = vectorFromOffset(eyeCoordinate, vec2(0.0, 1.0));
  78. vec3 leftRight = vectorFromOffset(eyeCoordinate, vec2(1.0, 0.0));
  79. vec3 normalEC = normalize(cross(leftRight, downUp));
  80. #endif
  81. #ifdef PER_INSTANCE_COLOR
  82. vec4 color = czm_gammaCorrect(v_color);
  83. #ifdef FLAT
  84. out_FragColor = color;
  85. #else // FLAT
  86. czm_materialInput materialInput;
  87. materialInput.normalEC = normalEC;
  88. materialInput.positionToEyeEC = -eyeCoordinate.xyz;
  89. czm_material material = czm_getDefaultMaterial(materialInput);
  90. material.diffuse = color.rgb;
  91. material.alpha = color.a;
  92. out_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC);
  93. #endif // FLAT
  94. // Premultiply alpha. Required for classification primitives on translucent globe.
  95. out_FragColor.rgb *= out_FragColor.a;
  96. #else // PER_INSTANCE_COLOR
  97. // Material support.
  98. // USES_ is distinct from REQUIRES_, because some things are dependencies of each other or
  99. // dependencies for culling but might not actually be used by the material.
  100. czm_materialInput materialInput;
  101. #ifdef USES_NORMAL_EC
  102. materialInput.normalEC = normalEC;
  103. #endif
  104. #ifdef USES_POSITION_TO_EYE_EC
  105. materialInput.positionToEyeEC = -eyeCoordinate.xyz;
  106. #endif
  107. #ifdef USES_TANGENT_TO_EYE
  108. materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(worldCoordinate, normalEC);
  109. #endif
  110. #ifdef USES_ST
  111. // Remap texture coordinates from computed (approximately aligned with cartographic space) to the desired
  112. // texture coordinate system, which typically forms a tight oriented bounding box around the geometry.
  113. // Shader is provided a set of reference points for remapping.
  114. materialInput.st.x = czm_lineDistance(v_uvMinAndSphericalLongitudeRotation.xy, v_uMaxAndInverseDistance.xy, uv) * v_uMaxAndInverseDistance.z;
  115. materialInput.st.y = czm_lineDistance(v_uvMinAndSphericalLongitudeRotation.xy, v_vMaxAndInverseDistance.xy, uv) * v_vMaxAndInverseDistance.z;
  116. #endif
  117. czm_material material = czm_getMaterial(materialInput);
  118. #ifdef FLAT
  119. out_FragColor = vec4(material.diffuse + material.emission, material.alpha);
  120. #else // FLAT
  121. out_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC);
  122. #endif // FLAT
  123. // Premultiply alpha. Required for classification primitives on translucent globe.
  124. out_FragColor.rgb *= out_FragColor.a;
  125. #endif // PER_INSTANCE_COLOR
  126. czm_writeDepthClamp();
  127. #endif // PICK
  128. }