three-gpu-pathtracer 0.0.2 → 0.0.3

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 CHANGED
@@ -43,6 +43,8 @@ _More features and capabilities in progress!_
43
43
 
44
44
  # Use
45
45
 
46
+ **Basic Renderer**
47
+
46
48
  ```js
47
49
  import * as THREE from 'three';
48
50
  import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
@@ -57,14 +59,24 @@ import {
57
59
  // initialize the path tracing material and renderer
58
60
  const ptMaterial = new PhysicalPathTracingMaterial();
59
61
  const ptRenderer = new PathTracingRenderer( renderer );
62
+ ptRenderer.setSize( window.innerWidth, window.innerHeight );
60
63
  ptRenderer.camera = camera;
61
64
  ptRenderer.material = ptMaterial;
62
65
 
66
+ // if rendering transparent background
67
+ ptRenderer.alpha = true;
68
+
63
69
  // init quad for rendering to the canvas
64
70
  const fsQuad = new FullScreenQuad( new THREE.MeshBasicMaterial( {
65
71
  map: ptRenderer.target.texture,
72
+
73
+ // if rendering transparent background
74
+ blending: THREE.CustomBlending,
66
75
  } ) );
67
76
 
77
+ // ensure scene matrices are up to date
78
+ scene.updateMatrixWorld();
79
+
68
80
  // initialize the scene and update the material properties with the bvh, materials, etc
69
81
  const generator = new PathTracingSceneGenerator();
70
82
  const { bvh, textures, materials } = generator.generate( scene );
@@ -79,13 +91,10 @@ ptMaterial.uvAttribute.updateFrom( geometry.attributes.uv );
79
91
  ptMaterial.materialIndexAttribute.updateFrom( geometry.attributes.materialIndex );
80
92
  ptMaterial.textures.setTextures( renderer, 2048, 2048, textures );
81
93
  ptMaterial.materials.updateFrom( materials, textures );
82
- ptMaterial.setDefine( 'MATERIAL_LENGTH', materials.length );
83
94
 
84
95
  // set the environment map
85
96
  const texture = await new RGBELoader().loadAsync( envMapUrl );
86
- const pmremGenerator = new THREE.PMREMGenerator( renderer );
87
- const envMap = pmremGenerator.fromEquirectangular( texture );
88
- ptRenderer.material.environmentMap = envMap.texture;
97
+ ptRenderer.material.envMapInfo.updateFrom( texture );
89
98
 
90
99
  animate();
91
100
 
@@ -108,6 +117,23 @@ function animate() {
108
117
  }
109
118
  ```
110
119
 
120
+ **Blurred Environment Map**
121
+
122
+ Using a pre blurred envioronment map can help improve frame convergence time at the cost of sharp environment reflections. If performance is concern then multiple importance sampling can be disabled and blurred environment map used.
123
+
124
+ ```js
125
+ import { BlurredEnvMapGenerator } from 'three-gpu-pathtracer';
126
+
127
+ // ...
128
+
129
+ const envMap = await new RGBELoader().loadAsync( envMapUrl );
130
+ const generator = new BlurredEnvMapGenerator( renderer );
131
+ const blurredEnvMap = generator.generate( envMap, 0.35 );
132
+
133
+ // render!
134
+
135
+ ```
136
+
111
137
  ## Dynamic Scenes
112
138
 
113
139
  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.
@@ -188,11 +214,19 @@ Number of tiles on x and y to render to. Can be used to improve the responsivene
188
214
  ### .stableNoise
189
215
 
190
216
  ```js
191
- stableNoise = false
217
+ stableNoise = false : Boolean
192
218
  ```
193
219
 
194
220
  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.
195
221
 
222
+ ### .alpha
223
+
224
+ ```js
225
+ alpha = false : Boolean
226
+ ```
227
+
228
+ 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.
229
+
196
230
  ### constructor
197
231
 
