@hology/core 0.0.123 → 0.0.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rendering/ssr/SSRPass.d.ts +4 -0
- package/dist/rendering/ssr/SSRPass.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRPass.js +1 -1
- package/dist/rendering/ssr/SSRShader.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRShader.js +1 -1
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/shader/shader.d.ts +3 -0
- package/dist/shader/shader.d.ts.map +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
@@ -58,6 +58,10 @@ export class SSRPass extends Pass {
|
|
58
58
|
* @param {SSRPass~Options} options - The pass options.
|
59
59
|
*/
|
60
60
|
constructor({ renderer, scene, camera, width, height, selects, bouncing, groundReflector }: SSRPass);
|
61
|
+
/**
|
62
|
+
* Elapsed time used for custom shaders
|
63
|
+
*/
|
64
|
+
elapsedTime: number;
|
61
65
|
/**
|
62
66
|
* The width of the effect.
|
63
67
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SSRPass.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRPass.js"],"names":[],"mappings":";;;;;;;
|
1
|
+
{"version":3,"file":"SSRPass.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRPass.js"],"names":[],"mappings":";;;;;;;cAs4Bc,aAAa;;;;WACb,KAAK;;;;YACL,MAAM;;;;YACN,MAAM;;;;aACN,MAAM;;;;cACL,KAAK,CAAC,QAAQ,CAAC,OAAA;;;;eAChB,OAAO;;;;sBACN,mBAAmB,OAAA;;AA92BlC;;;;;;;;;;;;;;;GAeG;AACH;IAEC;;;;OAIG;IACH,4FAFW,OAAO,EAmajB;IA7ZA;;OAEG;IACH,oBAAoB;IAEpB;;;;;OAKG;IACH,OAHU,MAAM,CAGE;IAElB;;;;;OAKG;IACH,QAHU,MAAM,CAGI;IAUpB;;;;OAIG;IACH,UAFU,aAAa,CAEC;IAExB;;;;OAIG;IACH,OAFU,KAAK,CAEG;IAElB;;;;OAIG;IACH,QAFU,MAAM,CAEI;IAEpB;;;;;OAKG;IACH,iBAHW,mBAAmB,OAAA,CAGQ;IAEtC;;;;;OAKG;IACH,SAHU,MAAM,CAG+B;IAE/C;;;;;OAKG;IACH,QAHU,MAAM,CAGD;IAEf;;;;;OAKG;IACH,aAHU,MAAM,CAGuC;IAEvD;;;;;;OAMG;IACH,WAHU,MAAM,CAGmC;IAEnD,iBAA4B;IAE5B,cAAuB;IAEvB;;;;;OAKG;IACH,WAHU,OAAO,CAG8B;IAoC/C,eAAyB;IAgCzB;;;;;OAKG;IACH,MAHU,OAAO,CAGD;IAEhB,0BAAkE;IA0BlE,cAAyC;IAyBzC,oBAAsD;IAgCtD,+DAMG;IAGH,6DAGG;IAIH,+DAIG;IAIH,kEAIG;IAMH,4DAGG;IAEH,6DAAoD;IACpD,8DAAqD;IAKrD,4BAQG;IAiBH,mCAA8C;IAK9C,uCAEG;IAIH,wCAEG;IAIH,6BAKG;IAMH,8BAKG;IAiBH,oCAMG;IAOH,6BAcG;IAEH,uBAAwC;IAExC,0BAAqC;IAqCtC;;;;;;;;;;OAUG;IACH,iBARW,aAAa,eACb,iBAAiB,QA0J3B;IAmCD,yGA2BC;IAID,iHAoEC;IAED,kHA8FC;CAED;;;;;;;;;;;qBA32BgD,8BAA8B;sBAFxE,OAAO;kCAAP,OAAO;+BAAP,OAAO;mCAAP,OAAO;kCAAP,OAAO;+BAEmC,8BAA8B"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{AddEquation as e,Color as t,NormalBlending as r,DepthTexture as s,SrcAlphaFactor as i,OneMinusSrcAlphaFactor as a,MeshNormalMaterial as n,MeshBasicMaterial as l,NearestFilter as h,NoBlending as o,ShaderMaterial as u,UniformsUtils as d,UnsignedShortType as c,WebGLRenderTarget as f,HalfFloatType as m,MeshStandardMaterial as p,Mesh as g}from"three";import{SSRBlurShader as M,SSRDepthShader as T,SSRShader as b}from"./SSRShader.js";import{CopyShader as R,Pass as v,FullScreenQuad as y}from"three/examples/jsm/Addons.js";import{traverseVisibleStop as S}from"../../utils/three/traverse.js";const C=new WeakMap;class _ extends v{constructor({renderer:r,scene:p,camera:g,width:v=512,height:S=512,selects:C=null,bouncing:_=!1,groundReflector:x=null}){super(),this.width=v,this.height=S,this.clear=!0,this.renderer=r,this.scene=p,this.camera=g,this.groundReflector=x,this.opacity=b.uniforms.opacity.value,this.output=0,this.maxDistance=b.uniforms.maxDistance.value,this.thickness=b.uniforms.thickness.value,this.tempColor=new t,this._selects=C,this.selective=Array.isArray(this._selects),Object.defineProperty(this,"selects",{get(){return this._selects},set(e){this._selects!==e&&(this._selects=e,Array.isArray(e)?(this.selective=!0,this.ssrMaterial.defines.SELECTIVE=!0,this.ssrMaterial.needsUpdate=!0):(this.selective=!1,this.ssrMaterial.defines.SELECTIVE=!1,this.ssrMaterial.needsUpdate=!0))}}),this._bouncing=_,Object.defineProperty(this,"bouncing",{get(){return this._bouncing},set(e){this._bouncing!==e&&(this._bouncing=e,this.ssrMaterial.uniforms.tDiffuse.value=e?this.prevRenderTarget.texture:this.beautyRenderTarget.texture)}}),this.blur=!0,this._distanceAttenuation=b.defines.DISTANCE_ATTENUATION,Object.defineProperty(this,"distanceAttenuation",{get(){return this._distanceAttenuation},set(e){this._distanceAttenuation!==e&&(this._distanceAttenuation=e,this.ssrMaterial.defines.DISTANCE_ATTENUATION=e,this.ssrMaterial.needsUpdate=!0)}}),this._fresnel=b.defines.FRESNEL,Object.defineProperty(this,"fresnel",{get(){return this._fresnel},set(e){this._fresnel!==e&&(this._fresnel=e,this.ssrMaterial.defines.FRESNEL=e,this.ssrMaterial.needsUpdate=!0)}}),this._infiniteThick=b.defines.INFINITE_THICK,Object.defineProperty(this,"infiniteThick",{get(){return this._infiniteThick},set(e){this._infiniteThick!==e&&(this._infiniteThick=e,this.ssrMaterial.defines.INFINITE_THICK=e,this.ssrMaterial.needsUpdate=!0)}});const P=new s;P.type=c,P.minFilter=h,P.magFilter=h,this.beautyRenderTarget=new f(this.width,this.height,{minFilter:h,magFilter:h,type:m,depthTexture:P,depthBuffer:!0}),this.prevRenderTarget=new f(this.width,this.height,{minFilter:h,magFilter:h}),this.normalRenderTarget=new f(this.width,this.height,{minFilter:h,magFilter:h,type:m}),this.metalnessRenderTarget=new f(this.width,this.height,{minFilter:h,magFilter:h,type:m}),this.ssrRenderTarget=new f(this.width,this.height,{minFilter:h,magFilter:h}),this.blurRenderTarget=this.ssrRenderTarget.clone(),this.blurRenderTarget2=this.ssrRenderTarget.clone(),this.ssrMaterial=new u({defines:Object.assign({},b.defines,{MAX_STEP:Math.sqrt(this.width*this.width+this.height*this.height)}),uniforms:d.clone(b.uniforms),vertexShader:b.vertexShader,fragmentShader:b.fragmentShader,blending:o}),this.ssrMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.ssrMaterial.uniforms.tNormal.value=this.normalRenderTarget.texture,this.ssrMaterial.defines.SELECTIVE=this.selective,this.ssrMaterial.needsUpdate=!0,this.ssrMaterial.uniforms.tMetalness.value=this.metalnessRenderTarget.texture,this.ssrMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.ssrMaterial.uniforms.cameraNear.value=this.camera.near,this.ssrMaterial.uniforms.cameraFar.value=this.camera.far,this.ssrMaterial.uniforms.thickness.value=this.thickness,this.ssrMaterial.uniforms.resolution.value.set(this.width,this.height),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.normalMaterial=new n,this.normalMaterial.blending=o,this.metalnessOnMaterial=new l({color:"white"}),this.metalnessOffMaterial=new l({color:"black"}),this.blurMaterial=new u({defines:Object.assign({},M.defines),uniforms:d.clone(M.uniforms),vertexShader:M.vertexShader,fragmentShader:M.fragmentShader}),this.blurMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.blurMaterial.uniforms.resolution.value.set(this.width,this.height),this.blurMaterial2=new u({defines:Object.assign({},M.defines),uniforms:d.clone(M.uniforms),vertexShader:M.vertexShader,fragmentShader:M.fragmentShader}),this.blurMaterial2.uniforms.tDiffuse.value=this.blurRenderTarget.texture,this.blurMaterial2.uniforms.resolution.value.set(this.width,this.height),this.depthRenderMaterial=new u({defines:Object.assign({},T.defines),uniforms:d.clone(T.uniforms),vertexShader:T.vertexShader,fragmentShader:T.fragmentShader,blending:o}),this.depthRenderMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.copyMaterial=new u({uniforms:d.clone(R.uniforms),vertexShader:R.vertexShader,fragmentShader:R.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blendSrc:i,blendDst:a,blendEquation:e,blendSrcAlpha:i,blendDstAlpha:a,blendEquationAlpha:e}),this.fsQuad=new y(null),this.originalClearColor=new t}dispose(){this.beautyRenderTarget.dispose(),this.prevRenderTarget.dispose(),this.normalRenderTarget.dispose(),this.metalnessRenderTarget.dispose(),this.ssrRenderTarget.dispose(),this.blurRenderTarget.dispose(),this.blurRenderTarget2.dispose(),this.normalMaterial.dispose(),this.metalnessOnMaterial.dispose(),this.metalnessOffMaterial.dispose(),this.blurMaterial.dispose(),this.blurMaterial2.dispose(),this.copyMaterial.dispose(),this.depthRenderMaterial.dispose(),this.fsQuad.dispose()}render(e,t){switch(e.setRenderTarget(this.beautyRenderTarget),e.clear(),this.groundReflector&&(this.groundReflector.visible=!1,this.groundReflector.doRender(this.renderer,this.scene,this.camera),this.groundReflector.visible=!0),e.render(this.scene,this.camera),this.groundReflector&&(this.groundReflector.visible=!1),this._renderOverride(e,this.normalMaterial,this.normalRenderTarget,0,0),this.selective&&this._renderMetalness(e,this.metalnessOnMaterial,this.metalnessRenderTarget,0,0),this.ssrMaterial.uniforms.opacity.value=this.opacity,this.ssrMaterial.uniforms.maxDistance.value=this.maxDistance,this.ssrMaterial.uniforms.thickness.value=this.thickness,this._renderPass(e,this.ssrMaterial,this.ssrRenderTarget),this.blur&&(this._renderPass(e,this.blurMaterial,this.blurRenderTarget),this._renderPass(e,this.blurMaterial2,this.blurRenderTarget2)),this.output){case _.OUTPUT.Default:this.bouncing?(this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=r,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.prevRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t)):(this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=r,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t));break;case _.OUTPUT.SSR:this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.bouncing&&(this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=r,this._renderPass(e,this.copyMaterial,this.prevRenderTarget));break;case _.OUTPUT.Beauty:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case _.OUTPUT.Depth:this._renderPass(e,this.depthRenderMaterial,this.renderToScreen?null:t);break;case _.OUTPUT.Normal:this.copyMaterial.uniforms.tDiffuse.value=this.normalRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case _.OUTPUT.Metalness:this.copyMaterial.uniforms.tDiffuse.value=this.metalnessRenderTarget.texture,this.copyMaterial.blending=o,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;default:console.warn("THREE.SSRPass: Unknown output type.")}}setSize(e,t){this.width=e,this.height=t,this.ssrMaterial.defines.MAX_STEP=Math.sqrt(e*e+t*t),this.ssrMaterial.needsUpdate=!0,this.beautyRenderTarget.setSize(e,t),this.prevRenderTarget.setSize(e,t),this.ssrRenderTarget.setSize(e,t),this.normalRenderTarget.setSize(e,t),this.metalnessRenderTarget.setSize(e,t),this.blurRenderTarget.setSize(e,t),this.blurRenderTarget2.setSize(e,t),this.ssrMaterial.uniforms.resolution.value.set(e,t),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.blurMaterial.uniforms.resolution.value.set(e,t),this.blurMaterial2.uniforms.resolution.value.set(e,t)}_renderPass(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const a=e.getClearAlpha(this.tempColor),n=e.autoClear;e.setRenderTarget(r),e.autoClear=!1,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),this.fsQuad.material=t,this.fsQuad.render(e),e.autoClear=n,e.setClearColor(this.originalClearColor),e.setClearAlpha(a)}_renderOverride(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const a=e.getClearAlpha(this.tempColor),l=e.autoClear;e.setRenderTarget(r),e.autoClear=!1,s=t.clearColor||s,i=t.clearAlpha||i,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),S(this.scene,(e=>{if(e.isTransformControlsGizmo)return!1;if(e instanceof g)if(e._SSRPassBackupMaterial=e.material,e.material instanceof p&&this._selects.includes(e)){let t=C.get(e.material);t||(t=new n({normalMap:e.material.normalMap,normalScale:e.material.normalScale}),C.set(e.material,t)),e.material=t}else e.material=t})),e.render(this.scene,this.camera),this.scene.traverseVisible((e=>{e._SSRPassBackupMaterial&&(e.material=e._SSRPassBackupMaterial)})),e.autoClear=l,e.setClearColor(this.originalClearColor),e.setClearAlpha(a)}_renderMetalness(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const a=e.getClearAlpha(this.tempColor),n=e.autoClear,l=this.scene.background,h=this.scene.fog;e.setRenderTarget(r),e.autoClear=!1,this.scene.background=null,this.scene.fog=null,s=t.clearColor||s,i=t.clearAlpha||i,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),this.scene.traverseVisible((e=>{e._SSRPassBackupMaterial=e.material,this._selects.includes(e)?e.material=this.metalnessOnMaterial:e.material=this.metalnessOffMaterial})),e.render(this.scene,this.camera),this.scene.traverseVisible((e=>{e.material=e._SSRPassBackupMaterial})),e.autoClear=n,e.setClearColor(this.originalClearColor),e.setClearAlpha(a),this.scene.background=l,this.scene.fog=h}}_.OUTPUT={Default:0,SSR:1,Beauty:3,Depth:4,Normal:5,Metalness:7};export{_ as SSRPass};/*
|
1
|
+
import{AddEquation as e,Color as t,DepthTexture as r,HalfFloatType as s,Mesh as i,MeshBasicMaterial as a,MeshLambertMaterial as n,MeshNormalMaterial as l,MeshStandardMaterial as h,NearestFilter as o,NoBlending as u,NormalBlending as d,OneMinusSrcAlphaFactor as c,ShaderMaterial as m,SrcAlphaFactor as f,UniformsUtils as p,UnsignedShortType as g,WebGLRenderTarget as M}from"three";import{NodeShaderMaterial as T,float as b,rgb as R,vec3 as v}from"three-shader-graph";import{CopyShader as y,FullScreenQuad as C,Pass as S}from"three/examples/jsm/Addons.js";import{oneMinus as _}from"../../shader-nodes/math.js";import{traverseVisibleStop as x}from"../../utils/three/traverse.js";import{elapsedTimeUniformName as w}from"../../shader-nodes/time.js";import{SSRBlurShader as P,SSRDepthShader as D,SSRShader as A}from"./SSRShader.js";const k=new WeakMap,O=new WeakMap;class E extends S{constructor({renderer:i,scene:n,camera:h,width:d=512,height:T=512,selects:b=null,bouncing:R=!1,groundReflector:v=null}){super(),this.elapsedTime=0,this.width=d,this.height=T,this.clear=!0,this.renderer=i,this.scene=n,this.camera=h,this.groundReflector=v,this.opacity=A.uniforms.opacity.value,this.output=0,this.maxDistance=A.uniforms.maxDistance.value,this.thickness=A.uniforms.thickness.value,this.tempColor=new t,this._selects=b,this.selective=Array.isArray(this._selects),Object.defineProperty(this,"selects",{get(){return this._selects},set(e){this._selects!==e&&(this._selects=e,Array.isArray(e)?(this.selective=!0,this.ssrMaterial.defines.SELECTIVE=!0,this.ssrMaterial.needsUpdate=!0):(this.selective=!1,this.ssrMaterial.defines.SELECTIVE=!1,this.ssrMaterial.needsUpdate=!0))}}),this._bouncing=R,Object.defineProperty(this,"bouncing",{get(){return this._bouncing},set(e){this._bouncing!==e&&(this._bouncing=e,this.ssrMaterial.uniforms.tDiffuse.value=e?this.prevRenderTarget.texture:this.beautyRenderTarget.texture)}}),this.blur=!0,this._distanceAttenuation=A.defines.DISTANCE_ATTENUATION,Object.defineProperty(this,"distanceAttenuation",{get(){return this._distanceAttenuation},set(e){this._distanceAttenuation!==e&&(this._distanceAttenuation=e,this.ssrMaterial.defines.DISTANCE_ATTENUATION=e,this.ssrMaterial.needsUpdate=!0)}}),this._fresnel=A.defines.FRESNEL,Object.defineProperty(this,"fresnel",{get(){return this._fresnel},set(e){this._fresnel!==e&&(this._fresnel=e,this.ssrMaterial.defines.FRESNEL=e,this.ssrMaterial.needsUpdate=!0)}}),this._infiniteThick=A.defines.INFINITE_THICK,Object.defineProperty(this,"infiniteThick",{get(){return this._infiniteThick},set(e){this._infiniteThick!==e&&(this._infiniteThick=e,this.ssrMaterial.defines.INFINITE_THICK=e,this.ssrMaterial.needsUpdate=!0)}});const S=new r;S.type=g,S.minFilter=o,S.magFilter=o,this.beautyRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:s,depthTexture:S,depthBuffer:!0}),this.prevRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o}),this.normalRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:s}),this.metalnessRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:s}),this.ssrRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o}),this.blurRenderTarget=this.ssrRenderTarget.clone(),this.blurRenderTarget2=this.ssrRenderTarget.clone(),this.ssrMaterial=new m({defines:Object.assign({},A.defines,{MAX_STEP:Math.sqrt(this.width*this.width+this.height*this.height)}),uniforms:p.clone(A.uniforms),vertexShader:A.vertexShader,fragmentShader:A.fragmentShader,blending:u}),this.ssrMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.ssrMaterial.uniforms.tNormal.value=this.normalRenderTarget.texture,this.ssrMaterial.defines.SELECTIVE=this.selective,this.ssrMaterial.needsUpdate=!0,this.ssrMaterial.uniforms.tMetalness.value=this.metalnessRenderTarget.texture,this.ssrMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.ssrMaterial.uniforms.cameraNear.value=this.camera.near,this.ssrMaterial.uniforms.cameraFar.value=this.camera.far,this.ssrMaterial.uniforms.thickness.value=this.thickness,this.ssrMaterial.uniforms.resolution.value.set(this.width,this.height),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.normalMaterial=new l,this.normalMaterial.blending=u,this.metalnessOnMaterial=new a({color:"white"}),this.metalnessOffMaterial=new a({color:"black"}),this.blurMaterial=new m({defines:Object.assign({},P.defines),uniforms:p.clone(P.uniforms),vertexShader:P.vertexShader,fragmentShader:P.fragmentShader}),this.blurMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.blurMaterial.uniforms.resolution.value.set(this.width,this.height),this.blurMaterial2=new m({defines:Object.assign({},P.defines),uniforms:p.clone(P.uniforms),vertexShader:P.vertexShader,fragmentShader:P.fragmentShader}),this.blurMaterial2.uniforms.tDiffuse.value=this.blurRenderTarget.texture,this.blurMaterial2.uniforms.resolution.value.set(this.width,this.height),this.depthRenderMaterial=new m({defines:Object.assign({},D.defines),uniforms:p.clone(D.uniforms),vertexShader:D.vertexShader,fragmentShader:D.fragmentShader,blending:u}),this.depthRenderMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.copyMaterial=new m({uniforms:p.clone(y.uniforms),vertexShader:y.vertexShader,fragmentShader:y.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blendSrc:f,blendDst:c,blendEquation:e,blendSrcAlpha:f,blendDstAlpha:c,blendEquationAlpha:e}),this.fsQuad=new C(null),this.originalClearColor=new t}dispose(){this.beautyRenderTarget.dispose(),this.prevRenderTarget.dispose(),this.normalRenderTarget.dispose(),this.metalnessRenderTarget.dispose(),this.ssrRenderTarget.dispose(),this.blurRenderTarget.dispose(),this.blurRenderTarget2.dispose(),this.normalMaterial.dispose(),this.metalnessOnMaterial.dispose(),this.metalnessOffMaterial.dispose(),this.blurMaterial.dispose(),this.blurMaterial2.dispose(),this.copyMaterial.dispose(),this.depthRenderMaterial.dispose(),this.fsQuad.dispose()}render(e,t){switch(e.setRenderTarget(this.beautyRenderTarget),e.clear(),this.groundReflector&&(this.groundReflector.visible=!1,this.groundReflector.doRender(this.renderer,this.scene,this.camera),this.groundReflector.visible=!0),e.render(this.scene,this.camera),this.groundReflector&&(this.groundReflector.visible=!1),this._renderOverride(e,this.normalMaterial,this.normalRenderTarget,0,0),this.selective&&this._renderMetalness(e,this.metalnessOnMaterial,this.metalnessRenderTarget,0,0),this.ssrMaterial.uniforms.opacity.value=this.opacity,this.ssrMaterial.uniforms.maxDistance.value=this.maxDistance,this.ssrMaterial.uniforms.thickness.value=this.thickness,this._renderPass(e,this.ssrMaterial,this.ssrRenderTarget),this.blur&&(this._renderPass(e,this.blurMaterial,this.blurRenderTarget),this._renderPass(e,this.blurMaterial2,this.blurRenderTarget2)),this.output){case E.OUTPUT.Default:this.bouncing?(this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.prevRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t)):(this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t));break;case E.OUTPUT.SSR:this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.bouncing&&(this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.prevRenderTarget));break;case E.OUTPUT.Beauty:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case E.OUTPUT.Depth:this._renderPass(e,this.depthRenderMaterial,this.renderToScreen?null:t);break;case E.OUTPUT.Normal:this.copyMaterial.uniforms.tDiffuse.value=this.normalRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case E.OUTPUT.Metalness:this.copyMaterial.uniforms.tDiffuse.value=this.metalnessRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;default:console.warn("THREE.SSRPass: Unknown output type.")}}setSize(e,t){this.width=e,this.height=t,this.ssrMaterial.defines.MAX_STEP=Math.sqrt(e*e+t*t),this.ssrMaterial.needsUpdate=!0,this.beautyRenderTarget.setSize(e,t),this.prevRenderTarget.setSize(e,t),this.ssrRenderTarget.setSize(e,t),this.normalRenderTarget.setSize(e,t),this.metalnessRenderTarget.setSize(e,t),this.blurRenderTarget.setSize(e,t),this.blurRenderTarget2.setSize(e,t),this.ssrMaterial.uniforms.resolution.value.set(e,t),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.blurMaterial.uniforms.resolution.value.set(e,t),this.blurMaterial2.uniforms.resolution.value.set(e,t)}_renderPass(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const a=e.getClearAlpha(this.tempColor),n=e.autoClear;e.setRenderTarget(r),e.autoClear=!1,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),this.fsQuad.material=t,this.fsQuad.render(e),e.autoClear=n,e.setClearColor(this.originalClearColor),e.setClearAlpha(a)}_renderOverride(e,t,r,s,a){this.originalClearColor.copy(e.getClearColor(this.tempColor));const n=e.getClearAlpha(this.tempColor),o=e.autoClear;e.setRenderTarget(r),e.autoClear=!1,s=t.clearColor||s,a=t.clearAlpha||a,null!=s&&(e.setClearColor(s),e.setClearAlpha(a||0),e.clear()),x(this.scene,(e=>{if(e.isTransformControlsGizmo)return!1;if(e instanceof i)if(e._SSRPassBackupMaterial=e.material,e.material instanceof h&&this._selects.includes(e)){let t=k.get(e.material);t||(t=new l({normalMap:e.material.normalMap,normalScale:e.material.normalScale}),k.set(e.material,t)),e.material=t}else e.material=t})),e.render(this.scene,this.camera),this.scene.traverseVisible((e=>{e._SSRPassBackupMaterial&&(e.material=e._SSRPassBackupMaterial)})),e.autoClear=o,e.setClearColor(this.originalClearColor),e.setClearAlpha(n)}_renderMetalness(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const l=e.getClearAlpha(this.tempColor),o=e.autoClear,u=this.scene.background,d=this.scene.fog;e.setRenderTarget(r),e.autoClear=!1,this.scene.background=null,this.scene.fog=null,s=t.clearColor||s,i=t.clearAlpha||i,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),this.scene.traverseVisible((e=>{if(e._SSRPassBackupMaterial=e.material,this._selects.includes(e))if((e.material instanceof h||e.material instanceof n)&&null!=e.material.alphaMap){let t=O.get(e.material);t||(t=new a({color:"white",alphaMap:e.material.alphaMap,alphaTest:.5}),O.set(e.material,t)),e.material=t}else if(e.material instanceof T){let t=O.get(e.material);if(!t){const r=e.material,s=r.outputRoughness??b(0),i=r.outputColor.a.multiply(_(s));t=new T({color:R("white").rgba(i),transparent:!0,fog:!1,outputEncoding:!1}),t.lights=!1,O.set(e.material,t)}e.material=t,null!=t.uniforms[w]&&(t.uniforms[w].value=this.elapsedTime)}else e.material=this.metalnessOnMaterial;else e.material=this.metalnessOffMaterial})),e.render(this.scene,this.camera),this.scene.traverseVisible((e=>{e.material=e._SSRPassBackupMaterial})),e.autoClear=o,e.setClearColor(this.originalClearColor),e.setClearAlpha(l),this.scene.background=u,this.scene.fog=d}}E.OUTPUT={Default:0,SSR:1,Beauty:3,Depth:4,Normal:5,Metalness:7};export{E as SSRPass};/*
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SSRShader.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRShader.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,
|
1
|
+
{"version":3,"file":"SSRShader.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRShader.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,4BAmOE;AAEF;;;;;GAKG;AACH,iCAmEE;AAEF;;;;;GAKG;AACH,gCA+DE"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{Matrix4 as t,Vector2 as e}from"three";const n={name:"SSRShader",defines:{MAX_STEP:0,PERSPECTIVE_CAMERA:!0,DISTANCE_ATTENUATION:!0,FRESNEL:!0,INFINITE_THICK:!1,SELECTIVE:!1},uniforms:{tDiffuse:{value:null},tNormal:{value:null},tMetalness:{value:null},tDepth:{value:null},cameraNear:{value:null},cameraFar:{value:null},resolution:{value:new e},cameraProjectionMatrix:{value:new t},cameraInverseProjectionMatrix:{value:new t},opacity:{value:.5},maxDistance:{value:180},cameraRange:{value:0},thickness:{value:.018}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:'\n\t\t// precision highp float;\n\t\tprecision highp sampler2D;\n\t\tvarying vec2 vUv;\n\t\tuniform sampler2D tDepth;\n\t\tuniform sampler2D tNormal;\n\t\tuniform sampler2D tMetalness;\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform float cameraRange;\n\t\tuniform vec2 resolution;\n\t\tuniform float opacity;\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\t\tuniform float maxDistance;\n\t\tuniform float thickness;\n\t\tuniform mat4 cameraProjectionMatrix;\n\t\tuniform mat4 cameraInverseProjectionMatrix;\n\t\t#include <packing>\n\t\tfloat pointToLineDistance(vec3 x0, vec3 x1, vec3 x2) {\n\t\t\t//x0: point, x1: linePointA, x2: linePointB\n\t\t\t//https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html\n\t\t\treturn length(cross(x0-x1,x0-x2))/length(x2-x1);\n\t\t}\n\t\tfloat pointPlaneDistance(vec3 point,vec3 planePoint,vec3 planeNormal){\n\t\t\t// https://mathworld.wolfram.com/Point-PlaneDistance.html\n\t\t\t//// https://en.wikipedia.org/wiki/Plane_(geometry)\n\t\t\t//// http://paulbourke.net/geometry/pointlineplane/\n\t\t\tfloat a=planeNormal.x,b=planeNormal.y,c=planeNormal.z;\n\t\t\tfloat x0=point.x,y0=point.y,z0=point.z;\n\t\t\tfloat x=planePoint.x,y=planePoint.y,z=planePoint.z;\n\t\t\tfloat d=-(a*x+b*y+c*z);\n\t\t\tfloat distance=(a*x0+b*y0+c*z0+d)/sqrt(a*a+b*b+c*c);\n\t\t\treturn distance;\n\t\t}\n\t\tfloat getDepth( const in vec2 uv ) {\n\t\t\treturn texture2D( tDepth, uv ).x;\n\t\t}\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#else\n\t\t\t\treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#endif\n\t\t}\n\t\tvec3 getViewPosition( const in vec2 uv, const in float depth/*clip space*/, const in float clipW ) {\n\t\t\tvec4 clipPosition = vec4( ( vec3( uv, depth ) - 0.5 ) * 2.0, 1.0 );//ndc\n\t\t\tclipPosition *= clipW; //clip\n\t\t\treturn ( cameraInverseProjectionMatrix * clipPosition ).xyz;//view\n\t\t}\n\t\tvec3 getViewNormal( const in vec2 uv ) {\n\t\t\treturn unpackRGBToNormal( texture2D( tNormal, uv ).xyz );\n\t\t}\n\t\tvec2 viewPositionToXY(vec3 viewPosition){\n\t\t\tvec2 xy;\n\t\t\tvec4 clip=cameraProjectionMatrix*vec4(viewPosition,1);\n\t\t\txy=clip.xy;//clip\n\t\t\tfloat clipW=clip.w;\n\t\t\txy/=clipW;//NDC\n\t\t\txy=(xy+1.)/2.;//uv\n\t\t\txy*=resolution;//screen\n\t\t\treturn xy;\n\t\t}\n\t\tvoid main(){\n\t\t\t#ifdef SELECTIVE\n\t\t\t\tfloat metalness=texture2D(tMetalness,vUv).r;\n\t\t\t\tif(metalness==0.) return;\n\t\t\t#endif\n\n\t\t\tfloat depth = getDepth( vUv );\n\t\t\tfloat viewZ = getViewZ( depth );\n\t\t\tif(-viewZ>=cameraFar) return;\n\n\t\t\tfloat clipW = cameraProjectionMatrix[2][3] * viewZ+cameraProjectionMatrix[3][3];\n\t\t\tvec3 viewPosition=getViewPosition( vUv, depth, clipW );\n\n\t\t\tvec2 d0=gl_FragCoord.xy;\n\t\t\tvec2 d1;\n\n\t\t\tvec3 viewNormal=getViewNormal( vUv );\n\n\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\tvec3 viewIncidentDir=normalize(viewPosition);\n\t\t\t\tvec3 viewReflectDir=reflect(viewIncidentDir,viewNormal);\n\t\t\t#else\n\t\t\t\tvec3 viewIncidentDir=vec3(0,0,-1);\n\t\t\t\tvec3 viewReflectDir=reflect(viewIncidentDir,viewNormal);\n\t\t\t#endif\n\n\t\t\tfloat maxReflectRayLen=maxDistance/dot(-viewIncidentDir,viewNormal);\n\t\t\t// dot(a,b)==length(a)*length(b)*cos(theta) // https://www.mathsisfun.com/algebra/vectors-dot-product.html\n\t\t\t// if(a.isNormalized&&b.isNormalized) dot(a,b)==cos(theta)\n\t\t\t// maxDistance/maxReflectRayLen=cos(theta)\n\t\t\t// maxDistance/maxReflectRayLen==dot(a,b)\n\t\t\t// maxReflectRayLen==maxDistance/dot(a,b)\n\n\t\t\tvec3 d1viewPosition=viewPosition+viewReflectDir*maxReflectRayLen;\n\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\tif(d1viewPosition.z>-cameraNear){\n\t\t\t\t\t//https://tutorial.math.lamar.edu/Classes/CalcIII/EqnsOfLines.aspx\n\t\t\t\t\tfloat t=(-cameraNear-viewPosition.z)/viewReflectDir.z;\n\t\t\t\t\td1viewPosition=viewPosition+viewReflectDir*t;\n\t\t\t\t}\n\t\t\t#endif\n\t\t\td1=viewPositionToXY(d1viewPosition);\n\n\t\t\tfloat totalLen=length(d1-d0);\n\t\t\tfloat xLen=d1.x-d0.x;\n\t\t\tfloat yLen=d1.y-d0.y;\n\t\t\tfloat totalStep=max(abs(xLen),abs(yLen));\n\t\t\tfloat xSpan=xLen/totalStep;\n\t\t\tfloat ySpan=yLen/totalStep;\n\t\t\tfor(float i=0.;i<float(MAX_STEP);i++){\n\t\t\t\tif(i>=totalStep) break;\n\t\t\t\tvec2 xy=vec2(d0.x+i*xSpan,d0.y+i*ySpan);\n\t\t\t\tif(xy.x<0.||xy.x>resolution.x||xy.y<0.||xy.y>resolution.y) break;\n\t\t\t\tfloat s=length(xy-d0)/totalLen;\n\t\t\t\tvec2 uv=xy/resolution;\n\n\t\t\t\tfloat d = getDepth(uv);\n\t\t\t\tfloat vZ = getViewZ( d );\n\t\t\t\tif(-vZ>=cameraFar) continue;\n\t\t\t\tfloat cW = cameraProjectionMatrix[2][3] * vZ+cameraProjectionMatrix[3][3];\n\t\t\t\tvec3 vP=getViewPosition( uv, d, cW );\n\n\t\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\t\t// https://comp.nus.edu.sg/~lowkl/publications/lowk_persp_interp_techrep.pdf\n\t\t\t\t\tfloat recipVPZ=1./viewPosition.z;\n\t\t\t\t\tfloat viewReflectRayZ=1./(recipVPZ+s*(1./d1viewPosition.z-recipVPZ));\n\t\t\t\t#else\n\t\t\t\t\tfloat viewReflectRayZ=viewPosition.z+s*(d1viewPosition.z-viewPosition.z);\n\t\t\t\t#endif\n\n\t\t\t\t// if(viewReflectRayZ>vZ) continue; // will cause "npm run make-screenshot webgl_postprocessing_ssr" high probability hang.\n\t\t\t\t// https://github.com/mrdoob/three.js/pull/21539#issuecomment-821061164\n\t\t\t\tif(viewReflectRayZ<=vZ){\n\n\t\t\t\t\tbool hit;\n\t\t\t\t\t#ifdef INFINITE_THICK\n\t\t\t\t\t\thit=true;\n\t\t\t\t\t#else\n\t\t\t\t\t\tfloat away=pointToLineDistance(vP,viewPosition,d1viewPosition);\n\n\t\t\t\t\t\tfloat minThickness;\n\t\t\t\t\t\tvec2 xyNeighbor=xy;\n\t\t\t\t\t\txyNeighbor.x+=1.;\n\t\t\t\t\t\tvec2 uvNeighbor=xyNeighbor/resolution;\n\t\t\t\t\t\tvec3 vPNeighbor=getViewPosition(uvNeighbor,d,cW);\n\t\t\t\t\t\tminThickness=vPNeighbor.x-vP.x;\n\t\t\t\t\t\tminThickness*=3.;\n\t\t\t\t\t\tfloat tk=max(minThickness,thickness);\n\n\t\t\t\t\t\thit=away<=tk;\n\t\t\t\t\t#endif\n\n\t\t\t\t\tif(hit){\n\t\t\t\t\t\tvec3 vN=getViewNormal( uv );\n\t\t\t\t\t\tif(dot(viewReflectDir,vN)>=0.) continue;\n\t\t\t\t\t\tfloat distance=pointPlaneDistance(vP,viewPosition,viewNormal);\n\t\t\t\t\t\tif(distance>maxDistance) break;\n\t\t\t\t\t\tfloat op=opacity;\n\t\t\t\t\t\t#ifdef DISTANCE_ATTENUATION\n\t\t\t\t\t\t\tfloat ratio=1.-(distance/maxDistance);\n\t\t\t\t\t\t\tfloat attenuation=ratio*ratio;\n\t\t\t\t\t\t\top=opacity*attenuation;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t#ifdef FRESNEL\n\t\t\t\t\t\t\tfloat fresnelCoe=(dot(viewIncidentDir,viewReflectDir)+1.)/2.;\n\t\t\t\t\t\t\top*=fresnelCoe;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\tvec4 reflectColor=texture2D(tDiffuse,uv);\n\t\t\t\t\t\tgl_FragColor.xyz=reflectColor.xyz;\n\t\t\t\t\t\tgl_FragColor.a=op;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t'},i={name:"SSRDepthShader",defines:{PERSPECTIVE_CAMERA:1},uniforms:{tDepth:{value:null},cameraNear:{value:null},cameraFar:{value:null}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:"\n\n\t\tuniform sampler2D tDepth;\n\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\n\t\tvarying vec2 vUv;\n\n\t\t#include <packing>\n\n\t\tfloat getLinearDepth( const in vec2 uv ) {\n\n\t\t\t#if PERSPECTIVE_CAMERA == 1\n\n\t\t\t\tfloat fragCoordZ = texture2D( tDepth, uv ).x;\n\t\t\t\tfloat viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );\n\t\t\t\treturn viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );\n\n\t\t\t#else\n\n\t\t\t\treturn texture2D( tDepth, uv ).x;\n\n\t\t\t#endif\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tfloat depth = getLinearDepth( vUv );\n\t\t\tfloat d = 1.0 - depth;\n\t\t\t// d=(d-.999)*1000.;\n\t\t\tgl_FragColor = vec4( vec3( d ), 1.0 );\n\n\t\t}\n\n\t"},a={name:"SSRBlurShader",uniforms:{tDiffuse:{value:null},resolution:{value:new e},opacity:{value:.5}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:"\n\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform vec2 resolution;\n\t\tvarying vec2 vUv;\n\t\tvoid main() {\n\t\t\t//reverse engineering from PhotoShop blur filter, then change coefficient\n\n\t\t\tvec2 texelSize = ( 1.0 / resolution );\n\n\t\t\tvec4 c=texture2D(tDiffuse,vUv);\n\n\t\t\tvec2 offset;\n\n\t\t\toffset=(vec2(-1,0))*texelSize;\n\t\t\tvec4 cl=texture2D(tDiffuse,vUv+offset);\n\n\t\t\toffset=(vec2(1,0))*texelSize;\n\t\t\tvec4 cr=texture2D(tDiffuse,vUv+offset);\n\n\t\t\toffset=(vec2(0,-1))*texelSize;\n\t\t\tvec4 cb=texture2D(tDiffuse,vUv+offset);\n\n\t\t\toffset=(vec2(0,1))*texelSize;\n\t\t\tvec4 ct=texture2D(tDiffuse,vUv+offset);\n\n\t\t\t// float coeCenter=.5;\n\t\t\t// float coeSide=.125;\n\t\t\tfloat coeCenter=.2;\n\t\t\tfloat coeSide=.2;\n\t\t\tfloat a=c.a*coeCenter+cl.a*coeSide+cr.a*coeSide+cb.a*coeSide+ct.a*coeSide;\n\t\t\tvec3 rgb=(c.rgb*c.a*coeCenter+cl.rgb*cl.a*coeSide+cr.rgb*cr.a*coeSide+cb.rgb*cb.a*coeSide+ct.rgb*ct.a*coeSide)/a;\n\t\t\tgl_FragColor=vec4(rgb,a);\n\n\t\t}\n\t"};export{n as SSRShader,i as SSRDepthShader,a as SSRBlurShader};/*
|
1
|
+
import{Matrix4 as t,Vector2 as e}from"three";const n={name:"SSRShader",defines:{MAX_STEP:0,PERSPECTIVE_CAMERA:!0,DISTANCE_ATTENUATION:!0,FRESNEL:!0,INFINITE_THICK:!1,SELECTIVE:!1},uniforms:{tDiffuse:{value:null},tNormal:{value:null},tMetalness:{value:null},tDepth:{value:null},cameraNear:{value:null},cameraFar:{value:null},resolution:{value:new e},cameraProjectionMatrix:{value:new t},cameraInverseProjectionMatrix:{value:new t},opacity:{value:.5},maxDistance:{value:180},cameraRange:{value:0},thickness:{value:.018}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:'\n\t\t// precision highp float;\n\t\tprecision highp sampler2D;\n\t\tvarying vec2 vUv;\n\t\tuniform sampler2D tDepth;\n\t\tuniform sampler2D tNormal;\n\t\tuniform sampler2D tMetalness;\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform float cameraRange;\n\t\tuniform vec2 resolution;\n\t\tuniform float opacity;\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\t\tuniform float maxDistance;\n\t\tuniform float thickness;\n\t\tuniform mat4 cameraProjectionMatrix;\n\t\tuniform mat4 cameraInverseProjectionMatrix;\n\t\t#include <packing>\n\t\tfloat pointToLineDistance(vec3 x0, vec3 x1, vec3 x2) {\n\t\t\t//x0: point, x1: linePointA, x2: linePointB\n\t\t\t//https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html\n\t\t\treturn length(cross(x0-x1,x0-x2))/length(x2-x1);\n\t\t}\n\t\tfloat pointPlaneDistance(vec3 point,vec3 planePoint,vec3 planeNormal){\n\t\t\t// https://mathworld.wolfram.com/Point-PlaneDistance.html\n\t\t\t//// https://en.wikipedia.org/wiki/Plane_(geometry)\n\t\t\t//// http://paulbourke.net/geometry/pointlineplane/\n\t\t\tfloat a=planeNormal.x,b=planeNormal.y,c=planeNormal.z;\n\t\t\tfloat x0=point.x,y0=point.y,z0=point.z;\n\t\t\tfloat x=planePoint.x,y=planePoint.y,z=planePoint.z;\n\t\t\tfloat d=-(a*x+b*y+c*z);\n\t\t\tfloat distance=(a*x0+b*y0+c*z0+d)/sqrt(a*a+b*b+c*c);\n\t\t\treturn distance;\n\t\t}\n\t\tfloat getDepth( const in vec2 uv ) {\n\t\t\treturn texture2D( tDepth, uv ).x;\n\t\t}\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#else\n\t\t\t\treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#endif\n\t\t}\n\t\tvec3 getViewPosition( const in vec2 uv, const in float depth/*clip space*/, const in float clipW ) {\n\t\t\tvec4 clipPosition = vec4( ( vec3( uv, depth ) - 0.5 ) * 2.0, 1.0 );//ndc\n\t\t\tclipPosition *= clipW; //clip\n\t\t\treturn ( cameraInverseProjectionMatrix * clipPosition ).xyz;//view\n\t\t}\n\t\tvec3 getViewNormal( const in vec2 uv ) {\n\t\t\treturn unpackRGBToNormal( texture2D( tNormal, uv ).xyz );\n\t\t}\n\t\tvec2 viewPositionToXY(vec3 viewPosition){\n\t\t\tvec2 xy;\n\t\t\tvec4 clip=cameraProjectionMatrix*vec4(viewPosition,1);\n\t\t\txy=clip.xy;//clip\n\t\t\tfloat clipW=clip.w;\n\t\t\txy/=clipW;//NDC\n\t\t\txy=(xy+1.)/2.;//uv\n\t\t\txy*=resolution;//screen\n\t\t\treturn xy;\n\t\t}\n\t\tvoid main(){\n\t\t\tfloat reflectivity = 1.0;\n\t\t\t#ifdef SELECTIVE\n\t\t\t\tfloat metalness=texture2D(tMetalness,vUv).r;\n\t\t\t\treflectivity = metalness;\n\t\t\t\tif(metalness==0.) return;\n\t\t\t#endif\n\n\t\t\tfloat depth = getDepth( vUv );\n\t\t\tfloat viewZ = getViewZ( depth );\n\t\t\tif(-viewZ>=cameraFar) return;\n\n\t\t\tfloat clipW = cameraProjectionMatrix[2][3] * viewZ+cameraProjectionMatrix[3][3];\n\t\t\tvec3 viewPosition=getViewPosition( vUv, depth, clipW );\n\n\t\t\tvec2 d0=gl_FragCoord.xy;\n\t\t\tvec2 d1;\n\n\t\t\tvec3 viewNormal=getViewNormal( vUv );\n\n\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\tvec3 viewIncidentDir=normalize(viewPosition);\n\t\t\t\tvec3 viewReflectDir=reflect(viewIncidentDir,viewNormal);\n\t\t\t#else\n\t\t\t\tvec3 viewIncidentDir=vec3(0,0,-1);\n\t\t\t\tvec3 viewReflectDir=reflect(viewIncidentDir,viewNormal);\n\t\t\t#endif\n\n\t\t\tfloat maxReflectRayLen=maxDistance/dot(-viewIncidentDir,viewNormal);\n\t\t\t// dot(a,b)==length(a)*length(b)*cos(theta) // https://www.mathsisfun.com/algebra/vectors-dot-product.html\n\t\t\t// if(a.isNormalized&&b.isNormalized) dot(a,b)==cos(theta)\n\t\t\t// maxDistance/maxReflectRayLen=cos(theta)\n\t\t\t// maxDistance/maxReflectRayLen==dot(a,b)\n\t\t\t// maxReflectRayLen==maxDistance/dot(a,b)\n\n\t\t\tvec3 d1viewPosition=viewPosition+viewReflectDir*maxReflectRayLen;\n\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\tif(d1viewPosition.z>-cameraNear){\n\t\t\t\t\t//https://tutorial.math.lamar.edu/Classes/CalcIII/EqnsOfLines.aspx\n\t\t\t\t\tfloat t=(-cameraNear-viewPosition.z)/viewReflectDir.z;\n\t\t\t\t\td1viewPosition=viewPosition+viewReflectDir*t;\n\t\t\t\t}\n\t\t\t#endif\n\t\t\td1=viewPositionToXY(d1viewPosition);\n\n\t\t\tfloat totalLen=length(d1-d0);\n\t\t\tfloat xLen=d1.x-d0.x;\n\t\t\tfloat yLen=d1.y-d0.y;\n\t\t\tfloat totalStep=max(abs(xLen),abs(yLen));\n\t\t\tfloat xSpan=xLen/totalStep;\n\t\t\tfloat ySpan=yLen/totalStep;\n\t\t\tfor(float i=0.;i<float(MAX_STEP);i++){\n\t\t\t\tif(i>=totalStep) break;\n\t\t\t\tvec2 xy=vec2(d0.x+i*xSpan,d0.y+i*ySpan);\n\t\t\t\tif(xy.x<0.||xy.x>resolution.x||xy.y<0.||xy.y>resolution.y) break;\n\t\t\t\tfloat s=length(xy-d0)/totalLen;\n\t\t\t\tvec2 uv=xy/resolution;\n\n\t\t\t\tfloat d = getDepth(uv);\n\t\t\t\tfloat vZ = getViewZ( d );\n\t\t\t\tif(-vZ>=cameraFar) continue;\n\t\t\t\tfloat cW = cameraProjectionMatrix[2][3] * vZ+cameraProjectionMatrix[3][3];\n\t\t\t\tvec3 vP=getViewPosition( uv, d, cW );\n\n\t\t\t\t#ifdef PERSPECTIVE_CAMERA\n\t\t\t\t\t// https://comp.nus.edu.sg/~lowkl/publications/lowk_persp_interp_techrep.pdf\n\t\t\t\t\tfloat recipVPZ=1./viewPosition.z;\n\t\t\t\t\tfloat viewReflectRayZ=1./(recipVPZ+s*(1./d1viewPosition.z-recipVPZ));\n\t\t\t\t#else\n\t\t\t\t\tfloat viewReflectRayZ=viewPosition.z+s*(d1viewPosition.z-viewPosition.z);\n\t\t\t\t#endif\n\n\t\t\t\t// if(viewReflectRayZ>vZ) continue; // will cause "npm run make-screenshot webgl_postprocessing_ssr" high probability hang.\n\t\t\t\t// https://github.com/mrdoob/three.js/pull/21539#issuecomment-821061164\n\t\t\t\tif(viewReflectRayZ<=vZ){\n\n\t\t\t\t\tbool hit;\n\t\t\t\t\t#ifdef INFINITE_THICK\n\t\t\t\t\t\thit=true;\n\t\t\t\t\t#else\n\t\t\t\t\t\tfloat away=pointToLineDistance(vP,viewPosition,d1viewPosition);\n\n\t\t\t\t\t\tfloat minThickness;\n\t\t\t\t\t\tvec2 xyNeighbor=xy;\n\t\t\t\t\t\txyNeighbor.x+=1.;\n\t\t\t\t\t\tvec2 uvNeighbor=xyNeighbor/resolution;\n\t\t\t\t\t\tvec3 vPNeighbor=getViewPosition(uvNeighbor,d,cW);\n\t\t\t\t\t\tminThickness=vPNeighbor.x-vP.x;\n\t\t\t\t\t\tminThickness*=3.;\n\t\t\t\t\t\tfloat tk=max(minThickness,thickness);\n\n\t\t\t\t\t\thit=away<=tk;\n\t\t\t\t\t#endif\n\n\t\t\t\t\tif(hit){\n\t\t\t\t\t\tvec3 vN=getViewNormal( uv );\n\t\t\t\t\t\tif(dot(viewReflectDir,vN)>=0.) continue;\n\t\t\t\t\t\tfloat distance=pointPlaneDistance(vP,viewPosition,viewNormal);\n\t\t\t\t\t\tif(distance>maxDistance) break;\n\t\t\t\t\t\tfloat op=opacity;\n\t\t\t\t\t\t#ifdef DISTANCE_ATTENUATION\n\t\t\t\t\t\t\tfloat ratio=1.-(distance/maxDistance);\n\t\t\t\t\t\t\tfloat attenuation=ratio*ratio;\n\t\t\t\t\t\t\top=opacity*attenuation;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\t#ifdef FRESNEL\n\t\t\t\t\t\t\tfloat fresnelCoe=(dot(viewIncidentDir,viewReflectDir)+1.)/2.;\n\t\t\t\t\t\t\top*=fresnelCoe;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\tvec4 reflectColor=texture2D(tDiffuse,uv);\n\t\t\t\t\t\tgl_FragColor.xyz=reflectColor.xyz;\n\t\t\t\t\t\top *= reflectivity;\n\t\t\t\t\t\tgl_FragColor.a=op;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t'},i={name:"SSRDepthShader",defines:{PERSPECTIVE_CAMERA:1},uniforms:{tDepth:{value:null},cameraNear:{value:null},cameraFar:{value:null}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:"\n\n\t\tuniform sampler2D tDepth;\n\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\n\t\tvarying vec2 vUv;\n\n\t\t#include <packing>\n\n\t\tfloat getLinearDepth( const in vec2 uv ) {\n\n\t\t\t#if PERSPECTIVE_CAMERA == 1\n\n\t\t\t\tfloat fragCoordZ = texture2D( tDepth, uv ).x;\n\t\t\t\tfloat viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );\n\t\t\t\treturn viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );\n\n\t\t\t#else\n\n\t\t\t\treturn texture2D( tDepth, uv ).x;\n\n\t\t\t#endif\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tfloat depth = getLinearDepth( vUv );\n\t\t\tfloat d = 1.0 - depth;\n\t\t\t// d=(d-.999)*1000.;\n\t\t\tgl_FragColor = vec4( vec3( d ), 1.0 );\n\n\t\t}\n\n\t"},a={name:"SSRBlurShader",uniforms:{tDiffuse:{value:null},resolution:{value:new e},opacity:{value:.5}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:"\n\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform vec2 resolution;\n\t\tvarying vec2 vUv;\n\t\tvoid main() {\n\t\t\t//reverse engineering from PhotoShop blur filter, then change coefficient\n\n\t\t\tvec2 texelSize = ( 1.0 / resolution );\n\n\t\t\tvec4 c=texture2D(tDiffuse,vUv);\n\n\t\t\tvec2 offset;\n\n\t\t\toffset=(vec2(-1,0))*texelSize;\n\t\t\tvec4 cl=texture2D(tDiffuse,vUv+offset);\n\n\t\t\toffset=(vec2(1,0))*texelSize;\n\t\t\tvec4 cr=texture2D(tDiffuse,vUv+offset);\n\n\t\t\toffset=(vec2(0,-1))*texelSize;\n\t\t\tvec4 cb=texture2D(tDiffuse,vUv+offset);\n\n\t\t\toffset=(vec2(0,1))*texelSize;\n\t\t\tvec4 ct=texture2D(tDiffuse,vUv+offset);\n\n\t\t\t// float coeCenter=.5;\n\t\t\t// float coeSide=.125;\n\t\t\tfloat coeCenter=.2;\n\t\t\tfloat coeSide=.2;\n\t\t\tfloat a=c.a*coeCenter+cl.a*coeSide+cr.a*coeSide+cb.a*coeSide+ct.a*coeSide;\n\t\t\tvec3 rgb=(c.rgb*c.a*coeCenter+cl.rgb*cl.a*coeSide+cr.rgb*cr.a*coeSide+cb.rgb*cb.a*coeSide+ct.rgb*ct.a*coeSide)/a;\n\t\t\tgl_FragColor=vec4(rgb,a);\n\n\t\t}\n\t"};export{n as SSRShader,i as SSRDepthShader,a as SSRBlurShader};/*
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
package/dist/rendering.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../src/rendering.ts"],"names":[],"mappings":"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
|
1
|
+
{"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../src/rendering.ts"],"names":[],"mappings":"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"}
|
package/dist/rendering.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as p,GammaCorrectionShader as u,LUTPass as m,RenderPass as g,ShaderPass as f,UnrealBloomPass as v,VRButton as x}from"three-stdlib";import{CSMShader as T,CSMUtil as b}from"./csm.js";import{NodeShaderMaterial as y}from"three-shader-graph";import{Reflector as P}from"three-stdlib";import{BokehPass as w,OutputPass as M}from"three/examples/jsm/Addons.js";import{CSM as R}from"three/examples/jsm/csm/CSM.js";import S from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as C}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as D}from"typedi";import{depthUniformName as F,farUniformName as I,nearUniformName as A,resolutionUniformName as W,supportsDepthTextureExtension as E}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as B}from"./shader-nodes/time.js";import{sceneMapUniformName as H}from"./shader-nodes/scene-sample.js";import{DepthPass as j}from"./utils/three/depth-pass.js";import{GPUStatsPanel as U}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as V}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as L}from"./utils/three/traverse.js";import{clamp as O}from"./utils/math.js";import{ColorPass as k}from"./rendering/color-pass.js";import{SSRPass as z}from"./rendering/ssr/SSRPass.js";import{SSRShader as _}from"./rendering/ssr/SSRShader.js";const N=document.createElement("div");N.style.position="absolute",N.style.left="50%",N.style.top="50%",N.style.color="black",N.style.zIndex="999";(new i.Layers).set(9);const G=new i.MeshBasicMaterial({color:"black"}),q=new i.MeshDepthMaterial;q.depthPacking=i.RGBADepthPacking,q.blending=i.NoBlending,q.side=i.DoubleSide;const X=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let Y=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||0!==this.container.clientWidth&&0!==this.container.clientHeight&&(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture,this.depthRenderTarget.dispose(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container))}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}constructor(t,s={}){this.container=t,this.options=s,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.resolutionScale=X?.5:1,this.maxPixelRatio=X?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new S,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new i.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(x.createButton(this.renderer)),this.composer=new c(this.renderer);var n=(t.clientWidth||1)/(t.clientHeight||1);const a=new i.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,b.renderingView=this,b.patchThreeAdd(),this.isDepthTextureExtensionSupported=E(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const o=new g(this.scene,this.camera);this.composer.addPass(o);const l=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);l.threshold=1,l.strength=.9,l.radius=.5,this.bloomPass=l;const h=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);h.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},h.blendMaterial.uniforms.tAODepth={value:h.depthTexture},h.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",h.output=C.OUTPUT.Default,h.enabled=!1,this.aoPass=h,!1!==this.options.ao?.enabled&&this.composer.addPass(h),_.fragmentShader=_.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const d=new z({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});d.output=z.OUTPUT.Default,d.blur=!0,d.fresnel=!1,d.distanceAttenuation=!0,d.maxDistance=50,d.selective=!0,d.bouncing=!1,d.opacity=.4,d.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=d,this.composer.addPass(d),this.renderer.info.autoReset=!1;const T=new c(this.renderer);T.renderToScreen=!1,T.addPass(o),T.addPass(l),this.bloomComposer=T,X||(T.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const y=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:T.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");y.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(y),this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const P=new k;if(this.composer.addPass(P),this.colorPass=P,P.vignetteEnabled=!1,this.outlinePass=new V(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===s.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(p);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(u).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const R=new M;this.composer.addPass(R)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof V?t.renderCamera=e:(t instanceof j||t instanceof C)&&(t.camera=e)})),null==this.csm?(this.csm=new R({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),h.lights_fragment_begin=T.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse((e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var s=!!e.extensions.get("WEBGL_depth_texture");const r=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===s&&(r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}static createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof y&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const s=this.stats,r=s.addPanel(new S.Panel("Calls","#83f","#002")),l=s.addPanel(new S.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new U(this.renderer.getContext()),s.addPanel(h)),this.showStats=t;let d=10,c=1e3;const p=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;const u=[],m=[],g=[];let f=0;const v=new a,x=new a,T=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>T(t)),500);this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin();let a=(t*=.001)-f;if(f=t,v.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(J),t-=J;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),x.copy(this.camera.matrixWorld),x.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),u.length=0,m.length=0,g.length=0;const l=Z;if(this.camera.updateMatrixWorld(),ee.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(ee),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof i.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof i.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[F])&&isObjectInFrustum(e,l)?(e.visible=!1,u.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof P&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[H]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[H].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof i.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[B])e.material.uniforms[B].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[B]&&(s.uniforms[B].value=t)})),u.length>0){if(this.scene.overrideMaterial=q,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(g.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1);try{this.renderer.render(this.scene,this.camera)}catch(e){}}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(u.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=q,this.camera.layers.set(5),this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.camera.layers.enableAll(),this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}try{!this.paused&&this.running&&(this.showStats&&h?.startQuery(),this.render(a),this.showStats&&h?.endQuery(),this.showStats&&p(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(T)}),1e3/this.fpsCap):requestAnimationFrame(T))};!0===this.options.enableXR?this.renderer.setAnimationLoop(T):requestAnimationFrame(T)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,r=!1,n=!1,a=!1;const o=this.camera?.position;if(null==o)return;let h=[];for(const e of this.postProcessVolumes){if(!K(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(o);d>e.blendRadius||(e.blendRadius>0&&(l*=O(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(h.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),n=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l)),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,a=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),a=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,this.scene.environment=t.envTexture,this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,r&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=a,a&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible((t=>{t instanceof o&&!0===t.material.userData?.reflective&&e.push(t)})),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}if(!1!==this.options.bloom?.enabled){const e=this.hasBloom();if(e||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e)));try{this.bloomComposer.render()}catch(e){Q||(console.error(e),Q=!0)}this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=e}this.composer.render(e),t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=L(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===G.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=G:e.visible=!1}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[F].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.near),null!=e.uniforms[I]&&(e.uniforms[I].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};Y=e=t([D(),s("design:paramtypes",[HTMLElement,Object])],Y);export{Y as RenderingView};let Q=!1;export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const J=.05;function K(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}C.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse((function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls)&&(e.visible=!1),null!=e.material){let t=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const Z=new i.Frustum,$=new i.Box3,ee=new i.Matrix4;export function isObjectInFrustum(e,t){const s=$.setFromObject(e);return t.intersectsBox(s)}/*
|
1
|
+
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as p,GammaCorrectionShader as u,LUTPass as m,RenderPass as g,ShaderPass as f,UnrealBloomPass as v,VRButton as x}from"three-stdlib";import{CSMShader as T,CSMUtil as b}from"./csm.js";import{NodeShaderMaterial as y}from"three-shader-graph";import{Reflector as P}from"three-stdlib";import{BokehPass as w,OutputPass as M}from"three/examples/jsm/Addons.js";import{CSM as R}from"three/examples/jsm/csm/CSM.js";import S from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as C}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as D}from"typedi";import{depthUniformName as F,farUniformName as I,nearUniformName as A,resolutionUniformName as W,supportsDepthTextureExtension as E}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as B}from"./shader-nodes/time.js";import{sceneMapUniformName as H}from"./shader-nodes/scene-sample.js";import{DepthPass as j}from"./utils/three/depth-pass.js";import{GPUStatsPanel as U}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as V}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as L}from"./utils/three/traverse.js";import{clamp as O}from"./utils/math.js";import{ColorPass as k}from"./rendering/color-pass.js";import{SSRPass as z}from"./rendering/ssr/SSRPass.js";import{SSRShader as _}from"./rendering/ssr/SSRShader.js";const N=document.createElement("div");N.style.position="absolute",N.style.left="50%",N.style.top="50%",N.style.color="black",N.style.zIndex="999";(new i.Layers).set(9);const G=new i.MeshBasicMaterial({color:"black"}),q=new i.MeshDepthMaterial;q.depthPacking=i.RGBADepthPacking,q.blending=i.NoBlending,q.side=i.DoubleSide;const X=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let Y=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||0!==this.container.clientWidth&&0!==this.container.clientHeight&&(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture,this.depthRenderTarget.dispose(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container))}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}constructor(t,s={}){this.container=t,this.options=s,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.resolutionScale=X?.5:1,this.maxPixelRatio=X?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new S,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new i.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(x.createButton(this.renderer)),this.composer=new c(this.renderer);var n=(t.clientWidth||1)/(t.clientHeight||1);const a=new i.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,b.renderingView=this,b.patchThreeAdd(),this.isDepthTextureExtensionSupported=E(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const o=new g(this.scene,this.camera);this.composer.addPass(o);const l=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);l.threshold=1,l.strength=.9,l.radius=.5,this.bloomPass=l;const h=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);h.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},h.blendMaterial.uniforms.tAODepth={value:h.depthTexture},h.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",h.output=C.OUTPUT.Default,h.enabled=!1,this.aoPass=h,!1!==this.options.ao?.enabled&&this.composer.addPass(h),_.fragmentShader=_.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const d=new z({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});d.output=z.OUTPUT.Default,d.blur=!0,d.fresnel=!1,d.distanceAttenuation=!0,d.maxDistance=50,d.selective=!0,d.bouncing=!1,d.opacity=.4,d.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=d,this.composer.addPass(d),this.renderer.info.autoReset=!1;const T=new c(this.renderer);T.renderToScreen=!1,T.addPass(o),T.addPass(l),this.bloomComposer=T,X||(T.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const y=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:T.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");y.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(y),this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const P=new k;if(this.composer.addPass(P),this.colorPass=P,P.vignetteEnabled=!1,this.outlinePass=new V(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===s.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(p);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(u).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const R=new M;this.composer.addPass(R)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof V?t.renderCamera=e:(t instanceof j||t instanceof C)&&(t.camera=e)})),null==this.csm?(this.csm=new R({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),h.lights_fragment_begin=T.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse((e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var s=!!e.extensions.get("WEBGL_depth_texture");const r=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===s&&(r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}static createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof y&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const s=this.stats,r=s.addPanel(new S.Panel("Calls","#83f","#002")),l=s.addPanel(new S.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new U(this.renderer.getContext()),s.addPanel(h)),this.showStats=t;let d=10,c=1e3;const p=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;const u=[],m=[],g=[];let f=0;const v=new a,x=new a,T=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>T(t)),500);this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin();let a=(t*=.001)-f;if(f=t,v.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(J),t-=J;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),x.copy(this.camera.matrixWorld),x.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),u.length=0,m.length=0,g.length=0;const l=Z;if(this.camera.updateMatrixWorld(),ee.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(ee),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof i.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof i.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[F])&&isObjectInFrustum(e,l)?(e.visible=!1,u.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof P&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[H]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[H].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof i.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[B])e.material.uniforms[B].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[B]&&(s.uniforms[B].value=t)})),u.length>0){if(this.scene.overrideMaterial=q,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(g.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1);try{this.renderer.render(this.scene,this.camera)}catch(e){}}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(u.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=q,this.camera.layers.set(5),this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.camera.layers.enableAll(),this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}this.ssrPass&&(this.ssrPass.elapsedTime=t);try{!this.paused&&this.running&&(this.showStats&&h?.startQuery(),this.render(a),this.showStats&&h?.endQuery(),this.showStats&&p(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(T)}),1e3/this.fpsCap):requestAnimationFrame(T))};!0===this.options.enableXR?this.renderer.setAnimationLoop(T):requestAnimationFrame(T)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,r=!1,n=!1,a=!1;const o=this.camera?.position;if(null==o)return;let h=[];for(const e of this.postProcessVolumes){if(!K(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(o);d>e.blendRadius||(e.blendRadius>0&&(l*=O(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(h.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),n=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l)),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,a=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),a=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,this.scene.environment=t.envTexture,this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,r&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=a,a&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible((t=>{t instanceof o&&!0===t.material.userData?.reflective&&e.push(t)})),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}if(!1!==this.options.bloom?.enabled){const e=this.hasBloom();if(e||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e)));try{this.bloomComposer.render()}catch(e){Q||(console.error(e),Q=!0)}this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=e}this.composer.render(e),t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=L(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===G.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=G:e.visible=!1}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[F].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.near),null!=e.uniforms[I]&&(e.uniforms[I].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};Y=e=t([D(),s("design:paramtypes",[HTMLElement,Object])],Y);export{Y as RenderingView};let Q=!1;export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const J=.05;function K(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}C.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse((function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls)&&(e.visible=!1),null!=e.material){let t=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const Z=new i.Frustum,$=new i.Box3,ee=new i.Matrix4;export function isObjectInFrustum(e,t){const s=$.setFromObject(e);return t.intersectsBox(s)}/*
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
package/dist/shader/shader.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/shader/shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAgC,QAAQ,EAAE,WAAW,EAAkB,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC9I,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,cAAc,gBAAgB,CAAA;AAE9B,8BAAsB,MAAM;IAC1B,QAAQ,CAAC,KAAK,IAAI,QAAQ;CAC3B;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;AAEvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;CACd,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,QAAQ,GAAC,QAAQ,GAAC,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAID,8BAAsB,UAAU;IAC9B,KAAK,IAAI,QAAQ;IAajB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
|
1
|
+
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/shader/shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAgC,QAAQ,EAAE,WAAW,EAAkB,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC9I,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,cAAc,gBAAgB,CAAA;AAE9B,8BAAsB,MAAM;IAC1B,QAAQ,CAAC,KAAK,IAAI,QAAQ;CAC3B;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;AAEvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;CACd,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,QAAQ,GAAC,QAAQ,GAAC,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAA;CACpB,CAAA;AAID,8BAAsB,UAAU;IAC9B,KAAK,IAAI,QAAQ;IAajB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hology/core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.124",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"type": "module",
|
@@ -168,14 +168,14 @@
|
|
168
168
|
"dependencies": {
|
169
169
|
"@babel/runtime": "^7.24.8",
|
170
170
|
"@dimforge/rapier3d-compat": "^0.14.0",
|
171
|
-
"@hology/nebula": "^0.0.
|
171
|
+
"@hology/nebula": "^0.0.124",
|
172
172
|
"@plumier/reflect": "^1.1.0",
|
173
173
|
"@recast-navigation/three": "^0.35.2",
|
174
174
|
"recast-navigation": "^0.35.2",
|
175
175
|
"rxjs": "7.8.1",
|
176
176
|
"three-csm": "^4.2.1",
|
177
177
|
"three-mesh-bvh": "^0.7.5",
|
178
|
-
"three-shader-graph": "^0.2.
|
178
|
+
"three-shader-graph": "^0.2.17",
|
179
179
|
"three-stdlib": "2.34.0",
|
180
180
|
"ts-key-enum": "^2.0.12",
|
181
181
|
"typedi": "^0.10.0"
|