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
@@ -0,0 +1,85 @@
1
+ import { WebGLRenderTarget } from 'three';
2
+ import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
3
+ import { PrecisionMaterial } from './PrecisionMaterial.js';
4
+
5
+ // see https://github.com/gkjohnson/webgl-precision
6
+ // Returns whether the platform can use highp precision consistently in structs
7
+ export class PrecisionDetector {
8
+
9
+ constructor( renderer ) {
10
+
11
+ this._renderer = renderer;
12
+ this._result = null;
13
+
14
+ }
15
+
16
+ detect() {
17
+
18
+ if ( this._result ) {
19
+
20
+ return this._result;
21
+
22
+ }
23
+
24
+ const renderer = this._renderer;
25
+ const material = new PrecisionMaterial();
26
+ const quad = new FullScreenQuad( material );
27
+ const target = new WebGLRenderTarget( 1, 1 );
28
+ const ogTarget = renderer.getRenderTarget();
29
+
30
+ const detail = {
31
+ 'int': extractResult( 'int' ),
32
+ 'uint': extractResult( 'uint' ),
33
+ 'float': extractResult( 'float' ),
34
+ };
35
+
36
+ const message = doesPass( 'int', detail.int ) || doesPass( 'uint', detail.uint ) || doesPass( 'float', detail.float );
37
+ this._result = {
38
+ detail,
39
+ message,
40
+ pass: ! Boolean( message ),
41
+ };
42
+
43
+ renderer.setRenderTarget( ogTarget );
44
+ quad.dispose();
45
+ target.dispose();
46
+ material.dispose();
47
+ return this._result;
48
+
49
+ function doesPass( type, info ) {
50
+
51
+ if ( info.vertex === info.vertexStruct && info.fragment === info.fragmentStruct ) {
52
+
53
+ return '';
54
+
55
+ } else {
56
+
57
+ return `Type "${ type }" cannot correctly provide highp precision in structs.`;
58
+
59
+ }
60
+
61
+ }
62
+
63
+ function extractResult( mode ) {
64
+
65
+ material.mode = mode;
66
+ renderer.setRenderTarget( target );
67
+ quad.render( renderer );
68
+
69
+ const readBuffer = new Uint8Array( 4 );
70
+ renderer.readRenderTargetPixels( target, 0, 0, 1, 1, readBuffer );
71
+
72
+ return {
73
+
74
+ vertex: readBuffer[ 0 ],
75
+ vertexStruct: readBuffer[ 1 ],
76
+ fragment: readBuffer[ 2 ],
77
+ fragmentStruct: readBuffer[ 3 ],
78
+
79
+ };
80
+
81
+ }
82
+
83
+ }
84
+
85
+ }
@@ -0,0 +1,160 @@
1
+ import { MaterialBase } from '../materials/MaterialBase.js';
2
+
3
+ const computePrecisionFunction = /* glsl */`
4
+ precision highp float;
5
+ precision highp int;
6
+ struct FloatStruct {
7
+ highp float value;
8
+ };
9
+
10
+ struct IntStruct {
11
+ highp int value;
12
+ };
13
+
14
+ struct UintStruct {
15
+ highp uint value;
16
+ };
17
+
18
+ vec2 computePrecision() {
19
+
20
+ #if MODE == 0 // float
21
+
22
+ float exponent = 0.0;
23
+ float value = 1.5;
24
+ while ( value > 1.0 ) {
25
+
26
+ exponent ++;
27
+ value = 1.0 + pow( 2.0, - exponent ) / 2.0;
28
+
29
+ }
30
+
31
+ float structExponent = 0.0;
32
+ FloatStruct str;
33
+ str.value = 1.5;
34
+ while ( str.value > 1.0 ) {
35
+
36
+ structExponent ++;
37
+ str.value = 1.0 + pow( 2.0, - structExponent ) / 2.0;
38
+
39
+ }
40
+
41
+ return vec2( exponent, structExponent );
42
+
43
+
44
+ #elif MODE == 1 // int
45
+
46
+ int bits = 0;
47
+ int value = 1;
48
+ while ( value > 0 ) {
49
+
50
+ value = value << 1;
51
+ value = value | 1;
52
+ bits ++;
53
+
54
+ }
55
+
56
+ int structBits = 0;
57
+ IntStruct str;
58
+ str.value = 1;
59
+ while ( str.value > 0 ) {
60
+
61
+ str.value = str.value << 1;
62
+ str.value = str.value | 1;
63
+ structBits ++;
64
+
65
+ }
66
+
67
+ return vec2( bits, structBits );
68
+
69
+ #else // uint
70
+
71
+ int bits = 0;
72
+ uint value = 1u;
73
+ while ( value > 0u ) {
74
+
75
+ value = value << 1u;
76
+ bits ++;
77
+
78
+ }
79
+
80
+ int structBits = 0;
81
+ UintStruct str;
82
+ str.value = 1u;
83
+ while( str.value > 0u ) {
84
+
85
+ str.value = str.value << 1u;
86
+ structBits ++;
87
+
88
+ }
89
+
90
+ return vec2( bits, structBits );
91
+
92
+ #endif
93
+
94
+ }
95
+
96
+
97
+ `;
98
+
99
+ export class PrecisionMaterial extends MaterialBase {
100
+
101
+ set mode( v ) {
102
+
103
+ this._mode = v;
104
+
105
+ switch ( v.toLowerCase() ) {
106
+
107
+ case 'float':
108
+ this.setDefine( 'MODE', 0 );
109
+ break;
110
+ case 'int':
111
+ this.setDefine( 'MODE', 1 );
112
+ break;
113
+ case 'uint':
114
+ this.setDefine( 'MODE', 2 );
115
+ break;
116
+
117
+ }
118
+
119
+ }
120
+
121
+ constructor() {
122
+
123
+ super( {
124
+
125
+ vertexShader: /* glsl */`
126
+
127
+ ${ computePrecisionFunction }
128
+
129
+ varying vec2 vPrecision;
130
+ void main() {
131
+
132
+ vec4 mvPosition = vec4( position, 1.0 );
133
+ mvPosition = modelViewMatrix * mvPosition;
134
+ gl_Position = projectionMatrix * mvPosition;
135
+
136
+ vPrecision = computePrecision();
137
+
138
+ }
139
+
140
+ `,
141
+
142
+ fragmentShader: /* glsl */`
143
+
144
+ ${ computePrecisionFunction }
145
+
146
+ varying vec2 vPrecision;
147
+ void main( void ) {
148
+
149
+ vec2 fPrecision = computePrecision();
150
+ gl_FragColor = vec4( vPrecision, fPrecision ) / 255.0;
151
+
152
+ }
153
+
154
+ `,
155
+
156
+ } );
157
+
158
+ }
159
+
160
+ }
package/src/index.js CHANGED
@@ -1,36 +1,40 @@
1
- // core
2
- export * from './core/PathTracingRenderer.js';
3
- export * from './core/QuiltPathTracingRenderer.js';
4
- export * from './core/PathTracingSceneGenerator.js';
5
- export * from './core/DynamicPathTracingSceneGenerator.js';
6
- export * from './core/MaterialReducer.js';
7
-
8
- // objects
9
- export * from './objects/PhysicalCamera.js';
10
- export * from './objects/EquirectCamera.js';
11
- export * from './objects/PhysicalSpotLight.js';
12
- export * from './objects/ShapedAreaLight.js';
13
-
14
- // textures
15
- export * from './textures/ProceduralEquirectTexture.js';
16
- export * from './textures/GradientEquirectTexture.js';
17
-
18
- // uniforms
19
- export * from './uniforms/MaterialsTexture.js';
20
- export * from './uniforms/RenderTarget2DArray.js';
21
- export * from './uniforms/EquirectHdrInfoUniform.js';
22
- export * from './uniforms/PhysicalCameraUniform.js';
23
- export * from './uniforms/LightsInfoUniformStruct.js';
24
- export * from './uniforms/IESProfilesTexture.js';
25
-
26
- // utils
27
- export * from './utils/GeometryPreparationUtils.js';
28
- export * from './utils/BlurredEnvMapGenerator.js';
29
- export * from './utils/IESLoader.js';
30
-
31
- // materials
32
- export * from './materials/fullscreen/DenoiseMaterial.js';
33
- export * from './materials/debug/GraphMaterial.js';
34
- export * from './materials/MaterialBase.js';
35
- export * from './materials/pathtracing/PhysicalPathTracingMaterial.js';
36
- export * from './materials/surface/FogVolumeMaterial.js';
1
+ // core
2
+ export * from './core/PathTracingRenderer.js';
3
+ export * from './core/QuiltPathTracingRenderer.js';
4
+ export * from './core/PathTracingSceneGenerator.js';
5
+ export * from './core/DynamicPathTracingSceneGenerator.js';
6
+ export * from './core/MaterialReducer.js';
7
+
8
+ // objects
9
+ export * from './objects/PhysicalCamera.js';
10
+ export * from './objects/EquirectCamera.js';
11
+ export * from './objects/PhysicalSpotLight.js';
12
+ export * from './objects/ShapedAreaLight.js';
13
+
14
+ // textures
15
+ export * from './textures/ProceduralEquirectTexture.js';
16
+ export * from './textures/GradientEquirectTexture.js';
17
+
18
+ // uniforms
19
+ export * from './uniforms/MaterialsTexture.js';
20
+ export * from './uniforms/RenderTarget2DArray.js';
21
+ export * from './uniforms/EquirectHdrInfoUniform.js';
22
+ export * from './uniforms/PhysicalCameraUniform.js';
23
+ export * from './uniforms/LightsInfoUniformStruct.js';
24
+ export * from './uniforms/IESProfilesTexture.js';
25
+
26
+ // utils
27
+ export * from './utils/GeometryPreparationUtils.js';
28
+ export * from './utils/BlurredEnvMapGenerator.js';
29
+ export * from './utils/IESLoader.js';
30
+
31
+ // materials
32
+ export * from './materials/fullscreen/DenoiseMaterial.js';
33
+ export * from './materials/fullscreen/GradientMapMaterial.js';
34
+ export * from './materials/debug/GraphMaterial.js';
35
+ export * from './materials/MaterialBase.js';
36
+ export * from './materials/pathtracing/PhysicalPathTracingMaterial.js';
37
+ export * from './materials/surface/FogVolumeMaterial.js';
38
+
39
+ // detectors
40
+ export * from './detectors/CompatibilityDetector.js';
@@ -1,56 +1,56 @@
1
- import { ShaderMaterial } from 'three';
2
-
3
- export class MaterialBase extends ShaderMaterial {
4
-
5
- constructor( shader ) {
6
-
7
- super( shader );
8
-
9
- for ( const key in this.uniforms ) {
10
-
11
- Object.defineProperty( this, key, {
12
-
13
- get() {
14
-
15
- return this.uniforms[ key ].value;
16
-
17
- },
18
-
19
- set( v ) {
20
-
21
- this.uniforms[ key ].value = v;
22
-
23
- }
24
-
25
- } );
26
-
27
- }
28
-
29
- }
30
-
31
- // sets the given named define value and sets "needsUpdate" to true if it's different
32
- setDefine( name, value = undefined ) {
33
-
34
- if ( value === undefined || value === null ) {
35
-
36
- if ( name in this.defines ) {
37
-
38
- delete this.defines[ name ];
39
- this.needsUpdate = true;
40
-
41
- }
42
-
43
- } else {
44
-
45
- if ( this.defines[ name ] !== value ) {
46
-
47
- this.defines[ name ] = value;
48
- this.needsUpdate = true;
49
-
50
- }
51
-
52
- }
53
-
54
- }
55
-
56
- }
1
+ import { ShaderMaterial } from 'three';
2
+
3
+ export class MaterialBase extends ShaderMaterial {
4
+
5
+ constructor( shader ) {
6
+
7
+ super( shader );
8
+
9
+ for ( const key in this.uniforms ) {
10
+
11
+ Object.defineProperty( this, key, {
12
+
13
+ get() {
14
+
15
+ return this.uniforms[ key ].value;
16
+
17
+ },
18
+
19
+ set( v ) {
20
+
21
+ this.uniforms[ key ].value = v;
22
+
23
+ }
24
+
25
+ } );
26
+
27
+ }
28
+
29
+ }
30
+
31
+ // sets the given named define value and sets "needsUpdate" to true if it's different
32
+ setDefine( name, value = undefined ) {
33
+
34
+ if ( value === undefined || value === null ) {
35
+
36
+ if ( name in this.defines ) {
37
+
38
+ delete this.defines[ name ];
39
+ this.needsUpdate = true;
40
+
41
+ }
42
+
43
+ } else {
44
+
45
+ if ( this.defines[ name ] !== value ) {
46
+
47
+ this.defines[ name ] = value;
48
+ this.needsUpdate = true;
49
+
50
+ }
51
+
52
+ }
53
+
54
+ }
55
+
56
+ }