UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

45 lines (42 loc) 4.31 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{getHeightParameters as e}from"../views/3d/environment/ChapmanApproximation.glsl.js";import{ChapmanRaymarching as r}from"../views/3d/environment/ChapmanRaymarching.glsl.js";import{Gamma as a}from"../views/3d/webgl-engine/core/shaderLibrary/shading/Gamma.glsl.js";import{addMainLightDirection as o}from"../views/3d/webgl-engine/core/shaderLibrary/shading/MainLighting.glsl.js";import{Float2PassUniform as i}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{Float3BindUniform as t}from"../views/3d/webgl-engine/core/shaderModules/Float3BindUniform.js";import{Float3PassUniform as n}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{Float4PassUniform as s}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{FloatPassUniform as l}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{FloatsPassUniform as d}from"../views/3d/webgl-engine/core/shaderModules/FloatsPassUniform.js";import{glsl as m,If as c}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Texture2DBindUniform as g}from"../views/3d/webgl-engine/core/shaderModules/Texture2DBindUniform.js";import{ScreenSpacePassAtmosphere as u}from"../views/3d/webgl-engine/shaders/ScreenSpacePassAtmosphere.glsl.js";import{SphereIntersect as h}from"../views/3d/webgl-engine/shaders/SphereIntersect.glsl.js";import{ToneMapping as p}from"../views/3d/webgl-engine/shaders/ToneMapping.glsl.js";import{ShaderBuilder as f}from"../views/webgl/ShaderBuilder.js";function w(w){const v=new f;v.include(u);const{reduced:y}=w,{fragment:D}=v;return o(D),D.include(a),D.include(h),D.include(p),D.include(r,!1),D.uniforms.add(new d("heightParameters",5,(r,a)=>e(a,r)),new i("radii",e=>e.radii),new t("cameraPosition",e=>e.camera.eye),new l("innerFadeDistance",e=>e.innerFadeDistance),new s("undergroundColor",e=>e.undergroundColor),new l("altitudeFade",e=>e.altitudeFade)).code.add(m`vec4 applyUndergroundAtmosphere(vec3 rayDir, vec3 lightDirection, vec4 fragColor) { float rayPlanetDistance = heightParameters[3]; vec2 rayPlanetIntersect = sphereIntersect(cameraPosition, rayDir, rayPlanetDistance); if (!((rayPlanetIntersect.x <= rayPlanetIntersect.y) && rayPlanetIntersect.y > 0.0)) { return fragColor; } float lightAngle = dot(lightDirection, normalize(cameraPosition + rayDir * max(0.0, rayPlanetIntersect.x))); float surfaceShade = max(0.0, (smoothstep(-1.0, 0.8, 2.0 * lightAngle))); vec4 color = vec4(undergroundColor.rgb * surfaceShade, undergroundColor.a * (1.0 - altitudeFade)); float relDist = (rayPlanetIntersect.y - max(0.0, rayPlanetIntersect.x)) / innerFadeDistance; if (relDist > 1.0) { return color; } return mix(fragColor, color, smoothstep(0.0, 1.0, relDist * relDist)); } float getGlow(float dist, float radius, float intensity) { return pow(radius / max(dist, 1e-6), intensity); } vec3 getSun(vec3 rayDir, vec3 lightDir){ float scaleFract = (length(cameraPosition) - radii[0]) / scaleHeight; float sunOpticalDepth = getOpticalDepth(cameraPosition, rayDir, max(scaleFract, 0.0)); vec3 sunTransmittance = exp(-(mix(betaCombined, betaRayleigh, 0.5)) * max(0.0, sunOpticalDepth)); float mu = clamp(dot(rayDir, lightDir), 0.0, 1.0); float sunDisc = 256.0 * smoothstep(0.0, 128.0, clamp(getGlow(1.0 - mu, 3e-5, 3.0), 0.0, 128.0)); return normalize(sunTransmittance) * sunDisc; }`),D.uniforms.add(new n("backgroundColor",e=>e.backgroundColor),new g("depthTexture",e=>e.mainDepth)).main.add(m` vec3 rayDir = normalize(worldRay); ${c(!y,m` float depthSample = texture(depthTexture, uv).r; if (depthSample != 1.0) { fragColor = vec4(0.0); return; }`)} vec3 color = linearizeGamma(backgroundColor) + raymarchAtmosphere(rayDir, mainLightDirection, -1.0) + getSun(rayDir, mainLightDirection); float alpha = smoothstep(0.0, mix(0.15, 0.01, heightParameters[2]), length(color)); color = tonemapACES(color); fragColor = delinearizeGamma(vec4(color, alpha)); fragColor = applyUndergroundAtmosphere(rayDir, mainLightDirection, fragColor); `),v}const v=Object.freeze(Object.defineProperty({__proto__:null,build:w},Symbol.toStringTag,{value:"Module"}));export{v as C,w as b};