SimpleAtmosphere.glsl.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{SimpleAtmosphereGeometry as e}from"../views/3d/environment/SimpleAtmosphereTechniqueConfiguration.js";import{Transform as o}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{Float2Uniform as i}from"../views/3d/webgl-engine/core/shaderModules/Float2Uniform.js";import{Float3PassUniform as r}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{Float3Uniform as n}from"../views/3d/webgl-engine/core/shaderModules/Float3Uniform.js";import{FloatUniform as t}from"../views/3d/webgl-engine/core/shaderModules/FloatUniform.js";import{NoParameters as s,glsl as a}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{Matrix4PassUniform as l}from"../views/3d/webgl-engine/core/shaderModules/Matrix4PassUniform.js";import{Matrix4Uniform as d}from"../views/3d/webgl-engine/core/shaderModules/Matrix4Uniform.js";import{ShaderBuilder as c}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{Texture2DPassUniform as m}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{VertexAttribute as g}from"../views/3d/webgl-engine/lib/VertexAttribute.js";class f extends s{}function p(s){const f=new c,{vertex:p,fragment:v}=f;if(s.geometry===e.Underground)f.attributes.add(g.POSITION,"vec2"),f.varyings.add("color","vec4"),p.uniforms.add([new r("lightingMainDirection",((e,o)=>o.lighting.lightingMainDirection)),new n("cameraPosition"),new t("undergroundFadeAlpha")]),p.code.add(a`void main(void) {
  6. float ndotl = dot(normalize(cameraPosition), lightingMainDirection);
  7. float lighting = max(0.0, smoothstep(-1.0, 0.8, 2.0 * ndotl));
  8. color = vec4(vec3(lighting), undergroundFadeAlpha);
  9. gl_Position = vec4(position.xy, 1.0, 1.0);
  10. }`),v.code.add(a`void main() {
  11. gl_FragColor = color;
  12. }`);else{f.include(o),f.attributes.add(g.POSITION,"vec3"),f.varyings.add("vtc","vec2"),f.varyings.add("falloff","float");const c=s.geometry===e.Cylinder;p.uniforms.add([new l("proj",((e,o)=>o.camera.projectionMatrix)),new d("view"),new r("lightingMainDirection",((e,o)=>o.lighting.lightingMainDirection))]),c||(f.varyings.add("innerFactor","float"),p.uniforms.add(new n("silCircleCenter")),p.uniforms.add(new n("silCircleV1")),p.uniforms.add(new n("silCircleV2")),p.uniforms.add(new i("texV")),p.uniforms.add(new t("innerScale")));const u=6.2831853,w=1/128;p.code.add(a`
  13. void main(void) {
  14. ${c?a`
  15. vec3 pos = position;
  16. float ndotl = lightingMainDirection.z;
  17. vtc = vec2(0.0, position.z + 0.05);`:a`
  18. innerFactor = clamp(-position.z, 0.0, 1.0);
  19. float scale = position.y * (1.0 + innerFactor * innerScale);
  20. float phi = position.x * ${a.float(u*w)} + 1.0;
  21. vec3 pos = (silCircleCenter + sin(phi) * silCircleV1 + cos(phi) * silCircleV2) * scale;
  22. float ndotl = dot(normalize(position.y > 0.0 ? pos: silCircleCenter), lightingMainDirection);
  23. vtc.x = position.x * ${a.float(w)};
  24. vtc.y = texV.x * (1.0 - position.z) + texV.y * position.z;
  25. `}
  26. falloff = max(0.0, smoothstep(-1.0, 0.8, 2.0 * ndotl));
  27. gl_Position = transformPosition(proj, view, pos);
  28. gl_Position.z = gl_Position.w; // project atmosphere onto the far plane
  29. }
  30. `),v.uniforms.add(new m("tex",(e=>e.texture))),c||v.uniforms.add(new t("altitudeFade")),v.code.add(a`
  31. void main() {
  32. vec4 atmosphereColor = texture2D(tex, vtc) * falloff;
  33. ${c?a`gl_FragColor = atmosphereColor;`:a`
  34. vec4 innerColor = vec4(atmosphereColor.rgb, 1.0 - altitudeFade);
  35. gl_FragColor = mix(atmosphereColor, innerColor, smoothstep(0.0, 1.0, innerFactor));
  36. `}
  37. }`)}return f}const v=Object.freeze(Object.defineProperty({__proto__:null,SimpleAtmospherePassParameters:f,build:p},Symbol.toStringTag,{value:"Module"}));export{f as S,v as a,p as b};