ShadowVolumeAppearanceFS.js 7.1 KB

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