/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{smoothstep as e}from"../../../../core/mathUtils.js";import{set as r}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{D as a}from"../../../../chunks/vec32.js";import{Float2BindUniform as o}from"../core/shaderModules/Float2BindUniform.js";import{Float3BindUniform as s}from"../core/shaderModules/Float3BindUniform.js";import{glsl as n}from"../core/shaderModules/glsl.js";import{SphereIntersect as i}from"./SphereIntersect.glsl.js";function c(t,c){t.fragment.uniforms.add(new o("cameraHeights",t=>{const o=t.camera,s=a(o.eye),n=Math.sqrt(s),i=c.radius,m=s-i*i;let h=e(4e6,5e6,n-i);return h=Math.min(h,.98),r(l,h,m)}),new s("cameraPosition",e=>e.camera.eye)),t.fragment.include(i),t.fragment.code.add(n`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;
}`)}const l=t();export{c as sphereDepthInterpolate};
