three-gpu-pathtracer 0.0.20 → 0.0.22

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 (75) hide show
  1. package/README.md +111 -464
  2. package/build/index.module.js +5691 -5312
  3. package/build/index.module.js.map +1 -1
  4. package/build/index.umd.cjs +5369 -5003
  5. package/build/index.umd.cjs.map +1 -1
  6. package/package.json +12 -6
  7. package/src/core/PathTracingRenderer.js +59 -46
  8. package/src/core/PathTracingSceneGenerator.js +245 -10
  9. package/src/core/WebGLPathTracer.js +472 -0
  10. package/src/core/utils/BakedGeometry.js +35 -0
  11. package/src/core/utils/BufferAttributeUtils.js +64 -0
  12. package/src/{utils → core/utils}/GeometryPreparationUtils.js +35 -35
  13. package/src/core/utils/MeshDiff.js +102 -0
  14. package/src/core/utils/StaticGeometryGenerator.js +285 -0
  15. package/src/core/utils/convertToStaticGeometry.js +344 -0
  16. package/src/core/utils/mergeGeometries.js +218 -0
  17. package/src/core/utils/sceneUpdateUtils.js +96 -0
  18. package/src/index.d.ts +274 -0
  19. package/src/index.js +4 -20
  20. package/src/materials/MaterialBase.js +4 -0
  21. package/src/materials/fullscreen/ClampedInterpolationMaterial.js +112 -0
  22. package/src/materials/fullscreen/DenoiseMaterial.js +4 -0
  23. package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +73 -76
  24. package/src/materials/pathtracing/glsl/{attenuateHit.glsl.js → attenuate_hit_function.glsl.js} +1 -1
  25. package/src/materials/pathtracing/glsl/{cameraUtils.glsl.js → camera_util_functions.glsl.js} +1 -1
  26. package/src/materials/pathtracing/glsl/{directLightContribution.glsl.js → direct_light_contribution_function.glsl.js} +1 -1
  27. package/src/materials/pathtracing/glsl/{getSurfaceRecord.glsl.js → get_surface_record_function.glsl.js} +1 -1
  28. package/src/materials/pathtracing/glsl/index.js +6 -0
  29. package/src/materials/pathtracing/glsl/{renderStructs.glsl.js → render_structs.glsl.js} +1 -1
  30. package/src/materials/pathtracing/glsl/{traceScene.glsl.js → trace_scene_function.glsl.js} +1 -3
  31. package/src/materials/surface/AmbientOcclusionMaterial.js +8 -8
  32. package/src/objects/PhysicalSpotLight.js +2 -2
  33. package/src/shader/bsdf/{bsdfSampling.glsl.js → bsdf_functions.glsl.js} +19 -72
  34. package/src/shader/bsdf/{fog.glsl.js → fog_functions.glsl.js} +1 -1
  35. package/src/shader/bsdf/{ggx.glsl.js → ggx_functions.glsl.js} +1 -1
  36. package/src/shader/bsdf/index.js +5 -0
  37. package/src/shader/bsdf/{iridescence.glsl.js → iridescence_functions.glsl.js} +1 -1
  38. package/src/shader/bsdf/{sheen.glsl.js → sheen_functions.glsl.js} +1 -1
  39. package/src/shader/bvh/index.js +2 -0
  40. package/src/shader/{structs/fogMaterialBvh.glsl.js → bvh/inside_fog_volume_function.glsl.js} +1 -1
  41. package/src/shader/{common/bvhAnyHit.glsl.js → bvh/ray_any_hit_function.glsl.js} +1 -1
  42. package/src/shader/common/{fresnel.glsl.js → fresnel_functions.glsl.js} +1 -1
  43. package/src/shader/common/index.js +5 -0
  44. package/src/shader/common/{math.glsl.js → math_functions.glsl.js} +1 -1
  45. package/src/shader/common/{intersectShapes.glsl.js → shape_intersection_functions.glsl.js} +1 -1
  46. package/src/shader/common/{arraySamplerTexelFetch.glsl.js → texture_sample_functions.glsl.js} +1 -1
  47. package/src/shader/common/{utils.glsl.js → util_functions.glsl.js} +1 -1
  48. package/src/shader/rand/index.js +3 -0
  49. package/src/shader/rand/pcg.glsl.js +1 -1
  50. package/src/shader/rand/sobol.glsl.js +4 -4
  51. package/src/shader/rand/{stratifiedTexture.glsl.js → stratified.glsl.js} +7 -2
  52. package/src/shader/sampling/{equirectSampling.glsl.js → equirect_sampling_functions.glsl.js} +1 -2
  53. package/src/shader/sampling/index.js +3 -0
  54. package/src/shader/sampling/{lightSampling.glsl.js → light_sampling_functions.glsl.js} +3 -3
  55. package/src/shader/sampling/{shapeSampling.glsl.js → shape_sampling_functions.glsl.js} +1 -1
  56. package/src/shader/structs/{cameraStruct.glsl.js → camera_struct.glsl.js} +1 -1
  57. package/src/shader/structs/{equirectStruct.glsl.js → equirect_struct.glsl.js} +1 -1
  58. package/src/shader/structs/index.js +5 -0
  59. package/src/shader/structs/{lightsStruct.glsl.js → lights_struct.glsl.js} +1 -1
  60. package/src/shader/structs/{materialStruct.glsl.js → material_struct.glsl.js} +2 -2
  61. package/src/shader/structs/surface_record_struct.glsl.js +63 -0
  62. package/src/uniforms/EquirectHdrInfoUniform.js +16 -11
  63. package/src/uniforms/LightsInfoUniformStruct.js +21 -10
  64. package/src/uniforms/MaterialsTexture.js +27 -86
  65. package/src/uniforms/RenderTarget2DArray.js +60 -20
  66. package/src/utils/BlurredEnvMapGenerator.js +12 -5
  67. package/src/utils/SobolNumberMapGenerator.js +3 -3
  68. package/src/utils/bufferToHash.js +22 -0
  69. package/src/core/DynamicPathTracingSceneGenerator.js +0 -164
  70. package/src/core/MaterialReducer.js +0 -256
  71. package/src/materials/pathtracing/LambertPathTracingMaterial.js +0 -297
  72. package/src/uniforms/IESProfilesTexture.js +0 -100
  73. package/src/uniforms/utils.js +0 -30
  74. package/src/utils/IESLoader.js +0 -327
  75. package/src/workers/PathTracingSceneWorker.js +0 -52
