three-gpu-pathtracer 0.0.14 → 0.0.16

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 (76) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1004 -981
  3. package/build/index.module.js +7413 -6902
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +7446 -6933
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +73 -73
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +346 -346
  11. package/src/core/PathTracingSceneGenerator.js +69 -69
  12. package/src/core/QuiltPathTracingRenderer.js +223 -223
  13. package/src/detectors/CompatibilityDetector.js +38 -0
  14. package/src/detectors/MaterialCompileDetector.js +50 -0
  15. package/src/detectors/PrecisionDetector.js +85 -0
  16. package/src/detectors/PrecisionMaterial.js +160 -0
  17. package/src/index.js +40 -36
  18. package/src/materials/MaterialBase.js +56 -56
  19. package/src/materials/debug/GraphMaterial.js +243 -243
  20. package/src/materials/fullscreen/AlphaDisplayMaterial.js +50 -48
  21. package/src/materials/fullscreen/BlendMaterial.js +67 -67
  22. package/src/materials/fullscreen/DenoiseMaterial.js +142 -142
  23. package/src/materials/fullscreen/GradientMapMaterial.js +82 -0
  24. package/src/materials/pathtracing/LambertPathTracingMaterial.js +296 -296
  25. package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +118 -196
  26. package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +177 -179
  27. package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +84 -81
  28. package/src/materials/pathtracing/glsl/directLightContribution.glsl.js +93 -0
  29. package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +323 -317
  30. package/src/materials/pathtracing/glsl/renderStructs.glsl.js +50 -0
  31. package/src/materials/pathtracing/glsl/traceScene.glsl.js +52 -54
  32. package/src/materials/surface/AmbientOcclusionMaterial.js +207 -207
  33. package/src/materials/surface/FogVolumeMaterial.js +23 -23
  34. package/src/objects/EquirectCamera.js +13 -13
  35. package/src/objects/PhysicalCamera.js +42 -28
  36. package/src/objects/PhysicalSpotLight.js +25 -14
  37. package/src/objects/ShapedAreaLight.js +22 -12
  38. package/src/shader/bsdf/bsdfSampling.glsl.js +499 -490
  39. package/src/shader/bsdf/fog.glsl.js +22 -23
  40. package/src/shader/bsdf/ggx.glsl.js +102 -102
  41. package/src/shader/bsdf/iridescence.glsl.js +135 -135
  42. package/src/shader/bsdf/sheen.glsl.js +98 -98
  43. package/src/shader/common/arraySamplerTexelFetch.glsl.js +25 -25
  44. package/src/shader/common/bvhAnyHit.glsl.js +76 -76
  45. package/src/shader/common/fresnel.glsl.js +98 -98
  46. package/src/shader/common/intersectShapes.glsl.js +62 -62
  47. package/src/shader/common/math.glsl.js +81 -81
  48. package/src/shader/common/utils.glsl.js +116 -116
  49. package/src/shader/rand/pcg.glsl.js +57 -57
  50. package/src/shader/rand/sobol.glsl.js +256 -256
  51. package/src/shader/sampling/equirectSampling.glsl.js +62 -62
  52. package/src/shader/sampling/lightSampling.glsl.js +223 -223
  53. package/src/shader/sampling/shapeSampling.glsl.js +86 -86
  54. package/src/shader/structs/cameraStruct.glsl.js +13 -13
  55. package/src/shader/structs/equirectStruct.glsl.js +13 -14
  56. package/src/shader/structs/fogMaterialBvh.glsl.js +62 -62
  57. package/src/shader/structs/lightsStruct.glsl.js +78 -78
  58. package/src/shader/structs/materialStruct.glsl.js +207 -207
  59. package/src/textures/GradientEquirectTexture.js +35 -35
  60. package/src/textures/ProceduralEquirectTexture.js +75 -75
  61. package/src/uniforms/AttributesTextureArray.js +35 -35
  62. package/src/uniforms/EquirectHdrInfoUniform.js +269 -277
  63. package/src/uniforms/FloatAttributeTextureArray.js +169 -169
  64. package/src/uniforms/IESProfilesTexture.js +100 -100
  65. package/src/uniforms/LightsInfoUniformStruct.js +212 -212
  66. package/src/uniforms/MaterialsTexture.js +503 -503
  67. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  68. package/src/uniforms/RenderTarget2DArray.js +97 -97
  69. package/src/uniforms/utils.js +30 -30
  70. package/src/utils/BlurredEnvMapGenerator.js +116 -116
  71. package/src/utils/GeometryPreparationUtils.js +214 -214
  72. package/src/utils/IESLoader.js +325 -325
  73. package/src/utils/SobolNumberMapGenerator.js +80 -80
  74. package/src/utils/UVUnwrapper.js +101 -101
  75. package/src/utils/macroify.js +9 -9
  76. package/src/workers/PathTracingSceneWorker.js +42 -42
