three-gpu-pathtracer 0.0.17 → 0.0.19
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/build/index.module.js +1013 -322
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +1010 -320
- package/build/index.umd.cjs.map +1 -1
- package/package.json +2 -2
- package/src/core/DynamicPathTracingSceneGenerator.js +80 -40
- package/src/core/PathTracingRenderer.js +28 -34
- package/src/core/PathTracingSceneGenerator.js +11 -60
- package/src/materials/pathtracing/LambertPathTracingMaterial.js +1 -1
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +37 -12
- package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +19 -9
- package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +2 -2
- package/src/materials/pathtracing/glsl/directLightContribution.glsl.js +4 -4
- package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +2 -1
- package/src/materials/pathtracing/glsl/traceScene.glsl.js +1 -1
- package/src/shader/bsdf/bsdfSampling.glsl.js +14 -10
- package/src/shader/common/fresnel.glsl.js +15 -9
- package/src/shader/rand/pcg.glsl.js +4 -4
- package/src/shader/rand/stratifiedTexture.glsl.js +45 -0
- package/src/shader/sampling/equirectSampling.glsl.js +8 -1
- package/src/shader/structs/lightsStruct.glsl.js +5 -7
- package/src/textures/BlueNoiseTexture.js +87 -0
- package/src/textures/ProceduralEquirectTexture.js +7 -8
- package/src/textures/blueNoise/BlueNoiseGenerator.js +115 -0
- package/src/textures/blueNoise/BlueNoiseSamples.js +214 -0
- package/src/textures/blueNoise/utils.js +24 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +45 -8
- package/src/uniforms/LightsInfoUniformStruct.js +11 -7
- package/src/uniforms/MaterialsTexture.js +1 -1
- package/src/uniforms/RenderTarget2DArray.js +50 -3
- package/src/uniforms/StratifiedSamplesTexture.js +49 -0
- package/src/uniforms/stratified/StratifiedSampler.js +73 -0
- package/src/uniforms/stratified/StratifiedSamplerCombined.js +59 -0
- package/src/uniforms/utils.js +1 -1
- package/src/utils/GeometryPreparationUtils.js +8 -101
- package/src/workers/PathTracingSceneWorker.js +18 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BufferAttribute } from 'three';
|
|
2
|
-
import {
|
|
2
|
+
import { mergeVertices } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
3
3
|
export function getGroupMaterialIndicesAttribute( geometry, materials, allMaterials ) {
|
|
4
4
|
|
|
5
5
|
const indexAttr = geometry.index;
|
|
@@ -54,25 +54,6 @@ export function getGroupMaterialIndicesAttribute( geometry, materials, allMateri
|
|
|
54
54
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export function trimToAttributes( geometry, attributes ) {
|
|
58
|
-
|
|
59
|
-
// trim any unneeded attributes
|
|
60
|
-
if ( attributes ) {
|
|
61
|
-
|
|
62
|
-
for ( const key in geometry.attributes ) {
|
|
63
|
-
|
|
64
|
-
if ( ! attributes.includes( key ) ) {
|
|
65
|
-
|
|
66
|
-
geometry.deleteAttribute( key );
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
57
|
export function setCommonAttributes( geometry, options ) {
|
|
77
58
|
|
|
78
59
|
const { attributes = [], normalMapRequired = false } = options;
|
|
@@ -90,6 +71,13 @@ export function setCommonAttributes( geometry, options ) {
|
|
|
90
71
|
|
|
91
72
|
}
|
|
92
73
|
|
|
74
|
+
if ( ! geometry.attributes.uv2 && ( attributes && attributes.includes( 'uv2' ) ) ) {
|
|
75
|
+
|
|
76
|
+
const vertCount = geometry.attributes.position.count;
|
|
77
|
+
geometry.setAttribute( 'uv2', new BufferAttribute( new Float32Array( vertCount * 2 ), 2, false ) );
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
93
81
|
if ( ! geometry.attributes.tangent && ( attributes && attributes.includes( 'tangent' ) ) ) {
|
|
94
82
|
|
|
95
83
|
if ( normalMapRequired ) {
|
|
@@ -137,84 +125,3 @@ export function setCommonAttributes( geometry, options ) {
|
|
|
137
125
|
}
|
|
138
126
|
|
|
139
127
|
}
|
|
140
|
-
|
|
141
|
-
export function mergeMeshes( meshes, options = {} ) {
|
|
142
|
-
|
|
143
|
-
options = { attributes: null, cloneGeometry: true, ...options };
|
|
144
|
-
|
|
145
|
-
const transformedGeometry = [];
|
|
146
|
-
const materialSet = new Set();
|
|
147
|
-
for ( let i = 0, l = meshes.length; i < l; i ++ ) {
|
|
148
|
-
|
|
149
|
-
// save any materials
|
|
150
|
-
const mesh = meshes[ i ];
|
|
151
|
-
if ( mesh.visible === false ) continue;
|
|
152
|
-
|
|
153
|
-
if ( Array.isArray( mesh.material ) ) {
|
|
154
|
-
|
|
155
|
-
mesh.material.forEach( m => materialSet.add( m ) );
|
|
156
|
-
|
|
157
|
-
} else {
|
|
158
|
-
|
|
159
|
-
materialSet.add( mesh.material );
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const materials = Array.from( materialSet );
|
|
166
|
-
for ( let i = 0, l = meshes.length; i < l; i ++ ) {
|
|
167
|
-
|
|
168
|
-
// ensure the matrix world is up to date
|
|
169
|
-
const mesh = meshes[ i ];
|
|
170
|
-
if ( mesh.visible === false ) continue;
|
|
171
|
-
|
|
172
|
-
mesh.updateMatrixWorld();
|
|
173
|
-
|
|
174
|
-
// apply the matrix world to the geometry
|
|
175
|
-
const originalGeometry = meshes[ i ].geometry;
|
|
176
|
-
const geometry = options.cloneGeometry ? originalGeometry.clone() : originalGeometry;
|
|
177
|
-
geometry.applyMatrix4( mesh.matrixWorld );
|
|
178
|
-
|
|
179
|
-
if ( mesh.matrixWorld.determinant() < 0 ) {
|
|
180
|
-
|
|
181
|
-
geometry.index.array.reverse();
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// ensure our geometry has common attributes
|
|
186
|
-
setCommonAttributes( geometry, {
|
|
187
|
-
attributes: options.attributes,
|
|
188
|
-
normalMapRequired: ! ! mesh.material.normalMap,
|
|
189
|
-
} );
|
|
190
|
-
trimToAttributes( geometry, options.attributes );
|
|
191
|
-
|
|
192
|
-
// create the material index attribute
|
|
193
|
-
const materialIndexAttribute = getGroupMaterialIndicesAttribute( geometry, mesh.material, materials );
|
|
194
|
-
geometry.setAttribute( 'materialIndex', materialIndexAttribute );
|
|
195
|
-
|
|
196
|
-
transformedGeometry.push( geometry );
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const textureSet = new Set();
|
|
201
|
-
materials.forEach( material => {
|
|
202
|
-
|
|
203
|
-
for ( const key in material ) {
|
|
204
|
-
|
|
205
|
-
const value = material[ key ];
|
|
206
|
-
if ( value && value.isTexture ) {
|
|
207
|
-
|
|
208
|
-
textureSet.add( value );
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
} );
|
|
215
|
-
|
|
216
|
-
const geometry = mergeGeometries( transformedGeometry, false );
|
|
217
|
-
const textures = Array.from( textureSet );
|
|
218
|
-
return { geometry, materials, textures };
|
|
219
|
-
|
|
220
|
-
}
|
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
import { PathTracingSceneGenerator } from '../core/PathTracingSceneGenerator.js';
|
|
2
|
-
import { SAH } from 'three-mesh-bvh';
|
|
3
1
|
import { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';
|
|
2
|
+
import { DynamicPathTracingSceneGenerator } from '../core/DynamicPathTracingSceneGenerator.js';
|
|
4
3
|
|
|
5
|
-
export class PathTracingSceneWorker
|
|
4
|
+
export class PathTracingSceneWorker {
|
|
6
5
|
|
|
7
6
|
constructor() {
|
|
8
7
|
|
|
9
|
-
super();
|
|
10
8
|
this.bvhGenerator = new GenerateMeshBVHWorker();
|
|
11
9
|
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
generate( scene, options = {} ) {
|
|
15
13
|
|
|
14
|
+
// ensure scene transforms are up to date
|
|
15
|
+
// TODO: remove this?
|
|
16
|
+
if ( Array.isArray( scene ) ) {
|
|
17
|
+
|
|
18
|
+
scene.forEach( s => s.updateMatrixWorld( true ) );
|
|
19
|
+
|
|
20
|
+
} else {
|
|
21
|
+
|
|
22
|
+
scene.updateMatrixWorld( true );
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
const { bvhGenerator } = this;
|
|
17
|
-
const
|
|
27
|
+
const sceneGenerator = new DynamicPathTracingSceneGenerator( scene );
|
|
28
|
+
sceneGenerator.prepScene();
|
|
18
29
|
|
|
19
|
-
const
|
|
20
|
-
const bvhPromise = bvhGenerator.generate( geometry,
|
|
30
|
+
const { geometry, materials, textures, lights } = sceneGenerator;
|
|
31
|
+
const bvhPromise = bvhGenerator.generate( geometry, options );
|
|
21
32
|
return bvhPromise.then( bvh => {
|
|
22
33
|
|
|
23
34
|
return {
|
|
@@ -25,7 +36,6 @@ export class PathTracingSceneWorker extends PathTracingSceneGenerator {
|
|
|
25
36
|
materials,
|
|
26
37
|
textures,
|
|
27
38
|
lights,
|
|
28
|
-
spotLights,
|
|
29
39
|
bvh,
|
|
30
40
|
};
|
|
31
41
|
|