package/README.md CHANGED
@@ -30,6 +30,8 @@ _More features and capabilities in progress!_
30
30
 
31
31
  [Depth of Field](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/depthOfField.html)
32
32
 
33
+ [HDR Image](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/hdr.html)
34
+
33
35
  **Features**
34
36
 
35
37
  [Skinned Geometry Support](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/skinnedMesh.html)
@@ -58,9 +60,6 @@ _More features and capabilities in progress!_
58
60
 
59
61
  [Ambient Occlusion Material](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/aoRender.html)
60
62
 
61
- [Looking Glass Portrait Quilt Render](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/lkg.html)
62
-
63
-
64
63
  ## Running examples locally
65
64
 
66
65
  To run and modify the examples locally, make sure you have Node and NPM installed. Check the supported versions in [the test configuration](./.github/workflows/node.js.yml).
@@ -79,82 +78,22 @@ On Debian or Ubuntu, run `sudo apt install build-essential`. It should just wor
79
78
 
80
79
  ```js
81
80
  import * as THREE from 'three';
82
- import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
83
- import {
84
- PathTracingSceneGenerator,
85
- PathTracingRenderer,
86
- PhysicalPathTracingMaterial,
87
- } from 'three-gpu-pathtracer';
81
+ import { WebGLPathTracer } from 'three-gpu-pathtracer';
88
82
 
89
- // init scene, renderer, camera, controls, etc
83
+ // init scene, camera, controls, etc
90
84
 
91
- renderer.outputEncoding = THREE.sRGBEncoding;
85
+ renderer = new THREE.WebGLRenderer();
92
86
  renderer.toneMapping = THREE.ACESFilmicToneMapping;
93
87
 
94
- // initialize the path tracing material and renderer
95
- const ptMaterial = new PhysicalPathTracingMaterial();
96
- const ptRenderer = new PathTracingRenderer( renderer );
97
- ptRenderer.setSize( window.innerWidth, window.innerHeight );
98
- ptRenderer.camera = camera;
99
- ptRenderer.material = ptMaterial;
100
-
101
- // if rendering transparent background
102
- ptRenderer.alpha = true;
103
-
104
- // init quad for rendering to the canvas
105
- const fsQuad = new FullScreenQuad( new THREE.MeshBasicMaterial( {
106
- map: ptRenderer.target.texture,
107
-
108
- // if rendering transparent background
109
- blending: THREE.CustomBlending,
110
- } ) );
111
-
112
- // ensure scene matrices are up to date
113
- scene.updateMatrixWorld();
114
-
115
- // initialize the scene and update the material properties with the bvh, materials, etc
116
- const generator = new PathTracingSceneGenerator();
117
- const { bvh, textures, materials, lights } = generator.generate( scene );
118
-
119
- // update bvh and geometry attribute textures
120
- ptMaterial.bvh.updateFrom( bvh );
121
- ptMaterial.attributesArray.updateFrom(
122
- geometry.attributes.normal,
123
- geometry.attributes.tangent,
124
- geometry.attributes.uv,
125
- geometry.attributes.color,
126
- );
127
-
128
- // update materials and texture arrays
129
- ptMaterial.materialIndexAttribute.updateFrom( geometry.attributes.materialIndex );
130
- ptMaterial.textures.setTextures( renderer, 2048, 2048, textures );
131
- ptMaterial.materials.updateFrom( materials, textures );
132
-
133
- // update the lights
134
- ptMaterial.lights.updateFrom( lights );
135
-
136
- // set the environment map
137
- const texture = await new RGBELoader().setDataType( THREE.FloatType ).loadAsync( envMapUrl );
138
- ptRenderer.material.envMapInfo.updateFrom( texture );
88
+ pathTracer = new WebGLPathTracer( renderer );
89
+ pathTracer.setScene( scene, camera );
139
90
 
140
91
  animate();
141
92
 
142
- // ...
143
-
144
93
  function animate() {
145
94
 
146
- // if the camera position changes call "ptRenderer.reset()"
147
-
148
- // update the camera and render one sample
149
- camera.updateMatrixWorld();
150
- ptRenderer.update();
151
-
152
- // if using alpha = true then the target texture will change every frame
153
- // so we must retrieve it before render.
154
- fsQuad.material.map = ptRenderer.target.texture;
155
-
156
- // copy the current state of the path tracer to canvas to display
157
- fsQuad.render( renderer );
95
+ requestAnimationFrame( animate );
96
+ pathTracer.renderSample();
158
97
 
159
98
  }
160
99
  ```
