three-gpu-pathtracer 0.0.24 → 0.0.25
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/README.md +53 -530
- package/build/index.module.js +262 -50
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +261 -48
- package/build/index.umd.cjs.map +1 -1
- package/package.json +28 -11
- package/src/core/WebGLPathTracer.js +8 -0
- package/src/core/utils/sceneUpdateUtils.js +8 -12
- package/src/detectors/PrecisionMaterial.js +9 -9
- package/src/index.js +1 -0
- package/src/objects/PhysicalSpotLight.js +2 -0
- package/src/shader/bsdf/bsdf_functions.glsl.js +0 -1
- package/src/textures/BlueNoiseTexture.js +6 -6
- package/src/textures/ProceduralEquirectTexture.js +8 -7
- package/src/textures/turquinMetal.png +0 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +9 -4
- package/src/uniforms/FloatAttributeTextureArray.js +11 -11
- package/src/uniforms/MaterialsTexture.js +9 -9
- package/src/webgpu/API.md +762 -0
- package/src/webgpu/AtlasTexture.js +471 -0
- package/src/webgpu/BlurredEnvMapGenerator.js +129 -0
- package/src/webgpu/EquirectBackgroundInfo.js +97 -0
- package/src/webgpu/EquirectHdrInfoNode.js +151 -0
- package/src/webgpu/LightsInfoNode.js +224 -0
- package/src/webgpu/MegaKernelPathTracer.js +277 -0
- package/src/webgpu/PathTracerBackend.js +216 -0
- package/src/webgpu/TurquinTexture.js +169 -0
- package/src/webgpu/WaveFrontPathTracer.js +586 -0
- package/src/webgpu/WebGPUPathTracer.js +1302 -0
- package/src/webgpu/compute/ComputeKernel.js +92 -0
- package/src/webgpu/compute/CopyBufferKernel.js +40 -0
- package/src/webgpu/compute/PathTracerMegaKernel.js +470 -0
- package/src/webgpu/compute/SampleDebugKernel.js +51 -0
- package/src/webgpu/compute/TallySampleCountsKernel.js +111 -0
- package/src/webgpu/compute/ZeroOutBufferKernel.js +35 -0
- package/src/webgpu/compute/ZeroOutKernel.js +31 -0
- package/src/webgpu/compute/wavefront/LogicKernel.js +349 -0
- package/src/webgpu/compute/wavefront/MaterialKernel.js +371 -0
- package/src/webgpu/compute/wavefront/PopulatePixelIndicesKernel.js +72 -0
- package/src/webgpu/compute/wavefront/QueueLengthToDispatchKernel.js +38 -0
- package/src/webgpu/compute/wavefront/ResetSlotsKernel.js +66 -0
- package/src/webgpu/compute/wavefront/TraceRayKernel.js +71 -0
- package/src/webgpu/compute/wavefront/TraceShadowRayKernel.js +67 -0
- package/src/webgpu/compute/wavefront/structs.js +155 -0
- package/src/webgpu/constants.js +62 -0
- package/src/webgpu/denoise/OIDNDenoiser.js +431 -0
- package/src/webgpu/index.d.ts +176 -0
- package/src/webgpu/index.js +11 -0
- package/src/webgpu/materials/GltfCompliantMaterial.js +608 -0
- package/src/webgpu/materials/GraphMaterial.js +331 -0
- package/src/webgpu/materials/PathtracingMaterial.js +89 -0
- package/src/webgpu/materials/RenderToScreenMaterial.js +150 -0
- package/src/webgpu/materials/debug/AtlasDebugMaterial.js +41 -0
- package/src/webgpu/materials/debug/SampleDensityMaterial.js +61 -0
- package/src/webgpu/nodes/PathtracerBVHComputeData.js +1037 -0
- package/src/webgpu/nodes/debugBounds.wgsl.js +228 -0
- package/src/webgpu/nodes/eon.wgsl.js +262 -0
- package/src/webgpu/nodes/ggx.wgsl.js +190 -0
- package/src/webgpu/nodes/lights.wgsl.js +203 -0
- package/src/webgpu/nodes/material.wgsl.js +990 -0
- package/src/webgpu/nodes/rand/bluedither.wgsl.js +92 -0
- package/src/webgpu/nodes/rand/pcg.wgsl.js +81 -0
- package/src/webgpu/nodes/rand/sobol.wgsl.js +287 -0
- package/src/webgpu/nodes/random.wgsl.js +20 -0
- package/src/webgpu/nodes/reset.wgsl.js +21 -0
- package/src/webgpu/nodes/sampling.wgsl.js +193 -0
- package/src/webgpu/nodes/sheen.wgsl.js +148 -0
- package/src/webgpu/nodes/structs.wgsl.js +272 -0
- package/src/webgpu/nodes/utils.wgsl.js +366 -0
- package/src/webgpu/shims/ArrayCameraShim.js +74 -0
- package/src/webgpu/shims/EquirectCameraShim.js +37 -0
- package/src/webgpu/shims/PhysicalCameraShim.js +151 -0
- 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.
|
|
3
|
+
"version": "0.0.25",
|
|
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":
|
|
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
|
-
"
|
|
26
|
+
"webgpu",
|
|
16
27
|
"threejs",
|
|
17
28
|
"performance",
|
|
18
29
|
"geometry",
|
|
@@ -32,28 +43,34 @@
|
|
|
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.
|
|
48
|
+
"@types/three": "^0.185.1",
|
|
37
49
|
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
|
38
|
-
"
|
|
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-jsdoc": "^50.8.0",
|
|
55
|
+
"jsdoc": "^4.0.5",
|
|
56
|
+
"mediabunny": "^1.50.9",
|
|
41
57
|
"node-fetch": "^3.2.9",
|
|
58
|
+
"oidn-web": "^0.4.0",
|
|
42
59
|
"pixelmatch": "^5.3.0",
|
|
43
60
|
"pngjs": "^6.0.0",
|
|
44
61
|
"process": "^0.11.10",
|
|
45
|
-
"puppeteer": "^
|
|
62
|
+
"puppeteer": "^24.42.0",
|
|
46
63
|
"rollup": "^2.70.0",
|
|
47
64
|
"simple-git": "^3.10.0",
|
|
48
|
-
"three": "^0.
|
|
49
|
-
"three-mesh-bvh": "^0.9.
|
|
65
|
+
"three": "^0.185.1",
|
|
66
|
+
"three-mesh-bvh": "^0.9.15",
|
|
50
67
|
"typescript": "^5.9.2",
|
|
51
|
-
"vite": "^
|
|
68
|
+
"vite": "^8.2.2",
|
|
52
69
|
"yargs": "^17.5.1"
|
|
53
70
|
},
|
|
54
71
|
"peerDependencies": {
|
|
55
|
-
"three": ">=0.
|
|
56
|
-
"three-mesh-bvh": ">=0.
|
|
72
|
+
"three": ">=0.185.0",
|
|
73
|
+
"three-mesh-bvh": ">=0.9.15",
|
|
57
74
|
"xatlas-web": "^0.1.0"
|
|
58
75
|
},
|
|
59
76
|
"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.
|
|
75
|
+
scene.traverseVisible( c => {
|
|
76
76
|
|
|
77
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
c.isRectAreaLight ||
|
|
79
|
+
c.isSpotLight ||
|
|
80
|
+
c.isPointLight ||
|
|
81
|
+
c.isDirectionalLight
|
|
82
|
+
) {
|
|
78
83
|
|
|
79
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
24
|
-
width, height, RGBAFormat,
|
|
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
|
|
222
|
-
//
|
|
223
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
|