@hology/webgpu-renderer 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as three from 'three';
2
- import { Color, Vector2, Vector3, Vector4, Matrix3, Matrix4, Material, Texture, MaterialParameters, Object3D, PerspectiveCamera, OrthographicCamera, Scene, DirectionalLight } from 'three';
2
+ import { Color, Vector2, Vector3, Vector4, Matrix3, Matrix4, Material, Texture, MaterialParameters, DirectionalLight, Object3D, PerspectiveCamera, OrthographicCamera, Scene } from 'three';
3
3
  export { AmbientLight, BackSide, BatchedMesh, Bone, BoxGeometry, BufferAttribute, BufferGeometry, CanvasTexture, Color, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedArrayTexture as CompressedTextureArray, CubeTexture, Data3DTexture, DataArrayTexture, DataTexture, DepthTexture, DirectionalLight, DoubleSide, FrontSide, Group, HemisphereLight, InstancedMesh, MathUtils, Matrix4, Mesh, Object3D, OrthographicCamera, PerspectiveCamera, PlaneGeometry, PointLight, RepeatWrapping, Scene, Skeleton, SkinnedMesh, SphereGeometry, SpotLight, Texture, Vector2, Vector3, Vector4 } from 'three';
4
4
 
5
5
  interface ComputeKernelDescriptor {
@@ -78,6 +78,8 @@ interface WGSLShaderMaterialParameters extends MaterialParameters {
78
78
  storageBuffers?: Record<string, WGSLStorageBufferBinding>;
79
79
  vertexAttributes?: readonly WGSLVertexAttributeBinding[];
80
80
  primitiveTopology?: GPUPrimitiveTopology;
81
+ /** Hash mutable uniform values on every renderer update. */
82
+ uniformValuesAutoUpdate?: boolean;
81
83
  /** Render triangle meshes as one-pixel triangle edges, matching Three.js wireframe materials. */
82
84
  wireframe?: boolean;
83
85
  }
@@ -108,6 +110,19 @@ declare class WGSLShaderMaterial extends Material {
108
110
  private storageBufferListCache;
109
111
  private textureLayoutKeyDeviceCache;
110
112
  private textureLayoutKeyCache;
113
+ /**
114
+ * Whether the renderer should hash mutable uniform values while rendering.
115
+ * Disable this for materials whose uniform changes are explicitly invalidated
116
+ * through `uniformValuesNeedsUpdate`.
117
+ */
118
+ uniformValuesAutoUpdate: boolean;
119
+ /**
120
+ * Incremented by setting uniformValuesNeedsUpdate to true.
121
+ * Each renderer resource keeps its own observed version, so one invalidation
122
+ * safely updates forward, depth, shadow, and other material variants.
123
+ */
124
+ uniformValuesAutoVersion: number;
125
+ set uniformValuesNeedsUpdate(value: boolean);
111
126
  constructor(parameters: WGSLShaderMaterialParameters);
112
127
  getUniformLayout(): UniformLayout;
113
128
  setUniform(name: string, definition: WGSLShaderMaterialUniformInput): this;
@@ -162,6 +177,97 @@ declare class RenderGraph {
162
177
  private resolveExecutionOrder;
163
178
  }
164
179
 
180
+ interface TextureResource {
181
+ version: number;
182
+ width: number;
183
+ height: number;
184
+ depthOrArrayLayers: number;
185
+ format: GPUTextureFormat;
186
+ textureDimension: GPUTextureDimension;
187
+ viewDimension: GPUTextureViewDimension;
188
+ sampleType: GPUTextureSampleType;
189
+ samplerBindingType: GPUSamplerBindingType;
190
+ mipLevelCount: number;
191
+ texture: GPUTexture;
192
+ view: GPUTextureView;
193
+ sampler: GPUSampler;
194
+ }
195
+ interface ExtractedLightState {
196
+ ambient: Vector4;
197
+ hemisphere: ExtractedHemisphereLight | null;
198
+ directionals: ExtractedDirectionalLight[];
199
+ points: ExtractedPointLight[];
200
+ spots: ExtractedSpotLight[];
201
+ directional: ExtractedDirectionalLight | null;
202
+ point: ExtractedPointLight | null;
203
+ spot: ExtractedSpotLight | null;
204
+ }
205
+ interface ExtractedHemisphereLight {
206
+ direction: Vector3;
207
+ skyColor: Vector3;
208
+ groundColor: Vector3;
209
+ intensity: number;
210
+ }
211
+ interface ExtractedDirectionalLight {
212
+ sourceLight: DirectionalLight | null;
213
+ position: Vector3;
214
+ target: Vector3;
215
+ direction: Vector3;
216
+ color: Vector3;
217
+ intensity: number;
218
+ volumetricIntensity: number;
219
+ castShadow: boolean;
220
+ shadowBias: number;
221
+ shadowNormalBias: number;
222
+ shadowRadius: number;
223
+ shadowIntensity: number;
224
+ shadowMapSize: number;
225
+ shadowCameraLeft: number;
226
+ shadowCameraRight: number;
227
+ shadowCameraTop: number;
228
+ shadowCameraBottom: number;
229
+ shadowCameraNear: number;
230
+ shadowCameraFar: number;
231
+ }
232
+ interface ExtractedPointLight {
233
+ position: Vector3;
234
+ color: Vector3;
235
+ intensity: number;
236
+ volumetricIntensity: number;
237
+ range: number;
238
+ decay: number;
239
+ castShadow: boolean;
240
+ shadowBias: number;
241
+ shadowNormalBias: number;
242
+ shadowRadius: number;
243
+ shadowIntensity: number;
244
+ shadowMapSize: number;
245
+ shadowCameraNear: number;
246
+ shadowCameraFar: number;
247
+ }
248
+ interface ExtractedSpotLight {
249
+ position: Vector3;
250
+ direction: Vector3;
251
+ color: Vector3;
252
+ intensity: number;
253
+ volumetricIntensity: number;
254
+ range: number;
255
+ angle: number;
256
+ penumbra: number;
257
+ decay: number;
258
+ castShadow: boolean;
259
+ shadowBias: number;
260
+ shadowNormalBias: number;
261
+ shadowRadius: number;
262
+ shadowIntensity: number;
263
+ shadowMapSize: number;
264
+ shadowCameraNear: number;
265
+ shadowCameraFar: number;
266
+ shadowCameraFov: number;
267
+ }
268
+
269
+ /** Camera-visible lights collected during the renderer's scene extraction. */
270
+ type RendererExtractedLightState = ExtractedLightState;
165
271
  /**
166
272
  * Resolves a scene-authored Three material to a renderer-native WGSL material
167
273
  * without mutating the scene's material slots. Return `undefined` to use the
@@ -211,6 +317,16 @@ interface StaticDrawSet {
211
317
  dispose(): void;
212
318
  }
213
319
  interface RendererGraphBuilderContext {
320
+ /**
321
+ * Visible fog-volume marker objects collected during ordinary scene
322
+ * extraction. Passing this list to volumetric fog avoids another scene walk.
323
+ */
324
+ readonly fogVolumeObjects: readonly Object3D[];
325
+ /**
326
+ * Camera-visible lights collected during ordinary scene extraction. The
327
+ * ordering matches the renderer's shadow-array layers.
328
+ */
329
+ readonly extractedLights: RendererExtractedLightState;
214
330
  addDirectionalShadowPass(): void;
215
331
  addPointShadowPass(): void;
216
332
  addSpotShadowPass(): void;
@@ -487,6 +603,16 @@ interface VolumetricFogInputs {
487
603
  readonly depth: FrameGraphTextureHandle;
488
604
  /** Explicit volumes can be mixed with compatible scene marker objects. */
489
605
  readonly volumes?: readonly VolumetricFogVolumeSettings[];
606
+ /**
607
+ * Fog marker objects already collected by the renderer. When supplied, this
608
+ * list is authoritative and avoids traversing the scene for volumes.
609
+ */
610
+ readonly volumeObjects?: readonly Object3D[];
611
+ /**
612
+ * Lights already collected by the renderer. When supplied, this list is
613
+ * authoritative and avoids traversing the scene for lights.
614
+ */
615
+ readonly lights?: RendererExtractedLightState;
490
616
  }
491
617
  /**
492
618
  * Compute-driven froxel fog. Add it after opaque rendering and before the late
@@ -507,6 +633,8 @@ declare class VolumetricFogEffect {
507
633
  private readonly projectionInverse;
508
634
  private readonly viewProjectionInverse;
509
635
  private explicitVolumes;
636
+ private volumeObjects;
637
+ private extractedLights;
510
638
  private cascadeDirectionalLights;
511
639
  private compositePass;
512
640
  private readonly blurPassCache;
@@ -524,8 +652,11 @@ declare class VolumetricFogEffect {
524
652
  private writeVolume;
525
653
  private lightColor;
526
654
  private writeDirectional;
655
+ private writeExtractedDirectional;
527
656
  private writePoint;
657
+ private writeExtractedPoint;
528
658
  private writeSpot;
659
+ private writeExtractedSpot;
529
660
  private getResources;
530
661
  }
531
662
  /** WGSL appended to a material that calls rendererApplyVolumetricFog(). */
@@ -533,22 +664,6 @@ declare const VOLUMETRIC_FOG_MATERIAL_WGSL = "\nfn rendererSampleIntegratedFog(u
533
664
  /** Adds the froxel input; append VOLUMETRIC_FOG_MATERIAL_WGSL and call its helper in fsMain. */
534
665
  declare function configureVolumetricFogMaterial(material: WGSLShaderMaterial, resource?: string, boundsResource?: string): WGSLShaderMaterial;
535
666
 
536
- interface TextureResource {
537
- version: number;
538
- width: number;
539
- height: number;
540
- depthOrArrayLayers: number;
541
- format: GPUTextureFormat;
542
- textureDimension: GPUTextureDimension;
543
- viewDimension: GPUTextureViewDimension;
544
- sampleType: GPUTextureSampleType;
545
- samplerBindingType: GPUSamplerBindingType;
546
- mipLevelCount: number;
547
- texture: GPUTexture;
548
- view: GPUTextureView;
549
- sampler: GPUSampler;
550
- }
551
-
552
667
  interface WebGpuPMREMGeneratorContext {
553
668
  device: GPUDevice;
554
669
  getTextureResource(texture: Texture): TextureResource;
@@ -640,6 +755,12 @@ declare class WebGpuRenderer {
640
755
  /** Fast variants for MRT/non-default target format combinations. */
641
756
  private readonly forwardMaterialTargetFastCache;
642
757
  private readonly forwardMaterialFrameCache;
758
+ /**
759
+ * DrawCall objects are pooled and many draws share one MaterialResource.
760
+ * Once a resource has passed its structural/material/texture checks in an
761
+ * extraction, avoid repeating texture-list scans for every matching draw.
762
+ */
763
+ private readonly drawMaterialResourceFrameValidation;
643
764
  private readonly depthMaterialFastCache;
644
765
  private readonly sharedForwardPipelineCache;
645
766
  private readonly sharedForwardPipelinePromiseCache;
@@ -679,8 +800,15 @@ declare class WebGpuRenderer {
679
800
  private readonly vertexAttributeGroupCache;
680
801
  private readonly vertexAttributeGroupBufferKeyCache;
681
802
  private readonly compileDrawScratch;
682
- private readonly indirectSubmissionStreamsScratch;
803
+ private readonly dynamicIndirectSubmissionCache;
804
+ private readonly indirectStreamKeyCache;
805
+ private nextIndirectStreamKey;
806
+ private indirectBundleInvalidationVersion;
807
+ private readonly colorFormatsIdentityCache;
808
+ private readonly colorFormatsValueCache;
809
+ private nextColorFormatsId;
683
810
  private readonly renderBundleScratch;
811
+ private readonly indirectMaterialResourcesScratch;
684
812
  private readonly directBundleDrawStatsScratch;
685
813
  private readonly sortedOpaqueBatchesScratch;
686
814
  private readonly opaqueBatchPool;
@@ -706,6 +834,7 @@ declare class WebGpuRenderer {
706
834
  private readonly activeDirectionalLightsScratch;
707
835
  private readonly activePointLightsScratch;
708
836
  private readonly activeSpotLightsScratch;
837
+ private readonly fogVolumeObjectsScratch;
709
838
  private readonly resolvedMeshMaterialsScratch;
710
839
  private readonly extractedLightsScratch;
711
840
  private readonly extractedFrameScratch;
@@ -866,8 +995,13 @@ declare class WebGpuRenderer {
866
995
  private getShadowCameraBuffer;
867
996
  private getSharedShadowBindGroupForCameraBuffer;
868
997
  private buildIndirectSubmissionStreams;
998
+ private getIndirectStreamKey;
869
999
  private getOrCreateStaticIndirectSubmissionStreams;
870
1000
  private getOrCreateIndirectForwardBundle;
1001
+ private submitIndirectStreamDirect;
1002
+ private setRetainedIndirectBundleState;
1003
+ private getIndirectBundleHash;
1004
+ private getColorFormatsId;
871
1005
  private getDirectForwardBundleKey;
872
1006
  private getOrCreateDirectForwardBundle;
873
1007
  private getOrCreateStaticMaterialBundle;
@@ -1145,6 +1279,49 @@ declare class FXAAEffect {
1145
1279
  addPass(graph: FrameGraphBuilder, source: FrameGraphTextureHandle, options?: FXAACompositeOptions): FrameGraphTextureHandle;
1146
1280
  }
1147
1281
 
1282
+ type SMAAQualityPreset = "low" | "medium" | "high" | "ultra";
1283
+ type SMAAEdgeDetectionMode = "luma" | "color";
1284
+ interface SMAAOptions {
1285
+ /** Pattern-search budget. Defaults to `high` (16 orthogonal and 8 diagonal steps). */
1286
+ readonly quality?: SMAAQualityPreset;
1287
+ /** Perceptual edge threshold. Defaults to 0.08, which retains dark toon outlines. */
1288
+ readonly threshold?: number;
1289
+ /** Rejects edges weak relative to their neighborhood. Defaults to 0.5. */
1290
+ readonly localContrastAdaptation?: number;
1291
+ /** Luma is fastest; color retains isoluminant stylized edges. Defaults to `color`. */
1292
+ readonly edgeDetection?: SMAAEdgeDetectionMode;
1293
+ /** Corner rounding from 0 (preserve) to 1 (round). Defaults to 0.25. */
1294
+ readonly cornerRounding?: number;
1295
+ /** Optional contrast-adaptive sharpening, from 0 to 1. Defaults to 0. */
1296
+ readonly sharpness?: number;
1297
+ readonly targetPrefix?: string;
1298
+ }
1299
+ interface SMAACompositeOptions {
1300
+ readonly output?: FrameGraphTextureHandle;
1301
+ }
1302
+ /**
1303
+ * SMAA 1x with local contrast adaptation, accurate area classification,
1304
+ * diagonal detection, corner preservation, and optional fused sharpening.
1305
+ */
1306
+ declare class SMAAEffect {
1307
+ threshold: number;
1308
+ localContrastAdaptation: number;
1309
+ edgeDetection: SMAAEdgeDetectionMode;
1310
+ cornerRounding: number;
1311
+ sharpness: number;
1312
+ private readonly quality;
1313
+ private readonly targetPrefix;
1314
+ private readonly areaTexture;
1315
+ private readonly edgePasses;
1316
+ private readonly weightPasses;
1317
+ private readonly blendPasses;
1318
+ constructor(options?: SMAAOptions);
1319
+ addPass(graph: FrameGraphBuilder, source: FrameGraphTextureHandle, options?: SMAACompositeOptions): FrameGraphTextureHandle;
1320
+ dispose(): void;
1321
+ get searchSteps(): number;
1322
+ get diagonalSteps(): number;
1323
+ }
1324
+
1148
1325
  interface BloomOptions {
1149
1326
  /** Overall bloom contribution. Defaults to 0.9. */
1150
1327
  readonly strength?: number;
@@ -1264,4 +1441,4 @@ declare class OutlineEffect {
1264
1441
  dispose(): void;
1265
1442
  }
1266
1443
 
1267
- export { type BloomCompositeOptions, BloomEffect, type BloomOptions, ColorGradingEffect, type ColorGradingOptions, type ColorGradingRange, type ColorGradingVector, type CompiledNodeFullscreenShader, ComputeKernel, type ComputeKernelDescriptor, DEFAULT_WGSL_VERTEX_ATTRIBUTES, DepthOfFieldEffect, type DepthOfFieldOptions, type FXAACompositeOptions, FXAAEffect, type FXAAOptions, FrameGraphBuilder, type FrameGraphFullscreenPassDescriptor, type FrameGraphMaterialPassDescriptor, type FrameGraphNodeFullscreenPassDescriptor, type FrameGraphPassDescriptor, type FrameGraphTextureHandle, type GTAOCompositeOptions, type GTAODenoiseOptions, GTAOEffect, type GTAOInputs, type GTAOOptions, OutlineEffect, type OutlineInputs, type OutlineInstanceSelection, type OutlineOptions, RenderGraph, type RenderGraphContext, type RenderGraphExecutionObserver, type RenderGraphPass, type RendererColorTargetDescriptor, type RendererCustomPassContext, type RendererCustomPassDescriptor, type RendererFrameProfile, type RendererGraphBuilder, type RendererGraphBuilderContext, type RendererMaterialPassDescriptor, type RendererMaterialResolver, type RendererOptions, type RendererPassProfile, type RendererShadowMapDebugInfo, type RendererShadowMapDebugTextureInfo, type RendererTextureTargetDescriptor, type RendererVisibilityProfile, SSREffect, type SSRInputs, type SSROptions, type ShaderDefineValue, type ShaderDefines, type StaticDrawSet, type StaticDrawSetOptions, TemporalAAEffect, type TemporalAAOptions, type ToneMappingMode, type ToonOutlineParameters, type UniformDefinition, type UniformType, type UniformValue, VOLUMETRIC_FOG_MATERIAL_WGSL, type VolumetricFogBlurOptions, VolumetricFogEffect, type VolumetricFogInputs, type VolumetricFogOptions, type VolumetricFogScatteringMode, VolumetricFogVolumeObject, type VolumetricFogVolumeSettings, type WGSLGraphTextureDimension, type WGSLGraphTextureInput, type WGSLSceneTextureSemantic, WGSLShaderMaterial, type WGSLShaderMaterialParameters, type WGSLShaderMaterialUniform, type WGSLShaderMaterialUniformInput, type WGSLStorageBufferBinding, type WGSLStorageBufferVisibility, type WGSLSupportedVertexFormat, type WGSLVertexAttributeBinding, WebGpuPMREMGenerator, WebGpuRenderer, configureVolumetricFogMaterial };
1444
+ export { type BloomCompositeOptions, BloomEffect, type BloomOptions, ColorGradingEffect, type ColorGradingOptions, type ColorGradingRange, type ColorGradingVector, type CompiledNodeFullscreenShader, ComputeKernel, type ComputeKernelDescriptor, DEFAULT_WGSL_VERTEX_ATTRIBUTES, DepthOfFieldEffect, type DepthOfFieldOptions, type FXAACompositeOptions, FXAAEffect, type FXAAOptions, FrameGraphBuilder, type FrameGraphFullscreenPassDescriptor, type FrameGraphMaterialPassDescriptor, type FrameGraphNodeFullscreenPassDescriptor, type FrameGraphPassDescriptor, type FrameGraphTextureHandle, type GTAOCompositeOptions, type GTAODenoiseOptions, GTAOEffect, type GTAOInputs, type GTAOOptions, OutlineEffect, type OutlineInputs, type OutlineInstanceSelection, type OutlineOptions, RenderGraph, type RenderGraphContext, type RenderGraphExecutionObserver, type RenderGraphPass, type RendererColorTargetDescriptor, type RendererCustomPassContext, type RendererCustomPassDescriptor, type RendererFrameProfile, type RendererGraphBuilder, type RendererGraphBuilderContext, type RendererMaterialPassDescriptor, type RendererMaterialResolver, type RendererOptions, type RendererPassProfile, type RendererShadowMapDebugInfo, type RendererShadowMapDebugTextureInfo, type RendererTextureTargetDescriptor, type RendererVisibilityProfile, type SMAACompositeOptions, type SMAAEdgeDetectionMode, SMAAEffect, type SMAAOptions, type SMAAQualityPreset, SSREffect, type SSRInputs, type SSROptions, type ShaderDefineValue, type ShaderDefines, type StaticDrawSet, type StaticDrawSetOptions, TemporalAAEffect, type TemporalAAOptions, type ToneMappingMode, type ToonOutlineParameters, type UniformDefinition, type UniformType, type UniformValue, VOLUMETRIC_FOG_MATERIAL_WGSL, type VolumetricFogBlurOptions, VolumetricFogEffect, type VolumetricFogInputs, type VolumetricFogOptions, type VolumetricFogScatteringMode, VolumetricFogVolumeObject, type VolumetricFogVolumeSettings, type WGSLGraphTextureDimension, type WGSLGraphTextureInput, type WGSLSceneTextureSemantic, WGSLShaderMaterial, type WGSLShaderMaterialParameters, type WGSLShaderMaterialUniform, type WGSLShaderMaterialUniformInput, type WGSLStorageBufferBinding, type WGSLStorageBufferVisibility, type WGSLSupportedVertexFormat, type WGSLVertexAttributeBinding, WebGpuPMREMGenerator, WebGpuRenderer, configureVolumetricFogMaterial };