@@ -176,245 +115,227 @@ const blurredEnvMap = generator.generate( envMap, 0.35 );
176
115
 
177
116
  ```
178
117
 
179
- ## Dynamic Scenes
118
+ # Exports
180
119
 
181
- Using the dynamic scene generator the same, frequently updated scene can be converted into a single reusable geometry multiple times and BVH refit which greatly improves subsequent scene updates. See `DynamicPathTracingSceneGenerator` docs for more info.
120
+ ## WebGLPathTracer
182
121
 
183
- ```js
184
- import { DynamicPathTracingSceneGenerator } from 'three-gpu-pathtracer';
122
+ ### constructor
185
123
 
186
- // ... initialize scene etc
124
+ ```
125
+ constructor( renderer : WebGLRenderer )
126
+ ```
187
127
 
188
- const generator = new DynamicPathTracingSceneGenerator( scene );
189
- const { bvh, textures, materials } = generator.generate( scene );
128
+ ### .bounces
190
129
 
191
- // ... update path tracer and render
130
+ ```js
131
+ bounces = 10 : Number
192
132
  ```
193
133
 
194
- ## Asynchronous Scene Generation
134
+ Max number of lights bounces to trace.
195
135
 
196
- _NOTE WebWorker syntax is inconsistently supported across bundlers and sometimes not supported at all so the PathTracingSceneWorker class is not exported from the package root. If needed the code from src/worker can be copied and modified to accomodate a particular build process._
136
+ ### .filteredGlossyFactor
197
137
 
198
138
  ```js
199
- import { PathTracingSceneWorker } from 'three-gpu-pathtracer/src/workers/PathTracingSceneWorker.js';
139
+ filteredGlossyFactor = 0 : Number
140
+ ```
200
141
 
201
- // ...
142
+ Factor for alleviating bright pixels from rays that hit diffuse surfaces then specular surfaces. Setting this higher alleviates fireflies but will remove some specular caustics.
202
143
 
203
- // initialize the scene and update the material properties with the bvh, materials, etc
204
- const generator = new PathTracingSceneWorker();
205
- const { bvh, textures, materials, lights } = await generator.generate( scene );
144
+ ### .tiles
206
145
 
207
- // ...
146
+ ```js
147
+ tiles = ( 3, 3 ) : Vector2
208
148
  ```
209
149
 
