/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import{smoothstep as r}from"../../../../core/mathUtils.js";import{set as t}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{squaredLength as a}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{radiusModifier as s}from"../../../../geometry/ellipsoidUtils.js";import{moon as i,mars as n,earth as l}from"../../../../geometry/support/Ellipsoid.js";import{Float2BindUniform as c}from"../core/shaderModules/Float2BindUniform.js";import{Float3BindUniform as m}from"../core/shaderModules/Float3BindUniform.js";import{glsl as p}from"../core/shaderModules/glsl.js";import{parameter as h,ShaderTechniqueConfiguration as d}from"../core/shaderTechnique/ShaderTechniqueConfiguration.js";import{SphereIntersect as f}from"./SphereIntersect.glsl.js";class u extends d{constructor(){super(...arguments),this.ellipsoidMode=1}}function y(e,o){e.fragment.uniforms.add(new c("cameraHeights",e=>{const i=e.camera,n=a(i.eye),l=Math.sqrt(n),c=j(o)*s,m=n-c*c;let p=r(4e6,5e6,l-c);return p=Math.min(p,.98),t(g,p,m)}),new m("cameraPosition",e=>e.camera.eye)),e.fragment.include(f),e.fragment.code.add(p`float sphereFade() {return cameraHeights[0];}
float sphereDepthInterpolate(vec3 worldRay, vec3 viewRay, float currentLinearDepth) {
vec2 rayPlanetIntersect = sphereIntersect(cameraPosition, worldRay, cameraHeights[1]);
bool hitsPlanet = (rayPlanetIntersect.x <= rayPlanetIntersect.y) && rayPlanetIntersect.x > 0.0;
if (hitsPlanet) {
float sphereDepth = rayPlanetIntersect.x;
viewRay *= viewRay.z*sphereDepth;
float linearDepth = length(viewRay);
float sphereFade = cameraHeights[0];
return (-linearDepth) * sphereFade + currentLinearDepth * (1.0 - sphereFade);
}
return currentLinearDepth;
}`)}e([h({count:4})],u.prototype,"ellipsoidMode",void 0);const g=o();function j({ellipsoidMode:e}){switch(e){case 4:case 1:return l.radius;case 2:return n.radius;case 3:return i.radius}}export{u as SphereDepthInterpolateConfiguration,j as getPlanetRadius,y as sphereDepthInterpolate};
