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.
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 +28 -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
@@ -0,0 +1,108 @@
1
+ import { Vector2 } from 'three/webgpu';
2
+ /** @import { Camera, Texture, WebGPURenderer } from 'three/webgpu' */
3
+
4
+ const _size = /*@__PURE__*/ new Vector2();
5
+
6
+ /**
7
+ * Upscales a path traced image to the drawing buffer size with FSR. Pass one to
8
+ * "WebGPUPathTracer.setUpscaler".
9
+ *
10
+ * The "Upscaler" class is passed in rather than imported so it does not become a dependency.
11
+ *
12
+ * ```js
13
+ * import { Upscaler } from '@pmndrs/upscaler';
14
+ * pathTracer.setUpscaler( new FSRUpscaler( { Upscaler } ) );
15
+ * ```
16
+ */
17
+ export class FSRUpscaler {
18
+
19
+ /**
20
+ * Every field below can also be assigned after construction.
21
+ *
22
+ * @param {Object} options
23
+ * @param {Function} options.Upscaler - The `Upscaler` class from `@pmndrs/upscaler`.
24
+ * @param {number} [options.sharpness]
25
+ */
26
+ constructor( options = {} ) {
27
+
28
+ const { Upscaler, sharpness = 1 } = options;
29
+
30
+ if ( ! Upscaler ) {
31
+
32
+ throw new Error( 'FSRUpscaler: the "Upscaler" class from "@pmndrs/upscaler" must be provided.' );
33
+
34
+ }
35
+
36
+ this.Upscaler = Upscaler;
37
+
38
+ // edge sharpening applied after the upscale, in [0,1]
39
+ this.sharpness = sharpness;
40
+
41
+ this.renderer = null;
42
+
43
+ this._upscaler = null;
44
+
45
+ }
46
+
47
+ /**
48
+ * @param {WebGPURenderer} renderer
49
+ */
50
+ init( renderer ) {
51
+
52
+ this.renderer = renderer;
53
+ this._upscaler = new this.Upscaler( { renderer } );
54
+ this._upscaler.init();
55
+
56
+ }
57
+
58
+ /**
59
+ * Upscales a texture to the renderer's drawing buffer size.
60
+ *
61
+ * @param {Texture} source
62
+ * @param {Camera} camera
63
+ * @returns {Texture}
64
+ */
65
+ upscale( source, camera ) {
66
+
67
+ const { renderer, _upscaler: upscaler } = this;
68
+
69
+ // the upscaler reads the raw GPUTexture, which only exists once three has initialized it
70
+ renderer.initTexture( source );
71
+
72
+ renderer.getDrawingBufferSize( _size );
73
+
74
+ // "configure" reallocates the working textures, so only call it when something moved
75
+ const changed =
76
+ upscaler.displayWidth !== _size.x ||
77
+ upscaler.displayHeight !== _size.y ||
78
+ upscaler.renderWidth !== source.width ||
79
+ upscaler.renderHeight !== source.height;
80
+
81
+ if ( changed ) {
82
+
83
+ upscaler.configure( {
84
+ displayWidth: _size.x,
85
+ displayHeight: _size.y,
86
+ renderWidth: source.width,
87
+ renderHeight: source.height,
88
+
89
+ // the temporal paths need motion vectors the path tracer does not produce
90
+ path: 'spatial',
91
+ } );
92
+
93
+ }
94
+
95
+ upscaler.settings.sharpness = this.sharpness;
96
+ upscaler.dispatch( { color: source }, camera );
97
+ return upscaler.outputTexture;
98
+
99
+ }
100
+
101
+ dispose() {
102
+
103
+ this._upscaler.dispose();
104
+ this._upscaler = null;
105
+
106
+ }
107
+
108
+ }