210
- # Exports
211
-
212
- ## PathTracingRenderer
213
-
214
- Utility class for tracking and rendering a path traced scene to a render target.
150
+ Number of tiles on x and y to render to. Can be used to improve the responsiveness of a page while still rendering a high resolution target.
215
151
 
216
- ### .samples
152
+ ### .renderDelay
217
153
 
218
154
  ```js
219
- readonly samples : Number
155
+ renderDelay = 100 : Number
220
156
  ```
221
157
 
222
- Number of samples per pixel that have been rendered to the target.
158
+ Number of milliseconds to delay rendering samples after the path tracer has been reset.
223
159
 
224
- ### .target
160
+ ### .fadeDuration
225
161
 
226
162
  ```js
227
- readonly target : WebGLRenderTarget
163
+ fadeDuration = 500 : Number
228
164
  ```
229
165
 
230
- The target being rendered to. The size of the target is updated with `setSize` and is initialized to a FloatType texture.
166
+ How long to take to fade the fully path traced scene in in milliseconds wen rendering to the canvas.
231
167
 
232
- > **Note**
233
- > Target will swap render targets after every full sample when alpha is enabled.
234
-
235
- ### .camera
168
+ ### .minSamples
236
169
 
237
170
  ```js
238
- camera = null : Camera
171
+ minSamples = 5 : Number
239
172
  ```
240
173
 
241
- The camera to render with. The view offset of the camera will be updated every sample to enable anti aliasing.
174
+ How many samples to render before displaying to the canvas.
242
175
 
243
- ### .material
176
+ ### .dynamicLowRes
244
177
 
245
178
  ```js
246
- material = null : ShaderMaterial
179
+ dynamicLowRes = false : Boolean
247
180
  ```
248
181
 
249
- The Path Tracing material to render. This is expected to be a full screen quad material that respects the "opacity" field for every pixel so samples can be accumulated over time. The material is also expected to have `cameraWorldMatrix` and `invProjectionMatrix` fields of type `Matrix4`.
182
+ Whether to render an extra low resolution of the scene while the full resolution renders. The scale is defined by `lowResScale`.
250
183
 
251
- ### .tiles
184
+ ### .lowResScale
252
185
 
253
186
  ```js
254
- tiles = ( 1, 1 ) : Vector2
187
+ lowResScale = 0.1 : Number
255
188
  ```
256
189
 
257
- Number of tiles on x and y to render to. Can be used to improve the responsiveness of a page while still rendering a high resolution target.
190
+ The scale to render the low resolution pass at.
258
191
 
259
- ### .stableNoise
192
+ ### .synchronizeRenderSize
260
193
 
261
194
  ```js
262
- stableNoise = false : Boolean
195
+ synchronizeRenderSize = true : Boolean
263
196
  ```
264
197
 
265
- Whether to reset the random seed to `0` when restarting the render. If true then a consistent random sample pattern will appear when moving the camera, for example.
198
+ Whether to automatically update the sie of the path traced buffer when the canvas size changes.
266
199
 
267
- ### .stableTiles
200
+ ### .renderScale
268
201
 
269
202
  ```js
270
- stableTiles = true : Boolean
203
+ renderScale = 1 : Number
271
204
  ```
272
205
 
273
- Whether the initial tile is reset to the top left tile when moving the camera or if it should continue to shift every frame.
206
+ The scale to render the path traced image at. Only relevant if `synchronizeRenderSize` is true.
274
207
 
275
- ### .alpha
208
+ ### .renderToCanvas
276
209
 
277
210
  ```js
278
- alpha = false : Boolean
211
+ renderToCanvas = true : Boolean
279
212
  ```
280
213
 
281
- Whether to support rendering scenes with transparent backgrounds. When transparent backgrounds are used two extra render targets are used, custom blending is performed, and PathTracingRenderer.target will change on every completed sample.
214
+ Whether to automatically render the path traced buffer to the canvas when `renderSample` is called.
282
215
 
283
- > **Note**
284
- > When a transparent background is used the material used for the final render to the canvas must use the same "premultipliedAlpha" setting as the canvas otherwise the final image may look incorrect.
285
-
286
- ### constructor
216
+ ### .rasterizeScene
287
217
 
288
218
  ```js
289
- constructor( renderer : WebGLRenderer )
219
+ rasterizeScene = true : Boolean
290
220
  ```
291
221
 
292
- ### .setSize
222
+ Whether to automatically rasterize the scene with the three.js renderer while the path traced buffer is rendering.
223
+
224
+ ### .textureSize
293
225
 
