@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
52 lines (51 loc) • 3.5 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{i}from"../../../../../../chunks/vec32.js";import{create as n}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as t}from"../../../../../../chunks/vec42.js";import{create as e}from"../../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{PBRMode as h}from"./PhysicallyBasedRenderingParameters.glsl.js";import{Float3BindUniform as s}from"../../shaderModules/Float3BindUniform.js";import{Float4BindUniform as g}from"../../shaderModules/Float4BindUniform.js";import{glsl as r}from"../../shaderModules/glsl.js";function m(n,e){const m=n.fragment,o=void 0!==e.lightingSphericalHarmonicsOrder?e.lightingSphericalHarmonicsOrder:2;0===o?(m.uniforms.add(new s("lightingAmbientSH0",(({lighting:n})=>i(l,n.sh.r[0],n.sh.g[0],n.sh.b[0])))),m.code.add(r`vec3 calculateAmbientIrradiance(vec3 normal, float ambientOcclusion) {
vec3 ambientLight = 0.282095 * lightingAmbientSH0;
return ambientLight * (1.0 - ambientOcclusion);
}`)):1===o?(m.uniforms.add(new g("lightingAmbientSH_R",(({lighting:i})=>t(a,i.sh.r[0],i.sh.r[1],i.sh.r[2],i.sh.r[3]))),new g("lightingAmbientSH_G",(({lighting:i})=>t(a,i.sh.g[0],i.sh.g[1],i.sh.g[2],i.sh.g[3]))),new g("lightingAmbientSH_B",(({lighting:i})=>t(a,i.sh.b[0],i.sh.b[1],i.sh.b[2],i.sh.b[3])))),m.code.add(r`vec3 calculateAmbientIrradiance(vec3 normal, float ambientOcclusion) {
vec4 sh0 = vec4(
0.282095,
0.488603 * normal.x,
0.488603 * normal.z,
0.488603 * normal.y
);
vec3 ambientLight = vec3(
dot(lightingAmbientSH_R, sh0),
dot(lightingAmbientSH_G, sh0),
dot(lightingAmbientSH_B, sh0)
);
return ambientLight * (1.0 - ambientOcclusion);
}`)):2===o&&(m.uniforms.add(new s("lightingAmbientSH0",(({lighting:n})=>i(l,n.sh.r[0],n.sh.g[0],n.sh.b[0]))),new g("lightingAmbientSH_R1",(({lighting:i})=>t(a,i.sh.r[1],i.sh.r[2],i.sh.r[3],i.sh.r[4]))),new g("lightingAmbientSH_G1",(({lighting:i})=>t(a,i.sh.g[1],i.sh.g[2],i.sh.g[3],i.sh.g[4]))),new g("lightingAmbientSH_B1",(({lighting:i})=>t(a,i.sh.b[1],i.sh.b[2],i.sh.b[3],i.sh.b[4]))),new g("lightingAmbientSH_R2",(({lighting:i})=>t(a,i.sh.r[5],i.sh.r[6],i.sh.r[7],i.sh.r[8]))),new g("lightingAmbientSH_G2",(({lighting:i})=>t(a,i.sh.g[5],i.sh.g[6],i.sh.g[7],i.sh.g[8]))),new g("lightingAmbientSH_B2",(({lighting:i})=>t(a,i.sh.b[5],i.sh.b[6],i.sh.b[7],i.sh.b[8])))),m.code.add(r`vec3 calculateAmbientIrradiance(vec3 normal, float ambientOcclusion) {
vec3 ambientLight = 0.282095 * lightingAmbientSH0;
vec4 sh1 = vec4(
0.488603 * normal.x,
0.488603 * normal.z,
0.488603 * normal.y,
1.092548 * normal.x * normal.y
);
vec4 sh2 = vec4(
1.092548 * normal.y * normal.z,
0.315392 * (3.0 * normal.z * normal.z - 1.0),
1.092548 * normal.x * normal.z,
0.546274 * (normal.x * normal.x - normal.y * normal.y)
);
ambientLight += vec3(
dot(lightingAmbientSH_R1, sh1),
dot(lightingAmbientSH_G1, sh1),
dot(lightingAmbientSH_B1, sh1)
);
ambientLight += vec3(
dot(lightingAmbientSH_R2, sh2),
dot(lightingAmbientSH_G2, sh2),
dot(lightingAmbientSH_B2, sh2)
);
return ambientLight * (1.0 - ambientOcclusion);
}`),e.pbrMode!==h.Normal&&e.pbrMode!==h.Schematic||m.code.add(r`const vec3 skyTransmittance = vec3(0.9, 0.9, 1.0);
vec3 calculateAmbientRadiance(float ambientOcclusion)
{
vec3 ambientLight = 1.2 * (0.282095 * lightingAmbientSH0) - 0.2;
return ambientLight *= (1.0 - ambientOcclusion) * skyTransmittance;
}`))}const l=n(),a=e();export{m as EvaluateAmbientLighting};