@hology/core 0.0.275 → 0.0.276
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/effects/sequence/sequence-player.d.ts +1 -0
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/gameplay/actors/builtin/components/index.d.ts +6 -0
- package/dist/gameplay/actors/builtin/components/index.js +1 -1
- package/dist/gameplay/actors/builtin/components/primitive-mesh-component.d.ts +66 -0
- package/dist/gameplay/actors/builtin/components/primitive-mesh-component.js +4 -0
- package/dist/gameplay/actors/builtin/index.d.ts +6 -0
- package/dist/gameplay/actors/builtin/index.js +1 -1
- package/dist/gameplay/actors/builtin/light-actor.d.ts +54 -0
- package/dist/gameplay/actors/builtin/light-actor.js +4 -0
- package/dist/gameplay/actors/builtin/mesh-actor.d.ts +9 -0
- package/dist/gameplay/actors/builtin/mesh-actor.js +4 -0
- package/dist/gameplay/actors/factory.js +1 -1
- package/dist/gameplay/actors/index.d.ts +5 -0
- package/dist/gameplay/actors/index.js +1 -1
- package/dist/gameplay/index.d.ts +1 -0
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/rendering-host.d.ts +1 -0
- package/dist/gameplay/rendering-host.js +1 -1
- package/dist/gameplay/services/asset-loader.d.ts +3 -0
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/rendering/node-material-webgpu-resolver.d.ts +1 -0
- package/dist/rendering/node-material-webgpu-resolver.js +1 -1
- package/dist/rendering/post-process-color.d.ts +9 -0
- package/dist/rendering/post-process-color.js +4 -0
- package/dist/rendering/webgl-backend.d.ts +243 -9
- package/dist/rendering/webgl-backend.js +1 -1
- package/dist/rendering/webgpu-experimental-backend.d.ts +4 -1
- package/dist/rendering/webgpu-experimental-backend.js +1 -1
- package/dist/rendering.d.ts +45 -209
- package/dist/rendering.js +1 -1
- package/dist/scene/actor-material-parameters.d.ts +19 -0
- package/dist/scene/actor-material-parameters.js +4 -0
- package/dist/scene/actor-mesh-provider.d.ts +2 -0
- package/dist/scene/actor-mesh-provider.js +4 -0
- package/dist/scene/actor-mesh-renderer.d.ts +40 -0
- package/dist/scene/actor-mesh-renderer.js +4 -0
- package/dist/scene/asset-resource-loader.d.ts +2 -0
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/batched-mesh-2.js +1 -1
- package/dist/scene/custom-param-deserialize.js +1 -1
- package/dist/scene/custom-param-runtime-types.js +1 -1
- package/dist/scene/material-ref.d.ts +7 -0
- package/dist/scene/material-ref.js +4 -0
- package/dist/scene/materializer.d.ts +16 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/model.d.ts +2 -1
- package/dist/scene/model.js +1 -1
- package/dist/scene/runtime-bundled-backend-service.d.ts +1 -0
- package/dist/scene/runtime-bundled-backend-service.js +1 -1
- package/dist/scene/scene-object-actor-conversion.d.ts +10 -0
- package/dist/scene/scene-object-actor-conversion.js +4 -0
- package/dist/shader/parameter.d.ts +5 -2
- package/dist/shader-nodes/particle.d.ts +2 -2
- package/dist/test/actor-mesh-renderer.test.d.ts +2 -0
- package/dist/test/actor-mesh-renderer.test.js +4 -0
- package/dist/test/actor-persistence-runtime.test.js +1 -1
- package/dist/test/asset-resource-loader-converted-fbx.test.js +1 -1
- package/dist/test/asset-resource-loader-skinned-merge.test.js +1 -1
- package/dist/test/landscape-static-draw-sets.test.js +1 -1
- package/dist/test/node-material-webgpu-resolver.test.js +1 -1
- package/dist/test/physics-ray-object.test.js +1 -1
- package/dist/test/primitive-actors.test.d.ts +2 -0
- package/dist/test/primitive-actors.test.js +4 -0
- package/dist/test/rendering-host.test.js +1 -1
- package/dist/test/runtime-bundled-backend-service.test.d.ts +2 -0
- package/dist/test/runtime-bundled-backend-service.test.js +4 -0
- package/dist/test/scene-object-actor-conversion.test.d.ts +2 -0
- package/dist/test/scene-object-actor-conversion.test.js +4 -0
- package/dist/test/webgl-backend.test.d.ts +2 -0
- package/dist/test/webgl-backend.test.js +4 -0
- package/dist/utils/async.d.ts +2 -0
- package/dist/utils/async.js +1 -1
- package/dist/utils/mesh.js +1 -1
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{skyPosition as e}from"../scene/sky.js";import*as a from"three";import{compileNodeWebGpuFullscreen as t,compileNodeShaderMaterialForWebGpu as i,NodeShaderMaterial as n,deriveNodeShaderMaterial as s,webGpuRendererBindings as o,webGpuTiledRendererBindings as r,textureSampler2d as l,float as u,length as p,max as m,rgba as c,isWgslCompiler as f,isWgslFragmentCompiler as h,sqrt as d,normalize as M,transformed as v,uniformFloat as y,uniforms as g,vec4 as V,Vec3Node as I,toonMaterial as S}from"three-shader-graph";import{StandardShader as w}from"../shader/builtin/standard-shader.js";import{LambertShader as x}from"../shader/builtin/lambert-shader.js";import{ToonShader as T}from"../shader/builtin/toon-shader.js";import{UnlitShader as E}from"../shader/builtin/unlit-shader.js";import{SpriteShader as C}from"../shader/sprite-shader.js";import{elapsedTimeUniformName as b}from"../shader-nodes/time.js";import{depthUniformName as U,farUniformName as A,nearUniformName as N,resolutionUniformName as k,sceneNormalUniformName as W}from"../shader-nodes/depth.js";import{sceneMapUniformName as R,transmissionMapUniformName as D}from"../shader-nodes/scene-sample.js";import{deriveSDFGISurfaceGraph as L}from"./sdfgi-surface-material.js";const F={...o,uniformExpressions:{...o.uniformExpressions,ambientLightColor:{type:"vec3",expression:"rendererAmbientLight()"},[b]:{type:"float",expression:"rendererElapsedTime()"},[N]:{type:"float",expression:"rendererCameraNear()"},[A]:{type:"float",expression:"rendererCameraFar()"},[k]:{type:"vec2",expression:"rendererViewportSize()"}},graphTextures:{[D]:{resource:"physicalTransmissionSnapshot",dimension:"2d",sampleType:"float",sampler:"filtering",requiresLatePass:!0}},sceneTextures:{[R]:{semantic:"sceneColor",sampleType:"float"},[U]:{semantic:"sceneDepth",sampleType:"depth"}},attributes:{material:{shaderLocation:6,format:"float32x4",defaultValue:[0,0,0,0]},material2:{shaderLocation:7,format:"float32x4",defaultValue:[0,0,0,0]},hole:{shaderLocation:8,format:"float32",defaultValue:[0]},offset:{shaderLocation:9,format:"float32x3",stepMode:"instance",defaultValue:[0,0,0]},velocity:{shaderLocation:10,format:"float32x4",stepMode:"instance",defaultValue:[0,0,0,0]},size:{shaderLocation:11,format:"float32x3",stepMode:"instance",defaultValue:[0,0,0]},rotation:{shaderLocation:12,format:"float32",stepMode:"instance",defaultValue:[0]},particleData:{shaderLocation:13,format:"float32x3",stepMode:"instance",defaultValue:[1,1,0]},particleColor:{shaderLocation:14,format:"float32x4",stepMode:"instance",defaultValue:[1,1,1,1]}}};class O extends I{constructor(e){super(),this.fallback=e}compile(e){if(!f(e))return{out:e.get(this.fallback)};if(h(e))throw new Error("OutlineLocalPositionNode can only be used in the vertex stage");const a=`outline_local_position_${e.variable()}`;return{chunk:`\n#ifdef USE_SKINNING\n let ${a} = rendererSkinPosition(input.position, input.skinIndex, input.skinWeight).xyz;\n#else\n let ${a} = input.position;\n#endif`,out:a}}}class P extends I{constructor(e){super(),this.fallback=e}compile(e){if(!f(e))return{out:e.get(this.fallback)};if(h(e))throw new Error("OutlineLocalNormalNode can only be used in the vertex stage");const a=`outline_local_normal_${e.variable()}`;return{chunk:`\n#ifdef USE_SKINNING\n let ${a} = rendererSkinNormal(input.normal, input.skinIndex, input.skinWeight);\n#else\n let ${a} = input.normal;\n#endif`,out:a}}}export function setMaterialUniformValuesAutoUpdate(e,a){e.uniformValuesAutoUpdate=a}export function markMaterialUniformValuesNeedUpdate(e){const a=e;"uniformValuesNeedsUpdate"in a?a.uniformValuesNeedsUpdate=!0:a.uniformValuesAutoVersion=(a.uniformValuesAutoVersion??0)+1}function j(e){return!1!==e.uniformValuesAutoUpdate}function G(e){return e.uniformValuesAutoVersion??0}export function withThreeDefaultVertexAttributeValues(e){return e.map(e=>"uv1"===e.name&&null==e.defaultValue?{...e,defaultValue:[0,0]}:e)}const B=new WeakMap,$=new WeakMap;export function createNodeMaterialSignature(e){const a=$.get(e);if(null!=a)return a;const t=JSON.stringify({version:e.version,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader,alphaTest:e.alphaTest,alphaToCoverage:e.alphaToCoverage,blending:e.blending,colorWrite:e.colorWrite,depthFunc:e.depthFunc,depthTest:e.depthTest,depthWrite:e.depthWrite,polygonOffset:e.polygonOffset,polygonOffsetFactor:e.polygonOffsetFactor,polygonOffsetUnits:e.polygonOffsetUnits,premultipliedAlpha:e.premultipliedAlpha,side:e.side,stencilWrite:e.stencilWrite,transparent:e.transparent,wireframe:e.wireframe});return $.set(e,t),t}export class NodeMaterialWebGpuResolver{constructor(e,a,t){this.webGpu=e,this.mrtResolver=a,this.environmentTextureResolver=t,this.cache=new WeakMap,this.failedSignatures=new WeakMap,this.mappedMaterialsCache=new WeakMap,this.sourcesByResolved=new WeakMap,this.mappedMaterialsSignatures=new WeakMap,this.observedNodeMaterials=new Map,this.outlineMaterials=new WeakMap,this.outlineUniformVersions=new WeakMap,this.worldEnvironmentMaterials=new WeakSet,this.worldEnvironment=null,this.worldEnvironmentTexture=null,this.worldEnvironmentIntensity=0,this.worldEnvironmentRevision=0,this.cacheValues=new Set}setWorldEnvironment(e){const a=e?.texture??null,t=e?.intensity??0;if(this.worldEnvironmentTexture!==a||this.worldEnvironmentIntensity!==t){if(this.worldEnvironmentTexture!==a)this.worldEnvironmentRevision++;else if(null!=e)for(const e of this.cacheValues)e.inheritsWorldEnvironment&&null!=e.material.uniforms.envMapIntensity&&(e.material.uniforms.envMapIntensity.value=t,e.material.uniformValuesNeedsUpdate=!0);this.worldEnvironment=e,this.worldEnvironmentTexture=a,this.worldEnvironmentIntensity=t}}resolve(a,t=void 0){let o,l=!1;if(a instanceof n)o=a,this.observeNodeMaterial(o);else{const e=this.getOrCreateMappedNodeMaterial(a);if(null==e)return;o=e,l=!0}if("outline"===t){if(null==o.outputAlbedo)return;l&&Y(a,o),o.userData.outlineParameters=a.userData?.outlineParameters,o=this.getOrCreateOutlineMaterial(o),l=!1}o.visible=a.visible,l&&(o.userData.receiveDecals=a.userData.receiveDecals,o.userData.receiveGI=a.userData.receiveGI);const u=t??"default",p=this.cache.get(o),m=p?.get(u);if(l&&null!=m&&m.sourceVersion===a.version&&m.worldEnvironmentRevision===this.worldEnvironmentRevision){const e=j(a),t=G(a);return m.material.uniformValuesAutoUpdate=e,this.syncInheritedWorldEnvironmentSource(o,m),e||m.sourceUniformValuesAutoVersion!==t?(Y(a,o),m.compiled.syncLiveUniforms(m.material.uniforms),_(o,m.material.uniforms),K(o,m.material),m.sourceUniformValuesAutoVersion=t,e||(m.material.uniformValuesNeedsUpdate=!0),m.material):m.material}if(!l&&null!=m&&m.sourceVersion===a.version&&m.worldEnvironmentRevision===this.worldEnvironmentRevision&&q(o,m.compiled))return this.syncInheritedWorldEnvironmentSource(o,m),z(o,m),m.material;l&&Y(a,o);const c=this.prepareWorldEnvironment(o),f=this.getNodeMaterialSignature(o,c);if(m?.signature===f&&q(o,m.compiled))return l?(m.material.uniformValuesAutoUpdate=j(a),m.compiled.syncLiveUniforms(m.material.uniforms),_(o,m.material.uniforms),K(o,m.material),m.sourceUniformValuesAutoVersion=G(a),m.material.uniformValuesAutoUpdate||(m.material.uniformValuesNeedsUpdate=!0)):z(o,m,!0),m.sourceVersion=a.version,m.worldEnvironmentRevision=this.worldEnvironmentRevision,m.material;try{const n="sdfgi"===t?L(o):null;if("sdfgi"===t&&null==n)return;const h=null==n?this.mrtResolver?.(o,t):void 0,d=n??(!0===a.userData.isSky?s(o,{position:e,fog:o.fog}):o);let M;try{M=i(d,"opaque"===t?{...F,arrays:r.arrays}:F,h)}finally{n?.dispose()}const v=new this.webGpu.WGSLShaderMaterial({vertexShader:M.vertexShader,fragmentShader:M.fragmentShader,depthVertexShader:M.depthVertexShader,depthFragmentShader:M.depthFragmentShader,pointShadowVertexShader:M.pointShadowVertexShader,pointShadowFragmentShader:M.pointShadowFragmentShader,uniforms:M.uniforms,textures:M.textures,sceneTextures:M.sceneTextures,graphTextures:M.graphTextures,vertexAttributes:withThreeDefaultVertexAttributeValues(M.vertexAttributes),uniformValuesAutoUpdate:l?j(a):o.uniformValuesAutoUpdate,transparent:M.renderState?.transparent,alphaTest:M.renderState?.alphaTest,depthTest:M.renderState?.depthTest,depthWrite:M.renderState?.depthWrite,side:M.renderState?.side,wireframe:o.wireframe});this.sourcesByResolved.set(v,a),v.userData.receiveGI=!1!==a.userData.receiveGI,v.name=a.name||o.name||a.uuid,v.userData.pipelineOrigin={assetId:a.userData.assetId??o.userData.assetId,assetName:a.userData.assetName??o.userData.assetName,sourceUuid:a.uuid,sourceName:a.name,sourceType:a.type,sourceVersion:a.version},v.uniformValuesAutoUpdate=l?j(a):o.uniformValuesAutoUpdate,function(e,a){if(null==e)return;Object.assign(a,e)}(M.renderState,v),null!=m&&(m.material.dispose(),this.cacheValues.delete(m));const y={signature:f,compiled:M,material:v,inheritsWorldEnvironment:c,sourceVersion:a.version,sourceUniformValuesAutoVersion:l?G(a):o.uniformValuesAutoVersion,worldEnvironmentRevision:this.worldEnvironmentRevision},g=p??new Map;return g.set(u,y),this.cache.set(o,g),this.cacheValues.add(y),_(o,v.uniforms),K(o,v),v}catch(e){let a=this.failedSignatures.get(o);if(null==a&&(a=new Map,this.failedSignatures.set(o,a)),a.get(u)!==f){a.set(u,f);const t=e instanceof Error?e.message:String(e),i=o.name||o.uuid;console.warn(`[Hology WebGPU experiment] Falling back for NodeShaderMaterial "${i}": ${t}`,{material:o,error:e})}return}}resolveSDFGISurface(e){const a=this.sourcesByResolved.get(e);return null==a||!0===a.userData.isSky||!1===a.userData.sdfgi?void 0:this.resolve(a,"sdfgi")}getOrCreateOutlineMaterial(e){let t=this.outlineMaterials.get(e);if(null==t){const i=e.nodeMaterialDefinition,s=e.outputAlbedo;if(null==s)throw new Error("Cannot derive an outline material without an albedo output");const o=y("outlineThickness",.003),r=y("outlineDarkening",.65),l=y("outlineAlpha",1),f=new O(v.position.xyz),h=new P(v.normal),I=i.transform?.multiplyVec(V(f,1))??V(f,1),w=g.modelViewMatrix.multiplyVec(I),x=M(g.normalMatrix.multiplyVec(h)),T=d(m(p(w.xyz),u(1e-4))).multiply(.5),E=w.xyz.add(x.multiplyScalar(o.multiply(T))),C=g.projectionMatrix.multiplyVec(w),b=g.projectionMatrix.multiplyVec(V(E,1)),U=(i.position??C).add(b.subtract(C)),A=c(S({color:s.rgb.multiplyScalar(u(1).subtract(r))}),e.outputOpacity.multiply(l));t=new n({color:A,position:U,opacity:e.outputOpacity,discard:i.discard,alphaTest:e.alphaTest,transparent:!0,fog:!1,outputEncoding:i.outputEncoding,uniforms:i.uniforms,uniformNodes:i.uniformNodes}),t.side=a.BackSide,t.depthTest=!0,t.depthWrite=!0,this.outlineMaterials.set(e,t),this.outlineUniformVersions.delete(e)}const i=e.userData?.outlineParameters,s=i?.thickness??.003,o=a.MathUtils.clamp(i?.darkening??.65,0,1),r=a.MathUtils.clamp(i?.alpha??e.opacity,0,1),l=t.uniforms.outlineThickness.value!==s||t.uniforms.outlineDarkening.value!==o||t.uniforms.outlineAlpha.value!==r;t.uniforms.outlineThickness.value=s,t.uniforms.outlineDarkening.value=o,t.uniforms.outlineAlpha.value=r,t.userData.outlineSource=e,t.uniformValuesAutoUpdate=e.uniformValuesAutoUpdate;let f=this.outlineUniformVersions.get(e);const h=e.uniformValuesAutoUpdate||null==f||f.version!==e.uniformValuesAutoVersion||f.uniforms!==e.uniforms;if(h){for(const a in e.uniforms)null!=t.uniforms[a]&&(t.uniforms[a].value=e.uniforms[a].value);f?(f.version=e.uniformValuesAutoVersion,f.uniforms=e.uniforms):(f={version:e.uniformValuesAutoVersion,uniforms:e.uniforms},this.outlineUniformVersions.set(e,f))}return e.uniformValuesAutoUpdate||!l&&!h||(t.uniformValuesNeedsUpdate=!0),t}compileFullscreen(e){const a=t({color:e.outputColor,wgslBindings:{...F,uniformExpressions:{},graphTextures:{...F.graphTextures,[W]:{resource:"hologyNormalRoughness",dimension:"2d",sampleType:"float",sampler:"filtering"}}}}),i=a.syncLiveUniforms;return{...a,syncLiveUniforms(a){i(a),_(e,a)}}}getOrCreateMappedNodeMaterial(e){const t=function(e){const t=[e.vertexColors,e.transparent,e.alphaTest,e.side,e.depthTest,e.depthWrite,e.wireframe??!1];if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshPhysicalMaterial){if(t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.roughnessMap?e.roughnessMap.uuid:null,e.metalnessMap?e.metalnessMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null),e instanceof a.MeshPhysicalMaterial){t.push(e.clearcoat>0,e.iridescence>0,e.transmission>0,e.sheen>0,e.anisotropy>0,1.5!==e.ior,1!==e.specularIntensity,1!==e.specularColor.r||1!==e.specularColor.g||1!==e.specularColor.b);for(const a of X)t.push(e[a]?.uuid??null)}}else e instanceof a.MeshLambertMaterial?t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null):e instanceof a.MeshToonMaterial?t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.gradientMap?e.gradientMap.uuid:null):e instanceof a.MeshBasicMaterial?t.push(e.map?e.map.uuid:null,e.aoMap?e.aoMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null):e instanceof a.MeshPhongMaterial?t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null):e instanceof a.SpriteMaterial&&t.push(e.map?e.map.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.sizeAttenuation);return t.join(",")}(e),i=this.mappedMaterialsCache.get(e),n=this.mappedMaterialsSignatures.get(e);if(null!=i&&n===t)return i;if(null!=i){i.dispose();const e=this.cache.get(i);if(null!=e){for(const a of e.values())a.material.dispose(),this.cacheValues.delete(a);this.cache.delete(i)}}const s=function(e){if(e instanceof a.SpriteMaterial){const a=new C;a.color=e.color,a.opacity=e.opacity,a.rotation=e.rotation,a.screenSpaceSize=e.sizeAttenuation?0:1,a.alphaTest=e.alphaTest,e.map&&(a.map=e.map),e.alphaMap&&(a.alphaMap=e.alphaMap);const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t}if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshPhysicalMaterial){const t=new w;if(t.color=e.color,t.opacity=e.opacity,t.roughness=e.roughness,t.metalness=e.metalness,t.vertexColor=e.vertexColors,e.map&&(t.map=l(e.map)),e.normalMap&&(t.normalMap=l(e.normalMap),t.normalScale=e.normalScale),e.roughnessMap&&(t.roughnessMap=l(e.roughnessMap)),e.metalnessMap&&(t.metalnessMap=l(e.metalnessMap)),e.aoMap&&(t.aoMap=l(e.aoMap),t.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(t.emissiveMap=l(e.emissiveMap)),e.lightMap&&(t.lightMap=l(e.lightMap),t.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(t.alphaMap=l(e.alphaMap)),t.emissive=e.emissive,t.emissiveIntensity=e.emissiveIntensity,t.envMap=e.envMap,t.envMapIntensity=e.envMapIntensity,t.alphaTest=e.alphaTest,e instanceof a.MeshPhysicalMaterial){for(const a of J)t[a]=e[a];for(const a of Q)t[a]=e[a];for(const a of X)e[a]&&(t[a]=l(e[a]));t.clearcoatNormalScale=e.clearcoatNormalScale,t.iridescenceThicknessRange=new a.Vector2(...e.iridescenceThicknessRange),t.anisotropyRotation=e.anisotropyRotation}const i=t.build();return i.transparent=e.transparent,i.side=e.side,i.depthTest=e.depthTest,i.depthWrite=e.depthWrite,i.wireframe=e.wireframe,i}if(e instanceof a.MeshLambertMaterial){const a=new x;a.color=e.color,a.opacity=e.opacity,a.vertexColor=e.vertexColors,e.map&&(a.map=l(e.map)),e.normalMap&&(a.normalMap=l(e.normalMap),a.normalScale=e.normalScale),e.aoMap&&(a.aoMap=l(e.aoMap),a.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(a.emissiveMap=l(e.emissiveMap)),e.lightMap&&(a.lightMap=l(e.lightMap),a.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(a.alphaMap=l(e.alphaMap)),a.emissive=e.emissive,a.emissiveIntensity=e.emissiveIntensity,a.envMap=e.envMap,a.alphaTest=e.alphaTest;const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.wireframe=e.wireframe,t}if(e instanceof a.MeshToonMaterial){const a=new T;a.color=e.color,a.opacity=e.opacity,a.vertexColor=e.vertexColors,e.map&&(a.map=l(e.map)),e.normalMap&&(a.normalMap=l(e.normalMap),a.normalScale=e.normalScale),e.aoMap&&(a.aoMap=l(e.aoMap),a.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(a.emissiveMap=l(e.emissiveMap)),e.lightMap&&(a.lightMap=l(e.lightMap),a.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(a.alphaMap=l(e.alphaMap)),a.emissive=e.emissive,a.emissiveIntensity=e.emissiveIntensity,a.alphaTest=e.alphaTest;const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.wireframe=e.wireframe,t}if(e instanceof a.MeshBasicMaterial||e instanceof a.LineBasicMaterial){const t=new E;t.color=e.color,t.opacity=e.opacity,t.vertexColor=e.vertexColors,e instanceof a.MeshBasicMaterial&&(e.map&&(t.map=l(e.map)),e.aoMap&&(t.aoMap=l(e.aoMap),t.aoMapIntensity=e.aoMapIntensity),e.lightMap&&(t.lightMap=l(e.lightMap),t.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(t.alphaMap=l(e.alphaMap)),t.envMap=e.envMap),t.alphaTest=e.alphaTest;const i=t.build();return i.transparent=e.transparent,i.side=e.side,i.depthTest=e.depthTest,i.depthWrite=e.depthWrite,i.wireframe=e instanceof a.MeshBasicMaterial&&e.wireframe,i}if(e instanceof a.MeshPhongMaterial){const a=new w;a.color=e.color,a.opacity=e.opacity,a.roughness=Math.max(0,1-e.shininess/100),a.metalness=0,a.vertexColor=e.vertexColors,e.map&&(a.map=l(e.map)),e.normalMap&&(a.normalMap=l(e.normalMap),a.normalScale=e.normalScale),e.aoMap&&(a.aoMap=l(e.aoMap),a.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(a.emissiveMap=l(e.emissiveMap)),e.lightMap&&(a.lightMap=l(e.lightMap),a.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(a.alphaMap=l(e.alphaMap)),a.emissive=e.emissive,a.emissiveIntensity=e.emissiveIntensity,a.envMap=e.envMap,a.alphaTest=e.alphaTest;const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.wireframe=e.wireframe,t}return null}(e);return null==s?null:(s.wireframe=e.wireframe??!1,this.mappedMaterialsCache.set(e,s),this.mappedMaterialsSignatures.set(e,t),e.addEventListener("dispose",()=>{const a=this.mappedMaterialsCache.get(e);if(null!=a){a.dispose(),this.mappedMaterialsCache.delete(e),this.mappedMaterialsSignatures.delete(e);const t=this.cache.get(a);if(null!=t){for(const e of t.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(a)}}}),s)}canResolve(e){return null!=this.resolve(e)}dispose(){for(const[e,a]of this.observedNodeMaterials)e.removeEventListener("dispose",a);this.observedNodeMaterials.clear();for(const e of this.cacheValues)e.material.dispose();this.cacheValues.clear()}syncInheritedWorldEnvironmentSource(e,a){a.inheritsWorldEnvironment&&null!=this.worldEnvironment&&(e.uniforms.envMap.value=this.worldEnvironment.texture,e.uniforms.envMapIntensity.value=this.worldEnvironment.intensity)}getNodeMaterialSignature(e,a){const t=`${createNodeMaterialSignature(e)}|receiveDecals:${!1!==e.userData.receiveDecals}|receiveGI:${!1!==e.userData.receiveGI}`;return a?`${t}|worldEnvironment:${this.worldEnvironmentRevision}`:t}prepareWorldEnvironment(e){var t,i,n,s,o,r;if(null!=e.envMap){const s=this.environmentTextureResolver?.(e.envMap)??e.envMap;return(t=e.uniforms).envMap??(t.envMap={value:s}),e.uniforms.envMap.value=s,(i=e.uniforms).envMapIntensity??(i.envMapIntensity={value:1}),(n=e.uniforms).envMapRotation??(n.envMapRotation={value:new a.Matrix3}),this.worldEnvironmentMaterials.delete(e),!1}return null==this.worldEnvironment?(this.worldEnvironmentMaterials.has(e)&&(delete e.uniforms.envMap,delete e.uniforms.envMapIntensity,delete e.uniforms.envMapRotation,this.worldEnvironmentMaterials.delete(e)),!1):((s=e.uniforms).envMap??(s.envMap={value:this.worldEnvironment.texture}),e.uniforms.envMap.value=this.worldEnvironment.texture,(o=e.uniforms).envMapIntensity??(o.envMapIntensity={value:this.worldEnvironment.intensity}),e.uniforms.envMapIntensity.value=this.worldEnvironment.intensity,(r=e.uniforms).envMapRotation??(r.envMapRotation={value:new a.Matrix3}),this.worldEnvironmentMaterials.add(e),!0)}observeNodeMaterial(e){if(this.observedNodeMaterials.has(e))return;const a=()=>{e.removeEventListener("dispose",a),this.observedNodeMaterials.delete(e);const t=this.cache.get(e);if(null!=t){for(const e of t.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(e)}const i=this.outlineMaterials.get(e);if(null!=i){const a=this.cache.get(i);if(null!=a){for(const e of a.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(i)}this.failedSignatures.delete(i),$.delete(i),i.dispose(),this.outlineMaterials.delete(e),this.outlineUniformVersions.delete(e)}this.failedSignatures.delete(e),$.delete(e)};this.observedNodeMaterials.set(e,a),e.addEventListener("dispose",a)}}function z(e,a,t=!1){const i=a.material;i.uniformValuesAutoUpdate=e.uniformValuesAutoUpdate,(t||e.uniformValuesAutoUpdate||a.sourceUniformValuesAutoVersion!==e.uniformValuesAutoVersion)&&(a.compiled.syncLiveUniforms(i.uniforms),_(e,i.uniforms),K(e,i),a.sourceUniformValuesAutoVersion=e.uniformValuesAutoVersion,i.uniformValuesAutoUpdate||(i.uniformValuesNeedsUpdate=!0))}function _(e,a){let t=B.get(a);if(null==t){t=[];for(const e in a){const i=a[e],n=i.value,s=!0===n?.isVector2?2:!0===n?.isVector3?3:!0===n?.isVector4?4:!0===n?.isColor?5:0;t.push({name:e,target:i,copyKind:s})}B.set(a,t)}const i=e.uniforms;for(let e=0;e<t.length;e++){const a=t[e],n=i[a.name];if(null==n)continue;const s=n.value,o=a.target.value;if(s!==o){if(0!==a.copyKind){const e=s,t=o;if((2===a.copyKind?!0===e?.isVector2:3===a.copyKind?!0===e?.isVector3:4===a.copyKind?!0===e?.isVector4:!0===e?.isColor)&&"function"==typeof t?.copy){t.copy(s);continue}}a.target.value=s}}}function K(e,t){const i=e.uniforms.envMapIntensity,n=t.uniforms.envMapIntensity;null!=i&&null!=n&&(n.value=i.value);const s=e.uniforms.envMapRotation?.value,o=t.uniforms.envMapRotation?.value;s instanceof a.Matrix3&&o instanceof a.Matrix3&&o.copy(s)}function q(e,a){for(const t in a.textures){const i=a.textures[t],n=e.uniforms[t]?.value;if(H(n)&&n!==i)return!1}return!0}function H(e){return!0===e?.isTexture}const J=["ior","specularIntensity","clearcoat","clearcoatRoughness","iridescence","iridescenceIOR","transmission","thickness","attenuationDistance","dispersion","sheen","sheenRoughness","anisotropy"],Q=["specularColor","attenuationColor","sheenColor"],X=["specularIntensityMap","specularColorMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","iridescenceMap","iridescenceThicknessMap","transmissionMap","thicknessMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function Y(e,t){if(e instanceof a.SpriteMaterial){const i=t;t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),i.rotation=e.rotation,i.screenSpaceSize=e.sizeAttenuation?0:1}else if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshPhysicalMaterial){if(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),t.uniforms.roughness&&(t.uniforms.roughness.value=e.roughness),t.uniforms.metalness&&(t.uniforms.metalness.value=e.metalness),t.uniforms.emissive&&(t.uniforms.emissive.value instanceof a.Vector3?t.uniforms.emissive.value.setFromColor(e.emissive):t.uniforms.emissive.value instanceof a.Color&&t.uniforms.emissive.value.copy(e.emissive)),t.uniforms.emissiveIntensity&&(t.uniforms.emissiveIntensity.value=e.emissiveIntensity),t.uniforms.normalScale&&e.normalScale&&(t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity),t.uniforms.envMapIntensity&&(t.uniforms.envMapIntensity.value=e.envMapIntensity),e instanceof a.MeshPhysicalMaterial){for(const a of J)t.uniforms[a]&&(t.uniforms[a].value=e[a]);for(const i of Q){const n=t.uniforms[i]?.value;n instanceof a.Vector3&&n.setFromColor(e[i])}const i=t.uniforms.clearcoatNormalScale?.value;i instanceof a.Vector2&&i.copy(e.clearcoatNormalScale),t.uniforms.iridescenceThicknessMin&&(t.uniforms.iridescenceThicknessMin.value=e.iridescenceThicknessRange[0]),t.uniforms.iridescenceThicknessMax&&(t.uniforms.iridescenceThicknessMax.value=e.iridescenceThicknessRange[1]);const n=t.uniforms.anisotropyDirection?.value;n instanceof a.Vector2&&n.set(Math.cos(e.anisotropyRotation),Math.sin(e.anisotropyRotation))}}else e instanceof a.MeshLambertMaterial||e instanceof a.MeshToonMaterial?(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),t.uniforms.emissive&&(t.uniforms.emissive.value instanceof a.Vector3?t.uniforms.emissive.value.setFromColor(e.emissive):t.uniforms.emissive.value instanceof a.Color&&t.uniforms.emissive.value.copy(e.emissive)),t.uniforms.emissiveIntensity&&(t.uniforms.emissiveIntensity.value=e.emissiveIntensity),t.uniforms.normalScale&&e.normalScale&&(t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity)):e instanceof a.MeshBasicMaterial||e instanceof a.LineBasicMaterial?(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),e instanceof a.MeshBasicMaterial&&(t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity))):e instanceof a.MeshPhongMaterial&&(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),t.uniforms.roughness&&(t.uniforms.roughness.value=Math.max(0,1-e.shininess/100)),t.uniforms.emissive&&(t.uniforms.emissive.value instanceof a.Vector3?t.uniforms.emissive.value.setFromColor(e.emissive):t.uniforms.emissive.value instanceof a.Color&&t.uniforms.emissive.value.copy(e.emissive)),t.uniforms.emissiveIntensity&&(t.uniforms.emissiveIntensity.value=e.emissiveIntensity),t.uniforms.normalScale&&e.normalScale&&(t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity))}/*
|
|
1
|
+
import{skyPosition as e}from"../scene/sky.js";import*as a from"three";import{compileNodeWebGpuFullscreen as t,compileNodeShaderMaterialForWebGpu as i,NodeShaderMaterial as n,deriveNodeShaderMaterial as s,webGpuRendererBindings as o,webGpuTiledRendererBindings as r,textureSampler2d as l,float as u,length as p,max as m,rgba as c,isWgslCompiler as f,isWgslFragmentCompiler as d,sqrt as h,normalize as M,transformed as v,uniformFloat as y,uniforms as g,vec4 as S,Vec3Node as V,toonMaterial as I}from"three-shader-graph";import{StandardShader as T}from"../shader/builtin/standard-shader.js";import{LambertShader as w}from"../shader/builtin/lambert-shader.js";import{ToonShader as x}from"../shader/builtin/toon-shader.js";import{UnlitShader as A}from"../shader/builtin/unlit-shader.js";import{SpriteShader as E}from"../shader/sprite-shader.js";import{elapsedTimeUniformName as C}from"../shader-nodes/time.js";import{depthUniformName as b,farUniformName as P,nearUniformName as W,resolutionUniformName as _,sceneNormalUniformName as N}from"../shader-nodes/depth.js";import{sceneMapUniformName as D,transmissionMapUniformName as U}from"../shader-nodes/scene-sample.js";import{deriveSDFGISurfaceGraph as k}from"./sdfgi-surface-material.js";const R={...o,uniformExpressions:{...o.uniformExpressions,ambientLightColor:{type:"vec3",expression:"rendererAmbientLight()"},[C]:{type:"float",expression:"rendererElapsedTime()"},[W]:{type:"float",expression:"rendererCameraNear()"},[P]:{type:"float",expression:"rendererCameraFar()"},[_]:{type:"vec2",expression:"rendererViewportSize()"}},graphTextures:{[U]:{resource:"physicalTransmissionSnapshot",dimension:"2d",sampleType:"float",sampler:"filtering",requiresLatePass:!0}},sceneTextures:{[D]:{semantic:"sceneColor",sampleType:"float"},[b]:{semantic:"sceneDepth",sampleType:"depth"}},attributes:{material:{shaderLocation:6,format:"float32x4",defaultValue:[0,0,0,0]},material2:{shaderLocation:7,format:"float32x4",defaultValue:[0,0,0,0]},hole:{shaderLocation:8,format:"float32",defaultValue:[0]},offset:{shaderLocation:9,format:"float32x3",stepMode:"instance",defaultValue:[0,0,0]},velocity:{shaderLocation:10,format:"float32x4",stepMode:"instance",defaultValue:[0,0,0,0]},size:{shaderLocation:11,format:"float32x3",stepMode:"instance",defaultValue:[0,0,0]},rotation:{shaderLocation:12,format:"float32",stepMode:"instance",defaultValue:[0]},particleData:{shaderLocation:13,format:"float32x3",stepMode:"instance",defaultValue:[1,1,0]},particleColor:{shaderLocation:14,format:"float32x4",stepMode:"instance",defaultValue:[1,1,1,1]}}};class O extends V{constructor(e){super(),this.fallback=e}compile(e){if(!f(e))return{out:e.get(this.fallback)};if(d(e))throw new Error("OutlineLocalPositionNode can only be used in the vertex stage");const a=`outline_local_position_${e.variable()}`;return{chunk:`\n#ifdef USE_SKINNING\n let ${a} = rendererSkinPosition(input.position, input.skinIndex, input.skinWeight).xyz;\n#else\n let ${a} = input.position;\n#endif`,out:a}}}class L extends V{constructor(e){super(),this.fallback=e}compile(e){if(!f(e))return{out:e.get(this.fallback)};if(d(e))throw new Error("OutlineLocalNormalNode can only be used in the vertex stage");const a=`outline_local_normal_${e.variable()}`;return{chunk:`\n#ifdef USE_SKINNING\n let ${a} = rendererSkinNormal(input.normal, input.skinIndex, input.skinWeight);\n#else\n let ${a} = input.normal;\n#endif`,out:a}}}export function setMaterialUniformValuesAutoUpdate(e,a){e.uniformValuesAutoUpdate=a}export function markMaterialUniformValuesNeedUpdate(e){const a=e;"uniformValuesNeedsUpdate"in a?a.uniformValuesNeedsUpdate=!0:a.uniformValuesAutoVersion=(a.uniformValuesAutoVersion??0)+1}function F(e){return!1!==e.uniformValuesAutoUpdate}function G(e){return e.uniformValuesAutoVersion??0}export function withThreeDefaultVertexAttributeValues(e){return e.map(e=>"uv1"===e.name&&null==e.defaultValue?{...e,defaultValue:[0,0]}:e)}const B=new WeakMap,$=new WeakMap;export function createNodeMaterialSignature(e){const a=$.get(e);if(null!=a)return a;const t=JSON.stringify({version:e.version,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader,alphaTest:e.alphaTest,alphaToCoverage:e.alphaToCoverage,blending:e.blending,colorWrite:e.colorWrite,depthFunc:e.depthFunc,depthTest:e.depthTest,depthWrite:e.depthWrite,polygonOffset:e.polygonOffset,polygonOffsetFactor:e.polygonOffsetFactor,polygonOffsetUnits:e.polygonOffsetUnits,premultipliedAlpha:e.premultipliedAlpha,side:e.side,stencilWrite:e.stencilWrite,transparent:e.transparent,wireframe:e.wireframe,shadowFilter:e.nodeMaterialDefinition?.shadowFilter??"renderer"});return $.set(e,t),t}export class NodeMaterialWebGpuResolver{constructor(e,a,t){this.webGpu=e,this.mrtResolver=a,this.environmentTextureResolver=t,this.cache=new WeakMap,this.failedSignatures=new WeakMap,this.mappedMaterialsCache=new WeakMap,this.sourcesByResolved=new WeakMap,this.mappedMaterialsSignatures=new WeakMap,this.observedNodeMaterials=new Map,this.outlineMaterials=new WeakMap,this.outlineUniformVersions=new WeakMap,this.worldEnvironmentMaterials=new WeakSet,this.worldEnvironment=null,this.worldEnvironmentTexture=null,this.worldEnvironmentIntensity=0,this.worldEnvironmentRevision=0,this.cacheValues=new Set}setWorldEnvironment(e){const a=e?.texture??null,t=e?.intensity??0;if(this.worldEnvironmentTexture!==a||this.worldEnvironmentIntensity!==t){if(this.worldEnvironmentTexture!==a)this.worldEnvironmentRevision++;else if(null!=e)for(const e of this.cacheValues)e.inheritsWorldEnvironment&&null!=e.material.uniforms.envMapIntensity&&(e.material.uniforms.envMapIntensity.value=t,e.material.uniformValuesNeedsUpdate=!0);this.worldEnvironment=e,this.worldEnvironmentTexture=a,this.worldEnvironmentIntensity=t}}resolve(a,t=void 0){let o,l=!1;if(a instanceof n)o=a,this.observeNodeMaterial(o);else{const e=this.getOrCreateMappedNodeMaterial(a);if(null==e)return;o=e,l=!0}if("outline"===t){if(null==o.outputAlbedo)return;l&&Q(a,o),o.userData.outlineParameters=a.userData?.outlineParameters,o=this.getOrCreateOutlineMaterial(o),l=!1}o.visible=a.visible,l&&(o.userData.receiveDecals=a.userData.receiveDecals,o.userData.receiveGI=a.userData.receiveGI,o.userData.indirectLighting=a.userData.indirectLighting);const u=t??"default",p=this.cache.get(o),m=p?.get(u);if(l&&null!=m&&m.sourceVersion===a.version&&m.worldEnvironmentRevision===this.worldEnvironmentRevision){const e=F(a),t=G(a);return m.material.uniformValuesAutoUpdate=e,this.syncInheritedWorldEnvironmentSource(o,m),e||m.sourceUniformValuesAutoVersion!==t?(Q(a,o),m.compiled.syncLiveUniforms(m.material.uniforms),H(o,m.material.uniforms),Y(o,m.material),m.sourceUniformValuesAutoVersion=t,e||(m.material.uniformValuesNeedsUpdate=!0),m.material):m.material}if(!l&&null!=m&&m.sourceVersion===a.version&&m.worldEnvironmentRevision===this.worldEnvironmentRevision&&z(o,m.compiled))return this.syncInheritedWorldEnvironmentSource(o,m),j(o,m),m.material;l&&Q(a,o);const c=this.prepareWorldEnvironment(o),f=this.getNodeMaterialSignature(o,c);if(m?.signature===f&&z(o,m.compiled))return l?(m.material.uniformValuesAutoUpdate=F(a),m.compiled.syncLiveUniforms(m.material.uniforms),H(o,m.material.uniforms),Y(o,m.material),m.sourceUniformValuesAutoVersion=G(a),m.material.uniformValuesAutoUpdate||(m.material.uniformValuesNeedsUpdate=!0)):j(o,m,!0),m.sourceVersion=a.version,m.worldEnvironmentRevision=this.worldEnvironmentRevision,m.material;try{const n="sdfgi"===t?k(o):null;if("sdfgi"===t&&null==n)return;const d=null==n?this.mrtResolver?.(o,t):void 0,h=n??(!0===a.userData.isSky?s(o,{position:e,fog:o.fog}):o);let M;try{M=i(h,"opaque"===t?{...R,arrays:r.arrays,indirectLighting:a.userData.indirectLighting}:{...R,indirectLighting:a.userData.indirectLighting},d)}finally{n?.dispose()}const v=new this.webGpu.WGSLShaderMaterial({vertexShader:M.vertexShader,fragmentShader:M.fragmentShader,defines:{TSG_SHADOWMAP_TYPE_BASIC:!!o.defines.TSG_SHADOWMAP_TYPE_BASIC,TSG_SHADOWMAP_TYPE_PCF_2X2:!!o.defines.TSG_SHADOWMAP_TYPE_PCF_2X2,TSG_SHADOWMAP_TYPE_PCF_5TAP:!!o.defines.TSG_SHADOWMAP_TYPE_PCF_5TAP,TSG_SHADOWMAP_TYPE_PCF_POISSON_5TAP:!!o.defines.TSG_SHADOWMAP_TYPE_PCF_POISSON_5TAP},depthVertexShader:M.depthVertexShader,depthFragmentShader:M.depthFragmentShader,pointShadowVertexShader:M.pointShadowVertexShader,pointShadowFragmentShader:M.pointShadowFragmentShader,uniforms:M.uniforms,textures:M.textures,sceneTextures:M.sceneTextures,graphTextures:M.graphTextures,vertexAttributes:withThreeDefaultVertexAttributeValues(M.vertexAttributes),uniformValuesAutoUpdate:l?F(a):o.uniformValuesAutoUpdate,transparent:M.renderState?.transparent,alphaTest:M.renderState?.alphaTest,depthTest:M.renderState?.depthTest,depthWrite:M.renderState?.depthWrite,side:M.renderState?.side,wireframe:o.wireframe});this.sourcesByResolved.set(v,a),v.userData.receiveGI=!1!==a.userData.receiveGI,v.name=a.name||o.name||a.uuid,v.userData.pipelineOrigin={assetId:a.userData.assetId??o.userData.assetId,assetName:a.userData.assetName??o.userData.assetName,sourceUuid:a.uuid,sourceName:a.name,sourceType:a.type,sourceVersion:a.version},v.uniformValuesAutoUpdate=l?F(a):o.uniformValuesAutoUpdate,function(e,a){if(null==e)return;Object.assign(a,e)}(M.renderState,v),null!=m&&(m.material.dispose(),this.cacheValues.delete(m));const y={signature:f,compiled:M,material:v,inheritsWorldEnvironment:c,sourceVersion:a.version,sourceUniformValuesAutoVersion:l?G(a):o.uniformValuesAutoVersion,worldEnvironmentRevision:this.worldEnvironmentRevision},g=p??new Map;return g.set(u,y),this.cache.set(o,g),this.cacheValues.add(y),H(o,v.uniforms),Y(o,v),v}catch(e){let a=this.failedSignatures.get(o);if(null==a&&(a=new Map,this.failedSignatures.set(o,a)),a.get(u)!==f){a.set(u,f);const t=e instanceof Error?e.message:String(e),i=o.name||o.uuid;console.warn(`[Hology WebGPU experiment] Falling back for NodeShaderMaterial "${i}": ${t}`,{material:o,error:e})}return}}resolveSDFGISurface(e){const a=this.sourcesByResolved.get(e);return null==a||!0===a.userData.isSky||!1===a.userData.sdfgi?void 0:this.resolve(a,"sdfgi")}getOrCreateOutlineMaterial(e){let t=this.outlineMaterials.get(e);if(null==t){const i=e.nodeMaterialDefinition,s=e.outputAlbedo;if(null==s)throw new Error("Cannot derive an outline material without an albedo output");const o=y("outlineThickness",.003),r=y("outlineDarkening",.65),l=y("outlineAlpha",1),f=new O(v.position.xyz),d=new L(v.normal),V=i.transform?.multiplyVec(S(f,1))??S(f,1),T=g.modelViewMatrix.multiplyVec(V),w=M(g.normalMatrix.multiplyVec(d)),x=h(m(p(T.xyz),u(1e-4))).multiply(.5),A=T.xyz.add(w.multiplyScalar(o.multiply(x))),E=g.projectionMatrix.multiplyVec(T),C=g.projectionMatrix.multiplyVec(S(A,1)),b=(i.position??E).add(C.subtract(E)),P=c(I({color:s.rgb.multiplyScalar(u(1).subtract(r))}),e.outputOpacity.multiply(l));t=new n({color:P,position:b,opacity:e.outputOpacity,discard:i.discard,alphaTest:e.alphaTest,transparent:!0,fog:!1,outputEncoding:i.outputEncoding,uniforms:i.uniforms,uniformNodes:i.uniformNodes}),t.side=a.BackSide,t.depthTest=!0,t.depthWrite=!0,this.outlineMaterials.set(e,t),this.outlineUniformVersions.delete(e)}const i=e.userData?.outlineParameters,s=i?.thickness??.003,o=a.MathUtils.clamp(i?.darkening??.65,0,1),r=a.MathUtils.clamp(i?.alpha??e.opacity,0,1),l=t.uniforms.outlineThickness.value!==s||t.uniforms.outlineDarkening.value!==o||t.uniforms.outlineAlpha.value!==r;t.uniforms.outlineThickness.value=s,t.uniforms.outlineDarkening.value=o,t.uniforms.outlineAlpha.value=r,t.userData.outlineSource=e,t.uniformValuesAutoUpdate=e.uniformValuesAutoUpdate;let f=this.outlineUniformVersions.get(e);const d=e.uniformValuesAutoUpdate||null==f||f.version!==e.uniformValuesAutoVersion||f.uniforms!==e.uniforms;if(d){for(const a in e.uniforms)null!=t.uniforms[a]&&(t.uniforms[a].value=e.uniforms[a].value);f?(f.version=e.uniformValuesAutoVersion,f.uniforms=e.uniforms):(f={version:e.uniformValuesAutoVersion,uniforms:e.uniforms},this.outlineUniformVersions.set(e,f))}return e.uniformValuesAutoUpdate||!l&&!d||(t.uniformValuesNeedsUpdate=!0),t}compileFullscreen(e){const a=t({color:e.outputColor,wgslBindings:{...R,uniformExpressions:{},graphTextures:{...R.graphTextures,[N]:{resource:"hologyNormalRoughness",dimension:"2d",sampleType:"float",sampler:"filtering"}}}}),i=a.syncLiveUniforms;return{...a,syncLiveUniforms(a){i(a),H(e,a)}}}getOrCreateMappedNodeMaterial(e){const t=function(e){const t=[e.vertexColors,e.transparent,e.alphaTest,e.side,e.depthTest,e.depthWrite,e.wireframe??!1];if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshPhysicalMaterial){if(t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.roughnessMap?e.roughnessMap.uuid:null,e.metalnessMap?e.metalnessMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null),e instanceof a.MeshPhysicalMaterial){t.push(e.clearcoat>0,e.iridescence>0,e.transmission>0,e.sheen>0,e.anisotropy>0,1.5!==e.ior,1!==e.specularIntensity,1!==e.specularColor.r||1!==e.specularColor.g||1!==e.specularColor.b);for(const a of J)t.push(e[a]?.uuid??null)}}else e instanceof a.MeshLambertMaterial?t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null):e instanceof a.MeshToonMaterial?t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.gradientMap?e.gradientMap.uuid:null):e instanceof a.MeshBasicMaterial?t.push(e.map?e.map.uuid:null,e.aoMap?e.aoMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null):e instanceof a.MeshPhongMaterial?t.push(e.map?e.map.uuid:null,e.normalMap?e.normalMap.uuid:null,e.aoMap?e.aoMap.uuid:null,e.emissiveMap?e.emissiveMap.uuid:null,e.lightMap?e.lightMap.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.envMap?e.envMap.uuid:null):e instanceof a.SpriteMaterial&&t.push(e.map?e.map.uuid:null,e.alphaMap?e.alphaMap.uuid:null,e.sizeAttenuation);return t.join(",")}(e),i=this.mappedMaterialsCache.get(e),n=this.mappedMaterialsSignatures.get(e);if(null!=i&&n===t)return i;if(null!=i){i.dispose();const e=this.cache.get(i);if(null!=e){for(const a of e.values())a.material.dispose(),this.cacheValues.delete(a);this.cache.delete(i)}}const s=function(e){if(e instanceof a.SpriteMaterial){const a=new E;a.color=e.color,a.opacity=e.opacity,a.rotation=e.rotation,a.screenSpaceSize=e.sizeAttenuation?0:1,a.alphaTest=e.alphaTest,e.map&&(a.map=e.map),e.alphaMap&&(a.alphaMap=e.alphaMap);const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t}if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshPhysicalMaterial){const t=new T;if(t.color=e.color,t.opacity=e.opacity,t.roughness=e.roughness,t.metalness=e.metalness,t.vertexColor=e.vertexColors,e.map&&(t.map=l(e.map)),e.normalMap&&(t.normalMap=l(e.normalMap),t.normalScale=e.normalScale),e.roughnessMap&&(t.roughnessMap=l(e.roughnessMap)),e.metalnessMap&&(t.metalnessMap=l(e.metalnessMap)),e.aoMap&&(t.aoMap=l(e.aoMap),t.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(t.emissiveMap=l(e.emissiveMap)),e.lightMap&&(t.lightMap=l(e.lightMap),t.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(t.alphaMap=l(e.alphaMap)),t.emissive=e.emissive,t.emissiveIntensity=e.emissiveIntensity,t.envMap=e.envMap,t.envMapIntensity=e.envMapIntensity,t.alphaTest=e.alphaTest,e instanceof a.MeshPhysicalMaterial){for(const a of X)t[a]=e[a];for(const a of q)t[a]=e[a];for(const a of J)e[a]&&(t[a]=l(e[a]));t.clearcoatNormalScale=e.clearcoatNormalScale,t.iridescenceThicknessRange=new a.Vector2(...e.iridescenceThicknessRange),t.anisotropyRotation=e.anisotropyRotation}const i=t.build();return i.transparent=e.transparent,i.side=e.side,i.depthTest=e.depthTest,i.depthWrite=e.depthWrite,i.wireframe=e.wireframe,i}if(e instanceof a.MeshLambertMaterial){const a=new w;a.color=e.color,a.opacity=e.opacity,a.vertexColor=e.vertexColors,e.map&&(a.map=l(e.map)),e.normalMap&&(a.normalMap=l(e.normalMap),a.normalScale=e.normalScale),e.aoMap&&(a.aoMap=l(e.aoMap),a.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(a.emissiveMap=l(e.emissiveMap)),e.lightMap&&(a.lightMap=l(e.lightMap),a.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(a.alphaMap=l(e.alphaMap)),a.emissive=e.emissive,a.emissiveIntensity=e.emissiveIntensity,a.envMap=e.envMap,a.alphaTest=e.alphaTest;const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.wireframe=e.wireframe,t}if(e instanceof a.MeshToonMaterial){const a=new x;a.color=e.color,a.opacity=e.opacity,a.vertexColor=e.vertexColors,e.map&&(a.map=l(e.map)),e.normalMap&&(a.normalMap=l(e.normalMap),a.normalScale=e.normalScale),e.aoMap&&(a.aoMap=l(e.aoMap),a.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(a.emissiveMap=l(e.emissiveMap)),e.lightMap&&(a.lightMap=l(e.lightMap),a.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(a.alphaMap=l(e.alphaMap)),a.emissive=e.emissive,a.emissiveIntensity=e.emissiveIntensity,a.alphaTest=e.alphaTest;const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.wireframe=e.wireframe,t}if(e instanceof a.MeshBasicMaterial||e instanceof a.LineBasicMaterial){const t=new A;t.color=e.color,t.opacity=e.opacity,t.vertexColor=e.vertexColors,e instanceof a.MeshBasicMaterial&&(e.map&&(t.map=l(e.map)),e.aoMap&&(t.aoMap=l(e.aoMap),t.aoMapIntensity=e.aoMapIntensity),e.lightMap&&(t.lightMap=l(e.lightMap),t.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(t.alphaMap=l(e.alphaMap)),t.envMap=e.envMap),t.alphaTest=e.alphaTest;const i=t.build();return i.transparent=e.transparent,i.side=e.side,i.depthTest=e.depthTest,i.depthWrite=e.depthWrite,i.wireframe=e instanceof a.MeshBasicMaterial&&e.wireframe,i}if(e instanceof a.MeshPhongMaterial){const a=new T;a.color=e.color,a.opacity=e.opacity,a.roughness=Math.max(0,1-e.shininess/100),a.metalness=0,a.vertexColor=e.vertexColors,e.map&&(a.map=l(e.map)),e.normalMap&&(a.normalMap=l(e.normalMap),a.normalScale=e.normalScale),e.aoMap&&(a.aoMap=l(e.aoMap),a.aoMapIntensity=e.aoMapIntensity),e.emissiveMap&&(a.emissiveMap=l(e.emissiveMap)),e.lightMap&&(a.lightMap=l(e.lightMap),a.lightMapIntensity=e.lightMapIntensity),e.alphaMap&&(a.alphaMap=l(e.alphaMap)),a.emissive=e.emissive,a.emissiveIntensity=e.emissiveIntensity,a.envMap=e.envMap,a.alphaTest=e.alphaTest;const t=a.build();return t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.wireframe=e.wireframe,t}return null}(e);return null==s?null:(s.wireframe=e.wireframe??!1,this.mappedMaterialsCache.set(e,s),this.mappedMaterialsSignatures.set(e,t),e.addEventListener("dispose",()=>{const a=this.mappedMaterialsCache.get(e);if(null!=a){a.dispose(),this.mappedMaterialsCache.delete(e),this.mappedMaterialsSignatures.delete(e);const t=this.cache.get(a);if(null!=t){for(const e of t.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(a)}}}),s)}canResolve(e){return null!=this.resolve(e)}dispose(){for(const[e,a]of this.observedNodeMaterials)e.removeEventListener("dispose",a);this.observedNodeMaterials.clear();for(const e of this.cacheValues)e.material.dispose();this.cacheValues.clear()}syncInheritedWorldEnvironmentSource(e,a){a.inheritsWorldEnvironment&&null!=this.worldEnvironment&&(e.uniforms.envMap.value=this.worldEnvironment.texture,e.uniforms.envMapIntensity.value=this.worldEnvironment.intensity)}getNodeMaterialSignature(e,a){const t=Number(!!e.defines?.TSG_SHADOWMAP_TYPE_BASIC)|Number(!!e.defines?.TSG_SHADOWMAP_TYPE_PCF_2X2)<<1|Number(!!e.defines?.TSG_SHADOWMAP_TYPE_PCF_5TAP)<<2|Number(!!e.defines?.TSG_SHADOWMAP_TYPE_PCF_POISSON_5TAP)<<3,i=`${createNodeMaterialSignature(e)}|receiveDecals:${!1!==e.userData.receiveDecals}|receiveGI:${!1!==e.userData.receiveGI}|indirectLighting:${"vertex"===e.userData.indirectLighting?"vertex":"fragment"}|shadowFilter:${t}`;return a?`${i}|worldEnvironment:${this.worldEnvironmentRevision}`:i}prepareWorldEnvironment(e){var t,i,n,s,o,r;if(null!=e.envMap){const s=this.environmentTextureResolver?.(e.envMap)??e.envMap;return(t=e.uniforms).envMap??(t.envMap={value:s}),e.uniforms.envMap.value=s,(i=e.uniforms).envMapIntensity??(i.envMapIntensity={value:1}),(n=e.uniforms).envMapRotation??(n.envMapRotation={value:new a.Matrix3}),this.worldEnvironmentMaterials.delete(e),!1}return null==this.worldEnvironment?(this.worldEnvironmentMaterials.has(e)&&(delete e.uniforms.envMap,delete e.uniforms.envMapIntensity,delete e.uniforms.envMapRotation,this.worldEnvironmentMaterials.delete(e)),!1):((s=e.uniforms).envMap??(s.envMap={value:this.worldEnvironment.texture}),e.uniforms.envMap.value=this.worldEnvironment.texture,(o=e.uniforms).envMapIntensity??(o.envMapIntensity={value:this.worldEnvironment.intensity}),e.uniforms.envMapIntensity.value=this.worldEnvironment.intensity,(r=e.uniforms).envMapRotation??(r.envMapRotation={value:new a.Matrix3}),this.worldEnvironmentMaterials.add(e),!0)}observeNodeMaterial(e){if(this.observedNodeMaterials.has(e))return;const a=()=>{e.removeEventListener("dispose",a),this.observedNodeMaterials.delete(e);const t=this.cache.get(e);if(null!=t){for(const e of t.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(e)}const i=this.outlineMaterials.get(e);if(null!=i){const a=this.cache.get(i);if(null!=a){for(const e of a.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(i)}this.failedSignatures.delete(i),$.delete(i),i.dispose(),this.outlineMaterials.delete(e),this.outlineUniformVersions.delete(e)}this.failedSignatures.delete(e),$.delete(e)};this.observedNodeMaterials.set(e,a),e.addEventListener("dispose",a)}}function j(e,a,t=!1){const i=a.material;i.uniformValuesAutoUpdate=e.uniformValuesAutoUpdate,(t||e.uniformValuesAutoUpdate||a.sourceUniformValuesAutoVersion!==e.uniformValuesAutoVersion)&&(a.compiled.syncLiveUniforms(i.uniforms),H(e,i.uniforms),Y(e,i),a.sourceUniformValuesAutoVersion=e.uniformValuesAutoVersion,i.uniformValuesAutoUpdate||(i.uniformValuesNeedsUpdate=!0))}function H(e,a){let t=B.get(a);if(null==t){t=[];for(const e in a){const i=a[e],n=i.value,s=!0===n?.isVector2?2:!0===n?.isVector3?3:!0===n?.isVector4?4:!0===n?.isColor?5:0;t.push({name:e,target:i,copyKind:s})}B.set(a,t)}const i=e.uniforms;for(let e=0;e<t.length;e++){const a=t[e],n=i[a.name];if(null==n)continue;const s=n.value,o=a.target.value;if(s!==o){if(0!==a.copyKind){const e=s,t=o;if((2===a.copyKind?!0===e?.isVector2:3===a.copyKind?!0===e?.isVector3:4===a.copyKind?!0===e?.isVector4:!0===e?.isColor)&&"function"==typeof t?.copy){t.copy(s);continue}}a.target.value=s}}}function Y(e,t){const i=e.uniforms.envMapIntensity,n=t.uniforms.envMapIntensity;null!=i&&null!=n&&(n.value=i.value);const s=e.uniforms.envMapRotation?.value,o=t.uniforms.envMapRotation?.value;s instanceof a.Matrix3&&o instanceof a.Matrix3&&o.copy(s)}function z(e,a){for(const t in a.textures){const i=a.textures[t],n=e.uniforms[t]?.value;if(K(n)&&n!==i)return!1}return!0}function K(e){return!0===e?.isTexture}const X=["ior","specularIntensity","clearcoat","clearcoatRoughness","iridescence","iridescenceIOR","transmission","thickness","attenuationDistance","dispersion","sheen","sheenRoughness","anisotropy"],q=["specularColor","attenuationColor","sheenColor"],J=["specularIntensityMap","specularColorMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","iridescenceMap","iridescenceThicknessMap","transmissionMap","thicknessMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function Q(e,t){if(e instanceof a.SpriteMaterial){const i=t;t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),i.rotation=e.rotation,i.screenSpaceSize=e.sizeAttenuation?0:1}else if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshPhysicalMaterial){if(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),t.uniforms.roughness&&(t.uniforms.roughness.value=e.roughness),t.uniforms.metalness&&(t.uniforms.metalness.value=e.metalness),t.uniforms.emissive&&(t.uniforms.emissive.value instanceof a.Vector3?t.uniforms.emissive.value.setFromColor(e.emissive):t.uniforms.emissive.value instanceof a.Color&&t.uniforms.emissive.value.copy(e.emissive)),t.uniforms.emissiveIntensity&&(t.uniforms.emissiveIntensity.value=e.emissiveIntensity),t.uniforms.normalScale&&e.normalScale&&(t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity),t.uniforms.envMapIntensity&&(t.uniforms.envMapIntensity.value=e.envMapIntensity),e instanceof a.MeshPhysicalMaterial){for(const a of X)t.uniforms[a]&&(t.uniforms[a].value=e[a]);for(const i of q){const n=t.uniforms[i]?.value;n instanceof a.Vector3&&n.setFromColor(e[i])}const i=t.uniforms.clearcoatNormalScale?.value;i instanceof a.Vector2&&i.copy(e.clearcoatNormalScale),t.uniforms.iridescenceThicknessMin&&(t.uniforms.iridescenceThicknessMin.value=e.iridescenceThicknessRange[0]),t.uniforms.iridescenceThicknessMax&&(t.uniforms.iridescenceThicknessMax.value=e.iridescenceThicknessRange[1]);const n=t.uniforms.anisotropyDirection?.value;n instanceof a.Vector2&&n.set(Math.cos(e.anisotropyRotation),Math.sin(e.anisotropyRotation))}}else e instanceof a.MeshLambertMaterial||e instanceof a.MeshToonMaterial?(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),t.uniforms.emissive&&(t.uniforms.emissive.value instanceof a.Vector3?t.uniforms.emissive.value.setFromColor(e.emissive):t.uniforms.emissive.value instanceof a.Color&&t.uniforms.emissive.value.copy(e.emissive)),t.uniforms.emissiveIntensity&&(t.uniforms.emissiveIntensity.value=e.emissiveIntensity),t.uniforms.normalScale&&e.normalScale&&(t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity)):e instanceof a.MeshBasicMaterial||e instanceof a.LineBasicMaterial?(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),e instanceof a.MeshBasicMaterial&&(t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity))):e instanceof a.MeshPhongMaterial&&(t.uniforms.color&&(t.uniforms.color.value instanceof a.Vector3?t.uniforms.color.value.setFromColor(e.color):t.uniforms.color.value instanceof a.Color&&t.uniforms.color.value.copy(e.color)),t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),t.uniforms.roughness&&(t.uniforms.roughness.value=Math.max(0,1-e.shininess/100)),t.uniforms.emissive&&(t.uniforms.emissive.value instanceof a.Vector3?t.uniforms.emissive.value.setFromColor(e.emissive):t.uniforms.emissive.value instanceof a.Color&&t.uniforms.emissive.value.copy(e.emissive)),t.uniforms.emissiveIntensity&&(t.uniforms.emissiveIntensity.value=e.emissiveIntensity),t.uniforms.normalScale&&e.normalScale&&(t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.aoMapIntensity&&(t.uniforms.aoMapIntensity.value=e.aoMapIntensity),t.uniforms.lightMapIntensity&&(t.uniforms.lightMapIntensity.value=e.lightMapIntensity))}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import type { PostProcessSettings } from '../gameplay/actors/builtin/post-process-volume-actor.js';
|
|
3
|
+
export declare function needsWhiteBalance(temperature: number, temperatureTint: number): boolean;
|
|
4
|
+
export declare function needsColorTint(color: THREE.Color, intensity: number): boolean;
|
|
5
|
+
export declare function needsColorGrading(settings: PostProcessSettings): boolean;
|
|
6
|
+
export declare function computeWhiteBalanceScale(target: THREE.Vector3, temperature: number, tint: number): THREE.Vector3;
|
|
7
|
+
export declare function approximatelyEqual(a: number, b: number, epsilon?: number): boolean;
|
|
8
|
+
export declare const postProcessEpsilon = 0.0001;
|
|
9
|
+
//# sourceMappingURL=post-process-color.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import*as t from"three";import{clamp as a}from"../utils/math.js";export function needsWhiteBalance(t,a){return!approximatelyEqual(t,6500)||!approximatelyEqual(a,0)}export function needsColorTint(t,a){return a>postProcessEpsilon&&(!approximatelyEqual(t.r,1)||!approximatelyEqual(t.g,1)||!approximatelyEqual(t.b,1))}export function needsColorGrading(t){return!(o(t.globalSaturation,1,1,1)&&o(t.globalContrast,1,1,1)&&o(t.globalGamma,1,1,1)&&o(t.globalGain,1,1,1)&&o(t.globalOffset,0,0,0)&&o(t.shadowsSaturation,1,1,1)&&o(t.shadowsContrast,1,1,1)&&o(t.shadowsGamma,1,1,1)&&o(t.shadowsGain,1,1,1)&&o(t.shadowsOffset,0,0,0)&&o(t.midtonesSaturation,1,1,1)&&o(t.midtonesContrast,1,1,1)&&o(t.midtonesGamma,1,1,1)&&o(t.midtonesGain,1,1,1)&&o(t.midtonesOffset,0,0,0)&&o(t.highlightsSaturation,1,1,1)&&o(t.highlightsContrast,1,1,1)&&o(t.highlightsGamma,1,1,1)&&o(t.highlightsGain,1,1,1)&&o(t.highlightsOffset,0,0,0))}function o(t,a,o,e){return null!=t&&approximatelyEqual(t.x,a)&&approximatelyEqual(t.y,o)&&approximatelyEqual(t.z,e)}export function computeWhiteBalanceScale(t,o,n){const s=function(t){const o=a(t,1e3,4e4)/100,n=o<=66?1:a(1.292936186062745*Math.pow(o-60,-.1332047592),0,1),s=a(o<=66?.3900815787690196*Math.log(o)-.6318414437886275:1.129890860895294*Math.pow(o-60,-.0755148492),0,1),r=o>=66?1:o<=19?0:a(.5432067891101962*Math.log(o-10)-1.19625408914,0,1);return e.set(n,s,r)}(o),r=1+.2*a(n,-1,1),i=s.x,l=s.y*r,p=s.z,h=Math.max(l,1e-4);return t.set(1/Math.max(i/h,1e-4),1/Math.max(l/h,1e-4),1/Math.max(p/h,1e-4)),t}export function approximatelyEqual(t,a,o=postProcessEpsilon){return Math.abs(t-a)<=o}export const postProcessEpsilon=1e-4;const e=new t.Vector3(1,1,1);/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type Stats from 'three/examples/jsm/libs/stats.module.js';
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import type { Camera, Object3D, Texture, WebGLRenderer } from 'three';
|
|
4
|
+
import { WebGLRenderTarget } from 'three';
|
|
5
|
+
import { ShaderPass } from "three-stdlib";
|
|
6
|
+
import { CSM } from 'three/examples/jsm/csm/CSM.js';
|
|
7
|
+
import type { FrameStats } from '../utils/three/frame-stats.js';
|
|
8
|
+
import type { WorldEnvironmentState } from './environment.js';
|
|
2
9
|
import type { RenderingBackendDriver } from './rendering-backend.js';
|
|
3
|
-
import {
|
|
10
|
+
import type { IRgbNode } from 'three-shader-graph';
|
|
11
|
+
import { RgbaNode } from 'three-shader-graph';
|
|
12
|
+
import { GTAOPass } from "three/examples/jsm/postprocessing/GTAOPass.js";
|
|
13
|
+
import { type PostProcessSettings } from "../gameplay/actors/builtin/post-process-volume-actor.js";
|
|
14
|
+
import type { RenderingView } from '../rendering.js';
|
|
15
|
+
import { OutlinePass } from '../utils/three/outline-pass.js';
|
|
16
|
+
import type { Cluster } from "./cluster-generator.js";
|
|
17
|
+
import { OutlineEffect } from "./outline-effect.js";
|
|
18
|
+
import { type PostProcessEffectEntry } from "./post-process-effect.js";
|
|
4
19
|
export interface WebGlBackendOptions {
|
|
5
20
|
readonly container: HTMLElement;
|
|
6
21
|
readonly pixelRatio: number;
|
|
@@ -10,23 +25,242 @@ export interface WebGlBackendOptions {
|
|
|
10
25
|
readonly autoUpdate: boolean;
|
|
11
26
|
};
|
|
12
27
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* RenderingView deliberately delegates through this adapter so resource-loading
|
|
16
|
-
* code never has to infer which concrete renderer happens to be active.
|
|
17
|
-
*/
|
|
28
|
+
type WebGlViewState = Pick<RenderingView, 'options' | 'camera' | 'scene' | 'container' | 'csm' | 'running' | 'paused' | 'lightVolume' | 'lightProbeIntensity' | 'simulationTime' | 'baseToneMapping' | 'baseToneMappingExposure' | 'currentRenderPixelRatio'>;
|
|
29
|
+
/** Owns the WebGL pipeline and all of its GPU resources. Shared scene state is read from the view. */
|
|
18
30
|
export declare class WebGlBackend implements RenderingBackendDriver {
|
|
19
31
|
readonly renderer: THREE.WebGLRenderer;
|
|
20
32
|
readonly outlineEffect: OutlineEffect;
|
|
33
|
+
private readonly view;
|
|
34
|
+
private readonly postProcessEffects;
|
|
21
35
|
readonly kind: "webgl";
|
|
22
36
|
readonly canvas: HTMLCanvasElement;
|
|
23
37
|
private pmremGenerator;
|
|
24
38
|
private readonly pmremResults;
|
|
25
39
|
private readonly ownedPmremResults;
|
|
26
40
|
private constructor();
|
|
27
|
-
static
|
|
41
|
+
static createCascadedShadows(camera: Camera, scene: THREE.Scene): CSM;
|
|
42
|
+
static initialize(options: WebGlBackendOptions, view: WebGlViewState, postProcessEffects: PostProcessEffectEntry[]): WebGlBackend;
|
|
28
43
|
initTexture(texture: THREE.Texture): void;
|
|
29
44
|
getEnvironmentTexture(texture: THREE.Texture): THREE.Texture;
|
|
30
|
-
dispose(): void;
|
|
45
|
+
dispose(disposeRenderer?: boolean): void;
|
|
46
|
+
rendererDepth: WebGLRenderer;
|
|
47
|
+
private composer;
|
|
48
|
+
outlinePass: OutlinePass;
|
|
49
|
+
fxaaPass: ShaderPass;
|
|
50
|
+
/** Copy pass is to copy the forward rendered result into the effect composer */
|
|
51
|
+
private copyPass;
|
|
52
|
+
private queryScene;
|
|
53
|
+
aoMaskDepthRenderTarget: WebGLRenderTarget;
|
|
54
|
+
depthRenderTarget: WebGLRenderTarget;
|
|
55
|
+
sceneColorRenderTarget: WebGLRenderTarget;
|
|
56
|
+
sceneDepthRenderTarget: WebGLRenderTarget;
|
|
57
|
+
aoPass: GTAOPass;
|
|
58
|
+
private bloomPass;
|
|
59
|
+
private colorPass;
|
|
60
|
+
private dofPass;
|
|
61
|
+
private lutPass;
|
|
62
|
+
private outputPass;
|
|
63
|
+
private postProcessEffectResolution;
|
|
64
|
+
private postProcessEffectUniformState;
|
|
65
|
+
private transmissionColorRenderTarget?;
|
|
66
|
+
private transmissionCopyQuad?;
|
|
67
|
+
private fquadCopySceneColor;
|
|
68
|
+
private fquadCopySceneDepth;
|
|
69
|
+
private occlusionClusters;
|
|
70
|
+
/**
|
|
71
|
+
* This should be used to multiply the AO with the opaque color.
|
|
72
|
+
*
|
|
73
|
+
* The reason for using an MRT for this is to be able to render the transparent
|
|
74
|
+
* pass and add to the samt MRT for bloom and other effects.
|
|
75
|
+
*
|
|
76
|
+
* An altnerative could be to have multiple bloom texture outputs that are
|
|
77
|
+
* additively combined. Normals as well could simply be overwritten for SSR.
|
|
78
|
+
*/
|
|
79
|
+
private fquadBlendAO;
|
|
80
|
+
private createAoblendQuad;
|
|
81
|
+
private upscaleOutputPass;
|
|
82
|
+
private readonly unjitteredProjectionMatrix;
|
|
83
|
+
private readonly temporalJitter;
|
|
84
|
+
private readonly temporalJitterUv;
|
|
85
|
+
private readonly currentUnjitteredViewProjectionMatrix;
|
|
86
|
+
private readonly currentViewProjectionMatrix;
|
|
87
|
+
private readonly currentViewProjectionMatrixInverse;
|
|
88
|
+
private readonly previousViewProjectionMatrix;
|
|
89
|
+
private readonly temporalUpscalingFrameState;
|
|
90
|
+
private temporalUpscalingFrameIndex;
|
|
91
|
+
private hasPreviousTemporalViewProjection;
|
|
92
|
+
private projectionJitterApplied;
|
|
93
|
+
private isTemporalUpscalingEnabled;
|
|
94
|
+
private prepareUpscalingFrame;
|
|
95
|
+
private finishUpscalingFrame;
|
|
96
|
+
private getPostProcessEffectStageAnchorPass;
|
|
97
|
+
private isDepthTextureExtensionSupported;
|
|
98
|
+
get supportsDepthTexture(): boolean;
|
|
99
|
+
private gRenderTarget;
|
|
100
|
+
addCluster(cluster: Cluster): void;
|
|
101
|
+
/**
|
|
102
|
+
* This finds the most relevant occlusion clusters to query.
|
|
103
|
+
* Optimizing this is a balance between minimizing the number of queries
|
|
104
|
+
* and reducing pop in.
|
|
105
|
+
*/
|
|
106
|
+
private updateRenderedOcclusionClusters;
|
|
107
|
+
private static createDepthRenderTarget;
|
|
108
|
+
/** */
|
|
109
|
+
private static createAOMaskDepthRenderTarget;
|
|
110
|
+
private createSceneColorRenderTarget;
|
|
111
|
+
private createSceneDepthRenderTarget;
|
|
112
|
+
private createGRenderTarget;
|
|
113
|
+
private applyEnvMap;
|
|
114
|
+
private hideOccluded;
|
|
115
|
+
private setupCsm;
|
|
116
|
+
private gbufferMaterialCache;
|
|
117
|
+
private gbufferDepthPrepassMaterialCache;
|
|
118
|
+
private tbufferMaterialCache;
|
|
119
|
+
private depthPrepassMaterialCache;
|
|
120
|
+
private depthPrepassCachedMaterials;
|
|
121
|
+
private depthPrepassCachedVisibility;
|
|
122
|
+
/**
|
|
123
|
+
* If the material such as a standard material has updated properties, then we need to update
|
|
124
|
+
* the corresponding g buffer material
|
|
125
|
+
* @param source
|
|
126
|
+
* @param target
|
|
127
|
+
*/
|
|
128
|
+
private updateMaterialProperties;
|
|
129
|
+
/**
|
|
130
|
+
* Updates uniform values from source material to target material.
|
|
131
|
+
* Optimized for hot path execution in rendering loop.
|
|
132
|
+
*/
|
|
133
|
+
private updateUniformValues;
|
|
134
|
+
/**
|
|
135
|
+
* Creates target-local uniform wrapper objects for any source uniforms that the
|
|
136
|
+
* derived material does not already declare. We keep the underlying value
|
|
137
|
+
* references instead of deep-cloning them so render-target textures and other
|
|
138
|
+
* runtime-owned resources are not duplicated or warned about.
|
|
139
|
+
*/
|
|
140
|
+
private inheritCustomUniformBindings;
|
|
141
|
+
private updateMaterialCommonProperties;
|
|
142
|
+
/**
|
|
143
|
+
* After rendering the opaque scene, we will also calculate lights which updates uniforms.
|
|
144
|
+
* These need to be present on the gbuffer materials so we need to copy them afterward.
|
|
145
|
+
*/
|
|
146
|
+
private updateLightUniformValues;
|
|
147
|
+
private createGBufferMaterial;
|
|
148
|
+
private isDepthPrepassEnabled;
|
|
149
|
+
private usesSceneFeedbackUniforms;
|
|
150
|
+
private usesShaderUniform;
|
|
151
|
+
private isDepthPrepassEligibleMaterial;
|
|
152
|
+
private isDepthPrepassEligibleMesh;
|
|
153
|
+
private createDepthPrepassMaterial;
|
|
154
|
+
private applyDepthPrepassMaterials;
|
|
155
|
+
private unapplyDepthPrepassMaterials;
|
|
156
|
+
private renderDepthPrepass;
|
|
157
|
+
private frameGBufferMeshes;
|
|
158
|
+
private frameGBufferPhaseMasks;
|
|
159
|
+
private frameUnsupportedGBufferObjects;
|
|
160
|
+
private frameGBufferExcludedObjects;
|
|
161
|
+
private appliedGBufferMeshes;
|
|
162
|
+
private originalGBufferMaterials;
|
|
163
|
+
private originalGBufferOnBeforeRender;
|
|
164
|
+
private hiddenGBufferObjects;
|
|
165
|
+
private gBufferPhaseMaskCache;
|
|
166
|
+
private gBufferMaterialArrayCache;
|
|
167
|
+
private gBufferShadowUpdaterCache;
|
|
168
|
+
private collectGBufferRenderables;
|
|
169
|
+
private getGBufferPhaseMask;
|
|
170
|
+
private getGBufferMaterialArray;
|
|
171
|
+
private applyGBufferMaterials;
|
|
172
|
+
private unapplyGBufferMaterials;
|
|
173
|
+
private applyGBufferShadowUniformUpdater;
|
|
174
|
+
private depthMaterialCachedMaterials;
|
|
175
|
+
private applyDepthMaterial;
|
|
176
|
+
private unapplyDepthMaterial;
|
|
177
|
+
private renderScene;
|
|
178
|
+
updatePostProcessEffectUniforms(simulationTime: number): void;
|
|
179
|
+
private insetHeight;
|
|
180
|
+
private insetWidth;
|
|
181
|
+
private insetOffsetY;
|
|
182
|
+
private insetMargin;
|
|
183
|
+
private maxInsetCameras;
|
|
184
|
+
private overlayCameras;
|
|
185
|
+
renderOverlay(): void;
|
|
186
|
+
addOverlayCamera(camera: Camera): void;
|
|
187
|
+
clearOverlayCameras(): void;
|
|
188
|
+
removeOverlayCamera(camera: Camera): void;
|
|
189
|
+
private hasBloom;
|
|
190
|
+
private usesSceneColorUniform;
|
|
191
|
+
private initSceneColorUniform;
|
|
192
|
+
private initDepthUniform;
|
|
193
|
+
private initNormalUniform;
|
|
194
|
+
private initShadowUniform;
|
|
195
|
+
private initLightVolumeUniform;
|
|
196
|
+
private initResolutionUniform;
|
|
197
|
+
private initAoUniform;
|
|
198
|
+
private initCustomDepthMaterial;
|
|
199
|
+
private _customDepthMaterialCache;
|
|
200
|
+
private volumetricFogPass;
|
|
201
|
+
private readonly hiddenWaterObjects;
|
|
202
|
+
private readonly hiddenReflectors;
|
|
203
|
+
private readonly hiddenSceneMapObjects;
|
|
204
|
+
private readonly hiddenOccluded;
|
|
205
|
+
private compileInProgress;
|
|
206
|
+
private renderWhilePaused;
|
|
207
|
+
private readonly cameraStartMatrix;
|
|
208
|
+
private lastShadowForceUpdateAt;
|
|
209
|
+
private csmCascadeLastUpdate?;
|
|
210
|
+
private maxDrawCalls;
|
|
211
|
+
private maxTriangles;
|
|
212
|
+
private gpuPanel?;
|
|
213
|
+
private collectGpuStats;
|
|
214
|
+
private initialized;
|
|
215
|
+
private ssrPass;
|
|
216
|
+
private phasedRenderPass;
|
|
217
|
+
updateCsm(nowSeconds: number): void;
|
|
218
|
+
initializePipeline(ambientOcclusionSettings: {
|
|
219
|
+
enabled: boolean;
|
|
220
|
+
blendIntensity: number;
|
|
221
|
+
options: Record<string, unknown>;
|
|
222
|
+
}): void;
|
|
223
|
+
resize(clientWidth: number, clientHeight: number, renderPixelRatio: number, presentationPixelRatio: number): void;
|
|
224
|
+
setCamera(camera: Camera): void;
|
|
225
|
+
refreshPostProcessEffectPassOrder(): void;
|
|
226
|
+
removePostProcessEffect(entry: PostProcessEffectEntry): void;
|
|
227
|
+
compileAsync(scene: Object3D): Promise<void>;
|
|
228
|
+
render(deltaTime?: number): void;
|
|
229
|
+
renderFrame(deltaTime: number, now: number, renderWhilePaused: boolean): void;
|
|
230
|
+
endGpuQuery(): void;
|
|
231
|
+
updateStatsPanels(drawCallsPanel: Stats.Panel, trianglesPanel: Stats.Panel): void;
|
|
232
|
+
setAnimationLoop(callback: Parameters<THREE.WebGLRenderer['setAnimationLoop']>[0]): void;
|
|
233
|
+
finishFrame(): void;
|
|
234
|
+
beginFrame(stats: FrameStats, detailedStatsEnabled: boolean): boolean;
|
|
235
|
+
applyPostProcessSettings(final: PostProcessSettings, useDepthOfField: boolean, lut: Texture | undefined): void;
|
|
236
|
+
private disposePipeline;
|
|
237
|
+
setWorldEnvironment(environment: WorldEnvironmentState | null): void;
|
|
238
|
+
resetPostProcessSettings(): void;
|
|
239
|
+
setBaseToneMapping(mapping: THREE.ToneMapping, exposure: number): void;
|
|
240
|
+
setEnableOutlines(enabled: boolean): void;
|
|
241
|
+
setSelectedObjects(objects: Object3D[]): void;
|
|
242
|
+
configureAmbientOcclusion(enabled: boolean, blendIntensity: number, options: Record<string, unknown>): void;
|
|
243
|
+
invalidateShadows(): void;
|
|
244
|
+
resetUpscalingHistory(): void;
|
|
245
|
+
private isUpscalingEnabled;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Checks if a given 3D object is within the camera's frustum.
|
|
249
|
+
*
|
|
250
|
+
* @param object - The 3D object to check.
|
|
251
|
+
* @param camera - The camera to check against.
|
|
252
|
+
* @returns `true` if the object is in the camera's frustum, `false` otherwise.
|
|
253
|
+
*/
|
|
254
|
+
export declare function isObjectInFrustum(object: THREE.Object3D, frustum: THREE.Frustum): boolean;
|
|
255
|
+
export declare class FogNode extends RgbaNode {
|
|
256
|
+
private readonly source;
|
|
257
|
+
private readonly fogColor;
|
|
258
|
+
constructor(source: RgbaNode, fogColor?: IRgbNode);
|
|
259
|
+
compile(c: any): {
|
|
260
|
+
pars: string;
|
|
261
|
+
chunk: string;
|
|
262
|
+
out: string;
|
|
263
|
+
};
|
|
31
264
|
}
|
|
265
|
+
export {};
|
|
32
266
|
//# sourceMappingURL=webgl-backend.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as e from"three";import{VRButton as t}from"three-stdlib";import{RectAreaLightUniformsLib as r}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{OutlineEffect as n}from"./outline-effect.js";export class WebGlBackend{constructor(e,t){this.renderer=e,this.outlineEffect=t,this.kind="webgl",this.pmremGenerator=null,this.pmremResults=new WeakMap,this.ownedPmremResults=new Set,this.canvas=e.domElement}static initialize(i){r.init();const a=window,o=a.renderer??new e.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});return a.renderer=o,o.setPixelRatio(i.pixelRatio),o.setSize(i.container.clientWidth,i.container.clientHeight),o.xr.enabled=i.enableXR,i.enableXR&&document.body.appendChild(t.createButton(o)),o.shadowMap.enabled=i.shadows.enabled,o.shadowMap.type=e.PCFSoftShadowMap,o.shadowMap.autoUpdate=i.shadows.autoUpdate,o.outputColorSpace=e.SRGBColorSpace,o.toneMapping=e.NoToneMapping,o.toneMappingExposure=1,o.gammaFactor=1.4,o.debug.checkShaderErrors=!1,new WebGlBackend(o,new n(o,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0}))}initTexture(e){this.renderer.initTexture(e)}getEnvironmentTexture(t){if(t.mapping===e.CubeUVReflectionMapping)return t;let r=this.pmremResults.get(t);return null==r&&(null==this.pmremGenerator&&(this.pmremGenerator=new e.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()),r=this.pmremGenerator.fromEquirectangular(t),this.pmremResults.set(t,r),this.ownedPmremResults.add(r)),r.texture}dispose(){this.pmremGenerator?.dispose(),this.pmremGenerator=null;for(const e of this.ownedPmremResults)e.dispose();this.ownedPmremResults.clear()}}/*
|
|
1
|
+
import*as e from"three";import{Euler as t,Matrix4 as s,Mesh as i,MeshStandardMaterial as a,PerspectiveCamera as r,ShaderMaterial as n,WebGLRenderTarget as o}from"three";import{CopyShader as l,EffectComposer as h,FXAAShader as p,GammaCorrectionShader as u,LUTPass as c,RenderPass as d,ShaderPass as f}from"three-stdlib";import{CSM as m}from"three/examples/jsm/csm/CSM.js";import{CSMShader as g,CSMUtil as M}from"../csm.js";import{skyPosition as v}from"../scene/sky.js";import{computeWhiteBalanceScale as w,needsColorGrading as P,needsColorTint as T,needsWhiteBalance as y,postProcessEpsilon as b}from"./post-process-color.js";import{attributes as S,BooleanExpression as x,colorToNormal as R,float as C,ifDefApply as U,lambertMaterial as B,min as A,mix as O,NodeShaderMaterial as F,normalize as D,packDepthToRGBA as G,rgb as E,rgba as j,RgbaNode as I,select as L,standardMaterial as W,toonMaterial as V,transformed as _,uniformFloat as k,uniformSampler2d as N,uniformVec2 as q,uniformVec3 as H,varying as z,varyingAttributes as $,varyingTransformed as Q,vec4 as J}from"three-shader-graph";import{FullScreenQuad as Y,Reflector as X}from"three-stdlib";import{BokehPass as K,OutputPass as Z,Pass as ee}from"three/examples/jsm/Addons.js";import{GTAOPass as te}from"three/examples/jsm/postprocessing/GTAOPass.js";import{BatchedMesh2 as se}from"../scene/batched-mesh-2.js";import{decalDiscard as ie}from"../shader-nodes/decal.js";import{depthUniformName as ae,farUniformName as re,highPrecisionEyeDepth as ne,nearUniformName as oe,resolutionUniformName as le,sceneNormalUniformName as he,screenUV as pe,supportsDepthTextureExtension as ue}from"../shader-nodes/depth.js";import{parallaxOcclusionMapping as ce}from"../shader-nodes/pom.js";import{aoMapUniformName as de,sceneMapUniformName as fe,transmissionMapUniformName as me}from"../shader-nodes/scene-sample.js";import{elapsedTimeUniformName as ge}from"../shader-nodes/time.js";import{ParallaxStandardMaterial as Me}from"../shader/builtin/standard-shader.js";import{applyUvTiling as ve}from"../shader/uv-nodes.js";import{DepthPass as we}from"../utils/three/depth-pass.js";import{GPUStatsPanel as Pe}from"../utils/three/gpu-stats-panel.js";import{OutlinePass as Te}from"../utils/three/outline-pass.js";import{createPlaceholderTexture as ye}from"../utils/three/placeholder-texture.js";import{findFirstVisibleObject as be,traverseVisibleStop as Se}from"../utils/three/traverse.js";import{UnrealBloomPass as xe}from"./bloom/UnrealBloomPass.js";import{ColorPass as Re}from"./color-pass.js";import{FogVolumeObject as Ce}from"./fog/fog-volume-object.js";import{VolumetricFogPass as Ue}from"./fog/volumetric-fog-pass.js";import{OutlineEffect as Be}from"./outline-effect.js";import{PostProcessEffectPass as Ae,postProcessEffectStages as Oe}from"./post-process-effect.js";import{SSRPass as Fe}from"./ssr/SSRPass.js";import{SSRShader as De}from"./ssr/SSRShader.js";import{getTemporalUpscalingJitter as Ge,getUpscalingMethod as Ee,UpscaleOutputPass as je}from"./upscaling-pass.js";import{VRButton as Ie}from"three-stdlib";import{RectAreaLightUniformsLib as Le}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";export class WebGlBackend{constructor(t,i,a,r){this.renderer=t,this.outlineEffect=i,this.view=a,this.postProcessEffects=r,this.kind="webgl",this.pmremGenerator=null,this.pmremResults=new WeakMap,this.ownedPmremResults=new Set,this.queryScene=new e.Scene,this.occlusionClusters=[],this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new s,this.temporalJitter=new e.Vector2,this.temporalJitterUv=new e.Vector2,this.currentUnjitteredViewProjectionMatrix=new s,this.currentViewProjectionMatrix=new s,this.currentViewProjectionMatrixInverse=new s,this.previousViewProjectionMatrix=new s,this.temporalUpscalingFrameState={depthTexture:null,currentJitterUv:this.temporalJitterUv,currentViewProjectionInverse:this.currentViewProjectionMatrixInverse,previousViewProjection:this.previousViewProjectionMatrix},this.temporalUpscalingFrameIndex=0,this.hasPreviousTemporalViewProjection=!1,this.projectionJitterApplied=!1,this.isDepthTextureExtensionSupported=!0,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.frameGBufferMeshes=[],this.frameGBufferPhaseMasks=[],this.frameUnsupportedGBufferObjects=[],this.frameGBufferExcludedObjects=new Set,this.appliedGBufferMeshes=[],this.originalGBufferMaterials=[],this.originalGBufferOnBeforeRender=[],this.hiddenGBufferObjects=[],this.gBufferPhaseMaskCache=new WeakMap,this.gBufferMaterialArrayCache=new WeakMap,this.gBufferShadowUpdaterCache=new WeakMap,this.depthMaterialCachedMaterials=new Map,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this._customDepthMaterialCache=new WeakMap,this.hiddenWaterObjects=[],this.hiddenReflectors=[],this.hiddenSceneMapObjects=[],this.hiddenOccluded=[],this.compileInProgress=!1,this.renderWhilePaused=!1,this.cameraStartMatrix=new s,this.lastShadowForceUpdateAt=0,this.maxDrawCalls=10,this.maxTriangles=1e3,this.collectGpuStats=!1,this.initialized=!1,this.canvas=t.domElement}static createCascadedShadows(t,s){const i=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),a=new m({maxFar:80,lightFar:250,lightMargin:20,shadowBias:0,cascades:i?2:3,shadowMapSize:i?512:1024,lightDirection:new e.Vector3(.5,-1,-.6).normalize(),lightIntensity:.25*Math.PI,camera:t,parent:s,mode:"practical"});for(const e of a.lights)e.shadow.normalBias=.01;return a}static initialize(t,s,i){Le.init();const a=window,r=a.renderer??new e.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});return a.renderer=r,r.setPixelRatio(t.pixelRatio),r.setSize(t.container.clientWidth,t.container.clientHeight),r.xr.enabled=t.enableXR,t.enableXR&&document.body.appendChild(Ie.createButton(r)),r.shadowMap.enabled=t.shadows.enabled,r.shadowMap.type=e.PCFSoftShadowMap,r.shadowMap.autoUpdate=t.shadows.autoUpdate,r.outputColorSpace=e.SRGBColorSpace,r.toneMapping=e.NoToneMapping,r.toneMappingExposure=1,r.gammaFactor=1.4,r.debug.checkShaderErrors=!1,new WebGlBackend(r,new Be(r,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0}),s,i)}initTexture(e){this.renderer.initTexture(e)}getEnvironmentTexture(t){if(t.mapping===e.CubeUVReflectionMapping)return t;let s=this.pmremResults.get(t);return null==s&&(null==this.pmremGenerator&&(this.pmremGenerator=new e.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()),s=this.pmremGenerator.fromEquirectangular(t),this.pmremResults.set(t,s),this.ownedPmremResults.add(s)),s.texture}dispose(e=!1){this.disposePipeline(),e&&this.renderer.dispose(),this.pmremGenerator?.dispose(),this.pmremGenerator=null;for(const e of this.ownedPmremResults)e.dispose();this.ownedPmremResults.clear()}createAoblendQuad(){const t=J(1),s=ye(),i=N("tAlphaTest",s).sample(pe).a,a=N("tAO",s).sample(pe),r=L(i.lt(.05),a,A(J(1,1,1,1),a.addScalar(.4))),n=new F({outputs:[r,t,t],transparent:!0});n.depthWrite=!1,n.depthTest=!1,n.blending=e.MultiplyBlending;return new Y(n)}isTemporalUpscalingEnabled(){if(!this.isUpscalingEnabled())return!1;const e=Ee(this.view.options.upscaling);return"temporal"===e||"dlss"===e}prepareUpscalingFrame(){if(!this.isTemporalUpscalingEnabled()||null==this.upscaleOutputPass)return void this.upscaleOutputPass?.setFrameState(null);this.unjitteredProjectionMatrix.copy(this.view.camera.projectionMatrix),this.currentUnjitteredViewProjectionMatrix.multiplyMatrices(this.unjitteredProjectionMatrix,this.view.camera.matrixWorldInverse),this.hasPreviousTemporalViewProjection||(this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.upscaleOutputPass.resetHistory());const e=(t=this.view.options.upscaling?.temporal?.jitterScale,s=1,null!=t&&Number.isFinite(t)&&t>0?t:s);var t,s;Ge(this.temporalUpscalingFrameIndex++,this.temporalJitter,e),this.temporalJitterUv.set(this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),this.temporalJitter.y/Math.max(1,this.gRenderTarget.height));const i=2*this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),a=2*this.temporalJitter.y/Math.max(1,this.gRenderTarget.height);this.view.camera instanceof r?(this.view.camera.projectionMatrix.elements[8]+=i,this.view.camera.projectionMatrix.elements[9]+=a):(this.view.camera.projectionMatrix.elements[12]+=i,this.view.camera.projectionMatrix.elements[13]+=a),this.view.camera.projectionMatrixInverse.copy(this.view.camera.projectionMatrix).invert(),this.projectionJitterApplied=!0,this.currentViewProjectionMatrix.multiplyMatrices(this.view.camera.projectionMatrix,this.view.camera.matrixWorldInverse),this.currentViewProjectionMatrixInverse.copy(this.currentViewProjectionMatrix).invert(),this.temporalUpscalingFrameState.depthTexture=this.gRenderTarget.depthTexture,this.upscaleOutputPass.setFrameState(this.temporalUpscalingFrameState)}finishUpscalingFrame(){this.projectionJitterApplied&&(this.view.camera.projectionMatrix.copy(this.unjitteredProjectionMatrix),this.view.camera.projectionMatrixInverse.copy(this.view.camera.projectionMatrix).invert(),this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.hasPreviousTemporalViewProjection=!0,this.projectionJitterApplied=!1)}getPostProcessEffectStageAnchorPass(e){switch(e){case"beforeFog":return this.volumetricFogPass;case"beforeDepthOfField":return this.dofPass;case"beforeColorAdjustment":return this.colorPass;case"beforeOutline":return this.outlinePass;case"beforeAntiAliasing":return this.fxaaPass;case"beforeLut":return this.lutPass;case"beforeOutput":return this.outputPass}}get supportsDepthTexture(){return this.isDepthTextureExtensionSupported}addCluster(e){if(!1===this.view.options.occlusionCulling?.enabled)return;if(!this.initialized)return;if(!this.renderer.capabilities.isWebGL2)return;const t=this.renderer.getContext(),s=t.createQuery();if(null==s)return;const i={query:s,visible:!0,awaitingResult:!1,cluster:e,lastTested:-1/0,distance:0,update:()=>{if(i.awaitingResult&&t.getQueryParameter(s,t.QUERY_RESULT_AVAILABLE)){const e=t.getQueryParameter(s,t.QUERY_RESULT);i.visible=!!e,i.awaitingResult=!1}}};e.boundsMesh.onBeforeRender=()=>{i.awaitingResult||t.beginQuery(t.ANY_SAMPLES_PASSED,s)},e.boundsMesh.onAfterRender=()=>{i.awaitingResult||(t.endQuery(t.ANY_SAMPLES_PASSED),i.awaitingResult=!0)},this.occlusionClusters.push(i)}updateRenderedOcclusionClusters(){this.queryScene.clear();const e=performance.now(),t=[];for(const s of this.occlusionClusters){if(s.awaitingResult)continue;const i=s.cluster.bounds.distanceToPoint(this.view.camera.position);if(s.distance=i,i<10){s.visible=!0,s.lastTested=e;continue}if(i>1e3)continue;const a=e-s.lastTested;if(!(s.visible&&a<4e3)&&((s.visible||!(a<100))&&ze.intersectsBox(s.cluster.bounds)))if(s.visible)t.push(s);else{let e=0;for(;e<t.length&&t[e].distance<s.distance;)e++;t.splice(e,0,s)}}if(t.length<50)for(const s of t)s.lastTested=e,this.queryScene.add(s.cluster.boundsMesh);else{const s=Math.max(Math.floor(Math.random()*t.length-50),0);for(let i=0;i<50;i++){const a=t[s+i];if(null==a)break;a.lastTested=e,this.queryScene.add(a.cluster.boundsMesh)}if(t.length>0){const s=t[0];s.lastTested=e,this.queryScene.add(s.cluster.boundsMesh)}}}static createDepthRenderTarget(t,s,i){const a=Math.max(1,Math.floor(s.clientWidth*i)),r=Math.max(1,Math.floor(s.clientHeight*i)),n=new e.WebGLRenderTarget(a,r);return n.texture.minFilter=e.NearestFilter,n.texture.magFilter=e.NearestFilter,n.texture.generateMipmaps=!1,n.stencilBuffer=!1,n.depthTexture=new e.DepthTexture(a,r),n.depthTexture.type=e.UnsignedShortType,n.depthTexture.minFilter=e.NearestFilter,n.depthTexture.magFilter=e.NearestFilter,n}static createAOMaskDepthRenderTarget(t,s,i=t.getPixelRatio()){const a=Math.max(1,s.clientWidth*i),r=Math.max(1,s.clientHeight*i),n=new e.DepthTexture(a,r);n.type=e.UnsignedInt248Type,n.minFilter=e.NearestFilter,n.magFilter=e.NearestFilter;const o=new e.WebGLRenderTarget(a,r,{type:e.HalfFloatType,depthTexture:n});return o.texture.minFilter=e.NearestFilter,o.texture.magFilter=e.NearestFilter,o.texture.generateMipmaps=!1,o.stencilBuffer=!1,o}createSceneColorRenderTarget(){const t=this.gRenderTarget.width,s=this.gRenderTarget.height,i=new e.WebGLRenderTarget(t,s,{type:e.HalfFloatType,format:e.RGBAFormat,colorSpace:e.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return i.texture.minFilter=e.LinearFilter,i.texture.magFilter=e.LinearFilter,i.texture.generateMipmaps=!1,i}createSceneDepthRenderTarget(){const t=new e.WebGLRenderTarget(this.gRenderTarget.width,this.gRenderTarget.height,{type:e.FloatType,format:e.RedFormat,minFilter:e.NearestFilter,magFilter:e.NearestFilter,depthBuffer:!1,stencilBuffer:!1});return t.texture.generateMipmaps=!1,t}createGRenderTarget(){const t=this.view.container;null!=this.gRenderTarget&&this.gRenderTarget?.dispose();const s=this.view.currentRenderPixelRatio,i=Math.max(1,t.clientWidth*s),a=Math.max(1,t.clientHeight*s),r=new e.DepthTexture(i,a);r.type=e.UnsignedIntType,r.minFilter=e.NearestFilter,r.magFilter=e.NearestFilter,this.gRenderTarget=new o(i,a,{count:3,samples:this.view.options?.msaa??0,minFilter:e.NearestFilter,magFilter:e.NearestFilter,type:e.HalfFloatType,format:e.RGBAFormat,depthTexture:r}),this.gRenderTarget.textures[2].type=e.UnsignedByteType,this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}applyEnvMap(t){if(null!=this.view.scene.environment&&(t instanceof F&&(null==t.envMap||t.userData.useSceneEnv)&&(t.userData.useSceneEnv=!0,null==t.uniforms.envMap&&(t.uniforms.envMap={value:this.view.scene.environment},t.uniformsNeedUpdate=!0,t.uniforms.envMapRotation={value:Xe(this.view.scene.environmentRotation,this.view.scene.environment,new e.Matrix3)}),null==t.uniforms.envMapIntensity&&(t.uniforms.envMapIntensity={value:1},t.uniformsNeedUpdate=!0),t.uniforms.envMap.value=this.view.scene.environment,t.uniforms.envMapIntensity.value=this.view.scene.environmentIntensity,t.envMap=this.view.scene.environment),t instanceof F||t instanceof e.MeshStandardMaterial)){const e=this.gbufferMaterialCache.get(t);null==e||this.gbufferMaterialCache.has(e)||this.applyEnvMap(e)}}hideOccluded(e){e.length=0;for(const t of this.occlusionClusters)if(!t.visible){let s=t.cluster.objects.length;for(;s--;){const i=t.cluster.objects[s];i.visible&&(i.visible=!1,e.push(i))}}}setupCsm(t){if(t instanceof e.Mesh||t instanceof e.SkinnedMesh)if(t.material instanceof Array)for(const e of t.material)this.view.csm.setupMaterial(e);else this.view.csm.setupMaterial(t.material)}updateMaterialProperties(t,s){(t instanceof e.MeshBasicMaterial||t instanceof a||t instanceof e.MeshLambertMaterial||t instanceof e.MeshPhongMaterial)&&(null!=s.uniforms.color&&s.uniforms.color.value.setFromColor(t.color),null!=s.uniforms.opacity&&(s.uniforms.opacity.value=t.opacity),null!=s.uniforms.map&&(s.uniforms.map.value=t.map),null!=s.uniforms.alphaMap&&(s.uniforms.alphaMap.value=t.alphaMap),null!=s.uniforms.lightMap&&(s.uniforms.lightMap.value=t.lightMap,s.uniforms.lightMapIntensity.value=t.lightMapIntensity),null!=s.uniforms.aoMap&&(s.uniforms.aoMap.value=t.aoMap,s.uniforms.aoMapIntensity.value=t.aoMapIntensity),null!=s.uniforms.alphaTest&&(s.uniforms.alphaTest.value=t.alphaTest)),(t instanceof a||t instanceof e.MeshLambertMaterial||t instanceof e.MeshPhongMaterial)&&(s.uniforms.normalMap&&(s.uniforms.normalMap.value=t.normalMap,s.uniforms.normalScale.value=t.normalScale.x),s.uniforms.emissiveMap&&(s.uniforms.emissiveMap.value=t.emissiveMap,s.uniforms.emissive.value.setFromColor(t.emissive),s.uniforms.emissiveIntensity.value=t.emissiveIntensity)),t instanceof a&&(null!=s.uniforms.roughnessMap&&(s.uniforms.roughnessMap.value=t.roughnessMap),null!=s.uniforms.metalnessMap&&(s.uniforms.metalnessMap.value=t.metalnessMap),null!=s.uniforms.roughness&&(s.uniforms.roughness.value=t.roughness),null!=s.uniforms.metalness&&(s.uniforms.metalness.value=t.metalness)),t instanceof e.MeshPhysicalMaterial&&(s.uniforms.sheenColor&&s.uniforms.sheenColor.value.setFromColor(t.sheenColor).multiplyScalar(t.sheen),s.uniforms.sheenColorMap&&(s.uniforms.sheenColorMap.value=t.sheenColorMap),s.uniforms.sheenRoughness&&(s.uniforms.sheenRoughness.value=t.sheenRoughness),s.uniforms.sheenRoughnessMap&&(s.uniforms.sheenRoughnessMap.value=t.sheenRoughnessMap)),t instanceof Me&&(s.uniforms.heightMap.value=t.heightMap,s.uniforms.heightScale.value=t.heightScale),this.updateMaterialCommonProperties(t,s)}updateUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s){const t=i[e],a=s[e].value;null!=t&&t.value!==a&&"receiveShadow"!==e&&!1===st.includes(e)&&(t.value=a)}this.updateMaterialCommonProperties(e,t)}inheritCustomUniformBindings(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s)null==i[e]&&("receiveShadow"===e||st.includes(e)||it.includes(e)||(i[e]={value:s[e].value}))}updateMaterialCommonProperties(e,t){t.alphaTest=e.alphaTest,t.side=e.side,t.depthTest=e.depthTest,t.blending=e.blending,t.colorWrite=e.colorWrite,t.premultipliedAlpha=e.premultipliedAlpha,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t.visible=e.visible}updateLightUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e of st){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(t,s,i=!1){const r=s===Ve.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let o=r.get(t);if(!0===t.userData.isGBufferMaterial)return t;if(null==o){const i=this.usesShaderUniform(t,ae),h=this.usesSceneColorUniform(t),p=this.usesShaderUniform(t,de),u=t.transparent&&t.alphaTest<=.01||t.blending===e.AdditiveBlending,c=s===Ve.opaque?!(i||h||p||u):u||i||h||p;if(!c)return r.set(t,ot),ot;let d=$.uv;if(t instanceof Me&&null!=t.heightMap){const e=k("heightScale",t.heightScale??1);d=ce(d,N("heightMap",t.heightMap),e)}let f=Q.normal;if(t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial){const e=t.normalMap??Ne,s=k("useNormalMap",null!=t.normalMap?1:0),i=k("normalScale",t.normalScale?.x??1),a=R(N("normalMap",e).sample(ve(d,t.normalMap)),i);f=O(Q.normal,a,s)}else t instanceof F&&null!=t.outputNormal&&(f=t.outputNormal);!0!==t.userData.disableAO&&(f=U("DOUBLE_SIDED",f,e=>L(new x("gl_FrontFacing"),e,e.multiplyScalar(-1))));let m=t.userData?.reflective?C(0):C(1);if(t instanceof e.MeshStandardMaterial){const e=k("roughness",t.roughness??1),s=t.roughnessMap??_e,i=k("useRoughnessMap",null!=t.roughnessMap?1:0),a=N("roughnessMap",s).sample(ve(d,t.roughnessMap)).g.multiply(e);m=O(e,a,i)}else t instanceof F&&null!=t.outputRoughness&&(m=t.outputRoughness);let g=null;if((t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial||t instanceof e.MeshBasicMaterial)&&null!=t.lightMap){const e=t.lightMap,s=k("useLightMap",null!=t.lightMap?1:0),i=k("lightMapIntensity",t.lightMapIntensity??1),a=N("lightMap",e).sample(d).rgb.multiplyScalar(i);g=O(E(0),a,s)}let M=C(0);if(t instanceof e.MeshStandardMaterial){const e=k("metalness",t.metalness??0),s=t.metalnessMap??ke,i=k("useMetalnessMap",null!=t.metalnessMap?1:0),a=N("metalnessMap",s).sample(ve(d,t.metalnessMap)).b.multiply(e);M=O(e,a,i)}else t instanceof F&&t.outputRoughness;let w=null,P=C(1);if(t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial||t instanceof e.MeshBasicMaterial){const e=t.aoMap??_e,s=k("useAoMap",null!=t.aoMap?1:0);P=k("aoMapIntensity",t.aoMapIntensity??1);const i=N("aoMap",e).sample(ve(d,t.aoMap)).r;w=O(C(1),i,s)}else t instanceof F&&t.outputRoughness;const T=k("opacity",t.opacity??1);let y=C(1);if(t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshBasicMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial){if(null!=t.alphaMap){const e=t.alphaMap;y=N("alphaMap",e).sample(ve(d,t.alphaMap)).r}y=y.multiply(T)}else t instanceof F&&null!=t.outputOpacity&&(y=t.outputOpacity);let b=j(0,1);if(t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial||t instanceof e.MeshBasicMaterial){let s=H("color",(new e.Vector3).setFromColor(t.color));const i=t.map??_e,a=k("useAlbedoMap",null!=t.map?1:0),r=N("map",i).sample(ve(d,t.map)),n=r.multiply(j(s,1)),o=j(s,1);b=O(o,n,a),t.vertexColors&&(b=b.multiply(J(z(S.color.rgb),1)));const l=O(C(1),r.w,a);y=y.multiply(l)}const A=!0===t.userData.hasBloom;let G=E(0);if(t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial){const s=H("emissive",(new e.Vector3).setFromColor(t.emissive)),i=k("emissiveIntensity",t.emissiveIntensity),a=t.emissiveMap??ke,r=k("useEmissiveMap",null!=t.emissiveMap?1:0),n=N("emissiveMap",a).sample(ve(d,t.emissiveMap)).rgb.multiply(s);G=O(s,n,r),G=G.multiplyScalar(i)}else t instanceof F&&null!=t.outputEmissive&&(G=t.outputEmissive);let I=null;if(t instanceof e.MeshPhysicalMaterial&&t.sheen>0&&(I=H("sheenColor",(new e.Vector3).setFromColor(t.sheenColor).multiplyScalar(t.sheen)),t.sheen>0&&null!=t.sheenColorMap)){const e=N("sheenColorMap",t.sheenColorMap).sample(d).rgb;I=I.multiply(e)}let _=null;if(t instanceof e.MeshPhysicalMaterial&&t.sheen>0&&(_=k("sheenRoughness",t.sheenRoughness),t.sheen>0&&null!=t.sheenRoughnessMap)){const e=N("sheenRoughnessMap",t.sheenRoughnessMap).sample(d).r;_=_.multiply(e)}let Y=null;if(t instanceof e.MeshPhysicalMaterial&&t.anisotropy>0&&(Y=k("anisotropy",t.anisotropy),t.anisotropy>0&&null!=t.anisotropyMap)){const e=N("anisotropyMap",t.anisotropyMap).sample(d).r;Y=Y.multiply(e)}let X=null;if(t instanceof e.MeshPhysicalMaterial&&t.anisotropy>0){const s=t.anisotropyRotation??0;X=q("anisotropyDirection",new e.Vector2(Math.cos(s),Math.sin(s)))}const K=k("alphaTest",t.alphaTest);let Z,ee=t.alphaTest>0?y.lt(K):u&&s===Ve.opaque?y.lt(.8):null;!0===t.userData.isDecal&&(ee=ee?ee.or(ie):ie),Z=u?J(0,0,0,0):(l=f,D(l).multiplyScalar(.5).addScalar(.5)).rgba(t.userData?.reflective?m:1);const te=t instanceof F?t.outputPosition:void 0,se=t instanceof F?t.outputTransform:void 0;let re,ne=j("black",1);if(t instanceof F&&null!=t.outputColor)ne=t.outputColor;else if(t instanceof e.MeshStandardMaterial)ne=W({color:b,metalness:M,roughness:m,emissive:G.rgb,normal:f,ambientOcclusion:w,ambientOcclusionIntensity:P,bakedLight:g,sheenColor:I,sheenRoughness:_,anisotropy:Y,anisotropyDirection:X});else if(t instanceof e.MeshLambertMaterial||t instanceof e.MeshPhongMaterial)ne=B({color:b.rgb,ambientOcclusion:w,ambientOcclusionIntensity:P});else if(t instanceof e.MeshBasicMaterial){let e=b.rgb,t=g??E("black");null!=w&&(t=t.multiplyScalar(w.subtract(1).multiply(P).add(1))),e=e.add(t),ne=e.rgba(y)}else t instanceof e.MeshToonMaterial&&(ne=V({color:b,emissive:G.rgb,normal:f,ambientOcclusion:w,ambientOcclusionIntensity:P,bakedLight:g}));(t instanceof F||t instanceof e.MeshStandardMaterial)&&(re=t.envMap);let oe=!0;(t instanceof a||t instanceof e.MeshBasicMaterial||t instanceof e.ShaderMaterial)&&(oe=t.fog);let le=j(ne.rgb,y);oe&&(le=new FogNode(le)),o=new F({transform:se,position:!0===t.userData.isSky?v:null==se?te:void 0,outputs:[le,G.rgba(s===Ve.opaque?K:A?1:0),Z],opacity:y,outputEncoding:!1,fog:oe,transparent:t.transparent,lights:!0,envMap:re,alphaTest:t.alphaTest,uniformNodes:t.uniformNodes??{},discard:ee}),t instanceof e.MeshStandardMaterial&&null!=t.envMap&&null!=o.uniforms.envMapIntensity&&(o.uniforms.envMapIntensity.value=t.envMapIntensity),"alphaMap"in t&&null!=t.alphaMap&&(o.alphaMap=t.alphaMap),(t instanceof F||t instanceof e.MeshStandardMaterial)&&this.applyEnvMap(o),t instanceof F&&(Object.assign(o.defines,t.defines),null!=o.uniforms[de]&&(o.uniforms[de].value=this.aoPass.pdRenderTarget.texture,o.defines.USE_SSAO_MAP="")),o.userData.mrtOutputs=3,o.forceSinglePass=t.forceSinglePass,o.side=t.side,o.blending=t.blending,u?(o.depthWrite=!t.transparent,o.depthTest=t.depthTest,o.colorWrite=s===Ve.transparent):(o.depthWrite=t.depthWrite,o.depthTest=t.depthTest),o.visible=t.visible,o.alphaTest=t.alphaTest,o.alphaHash=t.alphaHash,o.vertexColors=t.vertexColors,o.premultipliedAlpha=t.premultipliedAlpha,o.toneMapped=t.toneMapped,o.blendAlpha=t.blendAlpha,o.blendColor=t.blendColor,o.polygonOffset=t.polygonOffset,o.polygonOffsetFactor=t.polygonOffsetFactor,o.polygonOffsetUnits=t.polygonOffsetUnits,o.blending=t.blending,o.wireframe=t.wireframe??!1,o.userData.isGBufferMaterial=!0,o.visible=c,Object.assign(o.userData,t.userData),o.visible&&(this.view.csm.setupMaterial(o),t instanceof n&&this.inheritCustomUniformBindings(t,o)),r.set(t,o)}var l;return o.visible&&(t instanceof n?this.updateUniformValues(t,o):this.updateMaterialProperties(t,o)),this.usesSceneColorUniform(o)&&this.initSceneColorUniform(o),this.initLightVolumeUniform(o),o}isDepthPrepassEnabled(){return!0===this.view.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof n&&(this.usesShaderUniform(e,ae)||this.usesSceneColorUniform(e)||this.usesShaderUniform(e,de))}usesShaderUniform(e,t){return e instanceof n&&null!=e.uniforms[t]}isDepthPrepassEligibleMaterial(t){return null!=t&&(!1!==t.visible&&!1!==t.depthTest&&!1!==t.depthWrite&&(!t.transparent&&t.blending!==e.AdditiveBlending&&(!this.usesSceneFeedbackUniforms(t)&&(t instanceof F||t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshPhongMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshBasicMaterial))))}isDepthPrepassEligibleMesh(t){return!!this.isDepthPrepassEnabled()&&((t instanceof e.InstancedMesh||t instanceof se)&&(!Array.isArray(t.material)&&this.isDepthPrepassEligibleMaterial(t.material)))}createDepthPrepassMaterial(t){if(!this.isDepthPrepassEligibleMaterial(t))return null;let s=this.depthPrepassMaterialCache.get(t);if(null==s){let i,a=C(1);t instanceof e.MeshStandardMaterial||t instanceof e.MeshLambertMaterial||t instanceof e.MeshBasicMaterial||t instanceof e.MeshToonMaterial||t instanceof e.MeshPhongMaterial?(a=k("opacity",t.opacity??1),null!=t.map&&(a=a.multiply(N("map",t.map).sample($.uv).a)),null!=t.alphaMap&&(a=a.multiply(N("alphaMap",t.alphaMap).sample($.uv).r))):t instanceof F&&(a=t.outputOpacity??C(1)),null!=t.alphaTest&&t.alphaTest>0&&(i=a.lt(t.alphaTest));const r=t instanceof F?t.outputPosition:void 0,n=t instanceof F?t.outputTransform:void 0;s=new F({outputs:[j(0,0),j(0,0),j(0,0)],opacity:a,transform:n,position:null==n?r:void 0,discard:i,lights:!1,fog:!1,outputEncoding:!1,transparent:!1,alphaTest:t.alphaTest}),s.depthWrite=!0,s.depthTest=t.depthTest,s.colorWrite=!1,s.transparent=!1,s.blending=e.NoBlending,s.lights=!1,s.fog=!1,s.toneMapped=!1,s.side=t.side,s.alphaTest=t.alphaTest,s.visible=t.visible,s.polygonOffset=t.polygonOffset,s.polygonOffsetFactor=t.polygonOffsetFactor,s.polygonOffsetUnits=t.polygonOffsetUnits,s.onBeforeCompile=()=>{},s.customProgramCacheKey=()=>`depth-prepass:${t.id}:${t.version}:${t.alphaTest}:${t.side}`;for(const e of st)delete s.uniforms[e];for(const e of it)delete s.uniforms[e];delete s.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(t,s)}return t instanceof F?this.updateUniformValues(t,s):this.updateMaterialProperties(t,s),s.depthWrite=!0,s.depthTest=t.depthTest,s.colorWrite=!1,s.transparent=!1,s.blending=e.NoBlending,s.visible=t.visible,s.alphaTest=t.alphaTest,s.side=t.side,s.polygonOffset=t.polygonOffset,s.polygonOffsetFactor=t.polygonOffsetFactor,s.polygonOffsetUnits=t.polygonOffsetUnits,s}applyDepthPrepassMaterials(){const e=this.depthPrepassCachedMaterials,t=this.depthPrepassCachedVisibility;e.clear(),t.length=0,Se(this.view.scene,s=>{if(Ke(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof i))return;if(e.set(s,s.material),!this.isDepthPrepassEligibleMesh(s))return t.push(s),void(s.visible=!1);const a=this.createDepthPrepassMaterial(s.material);if(null==a)return t.push(s),void(s.visible=!1);s.material=a,s.visible=!0})}unapplyDepthPrepassMaterials(){this.depthPrepassCachedMaterials.forEach((e,t)=>{t.material=e}),this.depthPrepassCachedVisibility.forEach(e=>{e.visible=!0}),this.depthPrepassCachedMaterials.clear(),this.depthPrepassCachedVisibility.length=0}renderDepthPrepass(){if(!this.isDepthPrepassEnabled())return;this.applyDepthPrepassMaterials();const e=this.view.scene.matrixWorldAutoUpdate,t=this.view.scene.matrixAutoUpdate,s=this.renderer.shadowMap.autoUpdate;this.renderer.shadowMap.autoUpdate=!1,this.view.scene.matrixWorldAutoUpdate=!1,this.view.scene.matrixAutoUpdate=!1,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clearDepth();try{this.renderer.render(this.view.scene,this.view.camera)}catch(e){console.warn("Depth prepass render failed",e)}this.unapplyDepthPrepassMaterials(),this.renderer.shadowMap.autoUpdate=s,this.view.scene.matrixWorldAutoUpdate=e,this.view.scene.matrixAutoUpdate=t}collectGBufferRenderables(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,a=this.frameUnsupportedGBufferObjects){t.length=0,s.length=0,a.length=0,Se(e,e=>{if(Ke(e))return a.push(e),!1;e instanceof i&&(t.push(e),s.push(this.getGBufferPhaseMask(e.material)))})}getGBufferPhaseMask(t){if(Array.isArray(t)){let e=0;for(let s=0;s<t.length;s++)e|=this.getGBufferPhaseMask(t[s]);return e}if(null==t||!1===t.visible)return 0;let s=this.gBufferPhaseMaskCache.get(t);if(null!=s)return s;if(!0===t.userData.isGBufferMaterial)return s=1<<Ve.opaque|1<<Ve.transparent,this.gBufferPhaseMaskCache.set(t,s),s;const i=this.usesShaderUniform(t,ae),a=this.usesSceneColorUniform(t),r=this.usesShaderUniform(t,de),n=t.transparent&&t.alphaTest<=.01||t.blending===e.AdditiveBlending,o=i||a||r;return s=0,o||n||(s|=1<<Ve.opaque),(o||n)&&(s|=1<<Ve.transparent),this.gBufferPhaseMaskCache.set(t,s),s}getGBufferMaterialArray(e,t){let s=this.gBufferMaterialArrayCache.get(e);null==s&&(s={opaque:[],transparent:[]},this.gBufferMaterialArrayCache.set(e,s));const i=t===Ve.opaque?s.opaque:s.transparent;i.length=e.length;for(let s=0;s<e.length;s++)i[s]=this.createGBufferMaterial(e[s],t,!1);return i}applyGBufferMaterials(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,i=this.frameUnsupportedGBufferObjects){const a=this.appliedGBufferMeshes,r=this.originalGBufferMaterials,n=this.originalGBufferOnBeforeRender,o=this.hiddenGBufferObjects;a.length=0,r.length=0,n.length=0,o.length=0;for(let e=0;e<i.length;e++){const t=i[e];t.visible&&(o.push(t),t.visible=!1)}const l=1<<e;for(let i=0;i<t.length;i++){const h=t[i];if(!h.visible)continue;const p=h.material;if(0!==(s[i]&l)||0!==h.children.length)if(a.push(h),r.push(p),n.push(h.onBeforeRender),0!==(s[i]&l)){if(Array.isArray(p)){const t=this.getGBufferMaterialArray(p,e);h.material=t;for(let e=0;e<t.length;e++)this.initShadowUniform(h,t[e])}else{const t=this.createGBufferMaterial(p,e,e===Ve.opaque&&this.isDepthPrepassEligibleMesh(h));h.material=t,this.initShadowUniform(h,t)}this.applyGBufferShadowUniformUpdater(h)}else h.material=ot;else o.push(h),h.visible=!1}}unapplyGBufferMaterials(){const e=this.appliedGBufferMeshes;for(let t=0;t<e.length;t++){const s=e[t];s.material=this.originalGBufferMaterials[t],s.onBeforeRender=this.originalGBufferOnBeforeRender[t]}const t=this.hiddenGBufferObjects;for(let e=0;e<t.length;e++)t[e].visible=!0;e.length=0,this.originalGBufferMaterials.length=0,this.originalGBufferOnBeforeRender.length=0,t.length=0}applyGBufferShadowUniformUpdater(e){const t=e.onBeforeRender;let s=this.gBufferShadowUpdaterCache.get(e);if(null==s){const i=this,a={original:t,wrapper:null};a.wrapper=(t,s,r,n,o,l)=>{a.original.call(e,t,s,r,n,o,l),i.initShadowUniform(e,o)},s=a,this.gBufferShadowUpdaterCache.set(e,s)}s.original=t,e.onBeforeRender=s.wrapper}applyDepthMaterial(){const e=this.depthMaterialCachedMaterials;e.clear(),this.view.scene.traverse(t=>{(t.isMesh||t.isPoints||t.isLine||t.isSprite)&&(this.initCustomDepthMaterial(t),e.set(t,t.material),t.castShadow?null!=t.customDepthMaterial?t.material=t.customDepthMaterial:t.material=rt:t.material=null)})}unapplyDepthMaterial(){this.depthMaterialCachedMaterials.forEach((e,t)=>{t.material=e}),this.depthMaterialCachedMaterials.clear()}renderScene(e){if(!this.view.running||this.view.paused&&!this.renderWhilePaused)return;if(this.compileInProgress)return void console.error("Compile in progress, skipping render");this.applyGBufferMaterials(e);const t=this.view.scene.matrixWorldAutoUpdate,s=this.view.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==Ve.opaque&&(this.renderer.shadowMap.autoUpdate=!1,this.view.scene.matrixWorldAutoUpdate=!1,this.view.scene.matrixAutoUpdate=!1);try{this.renderer.render(this.view.scene,this.view.camera)}catch(e){console.warn("Render failed",e)}if(e===Ve.opaque){const e=this.appliedGBufferMeshes;for(let t=0;t<e.length;t++){const s=e[t],i=this.originalGBufferMaterials[t];!Array.isArray(i)&&!Array.isArray(s.material)&&i instanceof n&&this.updateLightUniformValues(s.material,i)}}this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.view.scene.matrixWorldAutoUpdate=t,this.view.scene.matrixAutoUpdate=s}updatePostProcessEffectUniforms(e){if(!this.initialized||0===this.postProcessEffects.length)return;const t=this.postProcessEffectUniformState;t.aoEnabled=this.aoPass.enabled,t.aoTexture=this.aoPass.enabled?this.aoPass.pdRenderTarget.texture:null,this.view.camera instanceof r?(t.cameraNear=this.view.camera.near,t.cameraFar=this.view.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.sceneDepthRenderTarget.texture,t.normalTexture=this.gRenderTarget.textures[2],t.resolution.set(this.gRenderTarget.width,this.gRenderTarget.height),t.simulationTime=e;for(const e of this.postProcessEffects)e.pass?.updateUniformState(t)}renderOverlay(){if(!this.view.running)return;if(0===this.overlayCameras.size)return;const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.view.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.view.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}hasBloom(){return null!=be(this.view.scene,e=>e instanceof i&&!0===e.material?.userData?.hasBloom)}usesSceneColorUniform(e){return this.usesShaderUniform(e,fe)||this.usesShaderUniform(e,me)}initSceneColorUniform(t){if(t instanceof n&&(null==t.uniforms[me]||(this.transmissionColorRenderTarget||(this.transmissionColorRenderTarget=new e.WebGLRenderTarget(this.gRenderTarget.width,this.gRenderTarget.height,{type:e.HalfFloatType,colorSpace:e.LinearSRGBColorSpace,minFilter:e.LinearMipmapLinearFilter,magFilter:e.LinearFilter,generateMipmaps:!0,depthBuffer:!1,stencilBuffer:!1}),this.transmissionCopyQuad=new Y(new n({uniforms:{tDiffuse:{value:null}},vertexShader:l.vertexShader,fragmentShader:"uniform sampler2D tDiffuse; varying vec2 vUv; void main() { gl_FragColor = vec4(texture2D(tDiffuse, vUv).rgb, 1.0); }",toneMapped:!1}))),this.transmissionColorRenderTarget.setSize(this.gRenderTarget.width,this.gRenderTarget.height),t.uniforms[me].value!==this.transmissionColorRenderTarget.texture&&(t.uniforms[me].value=this.transmissionColorRenderTarget.texture,t.uniformsNeedUpdate=!0),null!=t.uniforms[fe])))return null==t.uniforms[fe]?(t.uniforms[fe]={value:this.sceneColorRenderTarget.texture},void(t.uniformsNeedUpdate=!0)):void(t.uniforms[fe].value!==this.sceneColorRenderTarget.texture&&(t.uniforms[fe].value=this.sceneColorRenderTarget.texture,t.uniformsNeedUpdate=!0))}initDepthUniform(e){e instanceof n&&(e.uniforms[ae].value=this.sceneDepthRenderTarget.texture,this.view.camera instanceof r&&(null!=e.uniforms[oe]&&(e.uniforms[oe].value=this.view.camera.near),null!=e.uniforms[re]&&(e.uniforms[re].value=this.view.camera.far)))}initNormalUniform(e){e instanceof n&&null!=e.uniforms[he]&&(e.uniforms[he].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof F&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof F&&(null!=this.view.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.view.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.view.lightVolume.gridSize},e.uniforms.gridRes={value:this.view.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.view.lightProbeIntensity},e.uniforms.uSH={value:this.view.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.view.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof n&&null!=e.uniforms[le]&&e.uniforms[le].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[de].value=this.aoPass.pdRenderTarget.texture,null==e.defines.USE_SSAO_MAP&&(e.defines.USE_SSAO_MAP="",e.needsUpdate=!0),e.defines.USE_SSAO_MAP="";const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}else if(null!=e.defines.USE_SSAO_MAP){delete e.defines.USE_SSAO_MAP,e.needsUpdate=!0;const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}}initCustomDepthMaterial(e){if(null!=e.customDepthMaterial||!e.castShadow)return;const t=e.material;if(!(t instanceof F&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=G(ne);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new F({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}updateCsm(e){e-this.lastShadowForceUpdateAt>.08&&!this.view.camera.matrixWorld.equals(this.cameraStartMatrix)&&(this.invalidateShadows(),this.lastShadowForceUpdateAt=e);const t=this.view.options.shadows?.cascadeUpdateIntervals;if(this.renderer.shadowMap.autoUpdate&&null!=this.csmCascadeLastUpdate&&Array.isArray(t)){const e=performance.now();for(let s=0;s<this.view.csm.lights.length;++s){const i=t[s]??t[t.length-1]??16;(e-this.csmCascadeLastUpdate[s]>=i||0===s)&&this.view.csm.lights[s].shadow&&(this.view.csm.lights[s].shadow.needsUpdate=!0,this.csmCascadeLastUpdate[s]=e)}}this.view.csm.update()}initializePipeline(t){const s=this.view.container,i=this.view.options;if(e.ShaderChunk.lights_fragment_begin=g.lights_fragment_begin,null!=i.shadows?.cascadeUpdateIntervals){this.csmCascadeLastUpdate=new Array(this.view.csm.lights.length).fill(0);for(const e of this.view.csm.lights)e.shadow.autoUpdate=!1}this.createGRenderTarget(),this.composer=new h(this.renderer,function(t,s){const i=new e.WebGLRenderTarget(Math.max(1,t),Math.max(1,s),{minFilter:e.LinearFilter,magFilter:e.LinearFilter,format:e.RGBAFormat,type:e.HalfFloatType});return i.texture.name="EffectComposer.rt1",i.texture.generateMipmaps=!1,i}(s.clientWidth,s.clientHeight)),this.composer.setPixelRatio(this.view.currentRenderPixelRatio),this.composer.setSize(s.clientWidth,s.clientHeight),this.view.baseToneMapping=this.renderer.toneMapping,this.view.baseToneMappingExposure=this.renderer.toneMappingExposure,this.isDepthTextureExtensionSupported=ue(this.renderer),this.aoMaskDepthRenderTarget=WebGlBackend.createAOMaskDepthRenderTarget(this.renderer,this.view.container,this.view.currentRenderPixelRatio),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget(),this.postProcessEffectResolution=new e.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:ye(),normalTexture:ye(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopySceneColor=new Y(new n(l)),this.fquadCopySceneDepth=new Y(new F({color:J(N("tDepthTexture",ye()).sample($.uv).r)})),this.fquadBlendAO=this.createAoblendQuad();const a=new e.Vector2(s.clientWidth,s.clientHeight),r=(new d(this.view.scene,this.view.camera),new f(l,"prevtexture"));r.enabled=!0,r.needsSwap=!0,r.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=r;const o=new xe(a,1.5,.4,.85);o.threshold=1,o.strength=.9,o.radius=.2,this.bloomPass=o;const m=new te(this.view.scene,this.view.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});m.normalRenderTarget?.dispose(),m.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),m.output=te.OUTPUT.Off,m.enabled=!1,this.aoPass=m,m.enabled=t.enabled,m.blendIntensity=t.blendIntensity,m.updateGtaoMaterial(t.options),this.fquadBlendAO.material.uniforms.tAO.value=m.pdRenderTarget.texture,this.fquadBlendAO.material.uniforms.tAlphaTest.value=this.gRenderTarget.textures[1],De.fragmentShader=De.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const M=new Fe({renderer:this.renderer,scene:this.view.scene,camera:this.view.camera,width:this.gRenderTarget.width,height:this.gRenderTarget.height,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});M.output=Fe.OUTPUT.Default,M.blur=!0,M.fresnel=!1,M.distanceAttenuation=!0,M.maxDistance=50,M.selective=!0,M.bouncing=!1,M.opacity=.4,M.enabled=!1!==this.view.options?.reflection?.enabled,this.ssrPass=M,!1!==this.view.options.ao?.enabled&&this.composer.addPass(m);const v=new tt((e,t,s,i,a)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(v);const w=new tt((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Ve.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(w),this.composer.addPass(r),this.composer.addPass(M),this.phasedRenderPass=new et(this.view.scene,this.view.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(o),o.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),this.volumetricFogPass=new Ue(a),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new K(this.view.scene,this.view.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const P=new Re;this.composer.addPass(P),this.colorPass=P,P.vignetteEnabled=!1,this.outlinePass=new Te(new e.Vector2(s.clientWidth,s.clientHeight),this.view.scene,this.view.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const T=new f(p);T.uniforms.resolution.value.set(1/s.clientWidth,1/s.clientHeight),this.composer.addPass(T),this.fxaaPass=T,this.fxaaPass.enabled=!1,this.setEnableOutlines(!0===this.view.options.enableOutlines),new f(u).clear=!1,this.lutPass=new c({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const y=new f(l,"prevtexture");y.enabled=!0,y.needsSwap=!1,y.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],y.renderToScreen=!0;const b=this.isUpscalingEnabled()?new je(this.view.options.upscaling):new Z;!function(e){const t=e.material;if(t.dithering=!0,t.fragmentShader.includes("<dithering_fragment>"))return;const s="#include <colorspace_pars_fragment>";if(!t.fragmentShader.includes(s))return;t.fragmentShader=t.fragmentShader.replace(s,`${s}\n #include <common>\n #include <dithering_pars_fragment>`);const i=t.fragmentShader.lastIndexOf("}");if(i<0)return;t.fragmentShader=`${t.fragmentShader.slice(0,i)}\n #include <dithering_fragment>\n${t.fragmentShader.slice(i)}`,t.needsUpdate=!0}(b),this.outputPass=b,this.upscaleOutputPass=b instanceof je?b:null,this.composer.addPass(b),this.initialized=!0,this.refreshPostProcessEffectPassOrder()}resize(e,t,s,i){this.renderer.setPixelRatio(i),this.renderer.setSize(e,t),this.composer.setPixelRatio(s),this.composer.setSize(e,t);const a=e*s,r=t*s;this.dofPass.setSize(a,r),this.fxaaPass.setSize(a,r),this.fxaaPass.uniforms.resolution.value.set(1/a,1/r),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.fquadBlendAO.material.uniforms.tAlphaTest.value=this.gRenderTarget.textures[1],this.sceneColorRenderTarget.dispose(),this.sceneDepthRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget(),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0}setCamera(e){this.composer?.passes.forEach(t=>{t instanceof d?t.camera=e:t instanceof Te?t.renderCamera=e:(t instanceof we||t instanceof te)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e)}refreshPostProcessEffectPassOrder(){for(const e of this.postProcessEffects)e.pass??(e.pass=new Ae(e.material)),e.pass.enabled=e.enabled,this.composer.removePass(e.pass);for(const e of Oe){const t=this.getPostProcessEffectStageAnchorPass(e),s=null!=t?this.composer.passes.indexOf(t):this.composer.passes.length,i=this.postProcessEffects.filter(t=>t.stage===e).sort(qe);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}}removePostProcessEffect(e){null!=e.pass&&(this.composer.removePass(e.pass),e.pass.dispose())}async compileAsync(e){try{this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0;const t=[],s=[],i=[];this.collectGBufferRenderables(e,t,s,i),this.applyGBufferMaterials(Ve.opaque,t,s,i),await this.renderer.compileAsync(e,this.view.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(Ve.transparent,t,s,i),await this.renderer.compileAsync(e,this.view.camera),this.unapplyGBufferMaterials(),this.isDepthPrepassEnabled()&&(this.renderer.setRenderTarget(this.gRenderTarget),this.applyDepthPrepassMaterials(),await this.renderer.compileAsync(e,this.view.camera),this.unapplyDepthPrepassMaterials()),e===this.view.scene&&(this.renderer.setRenderTarget(this.gRenderTarget),await this.renderer.compileAsync(this.fquadBlendAO.mesh,this.fquadBlendAO.camera),this.renderer.setRenderTarget(this.sceneColorRenderTarget),await this.renderer.compileAsync(this.fquadCopySceneColor.mesh,this.fquadCopySceneColor.camera),this.transmissionColorRenderTarget&&this.transmissionCopyQuad&&(this.renderer.setRenderTarget(this.transmissionColorRenderTarget),await this.renderer.compileAsync(this.transmissionCopyQuad.mesh,this.transmissionCopyQuad.camera)),this.renderer.setRenderTarget(this.sceneDepthRenderTarget),await this.renderer.compileAsync(this.fquadCopySceneDepth.mesh,this.fquadCopySceneDepth.camera));const a=this.view.csm.lights[0]?.shadow.camera;null!=a&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,a),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}finally{this.unapplyGBufferMaterials(),this.unapplyDepthPrepassMaterials(),this.unapplyDepthMaterial(),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}}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&&!1!==this.view.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.view.scene.traverseVisible(t=>{t instanceof i&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,ze)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.composer.render(e),this.view.scene.matrixWorldAutoUpdate=!0,this.view.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}renderFrame(t,s,a){this.renderWhilePaused=a;const r=this.view.simulationTime,{hiddenWaterObjects:n,hiddenReflectors:o,hiddenSceneMapObjects:l,hiddenOccluded:h}=this;let p=!1;n.length=0,o.length=0,l.length=0;for(const e of h)e.visible=!0;h.length=0;const u=ze;Qe.multiplyMatrices(this.view.camera.projectionMatrix,this.view.camera.matrixWorldInverse),u.setFromProjectionMatrix(Qe);let c=!1,d=!1,f=!1,m=!1,g=!1;const M=this.frameGBufferMeshes,v=this.frameGBufferPhaseMasks,w=this.frameUnsupportedGBufferObjects,P=this.frameGBufferExcludedObjects;if(M.length=0,v.length=0,w.length=0,P.clear(),this.view.scene.traverseVisible(t=>{if(this.setupCsm(t),this.outlineEffect.apply(t),t instanceof Ce&&(c=!0),t instanceof i&&this.initCustomDepthMaterial(t),(t instanceof i||t instanceof e.Sprite)&&(this.initResolutionUniform(t.material),this.initNormalUniform(t.material),this.initShadowUniform(t,t.material),this.initLightVolumeUniform(t.material),null!=this.view.scene.environment&&He(t,e=>this.applyEnvMap(e)),!0===t.material?.userData?.hasBloom&&(p=!0)),(t instanceof i||t instanceof e.Sprite)&&t.visible&&(t.material?.userData?.water||t.material?.uniforms&&null!=t.material?.uniforms[ae])&&isObjectInFrustum(t,u)?(this.initDepthUniform(t.material),d=!0):t instanceof X&&(t.visible=!1,o.push(t)),(t instanceof i||t instanceof e.Sprite)&&t.material?.uniforms&&null!=t.material?.uniforms[de]&&isObjectInFrustum(t,u)&&t.material instanceof F&&this.initAoUniform(t.material),t instanceof i||t instanceof e.Sprite){let e=!1;He(t,t=>{this.usesSceneColorUniform(t)&&(this.initSceneColorUniform(t),e=!0,m||(m=this.usesShaderUniform(t,fe)),f||(f=this.usesShaderUniform(t,me)))}),e&&(l.push(t),g=!0)}if(t instanceof i&&t.material?.uniforms&&null!=t.material?.uniforms[ge])t.material.uniforms[ge].value=r;else if(t instanceof i&&Array.isArray(t.material))for(const e of t.material)e.uniforms&&null!=e.uniforms[ge]&&(e.uniforms[ge].value=r);if(P.has(t))for(let e=0;e<t.children.length;e++)P.add(t.children[e]);else if(Ke(t)){w.push(t);for(let e=0;e<t.children.length;e++)P.add(t.children[e])}else t instanceof i&&(M.push(t),v.push(this.getGBufferPhaseMask(t.material)))}),P.clear(),this.phasedRenderPass.enabled=w.length>0,this.bloomPass.enabled=p,!0===this.view.options.occlusionCulling?.enabled){for(const e of this.occlusionClusters)e.update();this.hideOccluded(h)}this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(Ve.opaque),this.updateRenderedOcclusionClusters(),this.renderer.render(this.queryScene,this.view.camera),this.aoPass.output=te.OUTPUT.Off;for(const e of this.postProcessEffects)if(e.pass?.enabled&&this.usesShaderUniform(e.pass.material,ae)){d=!0;break}f&&(this.transmissionCopyQuad.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.renderer.setRenderTarget(this.transmissionColorRenderTarget),this.transmissionCopyQuad.render(this.renderer)),m&&(this.fquadCopySceneColor.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.fquadCopySceneColor.render(this.renderer)),d&&(this.fquadCopySceneDepth.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.renderer.setRenderTarget(this.sceneDepthRenderTarget),this.fquadCopySceneDepth.render(this.renderer)),(d||g)&&this.renderer.setRenderTarget(this.gRenderTarget),l.length,n.forEach(e=>e.visible=!0),o.forEach(e=>e.visible=!0),l.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&c?(this.volumetricFogPass.update(this.view.camera,this.gRenderTarget,this.view.csm,this.view.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(r);try{this.view.paused&&!a||!this.view.running||(this.render(t),this.finishUpscalingFrame())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame(),this.renderWhilePaused=!1}}endGpuQuery(){this.collectGpuStats&&this.gpuPanel?.endQuery()}updateStatsPanels(e,t){const s=this.renderer.info.render.calls;s>this.maxDrawCalls&&(this.maxDrawCalls=s,setTimeout(()=>this.maxDrawCalls=10,5e3)),e.update(s,this.maxDrawCalls);const i=this.renderer.info.render.triangles;i>this.maxTriangles&&(this.maxTriangles=i,setTimeout(()=>this.maxTriangles=1e3,5e3)),t.update(i,this.maxTriangles)}setAnimationLoop(e){this.renderer.setAnimationLoop(e)}finishFrame(){try{this.renderer.info.reset(),this.renderOverlay()}catch(e){console.warn(e)}this.view.csm?.update()}beginFrame(e,t){this.cameraStartMatrix.copy(this.view.camera.matrixWorld);let s=!1;return this.collectGpuStats=t,t&&(null==this.gpuPanel&&navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(this.gpuPanel=e.addPanel(new Pe(this.renderer.getContext())),s=!0),this.gpuPanel?.startQuery()),this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.view.container.clientWidth,this.view.container.clientHeight),this.ssrPass.gpuPanel=t?this.gpuPanel:void 0,s}applyPostProcessSettings(t,s,i){const a=t.vignetteIntensity>b,n=y(t.temperature,t.temperatureTint),o=T(t.colorTint,t.colorTintIntensity),l=P(t),h=n||o||l||a,p=h&&t.tonemapMapping!==e.NoToneMapping,u=null!=i&&t.lutIntensity>b;h?(this.renderer.toneMapping=e.NoToneMapping,this.renderer.toneMappingExposure=1):(this.renderer.toneMapping=t.tonemapMapping,this.renderer.toneMappingExposure=t.tonemapExposure),null!=t.envTexture&&(this.view.scene.environment=this.getEnvironmentTexture(t.envTexture)),this.view.scene.environmentIntensity=t.envIntensity,h?(this.colorPass.whiteBalanceEnabled=n,this.colorPass.whiteBalanceScale=n?w(nt,t.temperature,t.temperatureTint):nt.set(1,1,1),this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=a,this.colorPass.colorTintEnabled=o,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,this.colorPass.colorGradingEnabled=l,this.colorPass.toneMapping=t.tonemapMapping,this.colorPass.toneMappingEnabled=p,this.colorPass.toneMappingExposure=t.tonemapExposure,this.colorPass.globalSaturation=t.globalSaturation,this.colorPass.globalContrast=t.globalContrast,this.colorPass.globalGamma=t.globalGamma,this.colorPass.globalGain=t.globalGain,this.colorPass.globalOffset=t.globalOffset,this.colorPass.shadowsSaturation=t.shadowsSaturation,this.colorPass.shadowsContrast=t.shadowsContrast,this.colorPass.shadowsGamma=t.shadowsGamma,this.colorPass.shadowsGain=t.shadowsGain,this.colorPass.shadowsOffset=t.shadowsOffset,this.colorPass.shadowsMax=t.shadowsMax,this.colorPass.midtonesSaturation=t.midtonesSaturation,this.colorPass.midtonesContrast=t.midtonesContrast,this.colorPass.midtonesGamma=t.midtonesGamma,this.colorPass.midtonesGain=t.midtonesGain,this.colorPass.midtonesOffset=t.midtonesOffset,this.colorPass.highlightsSaturation=t.highlightsSaturation,this.colorPass.highlightsContrast=t.highlightsContrast,this.colorPass.highlightsGamma=t.highlightsGamma,this.colorPass.highlightsGain=t.highlightsGain,this.colorPass.highlightsOffset=t.highlightsOffset,this.colorPass.highlightsMin=t.highlightsMin,this.colorPass.enabled=!0):this.colorPass.enabled=!1,s&&this.view.camera instanceof r?(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.lutPass.enabled=u,u&&(null!=i&&(i.flipY=!0,i.generateMipmaps=!1),this.lutPass.lut=i,this.lutPass.intensity=t.lutIntensity)}disposePipeline(){this.gRenderTarget?.dispose(),this.aoMaskDepthRenderTarget?.dispose(),this.sceneColorRenderTarget?.dispose(),this.sceneDepthRenderTarget?.dispose(),this.transmissionColorRenderTarget?.dispose(),this.transmissionCopyQuad?.material.dispose(),this.transmissionCopyQuad?.dispose();for(const e of this.postProcessEffects)null!=e.pass&&(this.composer?.removePass(e.pass),e.pass.dispose(),e.pass=null);this.volumetricFogPass?.dispose();const e=this.renderer.getContext();for(const t of this.occlusionClusters)e.deleteQuery(t.query);this.occlusionClusters.length=0;for(const e of this.hiddenOccluded)e.visible=!0;this.hiddenOccluded.length=0,this.initialized=!1}setWorldEnvironment(e){this.view.scene.environment=null==e?null:this.getEnvironmentTexture(e.source),this.view.scene.environmentIntensity=e?.intensity??1}resetPostProcessSettings(){this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.setBaseToneMapping(this.view.baseToneMapping,this.view.baseToneMappingExposure)}setBaseToneMapping(e,t){this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setSelectedObjects(e){this.outlinePass.selectedObjects=e}configureAmbientOcclusion(e,t,s){this.aoPass.enabled=e,this.aoPass.blendIntensity=t,this.aoPass.updateGtaoMaterial(s)}invalidateShadows(){this.renderer.shadowMap.needsUpdate=!0}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory()}isUpscalingEnabled(){return!0===this.view.options.upscaling?.enabled&&!0!==this.view.options.enableXR}}const We=new e.MeshDepthMaterial;var Ve;We.depthPacking=e.RGBADepthPacking,We.blending=e.NoBlending,We.side=e.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Ve||(Ve={}));const _e=(()=>{const t=new Uint8Array([255,255,255,255]),s=new e.DataTexture(t,1,1,e.RGBAFormat);return s.needsUpdate=!0,s})(),ke=(()=>{const t=new Uint8Array([0,0,0,255]),s=new e.DataTexture(t,1,1,e.RGBAFormat);return s.needsUpdate=!0,s})(),Ne=(()=>{const t=new Uint8Array([128,128,255,255]),s=new e.DataTexture(t,1,1,e.RGBAFormat);return s.needsUpdate=!0,s})();function qe(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function He(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}te.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.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!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:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const ze=new e.Frustum,$e=new e.Box3,Qe=new e.Matrix4;export function isObjectInFrustum(e,t){const s=$e.setFromObject(e);return t.intersectsBox(s)}const Je=new s,Ye=new t;function Xe(t,s,i=new e.Matrix3){return Ye.copy(t),Ye.x*=-1,Ye.y*=-1,Ye.z*=-1,s.isCubeTexture&&!1===s.isRenderTargetTexture&&(Ye.y*=-1,Ye.z*=-1),i.setFromMatrix4(Je.makeRotationFromEuler(Ye))}function Ke(t){return t instanceof e.Sprite||t.isPoints||t.isTransformControls||t.isTransformControlsGizmo||t instanceof i&&Ze(t,t.material)}function Ze(t,s){return null==s||(Array.isArray(s)?s.some(e=>Ze(t,e)):s instanceof e.RawShaderMaterial||s instanceof e.ShaderMaterial&&!(s instanceof F))}class et extends ee{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.cachedVisibility=[],this.toRender=[],this.needsSwap=!1}render(e,t,s,a,r){const n=e.autoClear;e.autoClear=!1;const o=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const p=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let u=0,c=this.toRender;if(c.length=0,this.scene.traverseVisible(e=>{const t=Ke(e);e instanceof i&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(u++,c.push(e))}),u>0)for(const t of c)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=n,s.depthTexture=p,this.scene.matrixWorldAutoUpdate=o,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class tt extends ee{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const st=["ambientLightColor","cameraNear","directionalLightShadows","directionalLights","directionalShadowMap","directionalShadowMatrix","fogColor","fogDensity","fogFar","fogNear","hemisphereLights","lightProbe","ltc_1","ltc_2","pointLightShadows","pointLights","pointShadowMap","pointShadowMatrix","rectAreaLights","shadowFar","spotLightMap","spotLightMatrix","spotLightShadows","spotLights","spotShadowMap"],it=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],at=H("fogColor");export class FogNode extends I{constructor(e,t=at){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),a=e.get(this.fogColor),r=e.get(k("fogFar")),n=e.get(k("fogNear")),o=e.get(k("fogDensity")),l=e.get(z(_.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${n}, ${r}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const rt=new e.MeshDepthMaterial({depthPacking:e.RGBADepthPacking});const nt=new e.Vector3(1,1,1);M.patchSetupMaterial();const ot=new F({color:C(0),position:J(C(0))});ot.visible=!1;/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -75,6 +75,7 @@ export interface ExperimentalWebGpuStaticDrawSet {
|
|
|
75
75
|
readonly label: string;
|
|
76
76
|
readonly drawCount: number;
|
|
77
77
|
readonly instanceCount: number;
|
|
78
|
+
updateTransforms(): void;
|
|
78
79
|
dispose(): void;
|
|
79
80
|
}
|
|
80
81
|
export interface WebGpuSceneCapabilitySummary {
|
|
@@ -163,9 +164,11 @@ export declare class ExperimentalWebGpuBackend implements RenderingBackendDriver
|
|
|
163
164
|
*/
|
|
164
165
|
resetViewHistory(): void;
|
|
165
166
|
compile(scene: THREE.Scene, camera: SupportedCamera): Promise<void>;
|
|
166
|
-
createStaticDrawSet(root: THREE.Object3D, label: string, allowUnsortedLateDraws?: boolean, onUnsupported?: 'throw' | 'skip'): ExperimentalWebGpuStaticDrawSet | null;
|
|
167
|
+
createStaticDrawSet(root: THREE.Object3D, label: string, allowUnsortedLateDraws?: boolean, onUnsupported?: 'throw' | 'skip', mutableTransforms?: boolean): ExperimentalWebGpuStaticDrawSet | null;
|
|
167
168
|
registerStaticSpatialObject(root: THREE.Object3D): import('@hology/webgpu-renderer').StaticSpatialObject;
|
|
168
169
|
render(scene: THREE.Scene, camera: SupportedCamera, timeSeconds: number): void;
|
|
170
|
+
prepareSceneGeometry(scene: THREE.Scene, camera: SupportedCamera): Promise<void>;
|
|
171
|
+
renderPresentationOnly(extensions: Iterable<WebGpuPresentationExtension>): void;
|
|
169
172
|
setMotionBlurOptions(options: MotionBlurOptions): void;
|
|
170
173
|
setSSROptions(options: SSROptions): void;
|
|
171
174
|
setGTAOOptions(options: GTAOOptions): void;
|