294
226
  ```js
295
- setSize( size : Vector2 ) : void
227
+ textureSize = ( 1024, 1024 ) : Vector2
296
228
  ```
297
229
 
298
- Sets the size of the target to render to.
230
+ The dimensions to expand or shrink all textures to so all scene textures can be packed into a single texture array.
299
231
 
300
- ### .update
232
+ ### .samples
301
233
 
302
234
  ```js
303
- update()
235
+ readonly samples : Number
304
236
  ```
305
237
 
306
- Renders a single sample to the target.
238
+ The number of samples that have been rendered.
307
239
 
308
- ### .reset
240
+ ### .target
309
241
 
310
242
  ```js
311
- reset() : void
243
+ readonly target : WebGLRenderTarget
312
244
  ```
313
245
 
314
- Resets and restarts the render from scratch.
315
-
316
- ## QuiltPathTracingRenderer
317
-
318
- Renderer that supports rendering to a quilt renderer to rendering on displays such as the Looking Glass display.
246
+ The path traced render target. This potentially changes every call to `renderSample`.
319
247
 
320
- ### .viewCount
248
+ ### .setScene
321
249
 
322
250
  ```js
323
- viewCount = 48 : Number
251
+ setScene( scene : Scene, camera : Camera ) : void
324
252
  ```
325
253
 
326
- The number of views to be rendered. If this is less than the product of the quiltDimensions then there will be gaps at the end of the quilt.
254
+ Sets the scene and camera to render. Must be called again when the camera object changes, the geometry in the scene changes, or new materials are assigned.
327
255
 
328
- ### .quiltDimensions
329
- ```js
330
- quiltDimensions = Vector2( 8, 6 ) : Vector2
331
- ```
256
+ While only changed data is updated it is still a relatively expensive function. Prefer to use the other "update" functions where possible.
332
257
 
333
- The number of quilt patches in each dimension.
258
+ ### .setSceneAsync
334
259
 
335
- ### .viewCone
336
260
  ```js
337
- viewCone = 35 * DEG2RAD : Number
261
+ setSceneAsync(
262
+ scene : Scene,
263
+ camera : Camera,
264
+ options = {
265
+ onProgress = null : value => void,
266
+ } : Object
267
+ ) : void
338
268
  ```
339
269
 
340
- The total angle sweep for the camera views rendered across the quilt.
270
+ Asynchronous version of `setScene`. Requires calling `setBVHWorker` first.
341
271
 
342
- ### .viewFoV
272
+ ### .updateCamera
343
273
 
344
274
  ```js
345
- viewFoV = 14 * DEG2RAD : Number
275
+ updateCamera() : void
346
276
  ```
347
277
 
348
- The camera field of view to render.
278
+ Updates the camera parameters. Must be called if any of the parameters on the previously set camera change.
349
279
 
350
- ### .displayDistance
280
+ ### .updateMaterials
351
281
 
352
282
  ```js
353
- displayDistance = 1 : Number
283
+ updateMaterials() : void
354
284
  ```
355
285
 
356
- The distance of the viewer to the display.
286
+ Updates the material properties. Must be called when properties change for any materials already being used.
357
287
 
358
- ### .displayAspect
288
+ Note that materials used with WebGLPathTracer support the following additional properties:
359
289
 
360
290
  ```js
361
- displayAspect = 0.75 : Number
362
- ```
291
+ // Whether to render the object as completely transparent against the rest
292
+ // of the environment so other objects can be composited later
293
+ matte = false : Boolean;
363
294
 
364
- The aspect ratio of the display.
295
+ // Whether the object should cast a shadow
296
+ castShadow = true : Boolean;
297
+ ```
365
298
 
366
- ### .setFromDisplayView
299
+ ### .updateEnvironment
367
300
 
368
301
  ```js
369
- setFromDisplayView(
370
- displayDistance : Number,
371
- displayWidth : Number,
372
- displayHeight : Number,
373
- ) : void
302
+ updateEnvironment() : void
374
303
  ```
375
304
 
376
- Updates the `displayDistance`, `displayAspect`, and the `viewFoV` from viewer and display information.
377
-
378
- ## PathTracingSceneGenerator
305
+ Updates lighting from the scene environment and background properties. Must be called if any associated scene settings change on the set scene object.
379
306
 
380
- Utility class for generating the set of data required for initializing the path tracing material with a bvh, geometry, materials, and textures.
381
-
382
- ### .generate
307
+ ### .updateLights
383
308
 
384
309
  ```js
