| NoBlending, | NoBlending, | ||||
| NoColorSpace, | NoColorSpace, | ||||
| OrthographicCamera, | OrthographicCamera, | ||||
| RGBAFormat, | |||||
| RGBAFormat, Texture, | |||||
| UnsignedByteType, | UnsignedByteType, | ||||
| Vector3, | Vector3, | ||||
| WebGLRenderTarget, | WebGLRenderTarget, | ||||
| @onChange(ContactShadowGroundPlugin.prototype._setDirty) | @onChange(ContactShadowGroundPlugin.prototype._setDirty) | ||||
| blurAmount = 1 | blurAmount = 1 | ||||
| shadowCamera = new OrthographicCamera(-1, 1, 1, -1, 0.001, this.shadowHeight) | shadowCamera = new OrthographicCamera(-1, 1, 1, -1, 0.001, this.shadowHeight) | ||||
| private _depthPass?: GBufferRenderPass<'contactShadowGround', WebGLRenderTarget|undefined> | private _depthPass?: GBufferRenderPass<'contactShadowGround', WebGLRenderTarget|undefined> | ||||
| private _blurHelper?: HVBlurHelper | private _blurHelper?: HVBlurHelper | ||||
| protected _preRender() { | protected _preRender() { | ||||
| super._preRender() | super._preRender() | ||||
| if (!this._viewer || !this._depthPass || !this._blurHelper) return | |||||
| if (!this._viewer || !this._depthPass || !this._blurHelper || !this.contactShadows || !this.visible) return | |||||
| this._depthPass.scene = this._viewer.scene | this._depthPass.scene = this._viewer.scene | ||||
| this._depthPass.camera = this.shadowCamera | this._depthPass.camera = this.shadowCamera | ||||
| super._removeMaterial() | super._removeMaterial() | ||||
| } | } | ||||
| private _depthTex: Texture|null = null | |||||
| public refresh(): void { | public refresh(): void { | ||||
| if (!this._viewer) return | if (!this._viewer) return | ||||
| // todo: shadow enabled check | |||||
| if (!this.contactShadows) { | |||||
| if (this._material?.alphaMap === this._depthTex) { | |||||
| this._material.alphaMap = null | |||||
| this._material.setDirty() | |||||
| } | |||||
| if (this._material?.userData.__csgpParamsSet) { | |||||
| delete this._material.userData.__csgpParamsSet | |||||
| delete this._material.userData.ssreflDisabled | |||||
| delete this._material.userData.ssreflNonPhysical | |||||
| } | |||||
| this._depthTex = null | |||||
| } else { | |||||
| this._depthTex = getOrCall(this._depthPass?.target)?.texture || null | |||||
| } | |||||
| super.refresh() | super.refresh() | ||||
| } | } | ||||
| mat.metalness = 0 | mat.metalness = 0 | ||||
| mat.color.set(0x111111) | mat.color.set(0x111111) | ||||
| mat.transparent = true | mat.transparent = true | ||||
| mat.userData.ssreflDisabled = true | |||||
| mat.userData.ssreflNonPhysical = false | |||||
| // mat.userData.inverseAlphaMap = false // this must be false, if getting inverted colors, check clear color of gbuffer render pass. | // mat.userData.inverseAlphaMap = false // this must be false, if getting inverted colors, check clear color of gbuffer render pass. | ||||
| return mat | return mat | ||||
| } | } | ||||
| if (!this._viewer) return false | if (!this._viewer) return false | ||||
| const isNewMaterial = super._refreshMaterial() | const isNewMaterial = super._refreshMaterial() | ||||
| if (!this._material) return isNewMaterial | if (!this._material) return isNewMaterial | ||||
| this._material.alphaMap = getOrCall(this._depthPass?.target)?.texture || null | |||||
| if (this.contactShadows) { | |||||
| this._material.userData.ssreflDisabled = true | |||||
| this._material.userData.ssreflNonPhysical = false | |||||
| this._material.userData.__csgpParamsSet = true | |||||
| this._material.alphaMap = this._depthTex || null | |||||
| this._material.setDirty() | |||||
| } | |||||
| return isNewMaterial | return isNewMaterial | ||||
| } | } | ||||