/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{smoothstep as t,clamp as s}from"../../../../../core/mathUtils.js";import{watch as i,syncAndInitial as r}from"../../../../../core/reactiveUtils.js";import{property as a,subclass as o}from"../../../../../core/accessorSupport/decorators.js";import{normalize as h,set as c,dot as p}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getDefaultHighlightOptions as d}from"../../../../2d/support/highlightOptionsUtils.js";import{RenderNodeOutput as m}from"../../../webgl.js";import l from"../../../webgl/RenderNode.js";import{ShadowHighlightPassParameters as u,ShadowHighlightTechnique as g}from"./ShadowHighlightTechnique.js";import{defaultShadowOpacity as f,defaultShadowDifference as w,defaultShadowColor as _}from"../../../../support/HighlightDefaults.js";const O=1/512,y=4e4,P=5e4;let v=class extends l{constructor(e){super(e),this.produces=m.COMPOSITE,this.consumes={required:[m.COMPOSITE,"highlights"]},this._passParameters=new u,this._maxOpacity=1,this._shadowDifference=.2}initialize(){this.addHandles([i(()=>d(this.view)?.shadowOpacity,e=>{this._passParameters.shadowOpacity=e??f,this._updateOccludedShadowOpacity(),this._ensureMaxOpacity()},r),i(()=>d(this.view)?.shadowDifference,e=>{this._shadowDifference=e??w,this._updateOccludedShadowOpacity(),this._ensureMaxOpacity()},r),i(()=>d(this.view)?.shadowColor,e=>{this._passParameters.shadowColor=(e??_).toUnitRGBA(),this._ensureMaxOpacity()},r)])}_updateOccludedShadowOpacity(){this._passParameters.occludedShadowOpacity=this._passParameters.shadowOpacity*(1-this._shadowDifference)}_ensureMaxOpacity(){const e=Math.max(this._passParameters.shadowOpacity,this._passParameters.occludedShadowOpacity);this._maxOpacity=e*this._passParameters.shadowColor[3],this.requestRender(1)}precompile(){this.techniques.precompile(g)}render(e){const t=e.find(({name:e})=>e===m.COMPOSITE),s=this.bindParameters;if(!s.shadowHighlightsVisible||!s.depth||!this._ensureIfVisible(s.camera,s.lighting.mainLight.direction))return t;const i=this.techniques.get(g);if(!i.compiled)return this.requestRender(1),t;this._passParameters.highlightTexture=e.find(({name:e})=>"highlights"===e)?.getTexture(),this._passParameters.origin=s.camera.center;const r=this.renderingContext;return r.bindFramebuffer(t.fbo),r.bindTechnique(i,s,this._passParameters),r.screen.draw(),t}_ensureIfVisible(e,i){this._passParameters.opacityElevation=1-t(y,P,e.relativeElevation);const r=1===this.viewingMode?h(x,e.center):c(x,0,0,1),a=p(r,i);return this._passParameters.dayNightTerminator=t(0,1,s(30*a,0,1)),this._maxOpacity*this._passParameters.opacityElevation*this._passParameters.dayNightTerminator>=O}};e([a()],v.prototype,"produces",void 0),e([a()],v.prototype,"consumes",void 0),e([a({constructOnly:!0})],v.prototype,"viewingMode",void 0),v=e([o("esri.views.3d.webgl-engine.effects.highlight.ShadowHighlight")],v);const x=n();export{v as ShadowHighlight};