385
- generate( scene : Object3D | Array<Object3D>, options = {} : Object ) : {
386
- bvh : MeshBVH,
387
- materials : Array<Material>,
388
- textures : Array<Texture>,
389
- lights : Array<Light>
390
- }
310
+ updateLights() : void
391
311
  ```
392
312
 
393
- Merges the geometry in the given scene with an additional "materialIndex" attribute that references the associated material array. Also produces a set of textures referenced by the scene materials.
313
+ Updates lights used in path tracing. Must be called if any lights are added or removed or properties change.
394
314
 
395
- ## PathTracingSceneWorker
315
+ ### .renderSample
396
316
 
397
- _extends PathTracingSceneGenerator_
317
+ ```js
318
+ renderSample() : void
319
+ ```
398
320
 
399
- See note in [Asyncronous Generation](#asynchronous-generation) use snippet.
321
+ Render a single sample to the path tracer target. If `renderToCanvas` is true then the image is rendered to the canvas.
400
322
 
401
- ### .generate
323
+ ### .reset
402
324
 
403
325
  ```js
404
- async generate( scene : Object3D | Array<Object3D>, options = {} : Object ) : {
405
- bvh : MeshBVH,
406
- materials : Array<Material>,
407
- textures : Array<Texture>,
408
- lights : Array<Light>
409
- }
326
+ reset() : void
410
327
  ```
411
328
 
329
+ Restart the rendering.
330
+
412
331
  ### .dispose
413
332
 
414
333
  ```js
415
334
  dispose() : void
416
335
  ```
417
336
 
337
+ Dispose the path tracer assets. Any materials or textures used must be disposed separately.
338
+
418
339
  ## PhysicalCamera
419
340
 
420
341
  _extends THREE.PerspectiveCamera_
@@ -487,10 +408,10 @@ radius = 0 : Number
487
408
 
488
409
  The radius of the spotlight surface. Increase this value to add softness to shadows.
489
410
 
490
- ### .iesTexture
411
+ ### .iesMap
491
412
 
492
413
  ```js
