/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{property as i,subclass as t}from"../../../../core/accessorSupport/decorators.js";import{set as s,scale as a,floor as r,subtract as o}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{positiveInfinity as l}from"../../../../geometry/support/aaBoundingBox.js";import{InternalRenderCategory as p}from"../../webgl.js";import h from"../../webgl/RenderNode.js";import{GaussianSplatRenderNode as m}from"./GaussianSplatRenderNode.js";import{G as d}from"../../../../chunks/GaussianSplatShadow.glsl.js";import{GaussianSplatShadowTechnique as u}from"../shaders/GaussianSplatShadowTechnique.js";import{GaussianSplatTechniqueConfiguration as c}from"../shaders/GaussianSplatTechniqueConfiguration.js";import{PrimitiveType as _}from"../../../webgl/enums.js";let P=class extends h{constructor(e){super(e),this.produces=p.SHADOW_CASTERS,this.layerView=null,this._passParameters=new d,this._cameraPosition=n(),this._configuration=new c(e.view.state.isGlobal)}render(){const e=this.bindRenderTarget();return this._render(),e}queryDepthRange(e){return this.layerView.suspended?null:this._data.queryVisibleTileDepthRange(e,this.layerView.clippingBox)}get _data(){return this.layerView.data}get _clippingEnabled(){return null!=this.layerView.clippingBox}get _isIdle(){return 2===this.view.state.mode}_render(){const e=this._data;if(this.layerView.suspended||0===e.visibleGaussians||!e.orderTexture.texture||!e.textureAtlas.texture)return;this._updateShadowConfigurations();const i=this.techniques.getCompiled(u,this._configuration);i?(this._prepareShadowParameters(this.bindParameters.camera),this.renderingContext.bindTechnique(i,this.bindParameters,this._passParameters),this.renderingContext.drawArraysInstanced(_.TRIANGLE_STRIP,0,4,e.visibleGaussians)):this.requestRender(1)}_updateShadowConfigurations(){this._configuration.clippingEnabled=this._clippingEnabled,this._configuration.hasSlicePlane=this.layerView.slicePlaneEnabled&&null!=this.bindParameters.slicePlane,this._configuration.output=this.bindParameters.output}_prepareShadowParameters(e){const i=this._data;this._passParameters.splatOrder=i.orderTexture.texture,this._passParameters.splatAtlas=i.textureAtlas.texture;const{fullHeight:t,fullWidth:s}=e,a=this.view.qualitySettings.gaussianSplat,r=this._isIdle?a.idleMinimumSplatPixelRadius:a.nonIdleMinimumSplatPixelRadius;this._passParameters.minSplatRadius=r*Math.sqrt(s*t)/Math.sqrt(2073600),this._updateShadowCameraPosition(e),this._prepareShadowHighPrecisionCameraPosition(),this._passParameters.slicePlaneLocalOrigin=this._cameraPosition,this._updateShadowClipUniforms()}_updateShadowClipUniforms(){const e=this.layerView.clippingBox||l,[i,t,a,r,o,n]=e,[p,h,m]=this._cameraPosition,{clipMinCameraRelative:d,clipMaxCameraRelative:u}=this._passParameters;s(d,i-p,t-h,a-m),s(u,r-p,o-h,n-m)}_prepareShadowHighPrecisionCameraPosition(){a(this._passParameters.tileCameraPosition,this._cameraPosition,1/m.tileSize),r(this._passParameters.tileCameraPosition,this._passParameters.tileCameraPosition),a(this._passParameters.cameraDelta,this._passParameters.tileCameraPosition,m.tileSize),o(this._passParameters.cameraDelta,this._cameraPosition,this._passParameters.cameraDelta)}_updateShadowCameraPosition(e){const i=e.viewInverseTransposeMatrix;s(this._cameraPosition,i[3],i[7],i[11])}};e([i()],P.prototype,"produces",void 0),e([i({constructOnly:!0})],P.prototype,"layerView",void 0),P=e([t("esri.views.3d.webgl-engine.lib.GaussianSplatShadowRenderNode")],P);export{P as GaussianSplatShadowRenderNode};
