/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{set as i}from"../../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as t}from"../../../../../../core/libs/gl-matrix-2/math/vec4.js";import{create as e}from"../../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{Float3BindUniform as h}from"../../shaderModules/Float3BindUniform.js";import{Float4BindUniform as g}from"../../shaderModules/Float4BindUniform.js";import{glsl as s}from"../../shaderModules/glsl.js";function m(n,e){const m=void 0!==e.lightingSphericalHarmonicsOrder?e.lightingSphericalHarmonicsOrder:2;0===m?(n.uniforms.add(new h("lightingAmbientSH0",({lighting:n})=>i(r,n.sh.r[0],n.sh.g[0],n.sh.b[0]))),n.code.add(s`vec3 calculateAmbientIrradiance(vec3 normal, float ambientOcclusion) {
vec3 ambientLight = 0.282095 * lightingAmbientSH0;
return ambientLight * (1.0 - ambientOcclusion);
}`)):1===m?(n.uniforms.add(new g("lightingAmbientSH_R",({lighting:i})=>t(l,i.sh.r[0],i.sh.r[1],i.sh.r[2],i.sh.r[3])),new g("lightingAmbientSH_G",({lighting:i})=>t(l,i.sh.g[0],i.sh.g[1],i.sh.g[2],i.sh.g[3])),new g("lightingAmbientSH_B",({lighting:i})=>t(l,i.sh.b[0],i.sh.b[1],i.sh.b[2],i.sh.b[3]))),n.code.add(s`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===m&&(n.uniforms.add(new h("lightingAmbientSH0",({lighting:n})=>i(r,n.sh.r[0],n.sh.g[0],n.sh.b[0])),new g("lightingAmbientSH_R1",({lighting:i})=>t(l,i.sh.r[1],i.sh.r[2],i.sh.r[3],i.sh.r[4])),new g("lightingAmbientSH_G1",({lighting:i})=>t(l,i.sh.g[1],i.sh.g[2],i.sh.g[3],i.sh.g[4])),new g("lightingAmbientSH_B1",({lighting:i})=>t(l,i.sh.b[1],i.sh.b[2],i.sh.b[3],i.sh.b[4])),new g("lightingAmbientSH_R2",({lighting:i})=>t(l,i.sh.r[5],i.sh.r[6],i.sh.r[7],i.sh.r[8])),new g("lightingAmbientSH_G2",({lighting:i})=>t(l,i.sh.g[5],i.sh.g[6],i.sh.g[7],i.sh.g[8])),new g("lightingAmbientSH_B2",({lighting:i})=>t(l,i.sh.b[5],i.sh.b[6],i.sh.b[7],i.sh.b[8]))),n.code.add(s`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);
}`),1!==e.pbrMode&&2!==e.pbrMode||n.code.add(s`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 r=n(),l=e();export{m as EvaluateAmbientLighting};
