@hology/core 0.0.274 → 0.0.275

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.
@@ -51,7 +51,7 @@ export interface ResolvedWorldEnvironment {
51
51
  * material only while the experimental backend is drawing.
52
52
  */
53
53
  export declare function createNodeMaterialSignature(material: NodeShaderMaterial): string;
54
- export type NodeMaterialWebGpuDrawStage = 'opaque' | 'late' | 'outline';
54
+ export type NodeMaterialWebGpuDrawStage = 'opaque' | 'late' | 'outline' | 'sdfgi';
55
55
  type MRTOutputsResolverFn = (mat: NodeShaderMaterial, drawStage?: NodeMaterialWebGpuDrawStage) => (Vec3Node | Vec4Node)[] | undefined;
56
56
  export declare class NodeMaterialWebGpuResolver {
57
57
  private readonly webGpu;
@@ -60,6 +60,7 @@ export declare class NodeMaterialWebGpuResolver {
60
60
  private readonly cache;
61
61
  private readonly failedSignatures;
62
62
  private readonly mappedMaterialsCache;
63
+ private readonly sourcesByResolved;
63
64
  private readonly mappedMaterialsSignatures;
64
65
  private readonly observedNodeMaterials;
65
66
  private readonly outlineMaterials;
@@ -72,6 +73,8 @@ export declare class NodeMaterialWebGpuResolver {
72
73
  constructor(webGpu: NodeMaterialWebGpuModule, mrtResolver?: MRTOutputsResolverFn, environmentTextureResolver?: (texture: THREE.Texture) => THREE.Texture);
73
74
  setWorldEnvironment(environment: ResolvedWorldEnvironment | null): void;
74
75
  resolve(material: THREE.Material, drawStage?: NodeMaterialWebGpuDrawStage): ResolvedWebGpuMaterial | undefined;
76
+ /** Resolve a cached forward material to its attribute-only capture variant. */
77
+ resolveSDFGISurface(source: THREE.Material): ResolvedWebGpuMaterial | undefined;
75
78
  private getOrCreateOutlineMaterial;
76
79
  compileFullscreen(material: NodeShaderMaterial): CompiledNodeWebGpuFullscreen;
77
80
  private getOrCreateMappedNodeMaterial;
@@ -1,4 +1,4 @@
1
- import{skyPosition as e}from"../scene/sky.js";import*as a from"three";import{compileNodeWebGpuFullscreen as t,compileNodeShaderMaterialForWebGpu as n,NodeShaderMaterial as i,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 w,toonMaterial as I}from"three-shader-graph";import{StandardShader as S}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 L}from"../shader-nodes/scene-sample.js";const D={...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:{[L]:{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 F extends w{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 O extends w{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 P(e){return!1!==e.uniformValuesAutoUpdate}function j(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 $=new WeakMap,z=new WeakMap;export function createNodeMaterialSignature(e){const a=z.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 z.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.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 i)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&&X(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);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=P(a),t=j(a);return m.material.uniformValuesAutoUpdate=e,this.syncInheritedWorldEnvironmentSource(o,m),e||m.sourceUniformValuesAutoVersion!==t?(X(a,o),m.compiled.syncLiveUniforms(m.material.uniforms),_(o,m.material.uniforms),G(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&&K(o,m.compiled))return this.syncInheritedWorldEnvironmentSource(o,m),B(o,m),m.material;l&&X(a,o);const c=this.prepareWorldEnvironment(o),f=this.getNodeMaterialSignature(o,c);if(m?.signature===f&&K(o,m.compiled))return l?(m.material.uniformValuesAutoUpdate=P(a),m.compiled.syncLiveUniforms(m.material.uniforms),_(o,m.material.uniforms),G(o,m.material),m.sourceUniformValuesAutoVersion=j(a),m.material.uniformValuesAutoUpdate||(m.material.uniformValuesNeedsUpdate=!0)):B(o,m,!0),m.sourceVersion=a.version,m.worldEnvironmentRevision=this.worldEnvironmentRevision,m.material;try{const i=this.mrtResolver?.(o,t),h=!0===a.userData.isSky?s(o,{position:e,fog:o.fog}):o,d=n(h,"opaque"===t?{...D,arrays:r.arrays}:D,i),M=new this.webGpu.WGSLShaderMaterial({vertexShader:d.vertexShader,fragmentShader:d.fragmentShader,depthVertexShader:d.depthVertexShader,depthFragmentShader:d.depthFragmentShader,pointShadowVertexShader:d.pointShadowVertexShader,pointShadowFragmentShader:d.pointShadowFragmentShader,uniforms:d.uniforms,textures:d.textures,sceneTextures:d.sceneTextures,graphTextures:d.graphTextures,vertexAttributes:withThreeDefaultVertexAttributeValues(d.vertexAttributes),uniformValuesAutoUpdate:l?P(a):o.uniformValuesAutoUpdate,transparent:d.renderState?.transparent,alphaTest:d.renderState?.alphaTest,depthTest:d.renderState?.depthTest,depthWrite:d.renderState?.depthWrite,side:d.renderState?.side,wireframe:o.wireframe});M.name=a.name||o.name||a.uuid,M.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},M.uniformValuesAutoUpdate=l?P(a):o.uniformValuesAutoUpdate,function(e,a){if(null==e)return;Object.assign(a,e)}(d.renderState,M),null!=m&&(m.material.dispose(),this.cacheValues.delete(m));const v={signature:f,compiled:d,material:M,inheritsWorldEnvironment:c,sourceVersion:a.version,sourceUniformValuesAutoVersion:l?j(a):o.uniformValuesAutoVersion,worldEnvironmentRevision:this.worldEnvironmentRevision},y=p??new Map;return y.set(u,v),this.cache.set(o,y),this.cacheValues.add(v),_(o,M.uniforms),G(o,M),M}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),n=o.name||o.uuid;console.warn(`[Hology WebGPU experiment] Falling back for NodeShaderMaterial "${n}": ${t}`,{material:o,error:e})}return}}getOrCreateOutlineMaterial(e){let t=this.outlineMaterials.get(e);if(null==t){const n=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 F(v.position.xyz),h=new O(v.normal),w=n.transform?.multiplyVec(V(f,1))??V(f,1),S=g.modelViewMatrix.multiplyVec(w),x=M(g.normalMatrix.multiplyVec(h)),T=d(m(p(S.xyz),u(1e-4))).multiply(.5),E=S.xyz.add(x.multiplyScalar(o.multiply(T))),C=g.projectionMatrix.multiplyVec(S),b=g.projectionMatrix.multiplyVec(V(E,1)),U=(n.position??C).add(b.subtract(C)),A=c(I({color:s.rgb.multiplyScalar(u(1).subtract(r))}),e.outputOpacity.multiply(l));t=new i({color:A,position:U,opacity:e.outputOpacity,discard:n.discard,alphaTest:e.alphaTest,transparent:!0,fog:!1,outputEncoding:n.outputEncoding,uniforms:n.uniforms,uniformNodes:n.uniformNodes}),t.side=a.BackSide,t.depthTest=!0,t.depthWrite=!0,this.outlineMaterials.set(e,t),this.outlineUniformVersions.delete(e)}const n=e.userData?.outlineParameters,s=n?.thickness??.003,o=a.MathUtils.clamp(n?.darkening??.65,0,1),r=a.MathUtils.clamp(n?.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:{...D,uniformExpressions:{},graphTextures:{...D.graphTextures,[W]:{resource:"hologyNormalRoughness",dimension:"2d",sampleType:"float",sampler:"filtering"}}}}),n=a.syncLiveUniforms;return{...a,syncLiveUniforms(a){n(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 Q)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),n=this.mappedMaterialsCache.get(e),i=this.mappedMaterialsSignatures.get(e);if(null!=n&&i===t)return n;if(null!=n){n.dispose();const e=this.cache.get(n);if(null!=e){for(const a of e.values())a.material.dispose(),this.cacheValues.delete(a);this.cache.delete(n)}}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 S;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 H)t[a]=e[a];for(const a of J)t[a]=e[a];for(const a of Q)e[a]&&(t[a]=l(e[a]));t.clearcoatNormalScale=e.clearcoatNormalScale,t.iridescenceThicknessRange=new a.Vector2(...e.iridescenceThicknessRange),t.anisotropyRotation=e.anisotropyRotation}const n=t.build();return n.transparent=e.transparent,n.side=e.side,n.depthTest=e.depthTest,n.depthWrite=e.depthWrite,n.wireframe=e.wireframe,n}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 n=t.build();return n.transparent=e.transparent,n.side=e.side,n.depthTest=e.depthTest,n.depthWrite=e.depthWrite,n.wireframe=e instanceof a.MeshBasicMaterial&&e.wireframe,n}if(e instanceof a.MeshPhongMaterial){const a=new S;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}`;return a?`${t}|worldEnvironment:${this.worldEnvironmentRevision}`:t}prepareWorldEnvironment(e){var t,n,i,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,(n=e.uniforms).envMapIntensity??(n.envMapIntensity={value:1}),(i=e.uniforms).envMapRotation??(i.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 n=this.outlineMaterials.get(e);if(null!=n){const a=this.cache.get(n);if(null!=a){for(const e of a.values())e.material.dispose(),this.cacheValues.delete(e);this.cache.delete(n)}this.failedSignatures.delete(n),z.delete(n),n.dispose(),this.outlineMaterials.delete(e),this.outlineUniformVersions.delete(e)}this.failedSignatures.delete(e),z.delete(e)};this.observedNodeMaterials.set(e,a),e.addEventListener("dispose",a)}}function B(e,a,t=!1){const n=a.material;n.uniformValuesAutoUpdate=e.uniformValuesAutoUpdate,(t||e.uniformValuesAutoUpdate||a.sourceUniformValuesAutoVersion!==e.uniformValuesAutoVersion)&&(a.compiled.syncLiveUniforms(n.uniforms),_(e,n.uniforms),G(e,n),a.sourceUniformValuesAutoVersion=e.uniformValuesAutoVersion,n.uniformValuesAutoUpdate||(n.uniformValuesNeedsUpdate=!0))}function _(e,a){let t=$.get(a);if(null==t){t=[];for(const e in a){const n=a[e],i=n.value,s=!0===i?.isVector2?2:!0===i?.isVector3?3:!0===i?.isVector4?4:!0===i?.isColor?5:0;t.push({name:e,target:n,copyKind:s})}$.set(a,t)}const n=e.uniforms;for(let e=0;e<t.length;e++){const a=t[e],i=n[a.name];if(null==i)continue;const s=i.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 G(e,t){const n=e.uniforms.envMapIntensity,i=t.uniforms.envMapIntensity;null!=n&&null!=i&&(i.value=n.value);const s=e.uniforms.envMapRotation?.value,o=t.uniforms.envMapRotation?.value;s instanceof a.Matrix3&&o instanceof a.Matrix3&&o.copy(s)}function K(e,a){for(const t in a.textures){const n=a.textures[t],i=e.uniforms[t]?.value;if(q(i)&&i!==n)return!1}return!0}function q(e){return!0===e?.isTexture}const H=["ior","specularIntensity","clearcoat","clearcoatRoughness","iridescence","iridescenceIOR","transmission","thickness","attenuationDistance","dispersion","sheen","sheenRoughness","anisotropy"],J=["specularColor","attenuationColor","sheenColor"],Q=["specularIntensityMap","specularColorMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","iridescenceMap","iridescenceThicknessMap","transmissionMap","thicknessMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function X(e,t){if(e instanceof a.SpriteMaterial){const n=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),n.rotation=e.rotation,n.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 H)t.uniforms[a]&&(t.uniforms[a].value=e[a]);for(const n of J){const i=t.uniforms[n]?.value;i instanceof a.Vector3&&i.setFromColor(e[n])}const n=t.uniforms.clearcoatNormalScale?.value;n instanceof a.Vector2&&n.copy(e.clearcoatNormalScale),t.uniforms.iridescenceThicknessMin&&(t.uniforms.iridescenceThicknessMin.value=e.iridescenceThicknessRange[0]),t.uniforms.iridescenceThicknessMax&&(t.uniforms.iridescenceThicknessMax.value=e.iridescenceThicknessRange[1]);const i=t.uniforms.anisotropyDirection?.value;i instanceof a.Vector2&&i.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 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))}/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -0,0 +1,8 @@
1
+ import type { SDFGIOptions } from '@hology/webgpu-renderer';
2
+ /** Authored lighting controls; performance budgets belong to the rendering view. */
3
+ export interface SceneSDFGISettings {
4
+ enabled: boolean;
5
+ intensity: number;
6
+ }
7
+ export declare function resolveSDFGISettings(defaults: SDFGIOptions | false | undefined, runtime: SDFGIOptions, scene: SceneSDFGISettings | null): SDFGIOptions;
8
+ //# sourceMappingURL=sdfgi-settings.d.ts.map
@@ -0,0 +1,4 @@
1
+ export function resolveSDFGISettings(n,e,t){const i={...!1===n?{enabled:!1}:n??{},...e},l=!1!==i.enabled,a=t?.enabled??(null!=n&&!1!==n||!0===e.enabled),s=null!=t&&Number.isFinite(t.intensity)?Math.max(0,Math.min(10,t.intensity)):1;return{...i,enabled:l&&a,intensity:(i.intensity??1)*s}}/*
2
+ * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -0,0 +1,8 @@
1
+ import { type NodeShaderMaterial } from 'three-shader-graph';
2
+ /**
3
+ * Evaluate material attributes without evaluating the lit outputColor graph.
4
+ * Derivation retains deformation, discard, attributes, and texture expressions;
5
+ * current uniform objects are supplied explicitly rather than guessed by name.
6
+ */
7
+ export declare function deriveSDFGISurfaceGraph(source: NodeShaderMaterial): NodeShaderMaterial | null;
8
+ //# sourceMappingURL=sdfgi-surface-material.d.ts.map
@@ -0,0 +1,4 @@
1
+ import{DoubleSide as t}from"three";import{RgbaNode as e,RendererWorldPositionNode as u,RendererWorldNormalNode as r,deriveNodeShaderMaterial as o,float as n,isWgslFragmentCompiler as i,rgba as s,vec3 as l}from"three-shader-graph";class a extends e{constructor(t){super(),this.source=t}compile(e){const o=this.source,a=(o.outputAlbedo??l(0)).multiplyScalar(n(1).subtract(o.outputMetalness??n(0))),c=o.outputOpacity??n(1);if(!i(e))return{out:e.get(s(a,c))};const p=e.get(new u(l(0))),d=e.get(new r(l(0))),f=e.get(a),g=e.get(o.outputEmissive??l(0)),h=e.get(c),m=o.nodeMaterialDefinition.discard,$=null==m?null:e.get(m);return{chunk:`\n ${null==$?"":`if (${$}) { discard; }`}\n if (${h} < ${Math.max(o.alphaTest,.001)}) { discard; }\n sdfgiWriteSurface(${p}, ${d}, ${f}, ${g}, ${o.side===t});\n `,out:"vec4<f32>(0.0)"}}}export function deriveSDFGISurfaceGraph(t){if(null==t.outputAlbedo&&null==t.outputEmissive)return null;const e=o(t,{color:new a(t),opacity:n(1),discard:null,uniforms:t.uniforms,fog:!1,outputEncoding:!1,outputs:null});return e.alphaTest=0,e.fog=!1,e}/*
2
+ * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -4,8 +4,8 @@ import type { WorldEnvironmentState } from './environment.js';
4
4
  import type { RenderingBackendDriver } from './rendering-backend.js';
5
5
  import type { PostProcessEffectStage } from './post-process-effect.js';
6
6
  import type { DlssQualityMode } from './upscaling-pass.js';
7
- import type { BloomOptions, ColorGradingOptions, DepthOfFieldOptions, FXAAOptions, FrameGraphBuilder, GTAOOptions, GTAOQuality, OutlineOptions, OutlineInstanceSelection, MotionBlurOptions, MotionBlurOverride, MotionBlurOverrideHandle, SSROptions, RendererFrameProfile, RendererSceneCapture, SMAAOptions, TemporalAAOptions, VolumetricFogOptions, VolumetricFogQuality } from '@hology/webgpu-renderer';
8
- export type { RendererFrameProfile, RendererSceneCapture, RendererSceneCaptureOptions, RendererSceneCapturePostProcessContext, GTAOOptions, GTAOQuality, MotionBlurOptions, MotionBlurOverride, MotionBlurOverrideHandle, VolumetricFogOptions, VolumetricFogQuality } from '@hology/webgpu-renderer';
7
+ import type { BloomOptions, ColorGradingOptions, DepthOfFieldOptions, FXAAOptions, FrameGraphBuilder, GTAOOptions, GTAOQuality, OutlineOptions, OutlineInstanceSelection, MotionBlurOptions, MotionBlurOverride, MotionBlurOverrideHandle, SSROptions, SDFGIOptions, SDFGIStats, RendererFrameProfile, RendererSceneCapture, SMAAOptions, TemporalAAOptions, VolumetricFogOptions, VolumetricFogQuality } from '@hology/webgpu-renderer';
8
+ export type { SDFGICascadeOptions, SDFGIOptions, SDFGIStats, RendererFrameProfile, RendererSceneCapture, RendererSceneCaptureOptions, RendererSceneCapturePostProcessContext, GTAOOptions, GTAOQuality, SSROptions, MotionBlurOptions, MotionBlurOverride, MotionBlurOverrideHandle, VolumetricFogOptions, VolumetricFogQuality } from '@hology/webgpu-renderer';
9
9
  type SupportedCamera = THREE.PerspectiveCamera | THREE.OrthographicCamera;
10
10
  export type AntiAliasingMode = 'off' | 'fxaa' | 'smaa' | 'taa';
11
11
  export type ExperimentalWebGpuRenderGraphExtension = ((graph: FrameGraphBuilder, color: string) => void) & {
@@ -23,6 +23,8 @@ export type WebGpuPresentationExtensionContext = {
23
23
  };
24
24
  export type WebGpuPresentationExtension = (context: WebGpuPresentationExtensionContext) => void;
25
25
  export interface ExperimentalWebGpuPostProcessingOptions {
26
+ /** Experimental world-space indirect diffuse lighting. Disabled by default. */
27
+ readonly sdfgi?: false | SDFGIOptions;
26
28
  /** Request native DLSS-SR when supported by the host. Falls back to TAA. */
27
29
  readonly nativeUpscaling?: false | {
28
30
  readonly method: 'dlss';
@@ -111,6 +113,8 @@ export declare class ExperimentalWebGpuBackend implements RenderingBackendDriver
111
113
  private readonly antiAliasingState;
112
114
  private readonly directionalShadowState;
113
115
  private readonly nativeDlss;
116
+ private sdfgi;
117
+ private readonly createSDFGI;
114
118
  readonly kind: "webgpu";
115
119
  readonly canvas: HTMLCanvasElement;
116
120
  private renderScale;
@@ -138,6 +142,9 @@ export declare class ExperimentalWebGpuBackend implements RenderingBackendDriver
138
142
  setPresentationExtensions(extensions: Iterable<WebGpuPresentationExtension>): void;
139
143
  setEnableOutlines(enabled: boolean): void;
140
144
  setTiledLightingEnabled(enabled: boolean): void;
145
+ setSDFGIOptions(options: SDFGIOptions): void;
146
+ invalidateSDFGI(): void;
147
+ getSDFGIStats(): Readonly<SDFGIStats> | null;
141
148
  setDynamicBatchingEnabled(enabled: boolean): void;
142
149
  setSelectedObjects(objects: Iterable<THREE.Object3D>): void;
143
150
  setSelectedObjectInstances(selections: Iterable<OutlineInstanceSelection>): void;
@@ -160,6 +167,7 @@ export declare class ExperimentalWebGpuBackend implements RenderingBackendDriver
160
167
  registerStaticSpatialObject(root: THREE.Object3D): import('@hology/webgpu-renderer').StaticSpatialObject;
161
168
  render(scene: THREE.Scene, camera: SupportedCamera, timeSeconds: number): void;
162
169
  setMotionBlurOptions(options: MotionBlurOptions): void;
170
+ setSSROptions(options: SSROptions): void;
163
171
  setGTAOOptions(options: GTAOOptions): void;
164
172
  setAntiAliasingMode(mode: AntiAliasingMode): void;
165
173
  setGTAOQuality(quality: GTAOQuality): void;
@@ -1,4 +1,4 @@
1
- import*as e from"three";import{NodeMaterialWebGpuResolver as t}from"./node-material-webgpu-resolver.js";import{configureWebGpuRuntimeBindings as i}from"./webgpu-runtime-bridge.js";import{float as n,varyingTransformed as r,vec4 as a}from"three-shader-graph";import{NodeShaderMaterial as o}from"../shader-nodes/index.js";import{sceneMapUniformName as s}from"../shader-nodes/scene-sample.js";import{depthUniformName as l}from"../shader-nodes/depth.js";import{MATERIAL_FLAG_ALPHA_TEST as d,MATERIAL_FLAG_RECEIVE_DECALS as c}from"../shader-nodes/material-flags.js";import{createMotionVectorOutput as h}from"./motion-vector-node.js";export class ExperimentalWebGpuBackend{constructor(e,t,i,n,r,a,o,s,l,d,c,h,u,p,m,g,f,v,S,b,P,x){this.renderer=e,this.fallbackMaterial=t,this.nodeMaterialResolver=i,this.gBufferFallbackSource=n,this.bloom=r,this.fxaa=a,this.smaa=o,this.gtao=s,this.ssr=l,this.taa=d,this.motionBlur=c,this.volumetricFog=h,this.colorGrading=u,this.depthOfField=p,this.outline=m,this.postProcessEffects=g,this.renderGraphExtensions=f,this.presentationExtensions=v,this.antiAliasingState=S,this.directionalShadowState=b,this.nativeDlss=P,this.kind="webgpu",this.renderScale=1,this.pmremGenerator=null,this.pmremResults=new WeakMap,this.ownedPmremResults=new Set,this.warnedUnsupportedPostProcessStages=new Set,this.secondaryMotionPrepared=!1,this.canvas=x}static async probeAvailability(){if("undefined"==typeof navigator||!("gpu"in navigator))return{available:!1,reason:"The runtime does not expose navigator.gpu."};try{const e=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});return null==e?{available:!1,reason:"No WebGPU adapter is available."}:{available:!0,adapter:e}}catch(e){return{available:!1,reason:`Requesting a WebGPU adapter failed: ${e instanceof Error?e.message:String(e)}`}}}static async create(m={},g){const f=await import("@hology/webgpu-renderer");i({registerPipelineDiagnosticOrigin:f.registerPipelineDiagnosticOrigin,createComputeKernel:(e,t)=>new f.ComputeKernel(e,t),buildParticleLightingShaderHeader:f.buildParticleLightingShaderHeader});const v=document.createElement("canvas");v.dataset.hologyRenderer="webgpu-experimental";const S=new f.WGSLShaderMaterial({vertexShader:u,fragmentShader:p}),b=!1!==m.nativeUpscaling&&"dlss"===m.nativeUpscaling?.method,P=b?(await import("./native-dlss-upscaler.js")).createNativeDlssUpscaler(m.nativeUpscaling?.mode??"quality"):null,x=null!=P;S.side=f.DoubleSide;const w=f,y=null!=m.motionBlur&&!1!==m.motionBlur,D=!1!==m.gtao&&(null==m.gtao||!1!==m.gtao.temporal),M=!1!==m.volumetricFog&&(null==m.volumetricFog||!1!==m.volumetricFog.temporal),O=x?"off":b?"taa":null!=(E=m).antiAliasing?E.antiAliasing:null!=E.taa&&!1!==E.taa?"taa":null!=E.smaa&&!1!==E.smaa?"smaa":null!=E.fxaa&&!1!==E.fxaa?"fxaa":!1===E.taa?"off":"taa";var E;const F=null!=m.antiAliasing,C=y||D||M||(F||"taa"===O)||x;let L=null;const G=new t(w,(e,t)=>"opaque"===t?[e.outputColor.xyz.rgba(n(e.alphaTest>0?d:0).add(!1===e.userData.receiveDecals?0:c)),a((e.outputNormal??r.normal).multiplyScalar(.5).addScalar(.5),e.outputRoughness??n(1)),...C?[h(e)]:[]]:void 0,e=>L?.getEnvironmentTexture(e)??e),R=new e.MeshStandardMaterial({color:8688803,roughness:1});if(null==G.resolve(R,"opaque"))throw S.dispose(),R.dispose(),new Error("Failed to compile the WebGPU G-buffer fallback material.");const T=!1===m.gtao?null:new f.GTAOEffect({normalSpace:"view",...f.GTAO_PRESETS.high,...m.gtao??{}}),A=!1===m.ssr||null==m.ssr?null:new f.SSREffect({normalSpace:"view",resolutionScale:.5,...m.ssr??{}}),B=!1===m.bloom?null:new f.BloomEffect({threshold:1,strength:.9,radius:.2,...m.bloom??{}}),U=F||!1!==m.fxaa&&"fxaa"===O?new f.FXAAEffect(!1===m.fxaa?{}:m.fxaa):null,W=F||!1!==m.smaa&&"smaa"===O?new f.SMAAEffect(!1===m.smaa?{}:m.smaa):null,k=x||F||!1!==m.taa&&"taa"===O?new f.TemporalAAEffect({renderScale:1,...!1===m.taa?{}:m.taa}):null,V={mode:O},I=!1===m.motionBlur||null==m.motionBlur?null:new f.MotionBlurEffect(m.motionBlur),j=m.volumetricFog||void 0,N=!1===m.volumetricFog?null:new f.VolumetricFogEffect(void 0,{...f.VOLUMETRIC_FOG_PRESETS.high,maxDistance:64,spatialJitter:!0,scatteringIntensity:Math.PI,...j,temporal:!1!==j?.temporal&&{...f.VOLUMETRIC_FOG_PRESETS.high.temporal,...j?.temporal},blur:!1!==j?.blur&&{...!1===f.VOLUMETRIC_FOG_PRESETS.high.blur?{}:f.VOLUMETRIC_FOG_PRESETS.high.blur,depthAwareUpsample:!0,...j?.blur}}),H=!1===m.colorGrading?null:new f.ColorGradingEffect({enabled:!1,...m.colorGrading??{}}),$=!1===m.depthOfField?null:new f.DepthOfFieldEffect({enabled:!1,...m.depthOfField??{}}),_=!1===m.outline?null:new f.OutlineEffect({enabled:!1,...m.outline??{}}),q=[],z=new WeakMap,J=new Set,K=[],Z=[],Q=(e,t,i)=>{let n=i;const r=q.filter(e=>e.enabled&&e.stage===t).sort((e,t)=>e.priority-t.priority||e.id-t.id);for(const t of r){if(!(t.material instanceof o)){const e=`${t.id}:material`;J.has(e)||(J.add(e),console.warn(`[Hology WebGPU experiment] Skipping custom post-process effect ${t.id}: only NodeShaderMaterial effects are supported.`));continue}try{let i=z.get(t.material);null!=i&&i.version===t.material.version||(i={version:t.material.version,shader:G.compileFullscreen(t.material),diagnosticOrigin:{key:"post-process:"+String(t.material.userData.assetId??(t.material.name||t.material.uuid)),material:{name:t.material.name,uuid:t.material.uuid,version:t.material.version,assetId:t.material.userData.assetId,assetName:t.material.userData.assetName}}},z.set(t.material,i));const r=e.createColorTarget(`hologyCustomPostProcess${t.id}`);e.addNodeFullscreenPass({name:`HologyCustomPostProcess${t.id}`,diagnosticOrigin:i.diagnosticOrigin,shader:i.shader,inputOverrides:{[s]:n},outputs:r}),n=r}catch(e){const i=`${t.id}:compile:${t.material.version}`;J.has(i)||(J.add(i),console.warn(`[Hology WebGPU experiment] Skipping custom post-process effect ${t.id}: ${e instanceof Error?e.message:String(e)}`,e))}}return n},X={enabled:!0},Y=new f.WebGpuRenderer({canvas:v,fallbackMaterial:S,materialResolver:(e,t)=>G.resolve(e,t),invokeObjectRenderCallbacks:!1,hiZOcclusionCulling:!0,renderGraphProfiling:!1,sampleCount:1,multiDrawIndirect:!1,nativePostSubmit:P?.postSubmit,presentationOverlay:e=>{for(const t of Z)t(e)}});Y.setRenderScale("taa"===O?k?.renderScale??1:1),Y.setRenderGraphBuilder((e,t)=>{const i=new f.FrameGraphBuilder(t),n=i.createColorTarget("hologyNormalRoughness",{format:"rgba8unorm"}),r=C?i.createColorTarget("hologyMotionVectors",{format:"rgba16float"}):null;for(const e of K)"beforeScene"===e.stage&&e(i,i.sceneColor);X.enabled&&i.addDirectionalShadowPass(),i.addPointShadowPass(),i.addSpotShadowPass(),i.addDepthPrepass(),i.addHiZPasses(),i.addVisibilityPass(),i.addMaterialPass({name:"OpaqueGBufferPass",outputs:null==r?[i.sceneColor,n]:[i.sceneColor,n,r],drawStage:"opaque",loadDepth:!0}),i.addHiZHistoryPass("OpaqueGBufferPass");let a=i.sceneColor;if(T?.enabled){const e=T.addPasses(i,{depth:i.mainDepth,normal:n,velocity:r??void 0});a=T.addCompositePass(i,a,e)}null!=A&&(a=A.addPasses(i,{sceneColor:a,depth:i.mainDepth,normalRoughness:n}));const o=new Set(K.flatMap(e=>e.getSceneTextureReads?.()??[]));i.addSceneTextureCopyPass(a,{sceneColor:o.has("sceneColorSnapshot"),sceneDepth:o.has("sceneDepthSnapshot")||q.some(e=>e.enabled&&null!=e.material.uniforms[l])}),i.addLatePass(a);for(const e of K)null!=e.stage&&"afterScene"!==e.stage||e(i,a);a=Q(i,"beforeFog",a),null!=N&&(a=N.addPasses(i,{sceneColor:a,depth:i.mainDepth,velocity:r??void 0,volumeObjects:t.fogVolumeObjects,lights:t.extractedLights})),null!=I&&null!=r&&(a=I.addPass(i,a,r,i.mainDepth)),null!=B&&(a=B.addPass(i,a)),a=Q(i,"beforeOutline",a),null!=_&&(a=_.addPass(i,a)),a=Q(i,"beforeDepthOfField",a),null!=$&&(a=$.addPass(i,a,i.mainDepth)),a=Q(i,"beforeColorAdjustment",a),null!=H&&(a=H.addPass(i,a)),a=Q(i,"beforeAntiAliasing",a);let s="taa"===V.mode&&null!=k?k.addPass(i,a,i.mainDepth,r??void 0):a;"smaa"===V.mode&&null!=W?s=W.addPass(i,s):"fxaa"===V.mode&&null!=U&&(s=U.addPass(i,s)),s=Q(i,"beforeOutput",s);for(const e of K)"beforePresent"===e.stage&&e(i,s);!0===P?.enabled&&null!=r?P.addInputPass(i,s,r):i.present(s)});try{return await Y.initialize(g),L=new ExperimentalWebGpuBackend(Y,S,G,R,B,U,W,T,A,k,I,N,H,$,_,q,K,Z,V,X,P,v),L}catch(e){throw Y.destroy(),S.dispose(),G.dispose(),R.dispose(),T?.dispose(),W?.dispose(),I?.dispose(),N?.dispose(),_?.dispose(),e}}static supportsCamera(t){return t instanceof e.PerspectiveCamera||t instanceof e.OrthographicCamera}setSize(e,t,i,n=1){const r=this.canvas.width,a=this.canvas.height;let o=Math.min(1,Math.max(.25,n));if(!0===this.nativeDlss?.enabled){const n=Math.max(1,Math.floor(e*i)),r=Math.max(1,Math.floor(t*i));o=this.nativeDlss.getRenderScale(n,r)}const s=o!==this.renderScale;this.renderScale=o,this.renderer.setRenderScale(o),this.taa?.setRenderScale(o),this.renderer.setSize(e,t,i),(s||this.canvas.width!==r||this.canvas.height!==a)&&this.resetViewHistory()}initTexture(e){this.renderer.initTexture(e)}setPostProcessEffects(e){this.postProcessEffects.splice(0,this.postProcessEffects.length,...e);for(const t of e){if("beforeLut"!==t.stage)continue;const e=`${t.id}:${t.stage}`;this.warnedUnsupportedPostProcessStages.has(e)||(this.warnedUnsupportedPostProcessStages.add(e),console.warn(`[Hology WebGPU experiment] Skipping custom post-process effect ${t.id}: stage "${t.stage}" has no native WebGPU anchor.`))}}getDevice(){return this.renderer.getDevice()}createSceneCapture(e,t,i){return this.renderer.createSceneCapture(e,t,i)}setRenderGraphExtensions(e){this.renderGraphExtensions.length=0;for(const t of e)this.renderGraphExtensions.push(t)}setPresentationExtensions(e){this.presentationExtensions.length=0;for(const t of e)this.presentationExtensions.push(t)}setEnableOutlines(e){null!=this.outline&&(this.outline.enabled=e)}setTiledLightingEnabled(e){this.renderer.setTiledLightingEnabled(e)}setDynamicBatchingEnabled(e){this.renderer.setDynamicBatchingEnabled(e)}setSelectedObjects(e){this.outline?.setSelectedObjects(e)}setSelectedObjectInstances(e){this.outline?.setSelectedInstances(e)}setCascadedShadowRanges(e,t=[]){this.renderer.setCascadedShadowRanges(e,t),this.volumetricFog?.setCascadedDirectionalLights(t)}setDirectionalShadowUpdateOptions(e){this.renderer.setDirectionalShadowUpdateOptions(e)}invalidateDirectionalShadows(){this.renderer.invalidateDirectionalShadows()}setDirectionalShadowOptions(e,t){this.directionalShadowState.enabled=e,this.renderer.setDirectionalShadowsEnabled(e),this.renderer.setDirectionalShadowMapSize(t)}setWorldEnvironment(e){if(null==e)return void this.nodeMaterialResolver.setWorldEnvironment(null);const t=this.getEnvironmentTexture(e.source);this.nodeMaterialResolver.setWorldEnvironment({texture:t,intensity:e.intensity})}getEnvironmentTexture(t){if(t.mapping===e.CubeUVReflectionMapping)return t;let i=this.pmremResults.get(t);return null==i&&(this.pmremGenerator??(this.pmremGenerator=this.renderer.createPMREMGenerator()),i=this.pmremGenerator.fromEquirectangular(t),this.pmremResults.set(t,i),this.ownedPmremResults.add(i)),i.texture}resetViewHistory(){this.renderer.resetViewHistory(),this.taa?.reset(),this.motionBlur?.reset(),this.gtao?.reset(),this.volumetricFog?.reset(),this.nativeDlss?.reset()}async compile(e,t){if(!this.secondaryMotionPrepared){let t=!1;e.traverse(e=>{const i=e.userData.secondaryMotion?.regions;Array.isArray(i)&&i.some(e=>e.enabled)&&(t=!0)});const i=this.renderer.getDevice();if(t&&i){const{prepareSecondaryMotionRuntime:e}=await import("../secondary-motion/runtime.js");e(i),this.secondaryMotionPrepared=!0}}await this.renderer.compileAsync(e,t)}createStaticDrawSet(e,t,i=!1,n="skip"){this.renderer.setHiZOcclusionCullingEnabled(!0);const r=this.renderer.createStaticDrawSet(e,{label:t,onUnsupported:n,allowUnsortedLateDraws:i});return 0===r.drawCount?(r.dispose(),null):r}registerStaticSpatialObject(e){return this.renderer.registerStaticSpatialObject(e)}render(e,t,i){const n="taa"===this.antiAliasingState.mode?this.taa:null;this.volumetricFog?.setScene(e),this.renderer.setMotionVectorProjection(t.projectionMatrix),this.motionBlur?.prepareCamera(t,this.canvas.width,this.canvas.height,i),this.motionBlur?.requiresRendererHistoryReset()&&(this.renderer.resetViewHistory(),this.gtao?.reset(),this.volumetricFog?.reset()),n?.prepareCamera(t,this.canvas.width,this.canvas.height),this.nativeDlss?.prepareFrame(t);const r=!0===this.nativeDlss?.enabled?this.nativeDlss.jitter:null;this.motionBlur?.setJitterUv(n?.currentJitterUv.x??(null==r?0:r.x/Math.max(1,this.canvas.width*this.renderScale)),n?.currentJitterUv.y??(null==r?0:-r.y/Math.max(1,this.canvas.height*this.renderScale))),null!=r&&this.renderer.setProjectionJitter(r.x,r.y);let a=!1;try{this.renderer.render(e,t,i),a=!0}finally{null!=r&&this.renderer.clearProjectionJitter(),n?.finishCamera(t),a&&this.motionBlur?.commitCamera(),a&&this.nativeDlss?.finishFrame(t)}}setMotionBlurOptions(e){null!=this.motionBlur&&Object.assign(this.motionBlur.options,e)}setGTAOOptions(e){this.gtao?.setOptions(e)}setAntiAliasingMode(e){e!==this.antiAliasingState.mode&&("taa"===e&&null==this.taa||"smaa"===e&&null==this.smaa||"fxaa"===e&&null==this.fxaa?console.warn(`[Hology WebGPU experiment] Anti-aliasing mode "${e}" was not initialized. Set webgpuPostProcessing.antiAliasing in the initial rendering configuration to enable runtime switching.`):(this.antiAliasingState.mode=e,this.resetTemporalHistory()))}setGTAOQuality(e){this.gtao?.applyPreset(e)}setVolumetricFogOptions(e){this.volumetricFog?.setOptions(e)}setVolumetricFogQuality(e){this.volumetricFog?.applyPreset(e)}pushMotionBlurOverride(e){return this.motionBlur?.pushOverride(e)??null}invalidateObjectMotion(e){this.renderer.invalidateObjectMotion(e)}getLastFrameProfile(){return this.renderer.getLastFrameProfile()}setPostProcessState(e){null!=this.colorGrading&&(Object.assign(this.colorGrading.options,e??{enabled:!1}),this.colorGrading.options.enabled=!0===e?.enabled),null!=this.depthOfField&&(this.depthOfField.options.enabled=null!=e?.depthFocus||null!=e?.depthAperture||null!=e?.depthMaxBlur,this.depthOfField.options.focus=e?.depthFocus,this.depthOfField.options.aperture=e?.depthAperture,this.depthOfField.options.maxBlur=e?.depthMaxBlur)}setProfilingEnabled(e){this.renderer.setRenderGraphProfilingEnabled(e)}resetTemporalHistory(){this.taa?.reset(),this.motionBlur?.reset(),this.gtao?.reset(),this.volumetricFog?.reset(),this.renderer.resetViewHistory(),this.nativeDlss?.reset()}inspect(e,t){return inspectWebGpuScene(e,t,this.nodeMaterialResolver)}destroy(){this.nativeDlss?.dispose(),this.nodeMaterialResolver.dispose(),this.gBufferFallbackSource.dispose(),this.gtao?.dispose(),this.smaa?.dispose(),this.motionBlur?.dispose(),this.volumetricFog?.dispose();for(const e of this.ownedPmremResults)e.dispose();this.ownedPmremResults.clear(),this.renderer.destroy(),this.fallbackMaterial.dispose()}}export function inspectWebGpuScene(e,t,i){const n={meshes:0,skinnedMeshes:0,instancedMeshes:0,batchedMeshes:0,sprites:0,points:0,lines:0,missingPositionGeometry:0,transparentMaterials:0,shaderMaterialsReplaced:0,materialsReplaced:0,unsupportedCamera:ExperimentalWebGpuBackend.supportsCamera(t)?0:1};return e.traverse(e=>{if(e.isSprite)return void n.sprites++;if(e.isPoints)return void n.points++;if(e.isLine)return void n.lines++;if(!e.isMesh)return;const t=e;t.isBatchedMesh?n.batchedMeshes++:t.isInstancedMesh?n.instancedMeshes++:t.isSkinnedMesh?n.skinnedMeshes++:n.meshes++,null==t.geometry?.getAttribute("position")&&n.missingPositionGeometry++;const r=Array.isArray(t.material)?t.material:[t.material];for(const e of r){if(null==e)continue;e.transparent&&n.transparentMaterials++;const t=!0===e.isWGSLShaderMaterial||!0===e.isLineMaterial,r=!t&&!0===i?.canResolve(e);t||r||(n.materialsReplaced++,e.isShaderMaterial&&n.shaderMaterialsReplaced++)}}),n}export function formatWebGpuSceneCapabilitySummary(e){return`[Hology WebGPU experiment] ${JSON.stringify(e)}`}const u="\nstruct VertexInput {\n @location(0) position: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @location(2) uv: vec2<f32>,\n @location(3) color: vec4<f32>,\n#ifdef USE_SKINNING\n @location(4) skinIndex: vec4<u32>,\n @location(5) skinWeight: vec4<f32>,\n#endif\n @builtin(instance_index) instanceIndex: u32,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) worldPosition: vec3<f32>,\n @location(1) worldNormal: vec3<f32>,\n @location(2) color: vec4<f32>,\n};\n\n@vertex\nfn vsMain(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n#ifdef USE_SKINNING\n let localPosition = rendererSkinPosition(input.position, input.skinIndex, input.skinWeight);\n let localNormal = rendererSkinNormal(input.normal, input.skinIndex, input.skinWeight);\n#else\n let localPosition = input.position;\n let localNormal = input.normal;\n#endif\n let world = rendererWorldPosition(localPosition, input.instanceIndex);\n output.position = rendererClipPosition(localPosition, input.instanceIndex);\n output.worldPosition = world.xyz;\n output.worldNormal = rendererWorldNormal(localNormal, input.instanceIndex);\n output.color = input.color * rendererObjectColor(input.instanceIndex);\n return output;\n}\n",p="\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) worldPosition: vec3<f32>,\n @location(1) worldNormal: vec3<f32>,\n @location(2) color: vec4<f32>,\n};\n\nfn distanceAttenuation(distanceToLight: f32, cutoffDistance: f32, decayExponent: f32) -> f32 {\n var distanceFalloff = 1.0 / max(pow(distanceToLight, decayExponent), 0.01);\n if (cutoffDistance > 0.0) {\n let ratio = distanceToLight / cutoffDistance;\n let cutoff = clamp(1.0 - ratio * ratio * ratio * ratio, 0.0, 1.0);\n distanceFalloff *= cutoff * cutoff;\n }\n return distanceFalloff;\n}\n\n@fragment\nfn fsMain(input: VertexOutput) -> @location(0) vec4<f32> {\n let normal = normalize(input.worldNormal);\n let normalTint = normal * 0.5 + vec3<f32>(0.5);\n let base = mix(vec3<f32>(0.52, 0.58, 0.64), normalTint, 0.22) * input.color.rgb;\n var lighting = rendererIndirectDiffuse(normal) + vec3<f32>(0.08);\n var directionalLighting = vec3<f32>(0.0);\n let directionalCount = rendererDirectionalLightCount();\n\n for (var index: u32 = 0u; index < directionalCount; index = index + 1u) {\n let lightDirection = rendererDirectionalLightDirectionForLight(index);\n let shadow = rendererSampleDirectionalShadowForLightWithNormal(index, input.worldPosition, normal);\n directionalLighting += rendererDirectionalLightColorForLight(index) * max(dot(normal, lightDirection), 0.0) * shadow;\n }\n if (directionalCount > 0u) {\n lighting += directionalLighting / f32(directionalCount);\n }\n\n for (var index: u32 = 0u; index < rendererPointLightCount(); index = index + 1u) {\n let lightVector = rendererPointLightPositionForLight(index) - input.worldPosition;\n let distanceToLight = length(lightVector);\n let lightDirection = normalize(lightVector);\n let shadow = rendererSamplePointShadowForLightWithNormal(index, input.worldPosition, normal);\n lighting += rendererPointLightColorForLight(index) * max(dot(normal, lightDirection), 0.0) * distanceAttenuation(distanceToLight, rendererPointLightRangeForLight(index), rendererPointLightDecayForLight(index)) * shadow;\n }\n\n for (var index: u32 = 0u; index < rendererSpotLightCount(); index = index + 1u) {\n let lightVector = rendererSpotLightPositionForLight(index) - input.worldPosition;\n let distanceToLight = length(lightVector);\n let lightDirection = normalize(lightVector);\n let angleCos = dot(-lightDirection, rendererSpotLightDirectionForLight(index));\n let cone = smoothstep(rendererSpotLightConeCosForLight(index), rendererSpotLightPenumbraCosForLight(index), angleCos);\n let shadow = rendererSampleSpotShadowForLightWithNormal(index, input.worldPosition, normal);\n lighting += rendererSpotLightColorForLight(index) * max(dot(normal, lightDirection), 0.0) * cone * distanceAttenuation(distanceToLight, rendererSpotLightRangeForLight(index), rendererSpotLightDecayForLight(index)) * shadow;\n }\n\n return vec4<f32>(base * max(lighting, vec3<f32>(0.08)), input.color.a);\n}\n";/*
1
+ import*as e from"three";import{NodeMaterialWebGpuResolver as t}from"./node-material-webgpu-resolver.js";import{configureWebGpuRuntimeBindings as i}from"./webgpu-runtime-bridge.js";import{float as n,varyingTransformed as r,vec4 as s}from"three-shader-graph";import{NodeShaderMaterial as a}from"../shader-nodes/index.js";import{sceneMapUniformName as o}from"../shader-nodes/scene-sample.js";import{surfaceReflectionStepsUniformName as l}from"../shader-nodes/surface-reflection.js";import{depthUniformName as d}from"../shader-nodes/depth.js";import{MATERIAL_FLAG_ALPHA_TEST as c,MATERIAL_FLAG_RECEIVE_DECALS as h}from"../shader-nodes/material-flags.js";import{createMotionVectorOutput as u}from"./motion-vector-node.js";export class ExperimentalWebGpuBackend{constructor(e,t,i,n,r,s,a,o,l,d,c,h,u,p,m,g,f,v,S,b,w,P,x,y){this.renderer=e,this.fallbackMaterial=t,this.nodeMaterialResolver=i,this.gBufferFallbackSource=n,this.bloom=r,this.fxaa=s,this.smaa=a,this.gtao=o,this.ssr=l,this.taa=d,this.motionBlur=c,this.volumetricFog=h,this.colorGrading=u,this.depthOfField=p,this.outline=m,this.postProcessEffects=g,this.renderGraphExtensions=f,this.presentationExtensions=v,this.antiAliasingState=S,this.directionalShadowState=b,this.nativeDlss=w,this.sdfgi=P,this.createSDFGI=x,this.kind="webgpu",this.renderScale=1,this.pmremGenerator=null,this.pmremResults=new WeakMap,this.ownedPmremResults=new Set,this.warnedUnsupportedPostProcessStages=new Set,this.secondaryMotionPrepared=!1,this.canvas=y}static async probeAvailability(){if("undefined"==typeof navigator||!("gpu"in navigator))return{available:!1,reason:"The runtime does not expose navigator.gpu."};try{const e=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});return null==e?{available:!1,reason:"No WebGPU adapter is available."}:{available:!0,adapter:e}}catch(e){return{available:!1,reason:`Requesting a WebGPU adapter failed: ${e instanceof Error?e.message:String(e)}`}}}static async create(g={},f){const v=await import("@hology/webgpu-renderer");i({registerPipelineDiagnosticOrigin:v.registerPipelineDiagnosticOrigin,createComputeKernel:(e,t)=>new v.ComputeKernel(e,t),buildParticleLightingShaderHeader:v.buildParticleLightingShaderHeader});const S=document.createElement("canvas");S.dataset.hologyRenderer="webgpu-experimental";const b=new v.WGSLShaderMaterial({vertexShader:p,fragmentShader:m}),w=!1!==g.nativeUpscaling&&"dlss"===g.nativeUpscaling?.method,P=w?(await import("./native-dlss-upscaler.js")).createNativeDlssUpscaler(g.nativeUpscaling?.mode??"quality"):null,x=null!=P;b.side=v.DoubleSide;const y=v,D=null!=g.motionBlur&&!1!==g.motionBlur,F=!1!==g.gtao&&(null==g.gtao||!1!==g.gtao.temporal),O=!1!==g.volumetricFog&&(null==g.volumetricFog||!1!==g.volumetricFog.temporal),M=x?"off":w?"taa":null!=(C=g).antiAliasing?C.antiAliasing:null!=C.taa&&!1!==C.taa?"taa":null!=C.smaa&&!1!==C.smaa?"smaa":null!=C.fxaa&&!1!==C.fxaa?"fxaa":!1===C.taa?"off":"taa";var C;const E=null!=g.antiAliasing,G=D||F||O||(E||"taa"===M)||x;let L=null;const R=new t(y,(e,t)=>"opaque"===t?[e.outputColor.xyz.rgba(n(e.alphaTest>0?c:0).add(!1===e.userData.receiveDecals?0:h)),s((e.outputNormal??r.normal).multiplyScalar(.5).addScalar(.5),e.outputRoughness??n(1)),...G?[u(e)]:[]]:void 0,e=>L?.getEnvironmentTexture(e)??e),T=new e.MeshStandardMaterial({color:8688803,roughness:1});if(null==R.resolve(T,"opaque"))throw b.dispose(),T.dispose(),new Error("Failed to compile the WebGPU G-buffer fallback material.");const A=!1===g.gtao?null:new v.GTAOEffect({normalSpace:"view",...v.GTAO_PRESETS.high,...g.gtao??{}}),I=new v.SSREffect({normalSpace:"view",enabled:null!=g.ssr&&!1!==g.ssr,...g.ssr||{}}),B=!1===g.bloom?null:new v.BloomEffect({threshold:1,strength:.9,radius:.2,...g.bloom??{}}),U=E||!1!==g.fxaa&&"fxaa"===M?new v.FXAAEffect(!1===g.fxaa?{}:g.fxaa):null,k=E||!1!==g.smaa&&"smaa"===M?new v.SMAAEffect(!1===g.smaa?{}:g.smaa):null,V=x||E||!1!==g.taa&&"taa"===M?new v.TemporalAAEffect({renderScale:1,...!1===g.taa?{}:g.taa}):null,W={mode:M},j=!1===g.motionBlur||null==g.motionBlur?null:new v.MotionBlurEffect(g.motionBlur),N=g.volumetricFog||void 0,H=!1===g.volumetricFog?null:new v.VolumetricFogEffect(void 0,{...v.VOLUMETRIC_FOG_PRESETS.high,maxDistance:64,spatialJitter:!0,scatteringIntensity:Math.PI,...N,temporal:!1!==N?.temporal&&{...v.VOLUMETRIC_FOG_PRESETS.high.temporal,...N?.temporal},blur:!1!==N?.blur&&{...!1===v.VOLUMETRIC_FOG_PRESETS.high.blur?{}:v.VOLUMETRIC_FOG_PRESETS.high.blur,depthAwareUpsample:!0,...N?.blur}}),$=!1===g.colorGrading?null:new v.ColorGradingEffect({enabled:!1,...g.colorGrading??{}}),_=!1===g.depthOfField?null:new v.DepthOfFieldEffect({enabled:!1,...g.depthOfField??{}}),q=!1===g.outline?null:new v.OutlineEffect({enabled:!1,...g.outline??{}}),z=[],J=new WeakMap,K=new Set,Z=[],Q=[],X=(e,t,i)=>{let n=i;const r=z.filter(e=>e.enabled&&e.stage===t).sort((e,t)=>e.priority-t.priority||e.id-t.id);for(const t of r){if(!(t.material instanceof a)){const e=`${t.id}:material`;K.has(e)||(K.add(e),console.warn(`[Hology WebGPU experiment] Skipping custom post-process effect ${t.id}: only NodeShaderMaterial effects are supported.`));continue}try{let i=J.get(t.material);null!=i&&i.version===t.material.version||(i={version:t.material.version,shader:R.compileFullscreen(t.material),diagnosticOrigin:{key:"post-process:"+String(t.material.userData.assetId??(t.material.name||t.material.uuid)),material:{name:t.material.name,uuid:t.material.uuid,version:t.material.version,assetId:t.material.userData.assetId,assetName:t.material.userData.assetName}}},J.set(t.material,i));const r=e.createColorTarget(`hologyCustomPostProcess${t.id}`);e.addNodeFullscreenPass({name:`HologyCustomPostProcess${t.id}`,diagnosticOrigin:i.diagnosticOrigin,shader:i.shader,inputOverrides:{[o]:n},outputs:r}),n=r}catch(e){const i=`${t.id}:compile:${t.material.version}`;K.has(i)||(K.add(i),console.warn(`[Hology WebGPU experiment] Skipping custom post-process effect ${t.id}: ${e instanceof Error?e.message:String(e)}`,e))}}return n},Y={enabled:!0};let ee=null;const te=e=>{if(null!=ee)return ee;const t=g.sdfgi||{},i=new v.SDFGI(ie.getDevice(),{...t,...e});try{i.setSurfaceCaptureFactory(e=>new v.SDFGISurfaceCapture(ie,e,e=>R.resolveSDFGISurface(e)??null,e!==i))}catch(e){throw i.dispose(),e}return ee=i,i},ie=new v.WebGpuRenderer({canvas:S,fallbackMaterial:b,materialResolver:(e,t)=>{const i=R.resolve(e,t);if(null!=i&&"outline"!==t&&!0!==e.userData.isSky&&ee?.configureMaterial(i),null!=i){const e=i,t=e.uniforms[l];null!=t&&t.value!==I.surfaceRaySteps&&(t.value=I.surfaceRaySteps,e.uniformValuesNeedsUpdate=!0)}return i},invokeObjectRenderCallbacks:!1,hiZOcclusionCulling:!0,renderGraphProfiling:!1,sampleCount:1,multiDrawIndirect:!1,nativePostSubmit:P?.postSubmit,presentationOverlay:e=>{for(const t of Q)t(e)}});ie.setRenderScale("taa"===M?V?.renderScale??1:1),ie.setRenderGraphBuilder((e,t)=>{const i=new v.FrameGraphBuilder(t),n=i.createColorTarget("hologyNormalRoughness",{format:"rgba8unorm"}),r=G?i.createColorTarget("hologyMotionVectors",{format:"rgba16float"}):null;for(const e of Z)"beforeScene"===e.stage&&e(i,i.sceneColor);ee?.addPasses(i),Y.enabled&&i.addDirectionalShadowPass(),i.addPointShadowPass(),i.addSpotShadowPass(),i.addDepthPrepass(),i.addHiZPasses(),i.addVisibilityPass(),i.addMaterialPass({name:"OpaqueGBufferPass",dependsOn:null==ee?void 0:["SDFGIUpdate"],outputs:null==r?[i.sceneColor,n]:[i.sceneColor,n,r],drawStage:"opaque",loadDepth:!0}),i.addHiZHistoryPass("OpaqueGBufferPass");let s=i.sceneColor;if(A?.enabled){const e=A.addPasses(i,{depth:i.mainDepth,normal:n,velocity:r??void 0});s=A.addCompositePass(i,s,e)}I.enabled&&(s=I.addPasses(i,{sceneColor:s,depth:i.mainDepth,normalRoughness:n}));const a=new Set(Z.flatMap(e=>e.getSceneTextureReads?.()??[]));i.addSceneTextureCopyPass(s,{sceneColor:a.has("sceneColorSnapshot"),sceneDepth:a.has("sceneDepthSnapshot")||z.some(e=>e.enabled&&null!=e.material.uniforms[d])}),i.addLatePass(s);for(const e of Z)null!=e.stage&&"afterScene"!==e.stage||e(i,s);s=X(i,"beforeFog",s),null!=H&&(s=H.addPasses(i,{sceneColor:s,depth:i.mainDepth,velocity:r??void 0,volumeObjects:t.fogVolumeObjects,lights:t.extractedLights})),null!=j&&null!=r&&(s=j.addPass(i,s,r,i.mainDepth)),null!=B&&(s=B.addPass(i,s)),s=X(i,"beforeOutline",s),null!=q&&(s=q.addPass(i,s)),s=X(i,"beforeDepthOfField",s),null!=_&&(s=_.addPass(i,s,i.mainDepth)),s=X(i,"beforeColorAdjustment",s),null!=$&&(s=$.addPass(i,s)),s=X(i,"beforeAntiAliasing",s);let o="taa"===W.mode&&null!=V?V.addPass(i,s,i.mainDepth,r??void 0):s;"smaa"===W.mode&&null!=k?o=k.addPass(i,o):"fxaa"===W.mode&&null!=U&&(o=U.addPass(i,o)),o=X(i,"beforeOutput",o);for(const e of Z)"beforePresent"===e.stage&&e(i,o);!0===P?.enabled&&null!=r?P.addInputPass(i,o,r):i.present(o)});try{return await ie.initialize(f),null!=g.sdfgi&&!1!==g.sdfgi&&te(g.sdfgi),L=new ExperimentalWebGpuBackend(ie,b,R,T,B,U,k,A,I,V,j,H,$,_,q,z,Z,Q,W,Y,P,ee,te,S),L}catch(e){throw ee?.dispose(),ie.destroy(),b.dispose(),R.dispose(),T.dispose(),A?.dispose(),k?.dispose(),j?.dispose(),H?.dispose(),q?.dispose(),e}}static supportsCamera(t){return t instanceof e.PerspectiveCamera||t instanceof e.OrthographicCamera}setSize(e,t,i,n=1){const r=this.canvas.width,s=this.canvas.height;let a=Math.min(1,Math.max(.25,n));if(!0===this.nativeDlss?.enabled){const n=Math.max(1,Math.floor(e*i)),r=Math.max(1,Math.floor(t*i));a=this.nativeDlss.getRenderScale(n,r)}const o=a!==this.renderScale;this.renderScale=a,this.renderer.setRenderScale(a),this.taa?.setRenderScale(a),this.renderer.setSize(e,t,i),(o||this.canvas.width!==r||this.canvas.height!==s)&&this.resetViewHistory()}initTexture(e){this.renderer.initTexture(e)}setPostProcessEffects(e){this.postProcessEffects.splice(0,this.postProcessEffects.length,...e);for(const t of e){if("beforeLut"!==t.stage)continue;const e=`${t.id}:${t.stage}`;this.warnedUnsupportedPostProcessStages.has(e)||(this.warnedUnsupportedPostProcessStages.add(e),console.warn(`[Hology WebGPU experiment] Skipping custom post-process effect ${t.id}: stage "${t.stage}" has no native WebGPU anchor.`))}}getDevice(){return this.renderer.getDevice()}createSceneCapture(e,t,i){return this.renderer.createSceneCapture(e,t,i)}setRenderGraphExtensions(e){this.renderGraphExtensions.length=0;for(const t of e)this.renderGraphExtensions.push(t)}setPresentationExtensions(e){this.presentationExtensions.length=0;for(const t of e)this.presentationExtensions.push(t)}setEnableOutlines(e){null!=this.outline&&(this.outline.enabled=e)}setTiledLightingEnabled(e){this.renderer.setTiledLightingEnabled(e)}setSDFGIOptions(e){null==this.sdfgi&&!0===e.enabled&&(this.sdfgi=this.createSDFGI(e),this.renderer.invalidateMaterialResolution()),this.sdfgi?.setOptions(e)}invalidateSDFGI(){this.sdfgi?.invalidate()}getSDFGIStats(){return this.sdfgi?.stats??null}setDynamicBatchingEnabled(e){this.renderer.setDynamicBatchingEnabled(e)}setSelectedObjects(e){this.outline?.setSelectedObjects(e)}setSelectedObjectInstances(e){this.outline?.setSelectedInstances(e)}setCascadedShadowRanges(e,t=[]){this.renderer.setCascadedShadowRanges(e,t),this.volumetricFog?.setCascadedDirectionalLights(t),this.sdfgi?.setCascadedDirectionalLights(t)}setDirectionalShadowUpdateOptions(e){this.renderer.setDirectionalShadowUpdateOptions(e)}invalidateDirectionalShadows(){this.renderer.invalidateDirectionalShadows()}setDirectionalShadowOptions(e,t){this.directionalShadowState.enabled=e,this.renderer.setDirectionalShadowsEnabled(e),this.renderer.setDirectionalShadowMapSize(t)}setWorldEnvironment(e){if(null==e)return void this.nodeMaterialResolver.setWorldEnvironment(null);const t=this.getEnvironmentTexture(e.source);this.nodeMaterialResolver.setWorldEnvironment({texture:t,intensity:e.intensity})}getEnvironmentTexture(t){if(t.mapping===e.CubeUVReflectionMapping)return t;let i=this.pmremResults.get(t);return null==i&&(this.pmremGenerator??(this.pmremGenerator=this.renderer.createPMREMGenerator()),i=this.pmremGenerator.fromEquirectangular(t),this.pmremResults.set(t,i),this.ownedPmremResults.add(i)),i.texture}resetViewHistory(){this.renderer.resetViewHistory(),this.taa?.reset(),this.motionBlur?.reset(),this.gtao?.reset(),this.volumetricFog?.reset(),this.nativeDlss?.reset()}async compile(e,t){if(!this.secondaryMotionPrepared){let t=!1;e.traverse(e=>{const i=e.userData.secondaryMotion?.regions;Array.isArray(i)&&i.some(e=>e.enabled)&&(t=!0)});const i=this.renderer.getDevice();if(t&&i){const{prepareSecondaryMotionRuntime:e}=await import("../secondary-motion/runtime.js");e(i),this.secondaryMotionPrepared=!0}}await this.renderer.compileAsync(e,t)}createStaticDrawSet(e,t,i=!1,n="skip"){this.renderer.setHiZOcclusionCullingEnabled(!0);const r=this.renderer.createStaticDrawSet(e,{label:t,onUnsupported:n,allowUnsortedLateDraws:i});if(0===r.drawCount)return r.dispose(),null;if(null==this.sdfgi)return r;const s=this.sdfgi.registerStaticDrawRoot(e);return{label:r.label,drawCount:r.drawCount,instanceCount:r.instanceCount,dispose:()=>{s(),r.dispose()}}}registerStaticSpatialObject(e){return this.renderer.registerStaticSpatialObject(e)}render(e,t,i){this.sdfgi?.prepare(e,t);const n="taa"===this.antiAliasingState.mode?this.taa:null;this.volumetricFog?.setScene(e),this.renderer.setMotionVectorProjection(t.projectionMatrix),this.motionBlur?.prepareCamera(t,this.canvas.width,this.canvas.height,i),this.motionBlur?.requiresRendererHistoryReset()&&(this.renderer.resetViewHistory(),this.gtao?.reset(),this.volumetricFog?.reset()),n?.prepareCamera(t,this.canvas.width,this.canvas.height),this.nativeDlss?.prepareFrame(t);const r=!0===this.nativeDlss?.enabled?this.nativeDlss.jitter:null;this.motionBlur?.setJitterUv(n?.currentJitterUv.x??(null==r?0:r.x/Math.max(1,this.canvas.width*this.renderScale)),n?.currentJitterUv.y??(null==r?0:-r.y/Math.max(1,this.canvas.height*this.renderScale))),null!=r&&this.renderer.setProjectionJitter(r.x,r.y);let s=!1;try{this.renderer.render(e,t,i),s=!0}finally{null!=r&&this.renderer.clearProjectionJitter(),n?.finishCamera(t),s&&this.motionBlur?.commitCamera(),s&&this.nativeDlss?.finishFrame(t)}}setMotionBlurOptions(e){null!=this.motionBlur&&Object.assign(this.motionBlur.options,e)}setSSROptions(e){this.ssr?.setOptions(e)}setGTAOOptions(e){this.gtao?.setOptions(e)}setAntiAliasingMode(e){e!==this.antiAliasingState.mode&&("taa"===e&&null==this.taa||"smaa"===e&&null==this.smaa||"fxaa"===e&&null==this.fxaa?console.warn(`[Hology WebGPU experiment] Anti-aliasing mode "${e}" was not initialized. Set webgpuPostProcessing.antiAliasing in the initial rendering configuration to enable runtime switching.`):(this.antiAliasingState.mode=e,this.resetTemporalHistory()))}setGTAOQuality(e){this.gtao?.applyPreset(e)}setVolumetricFogOptions(e){this.volumetricFog?.setOptions(e)}setVolumetricFogQuality(e){this.volumetricFog?.applyPreset(e)}pushMotionBlurOverride(e){return this.motionBlur?.pushOverride(e)??null}invalidateObjectMotion(e){this.renderer.invalidateObjectMotion(e)}getLastFrameProfile(){return this.renderer.getLastFrameProfile()}setPostProcessState(e){null!=this.colorGrading&&(Object.assign(this.colorGrading.options,e??{enabled:!1}),this.colorGrading.options.enabled=!0===e?.enabled),null!=this.depthOfField&&(this.depthOfField.options.enabled=null!=e?.depthFocus||null!=e?.depthAperture||null!=e?.depthMaxBlur,this.depthOfField.options.focus=e?.depthFocus,this.depthOfField.options.aperture=e?.depthAperture,this.depthOfField.options.maxBlur=e?.depthMaxBlur)}setProfilingEnabled(e){this.renderer.setRenderGraphProfilingEnabled(e)}resetTemporalHistory(){this.taa?.reset(),this.motionBlur?.reset(),this.gtao?.reset(),this.volumetricFog?.reset(),this.renderer.resetViewHistory(),this.nativeDlss?.reset()}inspect(e,t){return inspectWebGpuScene(e,t,this.nodeMaterialResolver)}destroy(){this.sdfgi?.dispose(),this.nativeDlss?.dispose(),this.nodeMaterialResolver.dispose(),this.gBufferFallbackSource.dispose(),this.gtao?.dispose(),this.smaa?.dispose(),this.motionBlur?.dispose(),this.volumetricFog?.dispose();for(const e of this.ownedPmremResults)e.dispose();this.ownedPmremResults.clear(),this.renderer.destroy(),this.fallbackMaterial.dispose()}}export function inspectWebGpuScene(e,t,i){const n={meshes:0,skinnedMeshes:0,instancedMeshes:0,batchedMeshes:0,sprites:0,points:0,lines:0,missingPositionGeometry:0,transparentMaterials:0,shaderMaterialsReplaced:0,materialsReplaced:0,unsupportedCamera:ExperimentalWebGpuBackend.supportsCamera(t)?0:1};return e.traverse(e=>{if(e.isSprite)return void n.sprites++;if(e.isPoints)return void n.points++;if(e.isLine)return void n.lines++;if(!e.isMesh)return;const t=e;t.isBatchedMesh?n.batchedMeshes++:t.isInstancedMesh?n.instancedMeshes++:t.isSkinnedMesh?n.skinnedMeshes++:n.meshes++,null==t.geometry?.getAttribute("position")&&n.missingPositionGeometry++;const r=Array.isArray(t.material)?t.material:[t.material];for(const e of r){if(null==e)continue;e.transparent&&n.transparentMaterials++;const t=!0===e.isWGSLShaderMaterial||!0===e.isLineMaterial,r=!t&&!0===i?.canResolve(e);t||r||(n.materialsReplaced++,e.isShaderMaterial&&n.shaderMaterialsReplaced++)}}),n}export function formatWebGpuSceneCapabilitySummary(e){return`[Hology WebGPU experiment] ${JSON.stringify(e)}`}const p="\nstruct VertexInput {\n @location(0) position: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @location(2) uv: vec2<f32>,\n @location(3) color: vec4<f32>,\n#ifdef USE_SKINNING\n @location(4) skinIndex: vec4<u32>,\n @location(5) skinWeight: vec4<f32>,\n#endif\n @builtin(instance_index) instanceIndex: u32,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) worldPosition: vec3<f32>,\n @location(1) worldNormal: vec3<f32>,\n @location(2) color: vec4<f32>,\n};\n\n@vertex\nfn vsMain(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n#ifdef USE_SKINNING\n let localPosition = rendererSkinPosition(input.position, input.skinIndex, input.skinWeight);\n let localNormal = rendererSkinNormal(input.normal, input.skinIndex, input.skinWeight);\n#else\n let localPosition = input.position;\n let localNormal = input.normal;\n#endif\n let world = rendererWorldPosition(localPosition, input.instanceIndex);\n output.position = rendererClipPosition(localPosition, input.instanceIndex);\n output.worldPosition = world.xyz;\n output.worldNormal = rendererWorldNormal(localNormal, input.instanceIndex);\n output.color = input.color * rendererObjectColor(input.instanceIndex);\n return output;\n}\n",m="\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) worldPosition: vec3<f32>,\n @location(1) worldNormal: vec3<f32>,\n @location(2) color: vec4<f32>,\n};\n\nfn distanceAttenuation(distanceToLight: f32, cutoffDistance: f32, decayExponent: f32) -> f32 {\n var distanceFalloff = 1.0 / max(pow(distanceToLight, decayExponent), 0.01);\n if (cutoffDistance > 0.0) {\n let ratio = distanceToLight / cutoffDistance;\n let cutoff = clamp(1.0 - ratio * ratio * ratio * ratio, 0.0, 1.0);\n distanceFalloff *= cutoff * cutoff;\n }\n return distanceFalloff;\n}\n\n@fragment\nfn fsMain(input: VertexOutput) -> @location(0) vec4<f32> {\n let normal = normalize(input.worldNormal);\n let normalTint = normal * 0.5 + vec3<f32>(0.5);\n let base = mix(vec3<f32>(0.52, 0.58, 0.64), normalTint, 0.22) * input.color.rgb;\n var lighting = rendererIndirectDiffuse(normal) + vec3<f32>(0.08);\n var directionalLighting = vec3<f32>(0.0);\n let directionalCount = rendererDirectionalLightCount();\n\n for (var index: u32 = 0u; index < directionalCount; index = index + 1u) {\n let lightDirection = rendererDirectionalLightDirectionForLight(index);\n let shadow = rendererSampleDirectionalShadowForLightWithNormal(index, input.worldPosition, normal);\n directionalLighting += rendererDirectionalLightColorForLight(index) * max(dot(normal, lightDirection), 0.0) * shadow;\n }\n if (directionalCount > 0u) {\n lighting += directionalLighting / f32(directionalCount);\n }\n\n for (var index: u32 = 0u; index < rendererPointLightCount(); index = index + 1u) {\n let lightVector = rendererPointLightPositionForLight(index) - input.worldPosition;\n let distanceToLight = length(lightVector);\n let lightDirection = normalize(lightVector);\n let shadow = rendererSamplePointShadowForLightWithNormal(index, input.worldPosition, normal);\n lighting += rendererPointLightColorForLight(index) * max(dot(normal, lightDirection), 0.0) * distanceAttenuation(distanceToLight, rendererPointLightRangeForLight(index), rendererPointLightDecayForLight(index)) * shadow;\n }\n\n for (var index: u32 = 0u; index < rendererSpotLightCount(); index = index + 1u) {\n let lightVector = rendererSpotLightPositionForLight(index) - input.worldPosition;\n let distanceToLight = length(lightVector);\n let lightDirection = normalize(lightVector);\n let angleCos = dot(-lightDirection, rendererSpotLightDirectionForLight(index));\n let cone = smoothstep(rendererSpotLightConeCosForLight(index), rendererSpotLightPenumbraCosForLight(index), angleCos);\n let shadow = rendererSampleSpotShadowForLightWithNormal(index, input.worldPosition, normal);\n lighting += rendererSpotLightColorForLight(index) * max(dot(normal, lightDirection), 0.0) * cone * distanceAttenuation(distanceToLight, rendererSpotLightRangeForLight(index), rendererSpotLightDecayForLight(index)) * shadow;\n }\n\n return vec4<f32>(base * max(lighting, vec3<f32>(0.08)), input.color.a);\n}\n";/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1,3 +1,5 @@
1
+ import { type SceneSDFGISettings } from './rendering/sdfgi-settings.js';
2
+ export type { SceneSDFGISettings } from './rendering/sdfgi-settings.js';
1
3
  import * as THREE from "three";
2
4
  import type { DirectionalShadowUpdateOptions } from "@hology/webgpu-renderer";
3
5
  export type { DirectionalShadowUpdateOptions } from "@hology/webgpu-renderer";
@@ -18,14 +20,14 @@ import { Cluster } from "./rendering/cluster-generator.js";
18
20
  import { LightVolume } from "./rendering/light-probes/light-volume-capture.js";
19
21
  import { type PostProcessMaterialSource } from "./shader/post-process-shader.js";
20
22
  import { type UpscalingOptions } from "./rendering/upscaling-pass.js";
21
- import { type AntiAliasingMode, type ExperimentalWebGpuPostProcessingOptions, type GTAOOptions, type GTAOQuality, type MotionBlurOptions, type MotionBlurOverride, type MotionBlurOverrideHandle, type RendererFrameProfile, type ExperimentalWebGpuRenderGraphExtension, type WebGpuPresentationExtension, type RendererSceneCapture, type VolumetricFogOptions, type VolumetricFogQuality } from './rendering/webgpu-experimental-backend.js';
23
+ import { type AntiAliasingMode, type ExperimentalWebGpuPostProcessingOptions, type SSROptions, type GTAOOptions, type GTAOQuality, type SDFGIOptions, type SDFGIStats, type MotionBlurOptions, type MotionBlurOverride, type MotionBlurOverrideHandle, type RendererFrameProfile, type ExperimentalWebGpuRenderGraphExtension, type WebGpuPresentationExtension, type RendererSceneCapture, type VolumetricFogOptions, type VolumetricFogQuality } from './rendering/webgpu-experimental-backend.js';
22
24
  import type { WorldEnvironmentState } from './rendering/environment.js';
23
25
  import type { VfxBackendPreference } from './effects/vfx/gpu-sprite-compiler.js';
24
26
  import { type GraphicsRuntime } from './rendering/graphics-runtime.js';
25
27
  export { GraphicsRuntime } from './rendering/graphics-runtime.js';
26
28
  export type { UpscalingOptions } from "./rendering/upscaling-pass.js";
27
29
  export type { AntiAliasingMode, ExperimentalWebGpuPostProcessingOptions, ExperimentalWebGpuRenderGraphExtension, WebGpuPresentationExtension, WebGpuPresentationExtensionContext, RendererSceneCapture, RendererSceneCaptureOptions, RendererSceneCapturePostProcessContext } from './rendering/webgpu-experimental-backend.js';
28
- export type { GTAOOptions, GTAOQuality, MotionBlurOptions, MotionBlurOverride, MotionBlurOverrideHandle, VolumetricFogOptions, VolumetricFogQuality } from './rendering/webgpu-experimental-backend.js';
30
+ export type { SSROptions, GTAOOptions, GTAOQuality, SDFGICascadeOptions, SDFGIOptions, SDFGIStats, MotionBlurOptions, MotionBlurOverride, MotionBlurOverrideHandle, VolumetricFogOptions, VolumetricFogQuality } from './rendering/webgpu-experimental-backend.js';
29
31
  /** Renderer requested by a view. `webgpu-experimental` is a deprecated alias. */
30
32
  export type RenderingBackend = 'webgl' | 'webgpu' | 'webgpu-experimental';
31
33
  export type ActiveRenderingBackend = 'webgl' | 'webgpu';
@@ -339,7 +341,17 @@ export declare class RenderingView {
339
341
  setDirectionalShadowUpdateOptions(options: DirectionalShadowUpdateOptions): void;
340
342
  invalidateDirectionalShadows(): void;
341
343
  setDirectionalShadowOptions(options: DirectionalShadowOptions): void;
344
+ setSSROptions(options: SSROptions): void;
342
345
  setGTAOOptions(options: GTAOOptions): void;
346
+ private sdfgiRuntimeOptions;
347
+ private sceneSDFGISettings;
348
+ /** Runtime/player quality overrides, combined with the scene's authored lighting. */
349
+ setSDFGIOptions(options: SDFGIOptions): void;
350
+ /** Null restores project defaults when a scene's World Environment is removed. */
351
+ setSceneSDFGISettings(settings: SceneSDFGISettings | null): void;
352
+ private syncSDFGISettings;
353
+ invalidateSDFGI(): void;
354
+ getSDFGIStats(): Readonly<SDFGIStats> | null;
343
355
  configureAmbientOcclusion(enabled: boolean, blendIntensity?: number, options?: Record<string, unknown>): void;
344
356
  invalidateShadows(): void;
345
357
  initTexture(texture: Texture): void;