three-gpu-pathtracer 0.0.6 → 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.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +887 -781
  3. package/build/index.module.js +6070 -5224
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6071 -5221
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +69 -68
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +270 -255
  11. package/src/core/PathTracingSceneGenerator.js +69 -68
  12. package/src/index.js +39 -33
  13. package/src/materials/AlphaDisplayMaterial.js +48 -48
  14. package/src/materials/AmbientOcclusionMaterial.js +197 -197
  15. package/src/materials/BlendMaterial.js +67 -67
  16. package/src/materials/DenoiseMaterial.js +142 -0
  17. package/src/materials/GraphMaterial.js +243 -0
  18. package/src/materials/LambertPathTracingMaterial.js +285 -285
  19. package/src/materials/MaterialBase.js +56 -56
  20. package/src/materials/PhysicalPathTracingMaterial.js +973 -922
  21. package/src/objects/EquirectCamera.js +13 -13
  22. package/src/objects/PhysicalCamera.js +28 -28
  23. package/src/objects/PhysicalSpotLight.js +14 -14
  24. package/src/objects/ShapedAreaLight.js +12 -12
  25. package/src/shader/shaderEnvMapSampling.js +59 -59
  26. package/src/shader/shaderGGXFunctions.js +100 -108
  27. package/src/shader/shaderIridescenceFunctions.js +130 -130
  28. package/src/shader/shaderLayerTexelFetchFunctions.js +25 -0
  29. package/src/shader/shaderLightSampling.js +231 -231
  30. package/src/shader/shaderMaterialSampling.js +504 -546
  31. package/src/shader/shaderSheenFunctions.js +98 -98
  32. package/src/shader/shaderStructs.js +321 -307
  33. package/src/shader/shaderUtils.js +403 -350
  34. package/src/textures/GradientEquirectTexture.js +35 -0
  35. package/src/textures/ProceduralEquirectTexture.js +75 -0
  36. package/src/uniforms/AttributesTextureArray.js +35 -0
  37. package/src/uniforms/EquirectHdrInfoUniform.js +259 -259
  38. package/src/uniforms/FloatAttributeTextureArray.js +169 -0
  39. package/src/uniforms/IESProfilesTexture.js +100 -100
  40. package/src/uniforms/LightsInfoUniformStruct.js +162 -162
  41. package/src/uniforms/MaterialsTexture.js +420 -406
  42. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  43. package/src/uniforms/RenderTarget2DArray.js +97 -93
  44. package/src/uniforms/utils.js +21 -0
  45. package/src/utils/BlurredEnvMapGenerator.js +116 -113
  46. package/src/utils/GeometryPreparationUtils.js +214 -194
  47. package/src/utils/IESLoader.js +325 -325
  48. package/src/utils/UVUnwrapper.js +101 -101
  49. package/src/workers/PathTracingSceneWorker.js +42 -42
@@ -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
+ }