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