ShadowVolumeAppearanceFS.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#ifdef GL_EXT_frag_depth\n\
  3. #extension GL_EXT_frag_depth : enable\n\
  4. #endif\n\
  5. #ifdef TEXTURE_COORDINATES\n\
  6. #ifdef SPHERICAL\n\
  7. varying vec4 v_sphericalExtents;\n\
  8. #else // SPHERICAL\n\
  9. varying vec2 v_inversePlaneExtents;\n\
  10. varying vec4 v_westPlane;\n\
  11. varying vec4 v_southPlane;\n\
  12. #endif // SPHERICAL\n\
  13. varying vec3 v_uvMinAndSphericalLongitudeRotation;\n\
  14. varying vec3 v_uMaxAndInverseDistance;\n\
  15. varying vec3 v_vMaxAndInverseDistance;\n\
  16. #endif // TEXTURE_COORDINATES\n\
  17. #ifdef PER_INSTANCE_COLOR\n\
  18. varying vec4 v_color;\n\
  19. #endif\n\
  20. #ifdef NORMAL_EC\n\
  21. vec3 getEyeCoordinate3FromWindowCoordinate(vec2 fragCoord, float logDepthOrDepth)\n\
  22. {\n\
  23. vec4 eyeCoordinate = czm_windowToEyeCoordinates(fragCoord, logDepthOrDepth);\n\
  24. return eyeCoordinate.xyz / eyeCoordinate.w;\n\
  25. }\n\
  26. vec3 vectorFromOffset(vec4 eyeCoordinate, vec2 positiveOffset)\n\
  27. {\n\
  28. vec2 glFragCoordXY = gl_FragCoord.xy;\n\
  29. float upOrRightLogDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, (glFragCoordXY + positiveOffset) / czm_viewport.zw));\n\
  30. float downOrLeftLogDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, (glFragCoordXY - positiveOffset) / czm_viewport.zw));\n\
  31. bvec2 upOrRightInBounds = lessThan(glFragCoordXY + positiveOffset, czm_viewport.zw);\n\
  32. float useUpOrRight = float(upOrRightLogDepth > 0.0 && upOrRightInBounds.x && upOrRightInBounds.y);\n\
  33. float useDownOrLeft = float(useUpOrRight == 0.0);\n\
  34. vec3 upOrRightEC = getEyeCoordinate3FromWindowCoordinate(glFragCoordXY + positiveOffset, upOrRightLogDepth);\n\
  35. vec3 downOrLeftEC = getEyeCoordinate3FromWindowCoordinate(glFragCoordXY - positiveOffset, downOrLeftLogDepth);\n\
  36. return (upOrRightEC - (eyeCoordinate.xyz / eyeCoordinate.w)) * useUpOrRight + ((eyeCoordinate.xyz / eyeCoordinate.w) - downOrLeftEC) * useDownOrLeft;\n\
  37. }\n\
  38. #endif // NORMAL_EC\n\
  39. void main(void)\n\
  40. {\n\
  41. #ifdef REQUIRES_EC\n\
  42. float logDepthOrDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw));\n\
  43. vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\n\
  44. #endif\n\
  45. #ifdef REQUIRES_WC\n\
  46. vec4 worldCoordinate4 = czm_inverseView * eyeCoordinate;\n\
  47. vec3 worldCoordinate = worldCoordinate4.xyz / worldCoordinate4.w;\n\
  48. #endif\n\
  49. #ifdef TEXTURE_COORDINATES\n\
  50. vec2 uv;\n\
  51. #ifdef SPHERICAL\n\
  52. vec2 sphericalLatLong = czm_approximateSphericalCoordinates(worldCoordinate);\n\
  53. sphericalLatLong.y += v_uvMinAndSphericalLongitudeRotation.z;\n\
  54. sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);\n\
  55. uv.x = (sphericalLatLong.y - v_sphericalExtents.y) * v_sphericalExtents.w;\n\
  56. uv.y = (sphericalLatLong.x - v_sphericalExtents.x) * v_sphericalExtents.z;\n\
  57. #else // SPHERICAL\n\
  58. uv.x = czm_planeDistance(v_westPlane, eyeCoordinate.xyz / eyeCoordinate.w) * v_inversePlaneExtents.x;\n\
  59. uv.y = czm_planeDistance(v_southPlane, eyeCoordinate.xyz / eyeCoordinate.w) * v_inversePlaneExtents.y;\n\
  60. #endif // SPHERICAL\n\
  61. #endif // TEXTURE_COORDINATES\n\
  62. #ifdef PICK\n\
  63. #ifdef CULL_FRAGMENTS\n\
  64. if (0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0)\n\
  65. {\n\
  66. gl_FragColor.a = 1.0;\n\
  67. czm_writeDepthClampedToFarPlane();\n\
  68. }\n\
  69. #else // CULL_FRAGMENTS\n\
  70. gl_FragColor.a = 1.0;\n\
  71. #endif // CULL_FRAGMENTS\n\
  72. #else // PICK\n\
  73. #ifdef CULL_FRAGMENTS\n\
  74. if (uv.x <= 0.0 || 1.0 <= uv.x || uv.y <= 0.0 || 1.0 <= uv.y)\n\
  75. {\n\
  76. discard;\n\
  77. }\n\
  78. #endif\n\
  79. #ifdef NORMAL_EC\n\
  80. vec3 downUp = vectorFromOffset(eyeCoordinate, vec2(0.0, 1.0));\n\
  81. vec3 leftRight = vectorFromOffset(eyeCoordinate, vec2(1.0, 0.0));\n\
  82. vec3 normalEC = normalize(cross(leftRight, downUp));\n\
  83. #endif\n\
  84. #ifdef PER_INSTANCE_COLOR\n\
  85. vec4 color = czm_gammaCorrect(v_color);\n\
  86. #ifdef FLAT\n\
  87. gl_FragColor = color;\n\
  88. #else // FLAT\n\
  89. czm_materialInput materialInput;\n\
  90. materialInput.normalEC = normalEC;\n\
  91. materialInput.positionToEyeEC = -eyeCoordinate.xyz;\n\
  92. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  93. material.diffuse = color.rgb;\n\
  94. material.alpha = color.a;\n\
  95. gl_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material);\n\
  96. #endif // FLAT\n\
  97. #else // PER_INSTANCE_COLOR\n\
  98. czm_materialInput materialInput;\n\
  99. #ifdef USES_NORMAL_EC\n\
  100. materialInput.normalEC = normalEC;\n\
  101. #endif\n\
  102. #ifdef USES_POSITION_TO_EYE_EC\n\
  103. materialInput.positionToEyeEC = -eyeCoordinate.xyz;\n\
  104. #endif\n\
  105. #ifdef USES_TANGENT_TO_EYE\n\
  106. materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(worldCoordinate, normalEC);\n\
  107. #endif\n\
  108. #ifdef USES_ST\n\
  109. materialInput.st.x = czm_lineDistance(v_uvMinAndSphericalLongitudeRotation.xy, v_uMaxAndInverseDistance.xy, uv) * v_uMaxAndInverseDistance.z;\n\
  110. materialInput.st.y = czm_lineDistance(v_uvMinAndSphericalLongitudeRotation.xy, v_vMaxAndInverseDistance.xy, uv) * v_vMaxAndInverseDistance.z;\n\
  111. #endif\n\
  112. czm_material material = czm_getMaterial(materialInput);\n\
  113. #ifdef FLAT\n\
  114. gl_FragColor = vec4(material.diffuse + material.emission, material.alpha);\n\
  115. #else // FLAT\n\
  116. gl_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material);\n\
  117. #endif // FLAT\n\
  118. #endif // PER_INSTANCE_COLOR\n\
  119. czm_writeDepthClampedToFarPlane();\n\
  120. #endif // PICK\n\
  121. }\n\
  122. ";