198
232
  ```js
@@ -351,6 +385,32 @@ reset() : void
351
385
 
352
386
  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.
353
387
 
388
+ ## BlurredEnvMapGenerator
389
+
390
+ Utility for generating a PMREM blurred environment map that can be used with the path tracer.
391
+
392
+ ### constructor
393
+
394
+ ```js
395
+ constructor( renderer : WebGLRenderer )
396
+ ```
397
+
398
+ ### .generate
399
+
400
+ ```js
401
+ generate( texture : Texture, blur : Number ) : DataTexture
402
+ ```
403
+
404
+ Takes a texture to blur and the amount to blur it. Returns a new `DataTexture` that has been PMREM blurred environment map that can have distribution data generated for importance sampling.
405
+
406
+ ### .dispose
407
+
408
+ ```js
409
+ dispose() : void
410
+ ```
411
+
412
+ Disposes of the temporary files and textures for generation.
413
+
354
414
  ## MaterialBase
355
415
 
356
416
  _extends THREE.ShaderMaterial_
@@ -375,39 +435,39 @@ _extends MaterialBase_
375
435
  {
376
436
  // The number of ray bounces to test. Higher is better quality but slower performance.
377
437
  bounces = 3 : Number,
378
-
438
+
379
439
  // The physical camera parameters to use
380
440
  physicalCamera : PhysicalCameraUniform,
381
-
382
- // Geometry and BVH information,
441
+
442
+ // Geometry and BVH information
383
443
  bvh: MeshBVHUniformStruct,
384
444
  normalAttribute: FloatVertexAttributeTexture,
385
445
  tangentAttribute: FloatVertexAttributeTexture,
386
446
  uvAttribute: FloatVertexAttributeTexture,
387
447
  materialIndexAttribute: UIntVertexAttributeTexture,
388
- materials: MaterialStructArrayUniform,
448
+ materials: MaterialsTexture,
389
449
  textures: RenderTarget2DArray,
390
450
 
391
- // PMREM-processed Environment Map,
392
- environmentMap: Texture,
393
- environmentRotaton: Matrix3,
394
-
395
- // Environment Map information,
396
- environmentBlur = 0: Number,
451
+ // Environment Map information
452
+ envMapInfo: EquirectHdrInfoUniform,
453
+ environmentRotation: Matrix3,
397
454
  environmentIntensity = 1: Number,
398
455
 
456
+ // background blur
457
+ backgroundBlur = 0: Number,
458
+
399
459
  // Factor for alleviating bright pixels from rays that hit diffuse surfaces then
400
460
  // specular surfaces. Setting this higher alleviates fireflies but will remove some
401
461
  // specular caustics.
402
462
  filterGlossyFactor = 0: Number,
403
463
 
404
- // The colors to use for the gradient env lighting when no environment map is provided.
405
- gradientTop: Color,
406
- gradientBottom: Color,
407
-
408
464
  // The colors to use for the gradient background when enabled.
409
465
  bgGradientTop: Color,
410
466
  bgGradientBottom: Color,
467
+
468
+ // The transparency to render the background with. Note that the "alpha" option
469
+ // must be set to true on PathTracingRenderer for this field to work properly.
470
+ backgroundAlpha: 1.0,
411
471
  }
412
472
  ```
413
473
 
@@ -415,17 +475,16 @@ _extends MaterialBase_
415
475
 
416
476
  ```js
417
477
  {
418
- // Whether the shader should include logic for physical camera and depth of field
419
- DOF_SUPPORT = 1 : Number,
478
+
479
+ // Whether to use multiple importance sampling to help the image converge more quickly
480
+ FEATURE_MIS = 1 : Number,
481
+
482
+ // Whether to use the "bg" gradient fields to sample for the background
483
+ FEATURE_GRADIENT_BG = 0 : Number
420
484
 
421
485
  // The number of transparent pixels to allow on top of existing bounces for object transparency.
422
486
  TRANSPARENT_TRAVERSALS = 5 : Number,
423
487
 
424
- // Whether to use the "bg" gradient fields to sample for the backround
425
- GRADIENT_BG = 0 : Number
426
-
427
- // The number of materials provided in the "materials" uniform.
428
- MATERIAL_LENGTH : Number,
429
488
 
430
489
  }
431
490
  ```
@@ -461,45 +520,49 @@ updateFrom( camera : PerspectiveCamera | PhysicalCamera ) : void
461
520
 
462
521
  Copies all fields from the passed PhysicalCamera if available otherwise the defaults are used.
463
522
 
464
- ## MaterialStructArrayUniform
523
+ ## MaterialsTexture
465
524
 
466
- _extends Array_
525
+ _extends DataTexture_
467
526
 
468
- Array of `MaterialStructUniform` definitions for use as a Shader uniform.
527
+ Helper texture uniform for encoding materials as texture data.
469
528
 
470
- ### .updateFrom
529
+ ### .setSide
471
530
 
472
531
  ```js
473
- updateFrom( materials : Array<Material>, textures : Array<Texture> ) : void
532
+ setSide( index : Number, side : FrontSide | BackSide | DoubleSide ) : void
474
533
  ```
475
534
 
476
- Updates the value of the uniform to align with the provided set of materials and textures.
477
-
478
- ## MaterialStructUniform
479
-
480
- Struct definiton for representing material information as a uniform. See the [implementation](https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/shader/shaderStructs.js) for full struct definition information.
535
+ Sets the side to render for the given material.
481
536
 
482
- ### .side
537
+ ### .setMatte
483
538
 
484
539
  ```js
485
- side = 0 : Number
540
+ setMatte( index : Number, matte : Boolean ) : void
486
541
  ```
487
542
 
488
- This is the only field that needs to be set explicitly and is not derived from the Material setting. It defaults to rendering double sided triangles since transmissive volumes require solid, double sided geometry. The possible options are as follows:
543
+ 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.
544
+
545
+ ### .updateFrom
489
546
 
490
547
  ```js
491
- 0 // Double Sided
492
- 1 // Front Sided
493
- -1 // Back Sided
548
+ updateFrom( materials : Array<Material>, textures : Array<Texture> ) : void
494
549
  ```
495
550
 
551
+ Updates the size and values of the texture to align with the provided set of materials and textures.
552
+
553
+ The "matte" and "side" values must be updated explicitly.
554
+
555
+ ## EquirectHdrInfoUniform
556
+
557
+ Stores the environment map contents along with the intensity distribution information to support multiple importance sampling.
558
+
496
559
  ### .updateFrom
497
560
 
498
561
  ```js
499
- updateFrame( material : Material, textures : Array<Texture> ) : void
562
+ updateFrom( environmentMap : Texture ) : void
500
563
  ```
501
564
 
502
- Updates the uniform with the information from the passed material. Texture fields are set to the index of the texture in the provided textures array.
565
+ 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.
503
566
 
504
567
  ## Functions
505
568