UNPKG

@doegis/core

Version:

DOE GIS API

49 lines (47 loc) 3.59 kB
import{s as i}from"../../../../../../chunks/vec3.js";import{c as n}from"../../../../../../chunks/vec3f64.js";import{s as t}from"../../../../../../chunks/vec4.js";import{c as g}from"../../../../../../chunks/vec4f64.js";import{PBRMode as h}from"./PhysicallyBasedRenderingParameters.glsl.js";import{Float3PassUniform as e}from"../../shaderModules/Float3PassUniform.js";import{Float4PassUniform as l}from"../../shaderModules/Float4PassUniform.js";import{glsl as s}from"../../shaderModules/interfaces.js";function m(n,g){const m=n.fragment,o=void 0!==g.lightingSphericalHarmonicsOrder?g.lightingSphericalHarmonicsOrder:2;0===o?(m.uniforms.add(new e("lightingAmbientSH0",((n,t)=>i(a,t.lighting.sh.r[0],t.lighting.sh.g[0],t.lighting.sh.b[0])))),m.code.add(s`vec3 calculateAmbientIrradiance(vec3 normal, float ambientOcclusion) { vec3 ambientLight = 0.282095 * lightingAmbientSH0; return ambientLight * (1.0 - ambientOcclusion); }`)):1===o?(m.uniforms.add([new l("lightingAmbientSH_R",((i,n)=>t(r,n.lighting.sh.r[0],n.lighting.sh.r[1],n.lighting.sh.r[2],n.lighting.sh.r[3]))),new l("lightingAmbientSH_G",((i,n)=>t(r,n.lighting.sh.g[0],n.lighting.sh.g[1],n.lighting.sh.g[2],n.lighting.sh.g[3]))),new l("lightingAmbientSH_B",((i,n)=>t(r,n.lighting.sh.b[0],n.lighting.sh.b[1],n.lighting.sh.b[2],n.lighting.sh.b[3])))]),m.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===o&&(m.uniforms.add([new e("lightingAmbientSH0",((n,t)=>i(a,t.lighting.sh.r[0],t.lighting.sh.g[0],t.lighting.sh.b[0]))),new l("lightingAmbientSH_R1",((i,n)=>t(r,n.lighting.sh.r[1],n.lighting.sh.r[2],n.lighting.sh.r[3],n.lighting.sh.r[4]))),new l("lightingAmbientSH_G1",((i,n)=>t(r,n.lighting.sh.g[1],n.lighting.sh.g[2],n.lighting.sh.g[3],n.lighting.sh.g[4]))),new l("lightingAmbientSH_B1",((i,n)=>t(r,n.lighting.sh.b[1],n.lighting.sh.b[2],n.lighting.sh.b[3],n.lighting.sh.b[4]))),new l("lightingAmbientSH_R2",((i,n)=>t(r,n.lighting.sh.r[5],n.lighting.sh.r[6],n.lighting.sh.r[7],n.lighting.sh.r[8]))),new l("lightingAmbientSH_G2",((i,n)=>t(r,n.lighting.sh.g[5],n.lighting.sh.g[6],n.lighting.sh.g[7],n.lighting.sh.g[8]))),new l("lightingAmbientSH_B2",((i,n)=>t(r,n.lighting.sh.b[5],n.lighting.sh.b[6],n.lighting.sh.b[7],n.lighting.sh.b[8])))]),m.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); }`),g.pbrMode!==h.Normal&&g.pbrMode!==h.Schematic||m.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 a=n(),r=g();export{m as EvaluateAmbientLighting};