shadowVisibility.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "\n\
  3. float czm_private_shadowVisibility(float visibility, float nDotL, float normalShadingSmooth, float darkness)\n\
  4. {\n\
  5. #ifdef USE_NORMAL_SHADING\n\
  6. #ifdef USE_NORMAL_SHADING_SMOOTH\n\
  7. float strength = clamp(nDotL / normalShadingSmooth, 0.0, 1.0);\n\
  8. #else\n\
  9. float strength = step(0.0, nDotL);\n\
  10. #endif\n\
  11. visibility *= strength;\n\
  12. #endif\n\
  13. \n\
  14. visibility = max(visibility, darkness);\n\
  15. return visibility;\n\
  16. }\n\
  17. \n\
  18. #ifdef USE_CUBE_MAP_SHADOW\n\
  19. float czm_shadowVisibility(samplerCube shadowMap, czm_shadowParameters shadowParameters)\n\
  20. {\n\
  21. float depthBias = shadowParameters.depthBias;\n\
  22. float depth = shadowParameters.depth;\n\
  23. float nDotL = shadowParameters.nDotL;\n\
  24. float normalShadingSmooth = shadowParameters.normalShadingSmooth;\n\
  25. float darkness = shadowParameters.darkness;\n\
  26. vec3 uvw = shadowParameters.texCoords;\n\
  27. \n\
  28. depth -= depthBias;\n\
  29. float visibility = czm_shadowDepthCompare(shadowMap, uvw, depth);\n\
  30. return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);\n\
  31. }\n\
  32. #else\n\
  33. float czm_shadowVisibility(sampler2D shadowMap, czm_shadowParameters shadowParameters)\n\
  34. {\n\
  35. float depthBias = shadowParameters.depthBias;\n\
  36. float depth = shadowParameters.depth;\n\
  37. float nDotL = shadowParameters.nDotL;\n\
  38. float normalShadingSmooth = shadowParameters.normalShadingSmooth;\n\
  39. float darkness = shadowParameters.darkness;\n\
  40. vec2 uv = shadowParameters.texCoords;\n\
  41. \n\
  42. depth -= depthBias;\n\
  43. #ifdef USE_SOFT_SHADOWS\n\
  44. vec2 texelStepSize = shadowParameters.texelStepSize;\n\
  45. float radius = 1.0;\n\
  46. float dx0 = -texelStepSize.x * radius;\n\
  47. float dy0 = -texelStepSize.y * radius;\n\
  48. float dx1 = texelStepSize.x * radius;\n\
  49. float dy1 = texelStepSize.y * radius;\n\
  50. float visibility = (\n\
  51. czm_shadowDepthCompare(shadowMap, uv, depth) +\n\
  52. czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, dy0), depth) +\n\
  53. czm_shadowDepthCompare(shadowMap, uv + vec2(0.0, dy0), depth) +\n\
  54. czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, dy0), depth) +\n\
  55. czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, 0.0), depth) +\n\
  56. czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, 0.0), depth) +\n\
  57. czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, dy1), depth) +\n\
  58. czm_shadowDepthCompare(shadowMap, uv + vec2(0.0, dy1), depth) +\n\
  59. czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, dy1), depth)\n\
  60. ) * (1.0 / 9.0);\n\
  61. #else\n\
  62. float visibility = czm_shadowDepthCompare(shadowMap, uv, depth);\n\
  63. #endif\n\
  64. \n\
  65. return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);\n\
  66. }\n\
  67. #endif\n\
  68. ";