three-gpu-pathtracer 0.0.11 → 0.0.12

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 (53) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +886 -886
  3. package/build/index.module.js +6478 -6470
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6473 -6465
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +72 -69
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +275 -275
  11. package/src/core/PathTracingSceneGenerator.js +69 -69
  12. package/src/index.js +39 -39
  13. package/src/materials/AlphaDisplayMaterial.js +48 -48
  14. package/src/materials/AmbientOcclusionMaterial.js +199 -199
  15. package/src/materials/BlendMaterial.js +67 -67
  16. package/src/materials/DenoiseMaterial.js +142 -142
  17. package/src/materials/GraphMaterial.js +243 -243
  18. package/src/materials/LambertPathTracingMaterial.js +285 -285
  19. package/src/materials/MaterialBase.js +56 -56
  20. package/src/materials/PhysicalPathTracingMaterial.js +982 -982
  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/shaderBvhAnyHit.js +76 -0
  26. package/src/shader/shaderEnvMapSampling.js +58 -58
  27. package/src/shader/shaderGGXFunctions.js +100 -100
  28. package/src/shader/shaderIridescenceFunctions.js +130 -130
  29. package/src/shader/shaderLayerTexelFetchFunctions.js +25 -25
  30. package/src/shader/shaderLightSampling.js +229 -229
  31. package/src/shader/shaderMaterialSampling.js +506 -498
  32. package/src/shader/shaderRandFunctions.js +57 -57
  33. package/src/shader/shaderSheenFunctions.js +98 -98
  34. package/src/shader/shaderSobolSampling.js +256 -256
  35. package/src/shader/shaderStructs.js +325 -325
  36. package/src/shader/shaderUtils.js +361 -361
  37. package/src/textures/GradientEquirectTexture.js +35 -35
  38. package/src/textures/ProceduralEquirectTexture.js +75 -75
  39. package/src/uniforms/AttributesTextureArray.js +35 -35
  40. package/src/uniforms/EquirectHdrInfoUniform.js +259 -259
  41. package/src/uniforms/FloatAttributeTextureArray.js +169 -169
  42. package/src/uniforms/IESProfilesTexture.js +100 -100
  43. package/src/uniforms/LightsInfoUniformStruct.js +207 -207
  44. package/src/uniforms/MaterialsTexture.js +426 -426
  45. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  46. package/src/uniforms/RenderTarget2DArray.js +97 -97
  47. package/src/uniforms/utils.js +30 -30
  48. package/src/utils/BlurredEnvMapGenerator.js +116 -116
  49. package/src/utils/GeometryPreparationUtils.js +214 -214
  50. package/src/utils/IESLoader.js +325 -325
  51. package/src/utils/SobolNumberMapGenerator.js +80 -80
  52. package/src/utils/UVUnwrapper.js +101 -101
  53. package/src/workers/PathTracingSceneWorker.js +42 -42
