three-gpu-pathtracer 0.0.7 → 0.0.8
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/LICENSE +21 -21
- package/README.md +887 -815
- package/build/index.module.js +5796 -5451
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +5795 -5448
- package/build/index.umd.cjs.map +1 -1
- package/package.json +69 -68
- package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
- package/src/core/MaterialReducer.js +256 -256
- package/src/core/PathTracingRenderer.js +270 -270
- package/src/core/PathTracingSceneGenerator.js +1 -1
- package/src/index.js +39 -35
- package/src/materials/AlphaDisplayMaterial.js +48 -48
- package/src/materials/AmbientOcclusionMaterial.js +197 -197
- package/src/materials/BlendMaterial.js +67 -67
- package/src/materials/DenoiseMaterial.js +142 -142
- package/src/materials/GraphMaterial.js +243 -243
- package/src/materials/LambertPathTracingMaterial.js +285 -285
- package/src/materials/MaterialBase.js +56 -56
- package/src/materials/PhysicalPathTracingMaterial.js +973 -970
- package/src/objects/EquirectCamera.js +13 -13
- package/src/objects/PhysicalCamera.js +28 -28
- package/src/objects/PhysicalSpotLight.js +14 -14
- package/src/objects/ShapedAreaLight.js +12 -12
- package/src/shader/shaderEnvMapSampling.js +59 -59
- package/src/shader/shaderGGXFunctions.js +100 -100
- package/src/shader/shaderIridescenceFunctions.js +130 -130
- package/src/shader/shaderLayerTexelFetchFunctions.js +25 -0
- package/src/shader/shaderLightSampling.js +231 -231
- package/src/shader/shaderMaterialSampling.js +504 -542
- package/src/shader/shaderSheenFunctions.js +98 -98
- package/src/shader/shaderStructs.js +321 -321
- package/src/shader/shaderUtils.js +403 -364
- package/src/textures/GradientEquirectTexture.js +35 -0
- package/src/textures/ProceduralEquirectTexture.js +75 -0
- package/src/uniforms/AttributesTextureArray.js +35 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +259 -259
- package/src/uniforms/FloatAttributeTextureArray.js +169 -0
- package/src/uniforms/IESProfilesTexture.js +100 -100
- package/src/uniforms/LightsInfoUniformStruct.js +162 -162
- package/src/uniforms/MaterialsTexture.js +420 -426
- package/src/uniforms/PhysicalCameraUniform.js +36 -36
- package/src/uniforms/RenderTarget2DArray.js +97 -93
- package/src/uniforms/utils.js +21 -0
- package/src/utils/BlurredEnvMapGenerator.js +116 -113
- package/src/utils/IESLoader.js +325 -325
- package/src/utils/UVUnwrapper.js +101 -101
- package/src/workers/PathTracingSceneWorker.js +42 -42
package/src/utils/UVUnwrapper.js
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
// https://github.com/mozilla/Spoke/commit/9701d647020e09d584885bd457eb225e9995c12f
|
|
2
|
-
import XAtlas from 'xatlas-web';
|
|
3
|
-
import { BufferGeometry, Float32BufferAttribute, Uint32BufferAttribute } from 'three';
|
|
4
|
-
|
|
5
|
-
export class UVUnwrapper {
|
|
6
|
-
|
|
7
|
-
constructor() {
|
|
8
|
-
|
|
9
|
-
this._module = null;
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async load() {
|
|
14
|
-
|
|
15
|
-
const wasmurl = new URL( '../../node_modules/xatlas-web/dist/xatlas-web.wasm', import.meta.url );
|
|
16
|
-
this._module = XAtlas( {
|
|
17
|
-
|
|
18
|
-
locateFile( path ) {
|
|
19
|
-
|
|
20
|
-
if ( path.endsWith( '.wasm' ) ) {
|
|
21
|
-
|
|
22
|
-
return wasmurl.toString();
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return path;
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
} );
|
|
31
|
-
return this._module.ready;
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
generate( geometry ) {
|
|
36
|
-
|
|
37
|
-
const xatlas = this._module;
|
|
38
|
-
const originalVertexCount = geometry.attributes.position.count;
|
|
39
|
-
const originalIndexCount = geometry.index.count;
|
|
40
|
-
|
|
41
|
-
xatlas.createAtlas();
|
|
42
|
-
|
|
43
|
-
const meshInfo = xatlas.createMesh( originalVertexCount, originalIndexCount, true, true );
|
|
44
|
-
xatlas.HEAPU16.set( geometry.index.array, meshInfo.indexOffset / Uint16Array.BYTES_PER_ELEMENT );
|
|
45
|
-
xatlas.HEAPF32.set( geometry.attributes.position.array, meshInfo.positionOffset / Float32Array.BYTES_PER_ELEMENT );
|
|
46
|
-
xatlas.HEAPF32.set( geometry.attributes.normal.array, meshInfo.normalOffset / Float32Array.BYTES_PER_ELEMENT );
|
|
47
|
-
xatlas.HEAPF32.set( geometry.attributes.uv.array, meshInfo.uvOffset / Float32Array.BYTES_PER_ELEMENT );
|
|
48
|
-
|
|
49
|
-
const statusCode = xatlas.addMesh();
|
|
50
|
-
if ( statusCode !== AddMeshStatus.Success ) {
|
|
51
|
-
|
|
52
|
-
throw new Error( `UVUnwrapper: Error adding mesh. Status code ${ statusCode }` );
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
xatlas.generateAtlas();
|
|
57
|
-
|
|
58
|
-
const meshData = xatlas.getMeshData( meshInfo.meshId );
|
|
59
|
-
const oldPositionArray = geometry.attributes.position.array;
|
|
60
|
-
const oldNormalArray = geometry.attributes.normal.array;
|
|
61
|
-
const oldUvArray = geometry.attributes.uv.array;
|
|
62
|
-
|
|
63
|
-
const newPositionArray = new Float32Array( meshData.newVertexCount * 3 );
|
|
64
|
-
const newNormalArray = new Float32Array( meshData.newVertexCount * 3 );
|
|
65
|
-
const newUvArray = new Float32Array( meshData.newVertexCount * 2 );
|
|
66
|
-
const newUv2Array = new Float32Array( xatlas.HEAPF32.buffer, meshData.uvOffset, meshData.newVertexCount * 2 );
|
|
67
|
-
const newIndexArray = new Uint32Array( xatlas.HEAPU32.buffer, meshData.indexOffset, meshData.newIndexCount );
|
|
68
|
-
const originalIndexArray = new Uint32Array(
|
|
69
|
-
xatlas.HEAPU32.buffer,
|
|
70
|
-
meshData.originalIndexOffset,
|
|
71
|
-
meshData.newVertexCount
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
for ( let i = 0; i < meshData.newVertexCount; i ++ ) {
|
|
75
|
-
|
|
76
|
-
const originalIndex = originalIndexArray[ i ];
|
|
77
|
-
newPositionArray[ i * 3 ] = oldPositionArray[ originalIndex * 3 ];
|
|
78
|
-
newPositionArray[ i * 3 + 1 ] = oldPositionArray[ originalIndex * 3 + 1 ];
|
|
79
|
-
newPositionArray[ i * 3 + 2 ] = oldPositionArray[ originalIndex * 3 + 2 ];
|
|
80
|
-
newNormalArray[ i * 3 ] = oldNormalArray[ originalIndex * 3 ];
|
|
81
|
-
newNormalArray[ i * 3 + 1 ] = oldNormalArray[ originalIndex * 3 + 1 ];
|
|
82
|
-
newNormalArray[ i * 3 + 2 ] = oldNormalArray[ originalIndex * 3 + 2 ];
|
|
83
|
-
newUvArray[ i * 2 ] = oldUvArray[ originalIndex * 2 ];
|
|
84
|
-
newUvArray[ i * 2 + 1 ] = oldUvArray[ originalIndex * 2 + 1 ];
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const newGeometry = new BufferGeometry();
|
|
89
|
-
newGeometry.addAttribute( 'position', new Float32BufferAttribute( newPositionArray, 3 ) );
|
|
90
|
-
newGeometry.addAttribute( 'normal', new Float32BufferAttribute( newNormalArray, 3 ) );
|
|
91
|
-
newGeometry.addAttribute( 'uv', new Float32BufferAttribute( newUvArray, 2 ) );
|
|
92
|
-
newGeometry.addAttribute( 'uv2', new Float32BufferAttribute( newUv2Array, 2 ) );
|
|
93
|
-
newGeometry.setIndex( new Uint32BufferAttribute( newIndexArray, 1 ) );
|
|
94
|
-
|
|
95
|
-
mesh.geometry = newGeometry;
|
|
96
|
-
|
|
97
|
-
xatlas.destroyAtlas();
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}
|
|
1
|
+
// https://github.com/mozilla/Spoke/commit/9701d647020e09d584885bd457eb225e9995c12f
|
|
2
|
+
import XAtlas from 'xatlas-web';
|
|
3
|
+
import { BufferGeometry, Float32BufferAttribute, Uint32BufferAttribute } from 'three';
|
|
4
|
+
|
|
5
|
+
export class UVUnwrapper {
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
|
|
9
|
+
this._module = null;
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async load() {
|
|
14
|
+
|
|
15
|
+
const wasmurl = new URL( '../../node_modules/xatlas-web/dist/xatlas-web.wasm', import.meta.url );
|
|
16
|
+
this._module = XAtlas( {
|
|
17
|
+
|
|
18
|
+
locateFile( path ) {
|
|
19
|
+
|
|
20
|
+
if ( path.endsWith( '.wasm' ) ) {
|
|
21
|
+
|
|
22
|
+
return wasmurl.toString();
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return path;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} );
|
|
31
|
+
return this._module.ready;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
generate( geometry ) {
|
|
36
|
+
|
|
37
|
+
const xatlas = this._module;
|
|
38
|
+
const originalVertexCount = geometry.attributes.position.count;
|
|
39
|
+
const originalIndexCount = geometry.index.count;
|
|
40
|
+
|
|
41
|
+
xatlas.createAtlas();
|
|
42
|
+
|
|
43
|
+
const meshInfo = xatlas.createMesh( originalVertexCount, originalIndexCount, true, true );
|
|
44
|
+
xatlas.HEAPU16.set( geometry.index.array, meshInfo.indexOffset / Uint16Array.BYTES_PER_ELEMENT );
|
|
45
|
+
xatlas.HEAPF32.set( geometry.attributes.position.array, meshInfo.positionOffset / Float32Array.BYTES_PER_ELEMENT );
|
|
46
|
+
xatlas.HEAPF32.set( geometry.attributes.normal.array, meshInfo.normalOffset / Float32Array.BYTES_PER_ELEMENT );
|
|
47
|
+
xatlas.HEAPF32.set( geometry.attributes.uv.array, meshInfo.uvOffset / Float32Array.BYTES_PER_ELEMENT );
|
|
48
|
+
|
|
49
|
+
const statusCode = xatlas.addMesh();
|
|
50
|
+
if ( statusCode !== AddMeshStatus.Success ) {
|
|
51
|
+
|
|
52
|
+
throw new Error( `UVUnwrapper: Error adding mesh. Status code ${ statusCode }` );
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
xatlas.generateAtlas();
|
|
57
|
+
|
|
58
|
+
const meshData = xatlas.getMeshData( meshInfo.meshId );
|
|
59
|
+
const oldPositionArray = geometry.attributes.position.array;
|
|
60
|
+
const oldNormalArray = geometry.attributes.normal.array;
|
|
61
|
+
const oldUvArray = geometry.attributes.uv.array;
|
|
62
|
+
|
|
63
|
+
const newPositionArray = new Float32Array( meshData.newVertexCount * 3 );
|
|
64
|
+
const newNormalArray = new Float32Array( meshData.newVertexCount * 3 );
|
|
65
|
+
const newUvArray = new Float32Array( meshData.newVertexCount * 2 );
|
|
66
|
+
const newUv2Array = new Float32Array( xatlas.HEAPF32.buffer, meshData.uvOffset, meshData.newVertexCount * 2 );
|
|
67
|
+
const newIndexArray = new Uint32Array( xatlas.HEAPU32.buffer, meshData.indexOffset, meshData.newIndexCount );
|
|
68
|
+
const originalIndexArray = new Uint32Array(
|
|
69
|
+
xatlas.HEAPU32.buffer,
|
|
70
|
+
meshData.originalIndexOffset,
|
|
71
|
+
meshData.newVertexCount
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
for ( let i = 0; i < meshData.newVertexCount; i ++ ) {
|
|
75
|
+
|
|
76
|
+
const originalIndex = originalIndexArray[ i ];
|
|
77
|
+
newPositionArray[ i * 3 ] = oldPositionArray[ originalIndex * 3 ];
|
|
78
|
+
newPositionArray[ i * 3 + 1 ] = oldPositionArray[ originalIndex * 3 + 1 ];
|
|
79
|
+
newPositionArray[ i * 3 + 2 ] = oldPositionArray[ originalIndex * 3 + 2 ];
|
|
80
|
+
newNormalArray[ i * 3 ] = oldNormalArray[ originalIndex * 3 ];
|
|
81
|
+
newNormalArray[ i * 3 + 1 ] = oldNormalArray[ originalIndex * 3 + 1 ];
|
|
82
|
+
newNormalArray[ i * 3 + 2 ] = oldNormalArray[ originalIndex * 3 + 2 ];
|
|
83
|
+
newUvArray[ i * 2 ] = oldUvArray[ originalIndex * 2 ];
|
|
84
|
+
newUvArray[ i * 2 + 1 ] = oldUvArray[ originalIndex * 2 + 1 ];
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const newGeometry = new BufferGeometry();
|
|
89
|
+
newGeometry.addAttribute( 'position', new Float32BufferAttribute( newPositionArray, 3 ) );
|
|
90
|
+
newGeometry.addAttribute( 'normal', new Float32BufferAttribute( newNormalArray, 3 ) );
|
|
91
|
+
newGeometry.addAttribute( 'uv', new Float32BufferAttribute( newUvArray, 2 ) );
|
|
92
|
+
newGeometry.addAttribute( 'uv2', new Float32BufferAttribute( newUv2Array, 2 ) );
|
|
93
|
+
newGeometry.setIndex( new Uint32BufferAttribute( newIndexArray, 1 ) );
|
|
94
|
+
|
|
95
|
+
mesh.geometry = newGeometry;
|
|
96
|
+
|
|
97
|
+
xatlas.destroyAtlas();
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { PathTracingSceneGenerator } from '../core/PathTracingSceneGenerator.js';
|
|
2
|
-
import { SAH } from 'three-mesh-bvh';
|
|
3
|
-
import { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';
|
|
4
|
-
|
|
5
|
-
export class PathTracingSceneWorker extends PathTracingSceneGenerator {
|
|
6
|
-
|
|
7
|
-
constructor() {
|
|
8
|
-
|
|
9
|
-
super();
|
|
10
|
-
this.bvhGenerator = new GenerateMeshBVHWorker();
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
generate( scene, options = {} ) {
|
|
15
|
-
|
|
16
|
-
const { bvhGenerator } = this;
|
|
17
|
-
const { geometry, materials, textures, lights, spotLights } = this.prepScene( scene );
|
|
18
|
-
|
|
19
|
-
const bvhOptions = { strategy: SAH, ...options, maxLeafTris: 1 };
|
|
20
|
-
const bvhPromise = bvhGenerator.generate( geometry, bvhOptions );
|
|
21
|
-
return bvhPromise.then( bvh => {
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
scene,
|
|
25
|
-
materials,
|
|
26
|
-
textures,
|
|
27
|
-
lights,
|
|
28
|
-
spotLights,
|
|
29
|
-
bvh,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
} );
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
dispose() {
|
|
37
|
-
|
|
38
|
-
this.bvhGenerator.dispose();
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}
|
|
1
|
+
import { PathTracingSceneGenerator } from '../core/PathTracingSceneGenerator.js';
|
|
2
|
+
import { SAH } from 'three-mesh-bvh';
|
|
3
|
+
import { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';
|
|
4
|
+
|
|
5
|
+
export class PathTracingSceneWorker extends PathTracingSceneGenerator {
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
|
|
9
|
+
super();
|
|
10
|
+
this.bvhGenerator = new GenerateMeshBVHWorker();
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
generate( scene, options = {} ) {
|
|
15
|
+
|
|
16
|
+
const { bvhGenerator } = this;
|
|
17
|
+
const { geometry, materials, textures, lights, spotLights } = this.prepScene( scene );
|
|
18
|
+
|
|
19
|
+
const bvhOptions = { strategy: SAH, ...options, maxLeafTris: 1 };
|
|
20
|
+
const bvhPromise = bvhGenerator.generate( geometry, bvhOptions );
|
|
21
|
+
return bvhPromise.then( bvh => {
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
scene,
|
|
25
|
+
materials,
|
|
26
|
+
textures,
|
|
27
|
+
lights,
|
|
28
|
+
spotLights,
|
|
29
|
+
bvh,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
} );
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
dispose() {
|
|
37
|
+
|
|
38
|
+
this.bvhGenerator.dispose();
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|