493
- iesTexture = null : Texture
414
+ iesMap = null : Texture
494
415
  ```
495
416
 
496
417
  The loaded IES texture describing directional light intensity. These can be loaded with the `IESLoader`.
@@ -509,42 +430,6 @@ isCircular = false : Boolean
509
430
 
510
431
  Whether the area light should be rendered as a circle or a rectangle.
511
432
 
512
- ## DynamicPathTracingSceneGenerator
513
-
514
- A variation of the path tracing scene generator intended for quickly regenerating a scene BVH representation that updates frequently. Ie those with animated objects or animated skinned geometry.
515
-
516
- In order to quickly update a dynamic scene the same BVH is reused across updates by refitting rather than regenerating. This is significantly faster but also results in a less optimal BVH after significant changes.
517
-
518
- If geometry or materials are added or removed from the scene then `reset` must be called.
519
-
520
- ### constructor
521
-
522
- ```js
523
- constructor( scene : Object3D | Array<Object3D> )
524
- ```
525
-
526
- Takes the scene to convert.
527
-
528
- ### .generate
529
-
530
- ```js
531
- generate() : {
532
- bvh : MeshBVH,
533
- materials : Array<Material>,
534
- textures : Array<Texture>
535
- }
536
- ```
537
-
538
- Generates and refits the bvh to the current scene state. The same bvh, materials, and textures objects are returns after the initial call until `reset` is called.
539
-
540
- ### .reset
541
-
542
- ```js
543
- reset() : void
544
- ```
545
-
546
- Resets the generator so a new BVH is generated. This must be called when geometry, objects, or materials are added or removed from the scene.
547
-
548
433
  ## IESLoader
549
434
 
550
435
  _extends Loader_
@@ -623,74 +508,6 @@ setDefine( name : string, value = undefined : any ) : void
623
508
 
624
509
  Sets the define of the given name to the provided value. If the value is set to null or undefined then it is deleted from the defines of the material. If the define changed from the previous value then `Material.needsUpdate` is set to `true`.
625
510
 
626
- ## PhysicalPathTracingMaterial
627
-
628
- _extends MaterialBase_
629
-
630
- **Uniforms**
631
-
632
- ```js
633
- {
634
- // The number of ray bounces to test. Higher is better quality but slower performance.
635
- // TransmissiveBounces indicates the number of additional transparent or translucent surfaces
636
- // the ray can pass through.
637
- bounces = 3 : Number,
638
- transmissiveBounces = 10 : Number,
639
-
640
- // The number of additional transmissive ray bounces to allow on top of existing bounces for object opacity / transmission.
641
- transmissiveBounces = 5 : Number,
642
-
643
- // The physical camera parameters to use
644
- physicalCamera : PhysicalCameraUniform,
645
-
646
- // Geometry and BVH information
647
- bvh: MeshBVHUniformStruct,
648
- attributesArray: AttributesTextureArray,
649
- materialIndexAttribute: UIntVertexAttributeTexture,
650
- materials: MaterialsTexture,
651
- textures: RenderTarget2DArray,
652
-
653
- // Light information
654
- lights: LightsInfoUniformStruct,
655
- iesProfiles: IESProfilesTexture,
656
-
657
- // Environment Map information
658
- envMapInfo: EquirectHdrInfoUniform,
659
- environmentRotation: Matrix4,
660
- environmentIntensity = 1: Number,
661
-
662
- // background blur
663
- backgroundBlur = 0: Number,
664
-
665
- // Factor for alleviating bright pixels from rays that hit diffuse surfaces then
666
- // specular surfaces. Setting this higher alleviates fireflies but will remove some
667
- // specular caustics.
668
- filterGlossyFactor = 0: Number,
669
-
670
- // The equirectangular map to render as the background.
671
- backgroundMap = null: Texture,
672
-
673
- // The transparency to render the background with. Note that the "alpha" option
674
- // must be set to true on PathTracingRenderer for this field to work properly.
675
- backgroundAlpha: 1.0,
676
- }
677
- ```
678
-
679
- **Defines**
680
-
681
- ```js
682
- {
683
-
684
- // Whether to use multiple importance sampling to help the image converge more quickly.
685
- FEATURE_MIS = 1 : Number,
686
-
687
- // Whether to use russian roulette path termination. Path termination will kick in after
688
- // a minimum three bounces have been performed.
689
- FEATURE_RUSSIAN_ROULETTE = 1 : Number,
690
-
691
- }
692
- ```
693
-
694
511
  ## FogVolumeMaterial
695
512
 
696
513
  _extends MeshStandardMaterial_
@@ -726,161 +543,7 @@ Denoise material based on [BrutPitt/glslSmartDeNoise](https://github.com/BrutPit
726
543
 
727
544
  }
728
545
  ```
