Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
322 commits
Select commit Hold shift + click to select a range
728d428
Update Fns
gkjohnson Feb 17, 2026
7455a34
Updates
gkjohnson Feb 18, 2026
9def446
Updates
gkjohnson Feb 18, 2026
d9999f7
Small fixes
gkjohnson Feb 18, 2026
4b096b6
Fix member name, paren
gkjohnson Feb 18, 2026
43838ce
Fix buffer types
gkjohnson Feb 18, 2026
0f71720
Fix switch statement
gkjohnson Feb 18, 2026
6e5cd11
Other fixes
gkjohnson Feb 18, 2026
4ddfd78
Fixes
gkjohnson Feb 18, 2026
01118fd
More fixes
gkjohnson Feb 18, 2026
2a85e75
Fix variable use
gkjohnson Feb 18, 2026
cc4e5ca
Fix stride
gkjohnson Feb 18, 2026
8193940
Add indirect buffer support
gkjohnson Feb 18, 2026
65f986c
comments
gkjohnson Feb 18, 2026
380b550
Add intersection function
gkjohnson Feb 18, 2026
3813704
Separate functions
gkjohnson Feb 18, 2026
86f60b4
Updates
gkjohnson Feb 18, 2026
f0bfafe
comments
gkjohnson Feb 18, 2026
7003d3c
update three-mesh-bvh
gkjohnson Feb 19, 2026
a9be061
Adjust WebGPUPathtracer
gkjohnson Feb 19, 2026
41fd208
Pass bvh compute fns to megakernelpathtracer
gkjohnson Feb 19, 2026
696cf08
Add temp dispose function
gkjohnson Feb 19, 2026
0472c13
add comment
gkjohnson Feb 19, 2026
dbaeae4
Update
gkjohnson Feb 19, 2026
ee41ab1
Get a basic version working
gkjohnson Feb 19, 2026
361a54a
Fix multiroot bvhs
gkjohnson Feb 19, 2026
fa4463e
Cleanup
gkjohnson Feb 19, 2026
f0eff98
Updates
gkjohnson Feb 19, 2026
6a49319
Add output for object index
gkjohnson Feb 19, 2026
4363359
Updates
gkjohnson Feb 19, 2026
86e5ea0
clean up
gkjohnson Feb 19, 2026
42f30e2
More cleanup
gkjohnson Feb 19, 2026
c3816e8
Cleanup
gkjohnson Feb 19, 2026
e73117a
Cleanup
gkjohnson Feb 19, 2026
9e03595
Move attributes to a wgslstruct definition
gkjohnson Feb 19, 2026
809ef0a
Cleanup
gkjohnson Feb 20, 2026
80e8959
Add material support
gkjohnson Feb 20, 2026
c51a6c9
Cleanup
gkjohnson Feb 20, 2026
ad0ade2
Add support for env map in megakernel
TheBlek Feb 13, 2026
63d4e12
Add support for env map for wavefront pathtracers
TheBlek Feb 14, 2026
66da98d
Remove unneeded file.
TheBlek Feb 20, 2026
fa67477
Add a node proxy mechanism
gkjohnson Feb 20, 2026
b771782
Get wavefront pathtracer working
gkjohnson Feb 20, 2026
d459bd1
Initial indirect bvh handling
gkjohnson Feb 20, 2026
a1c9d14
Fix SAH case
gkjohnson Feb 20, 2026
34acdf2
Cleanup
gkjohnson Feb 20, 2026
09b5fe8
Updates
gkjohnson Feb 20, 2026
8c2d7fc
update three.js, remove unnecessary compute kernel creation
gkjohnson Feb 21, 2026
2eef3bd
Remove unused variable
TheBlek Feb 21, 2026
fd3dadb
Merge pull request #720 from gkjohnson/webgpu/update-three
gkjohnson Feb 21, 2026
00013d6
Move NodeProxy
gkjohnson Feb 21, 2026
87518f4
Merge remote-tracking branch 'origin/webgpu-pathtracer' into scene-ra…
gkjohnson Feb 21, 2026
d20dcde
Rename computeFns
gkjohnson Feb 21, 2026
9d133b9
Move node to folder
gkjohnson Feb 21, 2026
7c97449
Proxy improvements
gkjohnson Feb 21, 2026
08a5fab
Add a wgslFnTagNode
gkjohnson Feb 21, 2026
e2ab877
Remove deprecated "clock"
gkjohnson Feb 21, 2026
13c7f7a
Use built-in struct definition calculation
gkjohnson Feb 21, 2026
10b9ef9
Remove unnecessary wgslstruct
gkjohnson Feb 21, 2026
2b8396d
Add lang arg
gkjohnson Feb 21, 2026
18547f4
Add support for includes, constants
gkjohnson Feb 21, 2026
9d02fe3
Use the tag function
gkjohnson Feb 22, 2026
15d21af
Pass attribute sizes
gkjohnson Feb 22, 2026
d2995cb
WGSLFnTagNode simplification
gkjohnson Feb 22, 2026
d1aed18
Simplification
gkjohnson Feb 22, 2026
0ce323f
Simplification
gkjohnson Feb 22, 2026
68c8f03
Fix up transforms
gkjohnson Feb 22, 2026
a48309e
Rename classes
gkjohnson Feb 22, 2026
2da88d9
Simplification
gkjohnson Feb 22, 2026
7fde608
Add comments
gkjohnson Feb 22, 2026
dae28f5
Move structs internally
gkjohnson Feb 22, 2026
fb71782
Simplify constants
gkjohnson Feb 22, 2026
25480cd
Simplify ray struct usage
gkjohnson Feb 22, 2026
228fbf3
Fix bvh compute data transform struct reference
gkjohnson Feb 22, 2026
c7bdc22
Add wgslTagCode
gkjohnson Feb 23, 2026
5135976
Deduplicate code
gkjohnson Feb 23, 2026
a9db555
Add shim for allowing structs to be passed to storage nodes
gkjohnson Feb 23, 2026
6e0d3ae
Add "getShapecastFn" impl
gkjohnson Feb 23, 2026
fef5d63
Switch to use the shapecast creation function for raycast
gkjohnson Feb 23, 2026
cb31eda
Fixups
gkjohnson Feb 23, 2026
51ce751
Move pathtracer compute data
gkjohnson Feb 23, 2026
8cf5a2a
comments
gkjohnson Feb 23, 2026
e919513
Fix instances
gkjohnson Feb 23, 2026
33b2b91
Make proxy call-able
gkjohnson Feb 24, 2026
d9fc765
Add glsl variants of the code tag functions
gkjohnson Feb 24, 2026
863beb2
Rename background -> environment; Use dispose
TheBlek Feb 24, 2026
8c1dc11
Add support for separate .background and .environment; Add support fo…
TheBlek Feb 24, 2026
a6fd8ea
Adjust proxy node
gkjohnson Feb 25, 2026
855925a
Remove unnecessary "writeOffset"
gkjohnson Feb 25, 2026
53ecd95
Update ObjectBVH, fix BatchedMesh instance bug
gkjohnson Feb 25, 2026
f5371e0
Improve bvh update
gkjohnson Feb 25, 2026
1f70053
Fix background blurriness
TheBlek Feb 25, 2026
b120269
Add support for environment/background to wavefront backend
TheBlek Feb 25, 2026
d15f6dc
Merge pull request #716 from gkjohnson/scene-raycast
gkjohnson Feb 25, 2026
eeec7e6
Merge branch 'webgpu-pathtracer' into webgpu-env
TheBlek Feb 25, 2026
ae38ed5
Remove unneeded file.
TheBlek Feb 25, 2026
11dc47c
Fix convertToTexture issues
TheBlek Feb 25, 2026
a59070d
Restore package lock
TheBlek Feb 25, 2026
4066880
Fix megakernel background blurriness
TheBlek Feb 25, 2026
42ea8ff
Merge pull request #719 from TheBlek/webgpu-env
gkjohnson Feb 25, 2026
955a665
Make sure the background is disposed
gkjohnson Feb 25, 2026
8eaac83
Add "enable" toggle to demo
gkjohnson Feb 25, 2026
eebb657
Cleanup imports
gkjohnson Feb 25, 2026
d1a67f9
Merge pull request #721 from gkjohnson/webgpu/add-enable-toggle
gkjohnson Feb 26, 2026
0cbaf57
Respect renderer clear color
gkjohnson Feb 26, 2026
4a30e44
Adjust env sampling function to support vec4
gkjohnson Feb 26, 2026
1bb8668
Add transparency support for megakernel
gkjohnson Feb 26, 2026
1d973ec
Extend material struct to include all fields.
TheBlek Feb 26, 2026
dd6b981
Process material into SurfaceRecord. Restructure bsdfSample interface…
TheBlek Feb 26, 2026
28401be
Pass hit side and normal in wavefront pathtracer
TheBlek Feb 26, 2026
2262526
Merge branch 'webgpu-pathtracer' into webgpu-materials
TheBlek Feb 26, 2026
b02396d
Fix comments
TheBlek Feb 26, 2026
d585202
Remove old wavefront experiment and PathTracerCore
TheBlek Feb 26, 2026
e23dd91
Add support to wavefront path tracer
gkjohnson Feb 26, 2026
1b09e02
Fix blending & composition
gkjohnson Feb 26, 2026
3e1ece7
Merge pull request #722 from TheBlek/webgpu-materials
gkjohnson Feb 26, 2026
399a71a
Merge commit '3e1ece75e4d9e6931d6c3c245c7e5755fc8bda4d' into webgpu/a…
gkjohnson Feb 26, 2026
b6e88c4
small merge fix
gkjohnson Feb 26, 2026
376e7e7
Add background
gkjohnson Feb 26, 2026
4e6a3c9
Use the TSL struct node
gkjohnson Feb 26, 2026
20ba2a4
More struct migration
gkjohnson Feb 26, 2026
4c7837d
Update more structs
gkjohnson Feb 27, 2026
86000be
Migrate to TSL structTypeNodes
gkjohnson Feb 27, 2026
44bcc02
Remove unused import
gkjohnson Feb 27, 2026
90cfe9e
Add support for per-instance colors
gkjohnson Feb 27, 2026
2eb8a10
Add viewer example
TheBlek Feb 19, 2026
876aaba
Remove embedded ray struct
gkjohnson Feb 27, 2026
37a6469
Remove embedded ray struct
gkjohnson Feb 27, 2026
4ad16ec
Merge pull request #724 from gkjohnson/webgpu/structs-tsl
gkjohnson Feb 27, 2026
deb27ab
Merge remote-tracking branch 'origin/webgpu-pathtracer' into webgpu/a…
gkjohnson Feb 27, 2026
25049cd
Fix RenderToScreenMaterial
gkjohnson Feb 27, 2026
c3c09c6
Merge pull request #723 from gkjohnson/webgpu/alpha-bg
gkjohnson Feb 27, 2026
d3fc279
Merge pull request #725 from gkjohnson/webgpu/instance-colors
gkjohnson Feb 27, 2026
e0ebc2e
Use struct references for storage buffers
gkjohnson Feb 27, 2026
968cf9a
Add support for webgpu pathtracer in existign viewerTest example. Upd…
TheBlek Feb 27, 2026
c82bdc5
Remove webgpu_ verison of viewerTest example.
TheBlek Feb 27, 2026
48b3586
Add comment about itemSize being 1
TheBlek Feb 27, 2026
e86e4af
Merge branch 'webgpu-pathtracer' into webgpu-viewer-test
TheBlek Feb 27, 2026
ed3c5a7
Remove unneded import
TheBlek Feb 27, 2026
b283f66
Carry pcg generator state through stage
TheBlek Feb 27, 2026
666010c
Fix urls to point to github content. Fix screenshotList example
TheBlek Feb 27, 2026
e46a2a9
Merge pull request #728 from TheBlek/webgpu-wavefront-rand-state
gkjohnson Feb 27, 2026
3df880f
Merge pull request #726 from gkjohnson/webgpu/cleanup
gkjohnson Feb 27, 2026
c9714fd
initial skinnedmesh bvh
gkjohnson Feb 28, 2026
7f635ea
Add skinned mesh bvh gen
gkjohnson Feb 28, 2026
8c24040
Handle skinned meshes
gkjohnson Feb 28, 2026
349735e
Handle normals
gkjohnson Feb 28, 2026
568e9cc
Add support for normals, tangents
gkjohnson Feb 28, 2026
29c38ff
Ensure BVH is updated
gkjohnson Feb 28, 2026
f19da21
Re-add error
gkjohnson Feb 28, 2026
121bbea
Remove unused field
gkjohnson Feb 28, 2026
9523cdd
Remove unused imports
gkjohnson Feb 28, 2026
4739f43
Merge pull request #727 from TheBlek/webgpu-viewer-test
gkjohnson Feb 28, 2026
0bdbd3d
Add support for visibility toggling
gkjohnson Feb 28, 2026
763ed0f
Add support for dynamic resolution
gkjohnson Feb 28, 2026
1a22eae
Adjust iteration approach
gkjohnson Feb 28, 2026
2720ede
fix low res mode
gkjohnson Feb 28, 2026
a1d4499
Simplify
gkjohnson Feb 28, 2026
b65e4fb
Merge pull request #730 from gkjohnson/webgpu/visibility
gkjohnson Feb 28, 2026
53c0cbd
Implement RenderTarget2DArray and add support for textures in megaker…
TheBlek Feb 28, 2026
56cf6d8
Fix isWebGPU url param
TheBlek Feb 28, 2026
fadd79e
Add support for textures in wavefront pathtracer
TheBlek Feb 28, 2026
1c1a165
Fix floating point issues in megakernel
TheBlek Feb 28, 2026
85bcee0
Merge pull request #733 from TheBlek/webgpu-fpoint-error
gkjohnson Feb 28, 2026
648f796
Add a minimum number of samples to fade the full res mode
gkjohnson Mar 1, 2026
651e3a9
Adjust WebGPUPathtracer
gkjohnson Mar 1, 2026
569eef2
Remove unused import
gkjohnson Mar 1, 2026
41dfe65
Merge pull request #731 from gkjohnson/webgpu/dynamic-res
gkjohnson Mar 1, 2026
738d5e6
Merge pull request #729 from gkjohnson/webgpu/skinning
gkjohnson Mar 1, 2026
3f8fb90
Megakernel: Transform ray to world coordinates
gkjohnson Mar 1, 2026
914eac7
Fix instanced mesh case
gkjohnson Mar 1, 2026
a850bef
Handle fade better to accommodate three.js issue, add autoclear support
gkjohnson Mar 2, 2026
73a50c0
Add comment
gkjohnson Mar 2, 2026
91757b0
Fix imports
gkjohnson Mar 2, 2026
473c26e
Improve ergonomics of BVHComputeData
gkjohnson Mar 2, 2026
9ef0c90
Improve node proxy so it works with textures, all other nodes
gkjohnson Mar 2, 2026
bab97d3
Review fixes
TheBlek Mar 2, 2026
c17047a
Merge branch 'webgpu-pathtracer' into webgpu-textures
TheBlek Mar 2, 2026
b7f1cbe
Simplify RenderTarget2DArray
TheBlek Mar 2, 2026
ba53990
Calculate detailed sample counts, display samples/s in viewerTest exa…
TheBlek Mar 2, 2026
bba2711
Merge pull request #738 from gkjohnson/webgpu/proxy-robustness
gkjohnson Mar 2, 2026
1ffed09
Merge pull request #734 from gkjohnson/webgpu/ray-fix
gkjohnson Mar 2, 2026
530282e
Merge branch 'webgpu-pathtracer' into webgpu-textures
gkjohnson Mar 2, 2026
11d4240
Ensure renderer is initialized before setting a scene.
TheBlek Mar 2, 2026
089c5f7
Merge pull request #732 from TheBlek/webgpu-textures
gkjohnson Mar 2, 2026
d356b42
Merge pull request #737 from gkjohnson/webgpu/bvh-data-ergo
gkjohnson Mar 2, 2026
352f00e
Merge pull request #736 from gkjohnson/webgpu/fade-fixes-2
gkjohnson Mar 2, 2026
1623681
Use a dummy geometry, instead
gkjohnson Mar 2, 2026
385ea62
Modify triangle intersection test epsilons, normalize ray direction
gkjohnson Mar 2, 2026
5244be6
Adjust DET_EPSILON
gkjohnson Mar 3, 2026
2b20f69
Add support for material arrays
gkjohnson Mar 3, 2026
181a7ec
Add "PathTracerBackend", use in megakernel
gkjohnson Mar 3, 2026
2a77dac
Remove unused fields from wavefront kernel
gkjohnson Mar 3, 2026
fd1201b
Inherit from backend in WavefrontPathTracer
gkjohnson Mar 3, 2026
49a8c67
Simplify megakernel
gkjohnson Mar 3, 2026
8cf7eb8
Comment out unused variable
gkjohnson Mar 3, 2026
a22e8eb
Display all detailed information. Request only once every N seconds.
TheBlek Mar 3, 2026
8460ec1
Merge branch 'webgpu-pathtracer' into webgpu-sample-counts
TheBlek Mar 3, 2026
0c54494
Fix import, fix "Loading..." not disappearing sometimes
TheBlek Mar 3, 2026
2ba48e8
Merge pull request #741 from gkjohnson/webgpu/material-arrays
gkjohnson Mar 3, 2026
3cf878e
Merge pull request #740 from gkjohnson/webgpu/precision-fix2
gkjohnson Mar 3, 2026
0616e1e
Update three-mesh-bvh
gkjohnson Mar 3, 2026
01e3002
Merge pull request #743 from gkjohnson/bvh-update
gkjohnson Mar 3, 2026
b049ca9
Merge pull request #742 from gkjohnson/webgpu/backend
gkjohnson Mar 3, 2026
5172405
Add a webgpu-export
gkjohnson Mar 4, 2026
cc4ca26
Merge branch 'main' into webgpu-pathtracer
gkjohnson Mar 4, 2026
c51876c
Merge branch 'webgpu-pathtracer' into webgpu/package
gkjohnson Mar 4, 2026
f9fd8f6
Remove webgpu content from main exports
gkjohnson Mar 4, 2026
877b94a
Fix lint issue
gkjohnson Mar 4, 2026
357ee2a
Merge pull request #744 from gkjohnson/webgpu/package
gkjohnson Mar 4, 2026
1080f1e
Get megakernel working cross-browser
gkjohnson Mar 4, 2026
d9af91a
Improve perf, fix resilience to 1 material, etc
gkjohnson Mar 6, 2026
363b6a2
Clean up TSL storage issue
gkjohnson Mar 6, 2026
ac88ea0
More cleanup
gkjohnson Mar 6, 2026
6999439
Fix attributes buffer
gkjohnson Mar 6, 2026
d4b9d86
Resilience to empty bounds
gkjohnson Mar 7, 2026
266e1d7
Little fixes from review
TheBlek Mar 10, 2026
1a23da6
Merge branch 'webgpu-pathtracer' into webgpu-sample-counts
TheBlek Mar 10, 2026
f4fd1f8
Merge pull request #739 from TheBlek/webgpu-sample-counts
gkjohnson Mar 10, 2026
fd360cc
Merge pull request #746 from gkjohnson/webgpu/fixes
gkjohnson Mar 10, 2026
e8a18e6
Merge pull request #745 from gkjohnson/webgpu/cross-browser
gkjohnson Mar 10, 2026
880d656
WGSLTagFnNode: normalize arguments on build rather than immediately
gkjohnson Mar 10, 2026
57eb9ca
Simplify megakernel
gkjohnson Mar 10, 2026
b0e9d93
Fix 2 wavefront kernels, normalize variable naming
gkjohnson Mar 10, 2026
00931af
Adjust wavefront ray generation kernel
gkjohnson Mar 10, 2026
13320ea
Update last two wavefront kernels
gkjohnson Mar 10, 2026
b498527
Fix zero out buffer kernel
gkjohnson Mar 10, 2026
a0d9744
Remove unneeded arguments
gkjohnson Mar 10, 2026
7292053
Merge pull request #748 from gkjohnson/kernel-cleanup
gkjohnson Mar 14, 2026
4ed7758
WGSL tag function updates
gkjohnson Mar 22, 2026
b890e2e
indentation adjustment
gkjohnson Mar 29, 2026
5861726
Fix visibility handling
gkjohnson Mar 29, 2026
93037d4
Add shapecastFn API flexibility
gkjohnson Mar 29, 2026
8c2e405
fix tag name
gkjohnson Mar 30, 2026
c88aa65
remove "prefix" field
gkjohnson Mar 30, 2026
4cd94c0
make "name" optional, include output struct and name
gkjohnson Mar 30, 2026
087cbc4
Fix invalid naming
gkjohnson Mar 30, 2026
f6bed5c
Clean up
gkjohnson Mar 30, 2026
dc8860d
Updates
gkjohnson Mar 30, 2026
fab5282
Use pointer for shapecast output
gkjohnson Mar 30, 2026
d000989
Make return type optional
gkjohnson Mar 30, 2026
aacc5cb
Remove explicit setting of "objectIndex"
gkjohnson Mar 30, 2026
587ad20
lint fixes
gkjohnson Mar 30, 2026
b26632b
Add bvh generation
gkjohnson Mar 30, 2026
14a772f
Auto gen bvhs
gkjohnson Mar 30, 2026
ad52cbf
Fixes
gkjohnson Mar 30, 2026
7e2e746
lint fix
gkjohnson Mar 30, 2026
02dd4e7
Add comment
gkjohnson Mar 30, 2026
43d2e54
comments
gkjohnson Mar 30, 2026
02be8ab
Merge pull request #754 from gkjohnson/webgpu/compute-updates
gkjohnson Mar 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"quotes": [ "error", "single" ],
"indent": [ "error", "tab" ],
"indent": [ "error", "tab", { "SwitchCase": 1 } ],
"no-var": [ "error" ]
},
"overrides": [
Expand Down
2 changes: 2 additions & 0 deletions example/screenshotList.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<option value="model-viewer">model-viewer</option>
<option value="rhodonite">rhodonite</option>
<option value="stellar">stellar</option>
<option value="vray">vray</option>
<option value="blender-cycles">blender-cycles</option>
<option value="prior-commit">prior-commit</option>
</select>
</label>
Expand Down
4 changes: 2 additions & 2 deletions example/screenshotList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const CONFIG_URL = 'https://raw.githubusercontent.com/google/model-viewer/master/packages/render-fidelity-tools/test/config.json';
const CONFIG_URL = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Render-Fidelity-Generator/refs/heads/main/test/config.json';
const COMMITS_URL = 'https://api.github.com/repos/gkjohnson/three-gpu-pathtracer/commits?sha=screenshots';

( async () => {
Expand Down Expand Up @@ -51,7 +51,7 @@ const COMMITS_URL = 'https://api.github.com/repos/gkjohnson/three-gpu-pathtracer

} else {

url2 = `https://raw.githubusercontent.com/google/model-viewer/master/packages/render-fidelity-tools/test/goldens/${ name }/${ imageType }-golden.png`;
url2 = `https://media.githubusercontent.com/media/KhronosGroup/glTF-Render-Fidelity-Generator/refs/heads/main/test/goldens/${ name }/${ imageType }-golden.png`;

}

Expand Down
19 changes: 18 additions & 1 deletion example/utils/LoaderElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,29 @@ export class LoaderElement {

}

setSamples( count, compiling = false ) {
setSamples( count, compiling = false, detailedSamples = null ) {

if ( compiling ) {

this._samples.innerText = 'compiling shader...';

} else if ( detailedSamples !== null ) {

const {
min,
max,
avg,
perSecond,
} = detailedSamples;

this._samples.innerText = `[${ min }..${ max }], avg = ${ avg } samples`;

if ( perSecond ) {

this._samples.innerText += ` (${ perSecond.toFixed( 1 ) } samples/sec)`;

}

} else {

this._samples.innerText = `${ Math.floor( count ) } samples`;
Expand Down
137 changes: 117 additions & 20 deletions example/viewerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@ import {
Group,
Sphere,
Box3,
Vector2,
} from 'three';
import { WebGPURenderer } from 'three/webgpu';
import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
import { WebGLPathTracer } from 'three-gpu-pathtracer';
import { WebGPUPathTracer } from 'three-gpu-pathtracer/webgpu';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import { ParallelMeshBVHWorker } from 'three-mesh-bvh/worker';
import { LoaderElement } from './utils/LoaderElement.js';

const CONFIG_URL = 'https://raw.githubusercontent.com/google/model-viewer/master/packages/render-fidelity-tools/test/config.json';
const BASE_URL = 'https://raw.githubusercontent.com/google/model-viewer/master/packages/render-fidelity-tools/test/config/';
const CONFIG_URL = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Render-Fidelity-Generator/refs/heads/main/test/config.json';
const BASE_URL = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Render-Fidelity-Generator/refs/heads/main/test/renderers/three-gpu-pathtracer/';

const urlParams = new URLSearchParams( window.location.search );
const maxSamples = parseInt( urlParams.get( 'samples' ) ) || - 1;
const hideUI = urlParams.get( 'hideUI' ) === 'true';
const tiles = parseInt( urlParams.get( 'tiles' ) ) || 2;
const scale = parseInt( urlParams.get( 'scale' ) ) || 1 / window.devicePixelRatio;
const isWebGPU = urlParams.get( 'isWebGPU' ) === 'true';

const params = {

isWebGPU,
useMegakernel: true,

enable: true,
bounces: 10,
transmissiveBounces: 10,
Expand All @@ -55,6 +62,9 @@ let pathTracer, renderer, camera, scene, controls;
let loadingModel = false;
let delaySamples = 0;
let modelDatabase;
let detailedSampleCount = null;
let lastDetailedSample = 0;
const detailedSampleInterval = 4;

init();

Expand All @@ -78,19 +88,7 @@ async function init() {

}

// renderer
renderer = new WebGLRenderer( { antialias: true, preserveDrawingBuffer: true } );
renderer.physicallyCorrectLights = true;
renderer.toneMapping = ACESFilmicToneMapping;
renderer.setClearAlpha( 0 );
containerEl.appendChild( renderer.domElement );

// path tracer
pathTracer = new WebGLPathTracer( renderer );
pathTracer.filterGlossyFactor = 0.5;
pathTracer.tiles.set( params.tiles );
pathTracer.setBVHWorker( new ParallelMeshBVHWorker() );
pathTracer.multipleImportanceSampling = params.multipleImportanceSampling;
await createRenderer( params.isWebGPU );

// scene
scene = new Scene();
Expand All @@ -116,6 +114,41 @@ async function init() {

}

async function createRenderer( isWebGPU ) {

if ( isWebGPU ) {

// renderer - WebGPU version
renderer = new WebGPURenderer( { antialias: true, trackTimestamp: false } );
await renderer.init();
renderer.toneMapping = ACESFilmicToneMapping;
renderer.setClearAlpha( 0 );
containerEl.appendChild( renderer.domElement );

// path tracer - WebGPU version
pathTracer = new WebGPUPathTracer( renderer );
pathTracer.useMegakernel( params.useMegakernel );

} else {

// renderer
renderer = new WebGLRenderer( { antialias: true, preserveDrawingBuffer: true } );
renderer.physicallyCorrectLights = true;
renderer.toneMapping = ACESFilmicToneMapping;
renderer.setClearAlpha( 0 );
containerEl.appendChild( renderer.domElement );

// path tracer
pathTracer = new WebGLPathTracer( renderer );
pathTracer.filterGlossyFactor = 0.5;
pathTracer.tiles.set( params.tiles );
pathTracer.setBVHWorker( new ParallelMeshBVHWorker() );
pathTracer.multipleImportanceSampling = params.multipleImportanceSampling;

}

}

function animate() {

requestAnimationFrame( animate );
Expand All @@ -127,6 +160,31 @@ function animate() {

}

if ( pathTracer.getRenderTime && pathTracer.getDetailedSampleCount ) {

const elapsed = pathTracer.getRenderTime() / 1000;
// Reset sample count state if no sample is taken yet
if ( elapsed < detailedSampleInterval ) {

detailedSampleCount = null;
lastDetailedSample = 0;

}

if ( elapsed - lastDetailedSample > detailedSampleInterval ) {

lastDetailedSample = Math.floor( elapsed / detailedSampleInterval ) * detailedSampleInterval;
pathTracer.getDetailedSampleCount().then( sampleCount => {

sampleCount.perSecond = sampleCount.avg / elapsed;
detailedSampleCount = sampleCount;

} );

}

}

imgEl.style.display = ! params.displayImage ? 'none' : 'inline-block';
imgEl.style.opacity = params.imageMode === 'side-by-side' ? 1.0 : params.imageOpacity;
imgEl.style.position = params.imageMode === 'side-by-side' ? 'initial' : 'absolute';
Expand All @@ -147,7 +205,7 @@ function animate() {

pathTracer.renderSample();

} else if ( delaySamples > 0 || ! params.enable ) {
} else if ( ( delaySamples > 0 || ! params.enable ) && renderer.initialized !== false ) {

delaySamples = Math.max( delaySamples - 1, 0 );
renderer.render( scene, camera );
Expand All @@ -161,7 +219,7 @@ function animate() {

}

loader.setSamples( pathTracer.samples, pathTracer.isCompiling );
loader.setSamples( pathTracer.samples, pathTracer.isCompiling, detailedSampleCount );

}

Expand Down Expand Up @@ -234,6 +292,38 @@ function buildGui() {
} );

const pathTracingFolder = gui.addFolder( 'Path Tracer' );

let webgpuOptions = null;
pathTracingFolder.add( params, 'isWebGPU' ).onChange( v => {

const size = renderer.getSize( new Vector2() );
pathTracer.dispose();
containerEl.removeChild( renderer.domElement );
renderer.dispose();

webgpuOptions.show( v );

createRenderer( v ).then( () => {

renderer.setSize( size.x, size.y );
renderer.setPixelRatio( window.devicePixelRatio );
pathTracer.setScene( scene, camera );

onParamsChange();

} );

} );

webgpuOptions = pathTracingFolder.add( params, 'useMegakernel' );
webgpuOptions.onChange( () => {

pathTracer.useMegakernel( params.useMegakernel );
pathTracer.reset();

} );
webgpuOptions.show( params.isWebGPU );

pathTracingFolder.add( params, 'enable' );
pathTracingFolder.add( params, 'pause' );
pathTracingFolder.add( params, 'scale', 0.1, 1 ).onChange( onParamsChange );
Expand Down Expand Up @@ -261,7 +351,9 @@ function buildGui() {
'gltf-sample-viewer',
'model-viewer',
'rhodonite',
'stellar'
'stellar',
'vray',
'blender-cycles',
] ).onChange( updateImage );
comparisonFolder.add( params, 'imageOpacity', 0, 1.0 );
comparisonFolder.add( params, 'checkerboardTransparency' ).onChange( onParamsChange );
Expand Down Expand Up @@ -315,7 +407,7 @@ async function updateModel() {
const modelInfo = modelDatabase[ params.model ];
const {
verticalFoV = 45,
lighting = '../../../shared-assets/environments/lightroom_14b.hdr',
lighting = '../../../environments/lightroom_14b.hdr',
} = modelInfo;

let {
Expand Down Expand Up @@ -352,6 +444,11 @@ async function updateModel() {

}

} ).then( value => {

loader.setPercentage( 1 );
return value;

} ),
new Promise( resolve => manager.onLoad = resolve ),
] );
Expand Down Expand Up @@ -428,6 +525,6 @@ async function updateModel() {

function updateImage() {

imgEl.src = `https://raw.githubusercontent.com/google/model-viewer/master/packages/render-fidelity-tools/test/goldens/${ params.model }/${ params.imageType }-golden.png`;
imgEl.src = `https://media.githubusercontent.com/media/KhronosGroup/glTF-Render-Fidelity-Generator/refs/heads/main/test/goldens/${ params.model }/${ params.imageType }-golden.png`;

}
49 changes: 49 additions & 0 deletions example/webgpu_primitives.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<html>
<head>
<title>Basic Primitives Path Tracing Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<style>
html, body {
margin: 0;
padding: 0;

/* transparent background checkerboard */
background-image: conic-gradient(#fff 25%, #eee 25%, #eee 50%, #fff 50%, #fff 75%, #eee 75%);
background-size: 20px 20px;
}

#info {
position: absolute;
bottom: 0;
left: 0;
font-family: 'Courier New', Courier, monospace;
color: white;
pointer-events: none;
}

#samples, #credits {

opacity: 0.5;
background-color: rgba( 0.0, 0.0, 0.0, 0.5 );
padding: 5px;
display: inline-block;

}

#corner-canvas {
position: fixed;
bottom: 0;
left: 0;
max-width: 500px;
max-height: 200px;
z-index: 1000;
}
</style>

</head>
<body>
<canvas id="corner-canvas" width="200" height="300"></canvas>
<script src="./webgpu_primitives.js" type="module"></script>
</body>
</html>
Loading
Loading