/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{smoothstep as s,clamp as t}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{n as h,h as c,g as p}from"../../../../../chunks/vec32.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getDefaultHighlightOptions as d}from"../../../../2d/support/highlightOptionsUtils.js";import{RenderCategory 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 s=e.find(({name:e})=>e===m.COMPOSITE),t=this.bindParameters;if(!t.shadowHighlightsVisible||!t.depth||!this._ensureIfVisible(t.camera,t.lighting.mainLight.direction))return s;const i=this.techniques.get(g);if(!i.compiled)return this.requestRender(1),s;this._passParameters.highlightTexture=e.find(({name:e})=>"highlights"===e)?.getTexture(),this._passParameters.origin=t.camera.center;const r=this.renderingContext;return r.bindFramebuffer(s.fbo),r.bindTechnique(i,t,this._passParameters),r.screen.draw(),s}_ensureIfVisible(e,i){this._passParameters.opacityElevation=1-s(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=s(0,1,t(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};
