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.
- package/README.md +111 -464
- package/build/index.module.js +5691 -5312
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +5369 -5003
- package/build/index.umd.cjs.map +1 -1
- package/package.json +12 -6
- package/src/core/PathTracingRenderer.js +59 -46
- package/src/core/PathTracingSceneGenerator.js +245 -10
- package/src/core/WebGLPathTracer.js +472 -0
- package/src/core/utils/BakedGeometry.js +35 -0
- package/src/core/utils/BufferAttributeUtils.js +64 -0
- package/src/{utils → core/utils}/GeometryPreparationUtils.js +35 -35
- package/src/core/utils/MeshDiff.js +102 -0
- package/src/core/utils/StaticGeometryGenerator.js +285 -0
- package/src/core/utils/convertToStaticGeometry.js +344 -0
- package/src/core/utils/mergeGeometries.js +218 -0
- package/src/core/utils/sceneUpdateUtils.js +96 -0
- package/src/index.d.ts +274 -0
- package/src/index.js +4 -20
- package/src/materials/MaterialBase.js +4 -0
- package/src/materials/fullscreen/ClampedInterpolationMaterial.js +112 -0
- package/src/materials/fullscreen/DenoiseMaterial.js +4 -0
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +73 -76
- package/src/materials/pathtracing/glsl/{attenuateHit.glsl.js → attenuate_hit_function.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{cameraUtils.glsl.js → camera_util_functions.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{directLightContribution.glsl.js → direct_light_contribution_function.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{getSurfaceRecord.glsl.js → get_surface_record_function.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/index.js +6 -0
- package/src/materials/pathtracing/glsl/{renderStructs.glsl.js → render_structs.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{traceScene.glsl.js → trace_scene_function.glsl.js} +1 -3
- package/src/materials/surface/AmbientOcclusionMaterial.js +8 -8
- package/src/objects/PhysicalSpotLight.js +2 -2
- package/src/shader/bsdf/{bsdfSampling.glsl.js → bsdf_functions.glsl.js} +19 -72
- package/src/shader/bsdf/{fog.glsl.js → fog_functions.glsl.js} +1 -1
- package/src/shader/bsdf/{ggx.glsl.js → ggx_functions.glsl.js} +1 -1
- package/src/shader/bsdf/index.js +5 -0
- package/src/shader/bsdf/{iridescence.glsl.js → iridescence_functions.glsl.js} +1 -1
- package/src/shader/bsdf/{sheen.glsl.js → sheen_functions.glsl.js} +1 -1
- package/src/shader/bvh/index.js +2 -0
- package/src/shader/{structs/fogMaterialBvh.glsl.js → bvh/inside_fog_volume_function.glsl.js} +1 -1
- package/src/shader/{common/bvhAnyHit.glsl.js → bvh/ray_any_hit_function.glsl.js} +1 -1
- package/src/shader/common/{fresnel.glsl.js → fresnel_functions.glsl.js} +1 -1
- package/src/shader/common/index.js +5 -0
- package/src/shader/common/{math.glsl.js → math_functions.glsl.js} +1 -1
- package/src/shader/common/{intersectShapes.glsl.js → shape_intersection_functions.glsl.js} +1 -1
- package/src/shader/common/{arraySamplerTexelFetch.glsl.js → texture_sample_functions.glsl.js} +1 -1
- package/src/shader/common/{utils.glsl.js → util_functions.glsl.js} +1 -1
- package/src/shader/rand/index.js +3 -0
- package/src/shader/rand/pcg.glsl.js +1 -1
- package/src/shader/rand/sobol.glsl.js +4 -4
- package/src/shader/rand/{stratifiedTexture.glsl.js → stratified.glsl.js} +7 -2
- package/src/shader/sampling/{equirectSampling.glsl.js → equirect_sampling_functions.glsl.js} +1 -2
- package/src/shader/sampling/index.js +3 -0
- package/src/shader/sampling/{lightSampling.glsl.js → light_sampling_functions.glsl.js} +3 -3
- package/src/shader/sampling/{shapeSampling.glsl.js → shape_sampling_functions.glsl.js} +1 -1
- package/src/shader/structs/{cameraStruct.glsl.js → camera_struct.glsl.js} +1 -1
- package/src/shader/structs/{equirectStruct.glsl.js → equirect_struct.glsl.js} +1 -1
- package/src/shader/structs/index.js +5 -0
- package/src/shader/structs/{lightsStruct.glsl.js → lights_struct.glsl.js} +1 -1
- package/src/shader/structs/{materialStruct.glsl.js → material_struct.glsl.js} +2 -2
- package/src/shader/structs/surface_record_struct.glsl.js +63 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +16 -11
- package/src/uniforms/LightsInfoUniformStruct.js +21 -10
- package/src/uniforms/MaterialsTexture.js +27 -86
- package/src/uniforms/RenderTarget2DArray.js +60 -20
- package/src/utils/BlurredEnvMapGenerator.js +12 -5
- package/src/utils/SobolNumberMapGenerator.js +3 -3
- package/src/utils/bufferToHash.js +22 -0
- package/src/core/DynamicPathTracingSceneGenerator.js +0 -164
- package/src/core/MaterialReducer.js +0 -256
- package/src/materials/pathtracing/LambertPathTracingMaterial.js +0 -297
- package/src/uniforms/IESProfilesTexture.js +0 -100
- package/src/uniforms/utils.js +0 -30
- package/src/utils/IESLoader.js +0 -327
- 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 {
|
|
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,
|
|
83
|
+
// init scene, camera, controls, etc
|
|
90
84
|
|
|
91
|
-
renderer
|
|
85
|
+
renderer = new THREE.WebGLRenderer();
|
|
92
86
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
-
|
|
118
|
+
# Exports
|
|
180
119
|
|
|
181
|
-
|
|
120
|
+
## WebGLPathTracer
|
|
182
121
|
|
|
183
|
-
|
|
184
|
-
import { DynamicPathTracingSceneGenerator } from 'three-gpu-pathtracer';
|
|
122
|
+
### constructor
|
|
185
123
|
|
|
186
|
-
|
|
124
|
+
```
|
|
125
|
+
constructor( renderer : WebGLRenderer )
|
|
126
|
+
```
|
|
187
127
|
|
|
188
|
-
|
|
189
|
-
const { bvh, textures, materials } = generator.generate( scene );
|
|
128
|
+
### .bounces
|
|
190
129
|
|
|
191
|
-
|
|
130
|
+
```js
|
|
131
|
+
bounces = 10 : Number
|
|
192
132
|
```
|
|
193
133
|
|
|
194
|
-
|
|
134
|
+
Max number of lights bounces to trace.
|
|
195
135
|
|
|
196
|
-
|
|
136
|
+
### .filteredGlossyFactor
|
|
197
137
|
|
|
198
138
|
```js
|
|
199
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
### .
|
|
152
|
+
### .renderDelay
|
|
217
153
|
|
|
218
154
|
```js
|
|
219
|
-
|
|
155
|
+
renderDelay = 100 : Number
|
|
220
156
|
```
|
|
221
157
|
|
|
222
|
-
Number of
|
|
158
|
+
Number of milliseconds to delay rendering samples after the path tracer has been reset.
|
|
223
159
|
|
|
224
|
-
### .
|
|
160
|
+
### .fadeDuration
|
|
225
161
|
|
|
226
162
|
```js
|
|
227
|
-
|
|
163
|
+
fadeDuration = 500 : Number
|
|
228
164
|
```
|
|
229
165
|
|
|
230
|
-
|
|
166
|
+
How long to take to fade the fully path traced scene in in milliseconds wen rendering to the canvas.
|
|
231
167
|
|
|
232
|
-
|
|
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
|
-
|
|
171
|
+
minSamples = 5 : Number
|
|
239
172
|
```
|
|
240
173
|
|
|
241
|
-
|
|
174
|
+
How many samples to render before displaying to the canvas.
|
|
242
175
|
|
|
243
|
-
### .
|
|
176
|
+
### .dynamicLowRes
|
|
244
177
|
|
|
245
178
|
```js
|
|
246
|
-
|
|
179
|
+
dynamicLowRes = false : Boolean
|
|
247
180
|
```
|
|
248
181
|
|
|
249
|
-
|
|
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
|
-
### .
|
|
184
|
+
### .lowResScale
|
|
252
185
|
|
|
253
186
|
```js
|
|
254
|
-
|
|
187
|
+
lowResScale = 0.1 : Number
|
|
255
188
|
```
|
|
256
189
|
|
|
257
|
-
|
|
190
|
+
The scale to render the low resolution pass at.
|
|
258
191
|
|
|
259
|
-
### .
|
|
192
|
+
### .synchronizeRenderSize
|
|
260
193
|
|
|
261
194
|
```js
|
|
262
|
-
|
|
195
|
+
synchronizeRenderSize = true : Boolean
|
|
263
196
|
```
|
|
264
197
|
|
|
265
|
-
Whether to
|
|
198
|
+
Whether to automatically update the sie of the path traced buffer when the canvas size changes.
|
|
266
199
|
|
|
267
|
-
### .
|
|
200
|
+
### .renderScale
|
|
268
201
|
|
|
269
202
|
```js
|
|
270
|
-
|
|
203
|
+
renderScale = 1 : Number
|
|
271
204
|
```
|
|
272
205
|
|
|
273
|
-
|
|
206
|
+
The scale to render the path traced image at. Only relevant if `synchronizeRenderSize` is true.
|
|
274
207
|
|
|
275
|
-
### .
|
|
208
|
+
### .renderToCanvas
|
|
276
209
|
|
|
277
210
|
```js
|
|
278
|
-
|
|
211
|
+
renderToCanvas = true : Boolean
|
|
279
212
|
```
|
|
280
213
|
|
|
281
|
-
Whether to
|
|
214
|
+
Whether to automatically render the path traced buffer to the canvas when `renderSample` is called.
|
|
282
215
|
|
|
283
|
-
|
|
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
|
-
|
|
219
|
+
rasterizeScene = true : Boolean
|
|
290
220
|
```
|
|
291
221
|
|
|
292
|
-
|
|
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
|
-
|
|
227
|
+
textureSize = ( 1024, 1024 ) : Vector2
|
|
296
228
|
```
|
|
297
229
|
|
|
298
|
-
|
|
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
|
-
### .
|
|
232
|
+
### .samples
|
|
301
233
|
|
|
302
234
|
```js
|
|
303
|
-
|
|
235
|
+
readonly samples : Number
|
|
304
236
|
```
|
|
305
237
|
|
|
306
|
-
|
|
238
|
+
The number of samples that have been rendered.
|
|
307
239
|
|
|
308
|
-
### .
|
|
240
|
+
### .target
|
|
309
241
|
|
|
310
242
|
```js
|
|
311
|
-
|
|
243
|
+
readonly target : WebGLRenderTarget
|
|
312
244
|
```
|
|
313
245
|
|
|
314
|
-
|
|
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
|
-
### .
|
|
248
|
+
### .setScene
|
|
321
249
|
|
|
322
250
|
```js
|
|
323
|
-
|
|
251
|
+
setScene( scene : Scene, camera : Camera ) : void
|
|
324
252
|
```
|
|
325
253
|
|
|
326
|
-
|
|
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
|
-
|
|
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
|
-
|
|
258
|
+
### .setSceneAsync
|
|
334
259
|
|
|
335
|
-
### .viewCone
|
|
336
260
|
```js
|
|
337
|
-
|
|
261
|
+
setSceneAsync(
|
|
262
|
+
scene : Scene,
|
|
263
|
+
camera : Camera,
|
|
264
|
+
options = {
|
|
265
|
+
onProgress = null : value => void,
|
|
266
|
+
} : Object
|
|
267
|
+
) : void
|
|
338
268
|
```
|
|
339
269
|
|
|
340
|
-
|
|
270
|
+
Asynchronous version of `setScene`. Requires calling `setBVHWorker` first.
|
|
341
271
|
|
|
342
|
-
### .
|
|
272
|
+
### .updateCamera
|
|
343
273
|
|
|
344
274
|
```js
|
|
345
|
-
|
|
275
|
+
updateCamera() : void
|
|
346
276
|
```
|
|
347
277
|
|
|
348
|
-
|
|
278
|
+
Updates the camera parameters. Must be called if any of the parameters on the previously set camera change.
|
|
349
279
|
|
|
350
|
-
### .
|
|
280
|
+
### .updateMaterials
|
|
351
281
|
|
|
352
282
|
```js
|
|
353
|
-
|
|
283
|
+
updateMaterials() : void
|
|
354
284
|
```
|
|
355
285
|
|
|
356
|
-
|
|
286
|
+
Updates the material properties. Must be called when properties change for any materials already being used.
|
|
357
287
|
|
|
358
|
-
|
|
288
|
+
Note that materials used with WebGLPathTracer support the following additional properties:
|
|
359
289
|
|
|
360
290
|
```js
|
|
361
|
-
|
|
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
|
-
|
|
295
|
+
// Whether the object should cast a shadow
|
|
296
|
+
castShadow = true : Boolean;
|
|
297
|
+
```
|
|
365
298
|
|
|
366
|
-
### .
|
|
299
|
+
### .updateEnvironment
|
|
367
300
|
|
|
368
301
|
```js
|
|
369
|
-
|
|
370
|
-
displayDistance : Number,
|
|
371
|
-
displayWidth : Number,
|
|
372
|
-
displayHeight : Number,
|
|
373
|
-
) : void
|
|
302
|
+
updateEnvironment() : void
|
|
374
303
|
```
|
|
375
304
|
|
|
376
|
-
Updates the
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
### .generate
|
|
307
|
+
### .updateLights
|
|
383
308
|
|
|
384
309
|
```js
|
|
385
|
-
|
|
386
|
-
bvh : MeshBVH,
|
|
387
|
-
materials : Array<Material>,
|
|
388
|
-
textures : Array<Texture>,
|
|
389
|
-
lights : Array<Light>
|
|
390
|
-
}
|
|
310
|
+
updateLights() : void
|
|
391
311
|
```
|
|
392
312
|
|
|
393
|
-
|
|
313
|
+
Updates lights used in path tracing. Must be called if any lights are added or removed or properties change.
|
|
394
314
|
|
|
395
|
-
|
|
315
|
+
### .renderSample
|
|
396
316
|
|
|
397
|
-
|
|
317
|
+
```js
|
|
318
|
+
renderSample() : void
|
|
319
|
+
```
|
|
398
320
|
|
|
399
|
-
|
|
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
|
-
### .
|
|
323
|
+
### .reset
|
|
402
324
|
|
|
403
325
|
```js
|
|
404
|
-
|
|
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
|
-
### .
|
|
411
|
+
### .iesMap
|
|
491
412
|
|
|
492
413
|
```js
|
|
493
|
-
|
|
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
|
-
|
|
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
|
|