@@ -1,80 +1,80 @@
1
- import { FloatType, NearestFilter, NoBlending, RGBAFormat, Vector2, WebGLRenderTarget } from 'three';
2
- import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
3
- import { MaterialBase } from '../materials/MaterialBase.js';
4
- import { sobolCommonGLSL, sobolGenerationGLSL } from '../shader/rand/sobol.glsl.js';
5
-
6
- class SobolNumbersMaterial extends MaterialBase {
7
-
8
- constructor() {
9
-
10
- super( {
11
-
12
- blending: NoBlending,
13
-
14
- uniforms: {
15
-
16
- resolution: { value: new Vector2() },
17
-
18
- },
19
-
20
- vertexShader: /* glsl */`
21
-
22
- varying vec2 vUv;
23
- void main() {
24
-
25
- vUv = uv;
26
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
27
-
28
- }
29
- `,
30
-
31
- fragmentShader: /* glsl */`
32
-
33
- ${ sobolCommonGLSL }
34
- ${ sobolGenerationGLSL }
35
-
36
- varying vec2 vUv;
37
- uniform vec2 resolution;
38
- void main() {
39
-
40
- uint index = uint( gl_FragCoord.y ) * uint( resolution.x ) + uint( gl_FragCoord.x );
41
- gl_FragColor = generateSobolPoint( index );
42
-
43
- }
44
- `,
45
-
46
- } );
47
-
48
- }
49
-
50
- }
51
-
52
- export class SobolNumberMapGenerator {
53
-
54
- generate( renderer, dimensions = 256 ) {
55
-
56
- const target = new WebGLRenderTarget( dimensions, dimensions, {
57
-
58
- type: FloatType,
59
- format: RGBAFormat,
60
- minFilter: NearestFilter,
61
- magFilter: NearestFilter,
62
- generateMipmaps: false,
63
-
64
- } );
65
-
66
- const ogTarget = renderer.getRenderTarget();
67
- renderer.setRenderTarget( target );
68
-
69
- const quad = new FullScreenQuad( new SobolNumbersMaterial() );
70
- quad.material.resolution.set( dimensions, dimensions );
71
- quad.render( renderer );
72
-
73
- renderer.setRenderTarget( ogTarget );
74
- quad.dispose();
75
-
76
- return target;
77
-
78
- }
79
-
80
- }
1
+ import { FloatType, NearestFilter, NoBlending, RGBAFormat, Vector2, WebGLRenderTarget } from 'three';
2
+ import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
3
+ import { MaterialBase } from '../materials/MaterialBase.js';
4
+ import { sobolCommonGLSL, sobolGenerationGLSL } from '../shader/rand/sobol.glsl.js';
5
+
6
+ class SobolNumbersMaterial extends MaterialBase {
7
+
8
+ constructor() {
9
+
10
+ super( {
11
+
12
+ blending: NoBlending,
13
+
14
+ uniforms: {
15
+
16
+ resolution: { value: new Vector2() },
17
+
18
+ },
19
+
20
+ vertexShader: /* glsl */`
21
+
22
+ varying vec2 vUv;
23
+ void main() {
24
+
25
+ vUv = uv;
26
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
27
+
28
+ }
29
+ `,
30
+
31
+ fragmentShader: /* glsl */`
32
+
33
+ ${ sobolCommonGLSL }
34
+ ${ sobolGenerationGLSL }
35
+
36
+ varying vec2 vUv;
37
+ uniform vec2 resolution;
38
+ void main() {
39
+
40
+ uint index = uint( gl_FragCoord.y ) * uint( resolution.x ) + uint( gl_FragCoord.x );
41
+ gl_FragColor = generateSobolPoint( index );
42
+
43
+ }
44
+ `,
45
+
46
+ } );
47
+
48
+ }
49
+
50
+ }
51
+
52
+ export class SobolNumberMapGenerator {
53
+
54
+ generate( renderer, dimensions = 256 ) {
55
+
56
+ const target = new WebGLRenderTarget( dimensions, dimensions, {
57
+
58
+ type: FloatType,
59
+ format: RGBAFormat,
60
+ minFilter: NearestFilter,
61
+ magFilter: NearestFilter,
62
+ generateMipmaps: false,
63
+
64
+ } );
65
+
66
+ const ogTarget = renderer.getRenderTarget();
67
+ renderer.setRenderTarget( target );
68
+
69
+ const quad = new FullScreenQuad( new SobolNumbersMaterial() );
70
+ quad.material.resolution.set( dimensions, dimensions );
71
+ quad.render( renderer );
72
+
73
+ renderer.setRenderTarget( ogTarget );
74
+ quad.dispose();
75
+
76
+ return target;
77
+
78
+ }
79
+
80
+ }
@@ -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,9 +1,9 @@
1
- export function macroify( contents ) {
2
-
3
- return contents
4
- .trim()
5
- .replace( /\/\/.*[\n\r]/g, '' )
6
- .split( /[\n\r]+/ )
7
- .join( '\\\n' ) + '\\\n';
8
-
9
- }
1
+ export function macroify( contents ) {
2
+
3
+ return contents
4
+ .trim()
5
+ .replace( /\/\/.*[\n\r]/g, '' )
6
+ .split( /[\n\r]+/ )
7
+ .join( '\\\n' ) + '\\\n';
8
+
9
+ }
@@ -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
+ }