sampleOctahedralProjection.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "vec3 czm_sampleOctahedralProjectionWithFiltering(sampler2D projectedMap, vec2 textureSize, vec3 direction, float lod)\n\
  3. {\n\
  4. direction /= dot(vec3(1.0), abs(direction));\n\
  5. vec2 rev = abs(direction.zx) - vec2(1.0);\n\
  6. vec2 neg = vec2(direction.x < 0.0 ? rev.x : -rev.x,\n\
  7. direction.z < 0.0 ? rev.y : -rev.y);\n\
  8. vec2 uv = direction.y < 0.0 ? neg : direction.xz;\n\
  9. vec2 coord = 0.5 * uv + vec2(0.5);\n\
  10. vec2 pixel = 1.0 / textureSize;\n\
  11. if (lod > 0.0)\n\
  12. {\n\
  13. float scale = 1.0 / pow(2.0, lod);\n\
  14. float offset = ((textureSize.y + 1.0) / textureSize.x);\n\
  15. coord.x *= offset;\n\
  16. coord *= scale;\n\
  17. coord.x += offset + pixel.x;\n\
  18. coord.y += (1.0 - (1.0 / pow(2.0, lod - 1.0))) + pixel.y * (lod - 1.0) * 2.0;\n\
  19. }\n\
  20. else\n\
  21. {\n\
  22. coord.x *= (textureSize.y / textureSize.x);\n\
  23. }\n\
  24. #ifndef OES_texture_float_linear\n\
  25. vec3 color1 = texture2D(projectedMap, coord + vec2(0.0, pixel.y)).rgb;\n\
  26. vec3 color2 = texture2D(projectedMap, coord + vec2(pixel.x, 0.0)).rgb;\n\
  27. vec3 color3 = texture2D(projectedMap, coord + pixel).rgb;\n\
  28. vec3 color4 = texture2D(projectedMap, coord).rgb;\n\
  29. vec2 texturePosition = coord * textureSize;\n\
  30. float fu = fract(texturePosition.x);\n\
  31. float fv = fract(texturePosition.y);\n\
  32. vec3 average1 = mix(color4, color2, fu);\n\
  33. vec3 average2 = mix(color1, color3, fu);\n\
  34. vec3 color = mix(average1, average2, fv);\n\
  35. #else\n\
  36. vec3 color = texture2D(projectedMap, coord).rgb;\n\
  37. #endif\n\
  38. return color;\n\
  39. }\n\
  40. vec3 czm_sampleOctahedralProjection(sampler2D projectedMap, vec2 textureSize, vec3 direction, float lod, float maxLod) {\n\
  41. float currentLod = floor(lod + 0.5);\n\
  42. float nextLod = min(currentLod + 1.0, maxLod);\n\
  43. vec3 colorCurrentLod = czm_sampleOctahedralProjectionWithFiltering(projectedMap, textureSize, direction, currentLod);\n\
  44. vec3 colorNextLod = czm_sampleOctahedralProjectionWithFiltering(projectedMap, textureSize, direction, nextLod);\n\
  45. return mix(colorNextLod, colorCurrentLod, nextLod - lod);\n\
  46. }\n\
  47. ";