729
-
730
- ## RenderTarget2DArray
731
-
732
- _extends WebGLArrayRenderTarget_
733
-
734
- A convenience extension from `WebGLArrayRenderTarget` that affords easily creating a uniform texture array from an array of textures.
735
-
736
- ### .setTextures
737
-
738
- ```js
739
- setTextures(
740
- renderer : WebGLRenderer,
741
- width : Number,
742
- height : Number,
743
- textures : Array<Texture>
744
- ) : void
745
- ```
746
-
747
- Takes the rendering context to update the target for, the target dimensions of the texture array, and the array of textures to render into the 2D texture array. Every texture is stretched to the dimensions of the texture array at the same index they are provided in.
748
-
749
- ## PhysicalCameraUniform
750
-
751
- Uniform for storing the camera parameters for use with the shader.
752
-
753
- ### .updateFrom
754
-
755
- ```js
756
- updateFrom( camera : PerspectiveCamera | PhysicalCamera ) : void
757
- ```
758
-
759
- Copies all fields from the passed PhysicalCamera if available otherwise the defaults are used.
760
-
761
- ## AttributesTextureArray
762
-
763
- A combined texture array used to store normal, tangent, uv, and color attributes in the same texture sampler array rather than separate samplers. Necessary to save texture slots.
764
-
765
- Normals, tangents, uvs, and color attribute data are stored in the 1st, 2nd, 3rd, and 4th layers of the array respectively.
766
-
767
- ### .updateNormalAttribute
768
-
769
- ```js
770
- updateNormalAttribute( attr : BufferAttribute ) : void
771
- ```
772
-
773
- ### .updateTangentAttribute
774
-
775
- ```js
776
- updateTangentAttribute( attr : BufferAttribute ) : void
777
- ```
778
-
779
- ### .updateUvAttribute
780
-
781
- ```js
782
- updateUvAttribute( attr : BufferAttribute ) : void
783
- ```
784
-
785
- ### .updateColorAttribute
786
-
787
- ```js
788
- updateColorAttribute( attr : BufferAttribute ) : void
789
- ```
790
-
791
- ### .updateFrom
792
-
793
- ```js
794
- updateFrom(
795
- normal : BufferAttribute,
796
- tangent : BufferAttribute,
797
- uv : BufferAttribute,
798
- color : BufferAttribute
799
- ) : void
800
- ```
801
-
802
- ## MaterialsTexture
803
-
804
- _extends DataTexture_
805
-
806
- Helper texture uniform for encoding materials as texture data.
807
-
808
- ### .threeCompatibilityTransforms
809
-
810
- ```js
811
- threeCompatibilityTransforms = false : Boolean
812
- ```
813
-
814
- Three.js materials support only a single set of UV transforms in a certain fallback priority while the pathtracer supports a unique set of transforms per texture. Set this field to true in order to use the same uv transform handling as three.js materials.
815
-
816
- See fallback order documentation [here](https://threejs.org/docs/#api/en/textures/Texture.offset).
817
-
818
- ### .setMatte
819
-
820
- ```js
821
- setMatte( index : Number, matte : Boolean ) : void
822
- ```
823
-
824
- Sets whether or not the material of the given index is matte or not. When "true" the background is rendered in place of the material.
825
-
826
- ### .setCastShadow
827
-
828
- ```js
829
- setCastShadow( index : Number, enabled : Boolean ) : void
830
- ```
831
-
832
- Sets whether or not the material of the given index will cast shadows. When "false" materials will not cast shadows on diffuse surfaces but will still be reflected. This is a good setting for lighting enclosed interiors with environment lighting.
833
-
834
- ### .updateFrom
835
-
836
- ```js
837
- updateFrom( materials : Array<Material>, textures : Array<Texture> ) : void
838
- ```
839
-
840
- Updates the size and values of the texture to align with the provided set of materials and textures.
841
-
842
- The "matte" and "side" values must be updated explicitly.
843
-
844
- > **Note**
845
- > In order for volume transmission to work the "attenuationDistance" must be set to a value less than Infinity or "thickness" must be set to a value greater than 0.
846
-
847
- ## LightsInfoUniformStruct
848
-
849
- Helper uniform for encoding lights as texture data with count.
850
-
851
- ### .updateFrom
852
-
853
- ```js
854
- updateFrom( lights : Array<Light>, iesTextures = [] : Array<Texture> ) : void
855
- ```
856
-
857
- Updates the size and values of the texture to align with the provided set of lights and IES textures.
858
-
859
- ## EquirectHdrInfoUniform
860
-
861
- Stores the environment map contents along with the intensity distribution information to support multiple importance sampling.
862
-
863
- ### .updateFrom
864
-
865
- ```js
866
- updateFrom( environmentMap : Texture ) : void
867
- ```
868
-
869
- Takes an environment map to process into something usable by the path tracer. Is expected to be a DataTexture so the data can be read.
870
-
871
- ## Functions
872
-
873
- ### mergeMeshes
874
-
875
- ```js
876
- mergeMeshes( meshes : Array<Mesh> ) : {
877
- materials : Array<Material>,
878
- textures : Array<Textures>,
879
- geometry : BufferGeometry
880
- }
881
- ```
882
-
883
- Merges the set of meshes into a single geometry with a `materialIndex` vertex attribute included on the geometry identifying the associated material in the returned `materials` array.
546
+ <!--
884
547
 
885
548
  ## CompatibilityDetector
886
549
 
@@ -905,23 +568,7 @@ detect() : {
905
568
 
906
569
  Returns `pass === true` if the path tracer can run. If it cannot run then a message is returned indicating why.
907
570
 
908
- ## Shader Chunks
909
-
910
- **shaderMaterialSampling**
911
-
912
- Set of functions for performing material scatter and PDF sampling. See the [implementation](https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/shader/shaderMaterialSampling.js) for full list of functions.
913
-
914
- **shaderLightSampling**
915
-
916
- Set of functions for performing light sampling. See the [implementation](https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/shader/shaderLightSampling.js) for full list of functions.
917
-
918
- **shaderStructs**
919
-
920
- Material and light struct definition for use with uniforms. See the [implementation](https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/shader/shaderStructs.js) for full list of functions.
921
-
922
- **shaderUtils**
923
-
924
- Set of randomness and other light transport utilities for use in a shader. See the [implementation](https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/shader/shaderUtils.js) for full list of functions.
571
+ -->
925
572
 
926
573
  # Gotchas
927
574