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,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 { utilsGLSL } from '../shader/common/utils.glsl.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
- ${ utilsGLSL }
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 { utilsGLSL } from '../shader/common/utils.glsl.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
+ ${ utilsGLSL }
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
+ }