@@ -1,36 +1,36 @@
1
- import { PhysicalCamera } from '../objects/PhysicalCamera.js';
2
- export class PhysicalCameraUniform {
3
-
4
- constructor() {
5
-
6
- this.bokehSize = 0;
7
- this.apertureBlades = 0;
8
- this.apertureRotation = 0;
9
- this.focusDistance = 10;
10
- this.anamorphicRatio = 1;
11
-
12
- }
13
-
14
- updateFrom( camera ) {
15
-
16
- if ( camera instanceof PhysicalCamera ) {
17
-
18
- this.bokehSize = camera.bokehSize;
19
- this.apertureBlades = camera.apertureBlades;
20
- this.apertureRotation = camera.apertureRotation;
21
- this.focusDistance = camera.focusDistance;
22
- this.anamorphicRatio = camera.anamorphicRatio;
23
-
24
- } else {
25
-
26
- this.bokehSize = 0;
27
- this.apertureRotation = 0;
28
- this.apertureBlades = 0;
29
- this.focusDistance = 10;
30
- this.anamorphicRatio = 1;
31
-
32
- }
33
-
34
- }
35
-
36
- }
1
+ import { PhysicalCamera } from '../objects/PhysicalCamera.js';
2
+ export class PhysicalCameraUniform {
3
+
4
+ constructor() {
5
+
6
+ this.bokehSize = 0;
7
+ this.apertureBlades = 0;
8
+ this.apertureRotation = 0;
9
+ this.focusDistance = 10;
10
+ this.anamorphicRatio = 1;
11
+
12
+ }
13
+
14
+ updateFrom( camera ) {
15
+
16
+ if ( camera instanceof PhysicalCamera ) {
17
+
18
+ this.bokehSize = camera.bokehSize;
19
+ this.apertureBlades = camera.apertureBlades;
20
+ this.apertureRotation = camera.apertureRotation;
21
+ this.focusDistance = camera.focusDistance;
22
+ this.anamorphicRatio = camera.anamorphicRatio;
23
+
24
+ } else {
25
+
26
+ this.bokehSize = 0;
27
+ this.apertureRotation = 0;
28
+ this.apertureBlades = 0;
29
+ this.focusDistance = 10;
30
+ this.anamorphicRatio = 1;
31
+
32
+ }
33
+
34
+ }
35
+
36
+ }
@@ -1,97 +1,97 @@
1
- import {
2
- WebGLArrayRenderTarget,
3
- RGBAFormat,
4
- UnsignedByteType,
5
- MeshBasicMaterial,
6
- Color,
7
- RepeatWrapping,
8
- LinearFilter,
9
- NoToneMapping,
10
- } from 'three';
11
- import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
12
- import { reduceTexturesToUniqueSources } from './utils.js';
13
-
14
- const prevColor = new Color();
15
- export class RenderTarget2DArray extends WebGLArrayRenderTarget {
16
-
17
- constructor( ...args ) {
18
-
19
- super( ...args );
20
-
21
- const tex = this.texture;
22
- tex.format = RGBAFormat;
23
- tex.type = UnsignedByteType;
24
- tex.minFilter = LinearFilter;
25
- tex.magFilter = LinearFilter;
26
- tex.wrapS = RepeatWrapping;
27
- tex.wrapT = RepeatWrapping;
28
- tex.setTextures = ( ...args ) => {
29
-
30
- this.setTextures( ...args );
31
-
32
- };
33
-
34
- const fsQuad = new FullScreenQuad( new MeshBasicMaterial() );
35
- this.fsQuad = fsQuad;
36
-
37
- }
38
-
39
- setTextures( renderer, width, height, textures ) {
40
-
41
- // get the list of textures with unique sources
42
- const uniqueTextures = reduceTexturesToUniqueSources( textures );
43
-
44
- // save previous renderer state
45
- const prevRenderTarget = renderer.getRenderTarget();
46
- const prevToneMapping = renderer.toneMapping;
47
- const prevAlpha = renderer.getClearAlpha();
48
- renderer.getClearColor( prevColor );
49
-
50
- // resize the render target and ensure we don't have an empty texture
51
- // render target depth must be >= 1 to avoid unbound texture error on android devices
52
- const depth = uniqueTextures.length || 1;
53
- this.setSize( width, height, depth );
54
- renderer.setClearColor( 0, 0 );
55
- renderer.toneMapping = NoToneMapping;
56
-
57
- // render each texture into each layer of the target
58
- const fsQuad = this.fsQuad;
59
- for ( let i = 0, l = depth; i < l; i ++ ) {
60
-
61
- const texture = uniqueTextures[ i ];
62
- if ( texture ) {
63
-
64
- // revert to default texture transform before rendering
65
- texture.matrixAutoUpdate = false;
66
- texture.matrix.identity();
67
-
68
- fsQuad.material.map = texture;
69
- fsQuad.material.transparent = true;
70
-
71
- renderer.setRenderTarget( this, i );
72
- fsQuad.render( renderer );
73
-
74
- // restore custom texture transform
75
- texture.updateMatrix();
76
- texture.matrixAutoUpdate = true;
77
-
78
- }
79
-
80
- }
81
-
82
- // reset the renderer
83
- fsQuad.material.map = null;
84
- renderer.setClearColor( prevColor, prevAlpha );
85
- renderer.setRenderTarget( prevRenderTarget );
86
- renderer.toneMapping = prevToneMapping;
87
-
88
- }
89
-
90
- dispose() {
91
-
92
- super.dispose();
93
- this.fsQuad.dispose();
94
-
95
- }
96
-
97
- }
1
+ import {
2
+ WebGLArrayRenderTarget,
3
+ RGBAFormat,
4
+ UnsignedByteType,
5
+ MeshBasicMaterial,
6
+ Color,
7
+ RepeatWrapping,
8
+ LinearFilter,
9
+ NoToneMapping,
10
+ } from 'three';
11
+ import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
12
+ import { reduceTexturesToUniqueSources } from './utils.js';
13
+
14
+ const prevColor = new Color();
15
+ export class RenderTarget2DArray extends WebGLArrayRenderTarget {
16
+
17
+ constructor( ...args ) {
18
+
19
+ super( ...args );
20
+
21
+ const tex = this.texture;
22
+ tex.format = RGBAFormat;
23
+ tex.type = UnsignedByteType;
24
+ tex.minFilter = LinearFilter;
25
+ tex.magFilter = LinearFilter;
26
+ tex.wrapS = RepeatWrapping;
27
+ tex.wrapT = RepeatWrapping;
28
+ tex.setTextures = ( ...args ) => {
29
+
30
+ this.setTextures( ...args );
31
+
32
+ };
33
+
34
+ const fsQuad = new FullScreenQuad( new MeshBasicMaterial() );
35
+ this.fsQuad = fsQuad;
36
+
37
+ }
38
+
39
+ setTextures( renderer, width, height, textures ) {
40
+
41
+ // get the list of textures with unique sources
42
+ const uniqueTextures = reduceTexturesToUniqueSources( textures );
43
+
44
+ // save previous renderer state
45
+ const prevRenderTarget = renderer.getRenderTarget();
46
+ const prevToneMapping = renderer.toneMapping;
47
+ const prevAlpha = renderer.getClearAlpha();
48
+ renderer.getClearColor( prevColor );
49
+
50
+ // resize the render target and ensure we don't have an empty texture
51
+ // render target depth must be >= 1 to avoid unbound texture error on android devices
52
+ const depth = uniqueTextures.length || 1;
53
+ this.setSize( width, height, depth );
54
+ renderer.setClearColor( 0, 0 );
55
+ renderer.toneMapping = NoToneMapping;
56
+
57
+ // render each texture into each layer of the target
58
+ const fsQuad = this.fsQuad;
59
+ for ( let i = 0, l = depth; i < l; i ++ ) {
60
+
61
+ const texture = uniqueTextures[ i ];
62
+ if ( texture ) {
63
+
64
+ // revert to default texture transform before rendering
65
+ texture.matrixAutoUpdate = false;
66
+ texture.matrix.identity();
67
+
68
+ fsQuad.material.map = texture;
69
+ fsQuad.material.transparent = true;
70
+
71
+ renderer.setRenderTarget( this, i );
72
+ fsQuad.render( renderer );
73
+
74
+ // restore custom texture transform
75
+ texture.updateMatrix();
76
+ texture.matrixAutoUpdate = true;
77
+
78
+ }
79
+
80
+ }
81
+
82
+ // reset the renderer
83
+ fsQuad.material.map = null;
84
+ renderer.setClearColor( prevColor, prevAlpha );
85
+ renderer.setRenderTarget( prevRenderTarget );
86
+ renderer.toneMapping = prevToneMapping;
87
+
88
+ }
89
+
90
+ dispose() {
91
+
92
+ super.dispose();
93
+ this.fsQuad.dispose();
94
+
95
+ }
96
+
97
+ }
@@ -1,30 +1,30 @@
1
- // we must hash the texture to determine uniqueness using the encoding, as well, because the
2
- // when rendering each texture to the texture array they must have a consistent color space.
3
- export function getTextureHash( t ) {
4
-
5
- return `${ t.source.uuid }:${ t.encoding }`;
6
-
7
- }
8
-
9
- // reduce the set of textures to just those with a unique source while retaining
10
- // the order of the textures.
11
- export function reduceTexturesToUniqueSources( textures ) {
12
-
13
- const sourceSet = new Set();
14
- const result = [];
15
- for ( let i = 0, l = textures.length; i < l; i ++ ) {
16
-
17
- const tex = textures[ i ];
18
- const hash = getTextureHash( tex );
19
- if ( ! sourceSet.has( hash ) ) {
20
-
21
- sourceSet.add( hash );
22
- result.push( tex );
23
-
24
- }
25
-
26
- }
27
-
28
- return result;
29
-
30
- }
1
+ // we must hash the texture to determine uniqueness using the encoding, as well, because the
2
+ // when rendering each texture to the texture array they must have a consistent color space.
3
+ export function getTextureHash( t ) {
4
+
5
+ return `${ t.source.uuid }:${ t.encoding }`;
6
+
7
+ }
8
+
9
+ // reduce the set of textures to just those with a unique source while retaining
10
+ // the order of the textures.
11
+ export function reduceTexturesToUniqueSources( textures ) {
12
+
13
+ const sourceSet = new Set();
14
+ const result = [];
15
+ for ( let i = 0, l = textures.length; i < l; i ++ ) {
16
+
17
+ const tex = textures[ i ];
18
+ const hash = getTextureHash( tex );
19
+ if ( ! sourceSet.has( hash ) ) {
20
+
21
+ sourceSet.add( hash );
22
+ result.push( tex );
23
+
24
+ }
25
+
26
+ }
27
+
28
+ return result;
29
+
30
+ }
@@ -1,116 +1,116 @@
1
- import { WebGLRenderTarget, RGBAFormat, FloatType, PMREMGenerator, DataTexture, EquirectangularReflectionMapping } from 'three';
2
- import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
3
- import { MaterialBase } from '../materials/MaterialBase.js';
4
- import { shaderUtils } from '../shader/shaderUtils.js';
5
-
6
- class PMREMCopyMaterial extends MaterialBase {
7
-
8
- constructor() {
9
-
10
- super( {
11
-
12
- uniforms: {
13
-
14
- envMap: { value: null },
15
- blur: { value: 0 },
16
-
17
- },
18
-
19
- vertexShader: /* glsl */`
20
-
21
- varying vec2 vUv;
22
- void main() {
23
- vUv = uv;
24
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
25
- }
26
-
27
- `,
28
-
29
- fragmentShader: /* glsl */`
30
-
31
- #include <common>
32
- #include <cube_uv_reflection_fragment>
33
-
34
- ${ shaderUtils }
35
-
36
- uniform sampler2D envMap;
37
- uniform float blur;
38
- varying vec2 vUv;
39
- void main() {
40
-
41
- vec3 rayDirection = equirectUvToDirection( vUv );
42
- gl_FragColor = textureCubeUV( envMap, rayDirection, blur );
43
-
44
- }
45
-
46
- `,
47
-
48
- } );
49
-
50
- }
51
-
52
- }
53
-
54
- export class BlurredEnvMapGenerator {
55
-
56
- constructor( renderer ) {
57
-
58
- this.renderer = renderer;
59
- this.pmremGenerator = new PMREMGenerator( renderer );
60
- this.copyQuad = new FullScreenQuad( new PMREMCopyMaterial() );
61
- this.renderTarget = new WebGLRenderTarget( 1, 1, { type: FloatType, format: RGBAFormat } );
62
-
63
- }
64
-
65
- dispose() {
66
-
67
- this.pmremGenerator.dispose();
68
- this.copyQuad.dispose();
69
- this.renderTarget.dispose();
70
-
71
- }
72
-
73
- generate( texture, blur ) {
74
-
75
- const { pmremGenerator, renderTarget, copyQuad, renderer } = this;
76
-
77
- // get the pmrem target
78
- const pmremTarget = pmremGenerator.fromEquirectangular( texture );
79
-
80
- // set up the material
81
- const { width, height } = texture.image;
82
- renderTarget.setSize( width, height );
83
- copyQuad.material.envMap = pmremTarget.texture;
84
- copyQuad.material.blur = blur;
85
-
86
- // render
87
- const prevRenderTarget = renderer.getRenderTarget();
88
- const prevClear = renderer.autoClear;
89
-
90
- renderer.setRenderTarget( renderTarget );
91
- renderer.autoClear = true;
92
- copyQuad.render( renderer );
93
-
94
- renderer.setRenderTarget( prevRenderTarget );
95
- renderer.autoClear = prevClear;
96
-
97
- // read the data back
98
- const buffer = new Float32Array( width * height * 4 );
99
- renderer.readRenderTargetPixels( renderTarget, 0, 0, width, height, buffer );
100
-
101
- const result = new DataTexture( buffer, width, height, RGBAFormat, FloatType );
102
- result.minFilter = texture.minFilter;
103
- result.magFilter = texture.magFilter;
104
- result.wrapS = texture.wrapS;
105
- result.wrapT = texture.wrapT;
106
- result.mapping = EquirectangularReflectionMapping;
107
- result.needsUpdate = true;
108
-
109
- // dispose of the now unneeded target
110
- pmremTarget.dispose();
111
-
112
- return result;
113
-
114
- }
115
-
116
- }
1
+ import { WebGLRenderTarget, RGBAFormat, FloatType, PMREMGenerator, DataTexture, EquirectangularReflectionMapping } from 'three';
2
+ import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
3
+ import { MaterialBase } from '../materials/MaterialBase.js';
4
+ import { shaderUtils } from '../shader/shaderUtils.js';
5
+
6
+ class PMREMCopyMaterial extends MaterialBase {
7
+
8
+ constructor() {
9
+
10
+ super( {
11
+
12
+ uniforms: {
13
+
14
+ envMap: { value: null },
15
+ blur: { value: 0 },
16
+
17
+ },
18
+
19
+ vertexShader: /* glsl */`
20
+
21
+ varying vec2 vUv;
22
+ void main() {
23
+ vUv = uv;
24
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
25
+ }
26
+
27
+ `,
28
+
29
+ fragmentShader: /* glsl */`
30
+
31
+ #include <common>
32
+ #include <cube_uv_reflection_fragment>
33
+
34
+ ${ shaderUtils }
35
+
36
+ uniform sampler2D envMap;
37
+ uniform float blur;
38
+ varying vec2 vUv;
39
+ void main() {
40
+
41
+ vec3 rayDirection = equirectUvToDirection( vUv );
42
+ gl_FragColor = textureCubeUV( envMap, rayDirection, blur );
43
+
44
+ }
45
+
46
+ `,
47
+
48
+ } );
49
+
50
+ }
51
+
52
+ }
53
+
54
+ export class BlurredEnvMapGenerator {
55
+
56
+ constructor( renderer ) {
57
+
58
+ this.renderer = renderer;
59
+ this.pmremGenerator = new PMREMGenerator( renderer );
60
+ this.copyQuad = new FullScreenQuad( new PMREMCopyMaterial() );
61
+ this.renderTarget = new WebGLRenderTarget( 1, 1, { type: FloatType, format: RGBAFormat } );
62
+
63
+ }
64
+
65
+ dispose() {
66
+
67
+ this.pmremGenerator.dispose();
68
+ this.copyQuad.dispose();
69
+ this.renderTarget.dispose();
70
+
71
+ }
72
+
73
+ generate( texture, blur ) {
74
+
75
+ const { pmremGenerator, renderTarget, copyQuad, renderer } = this;
76
+
77
+ // get the pmrem target
78
+ const pmremTarget = pmremGenerator.fromEquirectangular( texture );
79
+
80
+ // set up the material
81
+ const { width, height } = texture.image;
82
+ renderTarget.setSize( width, height );
83
+ copyQuad.material.envMap = pmremTarget.texture;
84
+ copyQuad.material.blur = blur;
85
+
86
+ // render
87
+ const prevRenderTarget = renderer.getRenderTarget();
88
+ const prevClear = renderer.autoClear;
89
+
90
+ renderer.setRenderTarget( renderTarget );
91
+ renderer.autoClear = true;
92
+ copyQuad.render( renderer );
93
+
94
+ renderer.setRenderTarget( prevRenderTarget );
95
+ renderer.autoClear = prevClear;
96
+
97
+ // read the data back
98
+ const buffer = new Float32Array( width * height * 4 );
99
+ renderer.readRenderTargetPixels( renderTarget, 0, 0, width, height, buffer );
100
+
101
+ const result = new DataTexture( buffer, width, height, RGBAFormat, FloatType );
102
+ result.minFilter = texture.minFilter;
103
+ result.magFilter = texture.magFilter;
104
+ result.wrapS = texture.wrapS;
105
+ result.wrapT = texture.wrapT;
106
+ result.mapping = EquirectangularReflectionMapping;
107
+ result.needsUpdate = true;
108
+
109
+ // dispose of the now unneeded target
110
+ pmremTarget.dispose();
111
+
112
+ return result;
113
+
114
+ }
115
+
116
+ }