/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{lerp as i}from"../../../../core/mathUtils.js";import{copy as t,scale as s,add as h,lerp as r}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as a,fromValues as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{SphericalHarmonicsAmbientLight as e,MainLight as o}from"./Lightsources.js";import{combineLights as c}from"./SphericalHarmonics.js";class g{constructor(){this.color=a(),this.intensity=1}}class m{constructor(){this.direction=a(),this.ambient=new g,this.diffuse=new g}}const l=.4;class _{constructor(){this._shOrder=2,this._legacy=new m,this.globalFactor=.5,this.noonFactor=.5,this._sphericalHarmonics=new e,this._mainLight=new o(a(),n(1,0,0),!1)}get legacy(){return this._legacy}get sh(){return this._sphericalHarmonics}get mainLight(){return this._mainLight}set(i){c(i,this._shOrder,this._mainLight,this._sphericalHarmonics),this.updateLegacy()}updateLegacy(){t(this._legacy.direction,this._mainLight.direction);const i=1/Math.PI;this._legacy.ambient.color[0]=.282095*this._sphericalHarmonics.r[0]*i,this._legacy.ambient.color[1]=.282095*this._sphericalHarmonics.g[0]*i,this._legacy.ambient.color[2]=.282095*this._sphericalHarmonics.b[0]*i,s(this._legacy.diffuse.color,this._mainLight.intensity,i),t(L,this._legacy.diffuse.color),s(L,L,l*this.globalFactor),h(this._legacy.ambient.color,this._legacy.ambient.color,L)}copyFrom(i){this._sphericalHarmonics.r=Array.from(i.sh.r),this._sphericalHarmonics.g=Array.from(i.sh.g),this._sphericalHarmonics.b=Array.from(i.sh.b),t(this._mainLight.direction,i.mainLight.direction),t(this._mainLight.intensity,i.mainLight.intensity),this._mainLight.castShadows=i.mainLight.castShadows,this._mainLight.specularStrength=i.mainLight.specularStrength,this._mainLight.environmentStrength=i.mainLight.environmentStrength,this.globalFactor=i.globalFactor,this.noonFactor=i.noonFactor}lerpLighting(s,h,a){if(r(this._mainLight.intensity,s.mainLight.intensity,h.mainLight.intensity,a),this._mainLight.environmentStrength=i(s.mainLight.environmentStrength,h.mainLight.environmentStrength,a),this._mainLight.specularStrength=i(s.mainLight.specularStrength,h.mainLight.specularStrength,a),t(this._mainLight.direction,h.mainLight.direction),this._mainLight.castShadows=h.mainLight.castShadows,this.globalFactor=i(s.globalFactor,h.globalFactor,a),this.noonFactor=i(s.noonFactor,h.noonFactor,a),s.sh.r.length===h.sh.r.length)for(let t=0;t<h.sh.r.length;t++)this._sphericalHarmonics.r[t]=i(s.sh.r[t],h.sh.r[t],a),this._sphericalHarmonics.g[t]=i(s.sh.g[t],h.sh.g[t],a),this._sphericalHarmonics.b[t]=i(s.sh.b[t],h.sh.b[t],a);else for(let i=0;i<h.sh.r.length;i++)this._sphericalHarmonics.r[i]=h.sh.r[i],this._sphericalHarmonics.g[i]=h.sh.g[i],this._sphericalHarmonics.b[i]=h.sh.b[i];this.updateLegacy()}}const L=a();export{_ as SceneLighting,m as SunLight,l as ambientBoost};
