three-gpu-pathtracer 0.0.24 → 0.0.26

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.
Files changed (73) hide show
  1. package/README.md +53 -530
  2. package/build/index.module.js +262 -50
  3. package/build/index.module.js.map +1 -1
  4. package/build/index.umd.cjs +261 -48
  5. package/build/index.umd.cjs.map +1 -1
  6. package/package.json +29 -11
  7. package/src/core/WebGLPathTracer.js +8 -0
  8. package/src/core/utils/sceneUpdateUtils.js +8 -12
  9. package/src/detectors/PrecisionMaterial.js +9 -9
  10. package/src/index.js +1 -0
  11. package/src/objects/PhysicalSpotLight.js +2 -0
  12. package/src/shader/bsdf/bsdf_functions.glsl.js +0 -1
  13. package/src/textures/BlueNoiseTexture.js +6 -6
  14. package/src/textures/ProceduralEquirectTexture.js +8 -7
  15. package/src/textures/turquinMetal.png +0 -0
  16. package/src/uniforms/EquirectHdrInfoUniform.js +9 -4
  17. package/src/uniforms/FloatAttributeTextureArray.js +11 -11
  18. package/src/uniforms/MaterialsTexture.js +9 -9
  19. package/src/webgpu/API.md +762 -0
  20. package/src/webgpu/AtlasTexture.js +471 -0
  21. package/src/webgpu/BlurredEnvMapGenerator.js +129 -0
  22. package/src/webgpu/EquirectBackgroundInfo.js +97 -0
  23. package/src/webgpu/EquirectHdrInfoNode.js +151 -0
  24. package/src/webgpu/LightsInfoNode.js +224 -0
  25. package/src/webgpu/MegaKernelPathTracer.js +277 -0
  26. package/src/webgpu/PathTracerBackend.js +216 -0
  27. package/src/webgpu/TurquinTexture.js +169 -0
  28. package/src/webgpu/WaveFrontPathTracer.js +586 -0
  29. package/src/webgpu/WebGPUPathTracer.js +1302 -0
  30. package/src/webgpu/compute/ComputeKernel.js +92 -0
  31. package/src/webgpu/compute/CopyBufferKernel.js +40 -0
  32. package/src/webgpu/compute/PathTracerMegaKernel.js +470 -0
  33. package/src/webgpu/compute/SampleDebugKernel.js +51 -0
  34. package/src/webgpu/compute/TallySampleCountsKernel.js +111 -0
  35. package/src/webgpu/compute/ZeroOutBufferKernel.js +35 -0
  36. package/src/webgpu/compute/ZeroOutKernel.js +31 -0
  37. package/src/webgpu/compute/wavefront/LogicKernel.js +349 -0
  38. package/src/webgpu/compute/wavefront/MaterialKernel.js +371 -0
  39. package/src/webgpu/compute/wavefront/PopulatePixelIndicesKernel.js +72 -0
  40. package/src/webgpu/compute/wavefront/QueueLengthToDispatchKernel.js +38 -0
  41. package/src/webgpu/compute/wavefront/ResetSlotsKernel.js +66 -0
  42. package/src/webgpu/compute/wavefront/TraceRayKernel.js +71 -0
  43. package/src/webgpu/compute/wavefront/TraceShadowRayKernel.js +67 -0
  44. package/src/webgpu/compute/wavefront/structs.js +155 -0
  45. package/src/webgpu/constants.js +62 -0
  46. package/src/webgpu/denoise/OIDNDenoiser.js +431 -0
  47. package/src/webgpu/index.d.ts +176 -0
  48. package/src/webgpu/index.js +11 -0
  49. package/src/webgpu/materials/GltfCompliantMaterial.js +608 -0
  50. package/src/webgpu/materials/GraphMaterial.js +331 -0
  51. package/src/webgpu/materials/PathtracingMaterial.js +89 -0
  52. package/src/webgpu/materials/RenderToScreenMaterial.js +150 -0
  53. package/src/webgpu/materials/debug/AtlasDebugMaterial.js +41 -0
  54. package/src/webgpu/materials/debug/SampleDensityMaterial.js +61 -0
  55. package/src/webgpu/nodes/PathtracerBVHComputeData.js +1037 -0
  56. package/src/webgpu/nodes/debugBounds.wgsl.js +228 -0
  57. package/src/webgpu/nodes/eon.wgsl.js +262 -0
  58. package/src/webgpu/nodes/ggx.wgsl.js +190 -0
  59. package/src/webgpu/nodes/lights.wgsl.js +203 -0
  60. package/src/webgpu/nodes/material.wgsl.js +990 -0
  61. package/src/webgpu/nodes/rand/bluedither.wgsl.js +92 -0
  62. package/src/webgpu/nodes/rand/pcg.wgsl.js +81 -0
  63. package/src/webgpu/nodes/rand/sobol.wgsl.js +287 -0
  64. package/src/webgpu/nodes/random.wgsl.js +20 -0
  65. package/src/webgpu/nodes/reset.wgsl.js +21 -0
  66. package/src/webgpu/nodes/sampling.wgsl.js +193 -0
  67. package/src/webgpu/nodes/sheen.wgsl.js +148 -0
  68. package/src/webgpu/nodes/structs.wgsl.js +272 -0
  69. package/src/webgpu/nodes/utils.wgsl.js +366 -0
  70. package/src/webgpu/shims/ArrayCameraShim.js +74 -0
  71. package/src/webgpu/shims/EquirectCameraShim.js +37 -0
  72. package/src/webgpu/shims/PhysicalCameraShim.js +151 -0
  73. package/src/webgpu/upscale/FSRUpscaler.js +108 -0
