three-gpu-pathtracer 0.0.1 → 0.0.2

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
@@ -1,29 +1,50 @@
1
1
  # three-gpu-pathtracer
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/three-gpu-pathtracer.svg?style=flat-square)](https://www.npmjs.com/package/three-gpu-pathtracer)
3
4
  [![lgtm code quality](https://img.shields.io/lgtm/grade/javascript/g/gkjohnson/three-gpu-pathtracer.svg?style=flat-square&label=code-quality)](https://lgtm.com/projects/g/gkjohnson/three-gpu-pathtracer/)
4
5
  [![build](https://img.shields.io/github/workflow/status/gkjohnson/three-gpu-pathtracer/Node.js%20CI?style=flat-square&label=build)](https://github.com/gkjohnson/three-gpu-pathtracer/actions)
6
+ [![github](https://flat.badgen.net/badge/icon/github?icon=github&label)](https://github.com/gkjohnson/three-gpu-pathtracer/)
7
+ [![twitter](https://flat.badgen.net/twitter/follow/garrettkjohnson)](https://twitter.com/garrettkjohnson)
8
+ [![sponsors](https://img.shields.io/github/sponsors/gkjohnson?style=flat-square&color=1da1f2)](https://github.com/sponsors/gkjohnson/)
5
9
 
6
10
  ![](https://user-images.githubusercontent.com/734200/162287477-96696b18-890b-4c1b-8a73-d662e577cc48.png)
7
11
 
8
- Path tracing project using [three-mesh-bvh](https://github.com/gkjohnson/three-mesh-bvh) to accelerate high quality, physically based rendering on the GPU. Features include support for GGX surface model, material information, textures, normal maps, emission, environment maps, tiled rendering, and more!
12
+ Path tracing project using [three-mesh-bvh](https://github.com/gkjohnson/three-mesh-bvh) and WebGL 2 to accelerate high quality, physically based rendering on the GPU. Features include support for GGX surface model, material information, textures, normal maps, emission, environment maps, tiled rendering, and more!
9
13
 
10
14
  _More features and capabilities in progress!_
11
15
 
12
16
  # Examples
13
17
 
14
- [PBR demo here](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html)!
18
+ **Beauty Demos**
15
19
 
16
- [Lego demo here](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/lego.html)!
20
+ [Physically Based Materials](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html)
17
21
 
18
- [Material demo here](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/materialBall.html)!
22
+ [Lego Models](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/lego.html)
19
23
 
20
- [Transmission preset demo here](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/materialBall.html#transmission)!
24
+ [Interior Scene](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/interior.html)
21
25
 
22
- [Ambient Occlusion Material demo here](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/aoRender.html)!
26
+ [Depth of Field](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/depthOfField.html)
27
+
28
+ **Features**
29
+
30
+ [Skinned Geometry Support](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/skinnedMesh.html)
31
+
32
+ [Morph Target Support](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/skinnedMesh.html#morphtarget)
33
+
34
+ **Test Scenes**
35
+
36
+ [Material Test Orb](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/materialBall.html)
37
+
38
+ [Transmission Preset Orb](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/materialBall.html#transmission)
39
+
40
+ **Light Baking**
41
+
42
+ [Ambient Occlusion Material](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/aoRender.html)
23
43
 
24
44
  # Use
25
45
 
26
46
  ```js
47
+ import * as THREE from 'three';
27
48
  import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
28
49
  import {
29
50
  PathTracingSceneGenerator,
@@ -46,7 +67,7 @@ const fsQuad = new FullScreenQuad( new THREE.MeshBasicMaterial( {
46
67
 
47
68
  // initialize the scene and update the material properties with the bvh, materials, etc
48
69
  const generator = new PathTracingSceneGenerator();
49
- const { bvh, textures, materials } = await generator.generate( scene );
70
+ const { bvh, textures, materials } = generator.generate( scene );
50
71
 
51
72
  // update bvh and geometry attribute textures
52
73
  ptMaterial.bvh.updateFrom( bvh );
@@ -63,8 +84,6 @@ ptMaterial.setDefine( 'MATERIAL_LENGTH', materials.length );
63
84
  // set the environment map
64
85
  const texture = await new RGBELoader().loadAsync( envMapUrl );
65
86
  const pmremGenerator = new THREE.PMREMGenerator( renderer );
66
- pmremGenerator.compileCubemapShader();
67
-
68
87
  const envMap = pmremGenerator.fromEquirectangular( texture );
69
88
  ptRenderer.material.environmentMap = envMap.texture;
70
89
 
@@ -89,6 +108,37 @@ function animate() {
89
108
  }
90
109
  ```
91
110
 
111
+ ## Dynamic Scenes
112
+
113
+ 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.
114
+
115
+ ```js
116
+ import { DynamicPathTracingSceneGenerator } from 'three-gpu-pathtracer';
117
+
118
+ // ... initialize scene etc
119
+
120
+ const generator = new DynamicPathTracingSceneGenerator( scene );
121
+ const { bvh, textures, materials } = generator.generate( scene );
122
+
123
+ // ... update path tracer and render
124
+ ```
125
+
126
+ ## Asynchronous Scene Generation
127
+
128
+ _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._
129
+
130
+ ```js
131
+ import { PathTracingSceneWorker } from 'three-gpu-pathtracer/src/workers/PathTracingSceneWorker.js';
132
+
133
+ // ...
134
+
135
+ // initialize the scene and update the material properties with the bvh, materials, etc
136
+ const generator = new PathTracingSceneWorker();
137
+ const { bvh, textures, materials } = await generator.generate( scene );
138
+
139
+ // ...
140
+ ```
141
+
92
142
  # Exports
93
143
 
94
144
  ## PathTracingRenderer
@@ -180,7 +230,7 @@ Utility class for generating the set of data required for initializing the path
180
230
  ### .generate
181
231
 
182
232
  ```js
183
- async generate( scene : Object3D ) : {
233
+ generate( scene : Object3D, options = {} : Object ) : {
184
234
  bvh : MeshBVH,
185
235
  materials : Array<Material>,
186
236
  textures : Array<Texture>
@@ -189,6 +239,118 @@ async generate( scene : Object3D ) : {
189
239
 
190
240
  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.
191
241
 
242
+ ## PathTracingSceneWorker
243
+
244
+ _extends PathTracingSceneGenerator_
245
+
246
+ See note in [Asyncronous Generation](#asynchronous-generation) use snippet.
247
+
248
+ ### .generate
249
+
250
+ ```js
251
+ async generate( scene : Object3D, options = {} : Object ) : {
252
+ bvh : MeshBVH,
253
+ materials : Array<Material>,
254
+ textures : Array<Texture>
255
+ }
256
+ ```
257
+
258
+ ### .dispose
259
+
260
+ ```js
261
+ dispose() : void
262
+ ```
263
+
264
+ ## PhysicalCamera
265
+
266
+ _extends THREE.PerspectiveCamera_
267
+
268
+ An extension of the three.js PerspectiveCamera with some other parameters associated with depth of field. These parameters otherwise do not affect the camera behavior are are for convenience of use with the PhysicalCameraUniform and pathtracer.
269
+
270
+ ### .focusDistance
271
+
272
+ ```js
273
+ focusDistance = 25 : Number
274
+ ```
275
+
276
+ The distance from the camera in meters that everything is is perfect focus.
277
+
278
+ ### .fStop
279
+
280
+ ```js
281
+ fStop = 1.4 : Number
282
+ ```
283
+
284
+ The fstop value of the camera. If this is changed then the `bokehSize` field is implicitly updated.
285
+
286
+ ### .bokehSize
287
+
288
+ ```js
289
+ bokehSize : Number
290
+ ```
291
+
292
+ The bokeh size as derived from the fStop and focal length in millimeters. If this is set then the fStop is implicitly updated.
293
+
294
+ ### .apertureBlades
295
+
296
+ ```js
297
+ apertureBlades = 0 : Number
298
+ ```
299
+
300
+ The number of sides / blades on the aperture.
301
+
302
+ ### .apertureRotation
303
+
304
+ ```js
305
+ apertureRotation = 0 : Number
306
+ ```
307
+
308
+ The rotation of the aperture shape in radians.
309
+
310
+ ### .anamorphicRatio
311
+
312
+ ```js
313
+ anamorphicRatio = 1 : Number
314
+ ```
315
+
316
+ The anamorphic ratio of the lens. A higher value will stretch the bokeh effect horizontally.
317
+
318
+ ## DynamicPathTracingSceneGenerator
319
+
320
+ 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.
321
+
322
+ 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.
323
+
324
+ If geometry or materials are added or removed from the scene then `reset` must be called.
325
+
326
+ ### constructor
327
+
328
+ ```js
329
+ constructor( scene : Object3D )
330
+ ```
331
+
332
+ Takes the scene to convert.
333
+
334
+ ### .generate
335
+
336
+ ```js
337
+ generate() : {
338
+ bvh : MeshBVH,
339
+ materials : Array<Material>,
340
+ textures : Array<Texture>
341
+ }
342
+ ```
343
+
344
+ 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.
345
+
346
+ ### .reset
347
+
348
+ ```js
349
+ reset() : void
350
+ ```
351
+
352
+ 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
+
192
354
  ## MaterialBase
193
355
 
194
356
  _extends THREE.ShaderMaterial_
@@ -211,6 +373,12 @@ _extends MaterialBase_
211
373
 
212
374
  ```js
213
375
  {
376
+ // The number of ray bounces to test. Higher is better quality but slower performance.
377
+ bounces = 3 : Number,
378
+
379
+ // The physical camera parameters to use
380
+ physicalCamera : PhysicalCameraUniform,
381
+
214
382
  // Geometry and BVH information,
215
383
  bvh: MeshBVHUniformStruct,
216
384
  normalAttribute: FloatVertexAttributeTexture,
@@ -225,13 +393,13 @@ _extends MaterialBase_
225
393
  environmentRotaton: Matrix3,
226
394
 
227
395
  // Environment Map information,
228
- environmentBlur: Number,
229
- environmentIntensity: Number,
396
+ environmentBlur = 0: Number,
397
+ environmentIntensity = 1: Number,
230
398
 
231
399
  // Factor for alleviating bright pixels from rays that hit diffuse surfaces then
232
400
  // specular surfaces. Setting this higher alleviates fireflies but will remove some
233
401
  // specular caustics.
234
- filterGlossyFactor: Number,
402
+ filterGlossyFactor = 0: Number,
235
403
 
236
404
  // The colors to use for the gradient env lighting when no environment map is provided.
237
405
  gradientTop: Color,
@@ -247,8 +415,8 @@ _extends MaterialBase_
247
415
 
248
416
  ```js
249
417
  {
250
- // The number of ray bounces to test. Higher is better quality but slower performance.
251
- BOUNCES = 3 : Number,
418
+ // Whether the shader should include logic for physical camera and depth of field
419
+ DOF_SUPPORT = 1 : Number,
252
420
 
253
421
  // The number of transparent pixels to allow on top of existing bounces for object transparency.
254
422
  TRANSPARENT_TRAVERSALS = 5 : Number,
@@ -259,7 +427,6 @@ _extends MaterialBase_
259
427
  // The number of materials provided in the "materials" uniform.
260
428
  MATERIAL_LENGTH : Number,
261
429
 
262
-
263
430
  }
264
431
  ```
265
432
 
@@ -282,6 +449,18 @@ setTextures(
282
449
 
283
450
  Takes the rendering context to updateh 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.
284
451
 
452
+ ## PhysicalCameraUniform
453
+
454
+ Uniform for storing the camera parameters for use with the shader.
455
+
456
+ ### .updateFrom
457
+
458
+ ```js
459
+ updateFrom( camera : PerspectiveCamera | PhysicalCamera ) : void
460
+ ```
461
+
462
+ Copies all fields from the passed PhysicalCamera if available otherwise the defaults are used.
463
+
285
464
  ## MaterialStructArrayUniform
286
465
 
287
466
  _extends Array_
@@ -300,6 +479,20 @@ Updates the value of the uniform to align with the provided set of materials and
300
479
 
301
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.
302
481
 
482
+ ### .side
483
+
484
+ ```js
485
+ side = 0 : Number
486
+ ```
487
+
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:
489
+
490
+ ```js
491
+ 0 // Double Sided
492
+ 1 // Front Sided
493
+ -1 // Back Sided
494
+ ```
495
+
303
496
  ### .updateFrom
304
497
 
305
498
  ```js
@@ -336,12 +529,28 @@ Material struct definition for use with uniforms. See the [implementation](https
336
529
 
337
530
  Set of randomness and other light transmport 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.
338
531
 
339
- # Caveats
532
+ # Gotchas
340
533
 
534
+ - The project requires use of WebGL2.
341
535
  - All textures must use the same wrap and interpolation flags.
536
+ - Texture repeat, rotation, and center properties are not supported.
342
537
 
343
538
  # Screenshots
344
539
 
540
+ ![](https://user-images.githubusercontent.com/734200/162584469-68e6df38-92da-4a13-b352-ca0bdea14548.png)
541
+
542
+ <p align="center">
543
+ <i>Sample materials</i>
544
+ </p>
545
+
546
+ ![](https://user-images.githubusercontent.com/734200/163835927-be75d2c0-f27b-4e4b-a3eb-2371043fa5e1.png)
547
+
548
+ ![](https://user-images.githubusercontent.com/734200/163839431-ed75e64d-9ae4-4423-afca-55162a44873e.png)
549
+
550
+ <p align="center">
551
+ <i>"SD Macross City Standoff Diorama" scene by <a href="https://sketchfab.com/3d-models/sd-macross-city-standoff-diorama-b154220f7e7441799d6be2f7ff9658c7">tipatat</a></i>
552
+ </p>
553
+
345
554
  ![](./docs/interior-scene-cropped.png)
346
555
 
347
556
  <p align="center">
@@ -350,8 +559,10 @@ Set of randomness and other light transmport utilities for use in a shader. See
350
559
 
351
560
  ![](https://user-images.githubusercontent.com/734200/161820794-df0da371-ee5c-4368-9e7b-5e7daf6cf3c7.png)
352
561
 
562
+ ![](https://user-images.githubusercontent.com/734200/162550315-3cdabf40-3dea-4d7d-bcfc-eb543eea2d93.png)
563
+
353
564
  <p align="center">
354
- <i>Perseverance Rover model by <a href="https://mars.nasa.gov/resources/25042/mars-perseverance-rover-3d-model/">NASA / JPL-Caltech</a></i>
565
+ <i>Perseverance Rover, Ingenuity Helicopter models by <a href="https://mars.nasa.gov/resources/25042/mars-perseverance-rover-3d-model/">NASA / JPL-Caltech</a></i>
355
566
  </p>
356
567
 
357
568
  ![](https://user-images.githubusercontent.com/734200/161877900-566652e4-c799-4940-bccb-0c8f4cea5387.png)