package/package.json CHANGED
@@ -1,18 +1,29 @@
1
1
  {
2
2
  "name": "three-gpu-pathtracer",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.",
5
5
  "module": "src/index.js",
6
6
  "main": "build/index.umd.cjs",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./src/index.js",
10
+ "require": "./build/index.umd.cjs"
11
+ },
12
+ "./webgpu": "./src/webgpu/index.js",
13
+ "./src/*": "./src/*"
14
+ },
7
15
  "type": "module",
8
16
  "types": "src/index.d.ts",
9
- "sideEffects": false,
17
+ "sideEffects": [
18
+ "./src/webgpu/index.js",
19
+ "./src/webgpu/shims/*.js"
20
+ ],
10
21
  "files": [
11
22
  "src/*",
12
23
  "build/*"
13
24
  ],
14
25
  "keywords": [
15
- "webgl",
26
+ "webgpu",
16
27
  "threejs",
17
28
  "performance",
18
29
  "geometry",
@@ -32,28 +43,35 @@
32
43
  "devDependencies": {
33
44
  "@lookingglass/webxr": "^0.6.0",
34
45
  "@monogrid/gainmap-js": "^3.0.5",
46
+ "@pmndrs/upscaler": "^0.2.0",
35
47
  "@types/node": "^24.3.1",
36
- "@types/three": "^0.181.0",
48
+ "@types/three": "^0.185.1",
37
49
  "@typescript-eslint/eslint-plugin": "^8.40.0",
38
- "canvas-capture": "^2.0.5",
50
+ "@vitejs/plugin-basic-ssl": "^2.3.0",
51
+ "@webgpu/types": "^0.1.72",
39
52
  "eslint": "^8.56.0",
40
53
  "eslint-config-mdcs": "^5.0.0",
54
+ "eslint-plugin-import": "^2.32.0",
55
+ "eslint-plugin-jsdoc": "^50.8.0",
56
+ "jsdoc": "^4.0.5",
57
+ "mediabunny": "^1.50.9",
41
58
  "node-fetch": "^3.2.9",
59
+ "oidn-web": "^0.4.0",
42
60
  "pixelmatch": "^5.3.0",
43
61
  "pngjs": "^6.0.0",
44
62
  "process": "^0.11.10",
45
- "puppeteer": "^15.4.0",
63
+ "puppeteer": "^24.42.0",
46
64
  "rollup": "^2.70.0",
47
65
  "simple-git": "^3.10.0",
48
- "three": "^0.181.1",
49
- "three-mesh-bvh": "^0.9.5",
66
+ "three": "^0.185.1",
67
+ "three-mesh-bvh": "^0.9.15",
50
68
  "typescript": "^5.9.2",
51
- "vite": "^6.2.2",
69
+ "vite": "^8.2.2",
52
70
  "yargs": "^17.5.1"
53
71
  },
54
72
  "peerDependencies": {
55
- "three": ">=0.180.0",
56
- "three-mesh-bvh": ">=0.7.4",
73
+ "three": ">=0.185.0",
74
+ "three-mesh-bvh": ">=0.9.15",
57
75
  "xatlas-web": "^0.1.0"
58
76
  },
59
77
  "scripts": {
@@ -102,6 +102,8 @@ export class WebGLPathTracer {
102
102
 
103
103
  constructor( renderer ) {
104
104
 
105
+ console.warn( 'WebGLPathTracer: This class has been deprecated and will be removed in a future release. Use "WebGPUPathTracer" instead.' );
106
+
105
107
  // members
106
108
  this._renderer = renderer;
107
109
  this._generator = new PathTracingSceneGenerator();
@@ -524,4 +526,10 @@ export class WebGLPathTracer {
524
526
 
525
527
  }
526
528
 
529
+ getRenderTime() {
530
+
531
+ return this._clock.getElapsedTime() * 1e3;
532
+
533
+ }
534
+
527
535
  }
@@ -72,20 +72,16 @@ export function getTextures( materials ) {
72
72
  export function getLights( scene ) {
73
73
 
74
74
  const lights = [];
75
- scene.traverse( c => {
75
+ scene.traverseVisible( c => {
76
76
 
77
- if ( c.visible ) {
77
+ if (
78
+ c.isRectAreaLight ||
79
+ c.isSpotLight ||
80
+ c.isPointLight ||
81
+ c.isDirectionalLight
82
+ ) {
78
83
 
79
- if (
80
- c.isRectAreaLight ||
81
- c.isSpotLight ||
82
- c.isPointLight ||
83
- c.isDirectionalLight
84
- ) {
85
-
86
- lights.push( c );
87
-
88
- }
84
+ lights.push( c );
89
85
 
90
86
  }
91
87
 
@@ -104,15 +104,15 @@ export class PrecisionMaterial extends MaterialBase {
104
104
 
105
105
  switch ( v.toLowerCase() ) {
106
106
 
107
- case 'float':
108
- this.setDefine( 'MODE', 0 );
109
- break;
110
- case 'int':
111
- this.setDefine( 'MODE', 1 );
112
- break;
113
- case 'uint':
114
- this.setDefine( 'MODE', 2 );
115
- break;
107
+ case 'float':
108
+ this.setDefine( 'MODE', 0 );
109
+ break;
110
+ case 'int':
111
+ this.setDefine( 'MODE', 1 );
112
+ break;
113
+ case 'uint':
114
+ this.setDefine( 'MODE', 2 );
115
+ break;
116
116
 
117
117
  }
118
118
 
package/src/index.js CHANGED
@@ -18,6 +18,7 @@ export * from './utils/BlurredEnvMapGenerator.js';
18
18
  // materials
19
19
  export * from './materials/fullscreen/DenoiseMaterial.js';
20
20
  export * from './materials/surface/FogVolumeMaterial.js';
21
+ export * from './materials/surface/AmbientOcclusionMaterial.js';
21
22
 
22
23
  // deprecated
23
24
  export * from './materials/pathtracing/PhysicalPathTracingMaterial.js';
@@ -1,5 +1,7 @@
1
1
  import { SpotLight } from 'three';
2
2
 
3
+ // TODO: this should extend IESSpotLight, but the class is only exported from "three/webgpu" and
4
+ // the node library resolves light nodes by exact constructor so a subclass would not rasterize
3
5
  export class PhysicalSpotLight extends SpotLight {
4
6
 
5
7
  constructor( ...args ) {
@@ -233,7 +233,6 @@ export const bsdf_functions = /* glsl */`
233
233
  // See equation (1) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
234
234
  vec3 color = surf.sheenColor;
235
235
  color *= D * G / ( 4.0 * abs( cosThetaO * cosThetaI ) );
236
- color *= wi.z;
237
236
 
238
237
  return color;
239
238
 
@@ -19,12 +19,12 @@ function getFormat( channels ) {
19
19
 
20
20
  switch ( channels ) {
21
21
 
22
- case 1:
23
- return RedFormat;
24
- case 2:
25
- return RGFormat;
26
- default:
27
- return RGBAFormat;
22
+ case 1:
23
+ return RedFormat;
24
+ case 2:
25
+ return RGFormat;
26
+ default:
27
+ return RGBAFormat;
28
28
 
29
29
  }
30
30
 
@@ -2,13 +2,14 @@ import {
2
2
  ClampToEdgeWrapping,
3
3
  Color,
4
4
  DataTexture,
5
+ DataUtils,
5
6
  EquirectangularReflectionMapping,
7
+ HalfFloatType,
6
8
  LinearFilter,
7
9
  RepeatWrapping,
8
10
  RGBAFormat,
9
11
  Spherical,
10
12
  Vector2,
11
- FloatType
12
13
  } from 'three';
13
14
 
14
15
  const _uv = new Vector2();
@@ -20,8 +21,8 @@ export class ProceduralEquirectTexture extends DataTexture {
20
21
  constructor( width = 512, height = 512 ) {
21
22
 
22
23
  super(
23
- new Float32Array( width * height * 4 ),
24
- width, height, RGBAFormat, FloatType, EquirectangularReflectionMapping,
24
+ new Uint16Array( width * height * 4 ),
25
+ width, height, RGBAFormat, HalfFloatType, EquirectangularReflectionMapping,
25
26
  RepeatWrapping, ClampToEdgeWrapping, LinearFilter, LinearFilter,
26
27
  );
27
28
 
@@ -53,10 +54,10 @@ export class ProceduralEquirectTexture extends DataTexture {
53
54
 
54
55
  const i = y * width + x;
55
56
  const i4 = 4 * i;
56
- data[ i4 + 0 ] = ( _color.r );
57
- data[ i4 + 1 ] = ( _color.g );
58
- data[ i4 + 2 ] = ( _color.b );
59
- data[ i4 + 3 ] = ( 1.0 );
57
+ data[ i4 + 0 ] = DataUtils.toHalfFloat( _color.r );
58
+ data[ i4 + 1 ] = DataUtils.toHalfFloat( _color.g );
59
+ data[ i4 + 2 ] = DataUtils.toHalfFloat( _color.b );
60
+ data[ i4 + 3 ] = DataUtils.toHalfFloat( 1.0 );
60
61
 
61
62
  }
62
63
 
Binary file
@@ -178,6 +178,12 @@ export class EquirectHdrInfoUniform {
178
178
 
179
179
  }
180
180
 
181
+ getPixelWeight( r, g, b ) {
182
+
183
+ return colorToLuminance( r, g, b );
184
+
185
+ }
186
+
181
187
  dispose() {
182
188
 
183
189
  this.marginalWeights.dispose();
@@ -218,10 +224,9 @@ export class EquirectHdrInfoUniform {
218
224
  const g = DataUtils.fromHalfFloat( data[ 4 * i + 1 ] );
219
225
  const b = DataUtils.fromHalfFloat( data[ 4 * i + 2 ] );
220
226
 
221
- // the probability of the pixel being selected in this row is the
222
- // scale of the luminance relative to the rest of the pixels.
223
- // TODO: this should also account for the solid angle of the pixel when sampling
224
- const weight = colorToLuminance( r, g, b );
227
+ // the probability of the pixel being selected in its row is proportional
228
+ // to its luminance relative to the other pixels.
229
+ const weight = this.getPixelWeight( r, g, b, y, height );
225
230
  cumulativeRowWeight += weight;
226
231
  totalSumValue += weight;
227
232
 
@@ -15,17 +15,17 @@ function copyArrayToArray( fromArray, fromStride, toArray, toStride, offset ) {
15
15
  let maxValue = 1.0;
16
16
  switch ( fromArray.constructor ) {
17
17
 
18
- case Uint8Array:
19
- case Uint16Array:
20
- case Uint32Array:
21
- maxValue = 2 ** bpe - 1;
22
- break;
23
-
24
- case Int8Array:
25
- case Int16Array:
26
- case Int32Array:
27
- maxValue = 2 ** ( bpe - 1 ) - 1;
28
- break;
18
+ case Uint8Array:
19
+ case Uint16Array:
20
+ case Uint32Array:
21
+ maxValue = 2 ** bpe - 1;
22
+ break;
23
+
24
+ case Int8Array:
25
+ case Int16Array:
26
+ case Int32Array:
27
+ maxValue = 2 ** ( bpe - 1 ) - 1;
28
+ break;
29
29
 
30
30
  }
31
31
 
@@ -362,15 +362,15 @@ export class MaterialsTexture extends DataTexture {
362
362
 
363
363
  switch ( m.side ) {
364
364
 
365
- case FrontSide:
366
- floatArray[ index ++ ] = 1;
367
- break;
368
- case BackSide:
369
- floatArray[ index ++ ] = - 1;
370
- break;
371
- case DoubleSide:
372
- floatArray[ index ++ ] = 0;
373
- break;
365
+ case FrontSide:
366
+ floatArray[ index ++ ] = 1;
367
+ break;
368
+ case BackSide:
369
+ floatArray[ index ++ ] = - 1;
370
+ break;
371
+ case DoubleSide:
372
+ floatArray[ index ++ ] = 0;
373
+ break;
374
374
 
375
375
  }
376
376