three-gpu-pathtracer 0.0.10 → 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 +6479 -6472
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6478 -6470
  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
package/src/index.js CHANGED
@@ -1,39 +1,39 @@
1
- // core
2
- export * from './core/PathTracingRenderer.js';
3
- export * from './core/PathTracingSceneGenerator.js';
4
- export * from './core/DynamicPathTracingSceneGenerator.js';
5
- export * from './core/MaterialReducer.js';
6
-
7
- // objects
8
- export * from './objects/PhysicalCamera.js';
9
- export * from './objects/EquirectCamera.js';
10
- export * from './objects/PhysicalSpotLight.js';
11
- export * from './objects/ShapedAreaLight.js';
12
-
13
- // textures
14
- export * from './textures/ProceduralEquirectTexture.js';
15
- export * from './textures/GradientEquirectTexture.js';
16
-
17
- // uniforms
18
- export * from './uniforms/MaterialsTexture.js';
19
- export * from './uniforms/RenderTarget2DArray.js';
20
- export * from './uniforms/EquirectHdrInfoUniform.js';
21
- export * from './uniforms/PhysicalCameraUniform.js';
22
- export * from './uniforms/LightsInfoUniformStruct.js';
23
- export * from './uniforms/IESProfilesTexture.js';
24
-
25
- // utils
26
- export * from './utils/GeometryPreparationUtils.js';
27
- export * from './utils/BlurredEnvMapGenerator.js';
28
- export * from './utils/IESLoader.js';
29
-
30
- // materials
31
- export * from './materials/DenoiseMaterial.js';
32
- export * from './materials/GraphMaterial.js';
33
- export * from './materials/MaterialBase.js';
34
- export * from './materials/PhysicalPathTracingMaterial.js';
35
-
36
- // shaders
37
- export * from './shader/shaderMaterialSampling.js';
38
- export * from './shader/shaderUtils.js';
39
- export * from './shader/shaderStructs.js';
1
+ // core
2
+ export * from './core/PathTracingRenderer.js';
3
+ export * from './core/PathTracingSceneGenerator.js';
4
+ export * from './core/DynamicPathTracingSceneGenerator.js';
5
+ export * from './core/MaterialReducer.js';
6
+
7
+ // objects
8
+ export * from './objects/PhysicalCamera.js';
9
+ export * from './objects/EquirectCamera.js';
10
+ export * from './objects/PhysicalSpotLight.js';
11
+ export * from './objects/ShapedAreaLight.js';
12
+
13
+ // textures
14
+ export * from './textures/ProceduralEquirectTexture.js';
15
+ export * from './textures/GradientEquirectTexture.js';
16
+
17
+ // uniforms
18
+ export * from './uniforms/MaterialsTexture.js';
19
+ export * from './uniforms/RenderTarget2DArray.js';
20
+ export * from './uniforms/EquirectHdrInfoUniform.js';
21
+ export * from './uniforms/PhysicalCameraUniform.js';
22
+ export * from './uniforms/LightsInfoUniformStruct.js';
23
+ export * from './uniforms/IESProfilesTexture.js';
24
+
25
+ // utils
26
+ export * from './utils/GeometryPreparationUtils.js';
27
+ export * from './utils/BlurredEnvMapGenerator.js';
28
+ export * from './utils/IESLoader.js';
29
+
30
+ // materials
31
+ export * from './materials/DenoiseMaterial.js';
32
+ export * from './materials/GraphMaterial.js';
33
+ export * from './materials/MaterialBase.js';
34
+ export * from './materials/PhysicalPathTracingMaterial.js';
35
+
36
+ // shaders
37
+ export * from './shader/shaderMaterialSampling.js';
38
+ export * from './shader/shaderUtils.js';
39
+ export * from './shader/shaderStructs.js';
@@ -1,48 +1,48 @@
1
- import { NoBlending } from 'three';
2
- import { MaterialBase } from './MaterialBase.js';
3
-
4
- export class AlphaDisplayMaterial extends MaterialBase {
5
-
6
- constructor( parameters ) {
7
-
8
- super( {
9
-
10
- uniforms: {
11
-
12
- map: { value: null },
13
-
14
- },
15
-
16
- blending: NoBlending,
17
-
18
- vertexShader: /* glsl */`
19
-
20
- varying vec2 vUv;
21
-
22
- void main() {
23
-
24
- vUv = uv;
25
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
26
-
27
- }`,
28
-
29
- fragmentShader: /* glsl */`
30
-
31
- uniform sampler2D map;
32
-
33
- varying vec2 vUv;
34
-
35
- void main() {
36
-
37
- gl_FragColor = vec4( texture( map, vUv ).a );
38
- gl_FragColor.a = 1.0;
39
-
40
- }`
41
-
42
- } );
43
-
44
- this.setValues( parameters );
45
-
46
- }
47
-
48
- }
1
+ import { NoBlending } from 'three';
2
+ import { MaterialBase } from './MaterialBase.js';
3
+
4
+ export class AlphaDisplayMaterial extends MaterialBase {
5
+
6
+ constructor( parameters ) {
7
+
8
+ super( {
9
+
10
+ uniforms: {
11
+
12
+ map: { value: null },
13
+
14
+ },
15
+
16
+ blending: NoBlending,
17
+
18
+ vertexShader: /* glsl */`
19
+
20
+ varying vec2 vUv;
21
+
22
+ void main() {
23
+
24
+ vUv = uv;
25
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
26
+
27
+ }`,
28
+
29
+ fragmentShader: /* glsl */`
30
+
31
+ uniform sampler2D map;
32
+
33
+ varying vec2 vUv;
34
+
35
+ void main() {
36
+
37
+ gl_FragColor = vec4( texture( map, vUv ).a );
38
+ gl_FragColor.a = 1.0;
39
+
40
+ }`
41
+
42
+ } );
43
+
44
+ this.setValues( parameters );
45
+
46
+ }
47
+
48
+ }
@@ -1,199 +1,199 @@
1
- import { TangentSpaceNormalMap, Vector2 } from 'three';
2
- import { MaterialBase } from './MaterialBase.js';
3
- import { MeshBVHUniformStruct, shaderStructs, shaderIntersectFunction } from 'three-mesh-bvh';
4
- import { shaderMaterialStructs } from '../shader/shaderStructs.js';
5
- import { shaderUtils } from '../shader/shaderUtils.js';
6
- import { shaderRandFunctions } from '../shader/shaderRandFunctions.js';
7
-
8
- export class AmbientOcclusionMaterial extends MaterialBase {
9
-
10
- get normalMap() {
11
-
12
- return this.uniforms.normalMap.value;
13
-
14
- }
15
-
16
- set normalMap( v ) {
17
-
18
- this.uniforms.normalMap.value = v;
19
- this.setDefine( 'USE_NORMALMAP', v ? null : '' );
20
-
21
- }
22
-
23
- get normalMapType() {
24
-
25
- return TangentSpaceNormalMap;
26
-
27
- }
28
-
29
- set normalMapType( v ) {
30
-
31
- if ( v !== TangentSpaceNormalMap ) {
32
-
33
- throw new Error( 'AmbientOcclusionMaterial: Only tangent space normal map are supported' );
34
-
35
- }
36
-
37
- }
38
-
39
- constructor( parameters ) {
40
-
41
- super( {
42
-
43
- defines: {
44
- SAMPLES: 10,
45
- },
46
-
47
- uniforms: {
48
- bvh: { value: new MeshBVHUniformStruct() },
49
- radius: { value: 1.0 },
50
- seed: { value: 0 },
51
-
52
- normalMap: { value: null },
53
- normalScale: { value: new Vector2( 1, 1 ) },
54
- },
55
-
56
- vertexShader: /* glsl */`
57
-
58
- varying vec3 vNorm;
59
- varying vec3 vPos;
60
-
61
- #if defined(USE_NORMALMAP) && defined(USE_TANGENT)
62
-
63
- varying vec2 vUv;
64
- varying vec4 vTan;
65
-
66
- #endif
67
-
68
- void main() {
69
-
70
- vec4 mvPosition = vec4( position, 1.0 );
71
- mvPosition = modelViewMatrix * mvPosition;
72
- gl_Position = projectionMatrix * mvPosition;
73
-
74
- mat3 modelNormalMatrix = transpose( inverse( mat3( modelMatrix ) ) );
75
- vNorm = normalize( modelNormalMatrix * normal );
76
- vPos = ( modelMatrix * vec4( position, 1.0 ) ).xyz;
77
-
78
- #if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
79
-
80
- vUv = uv;
81
- vTan = tangent;
82
-
83
- #endif
84
-
85
- }
86
-
87
- `,
88
-
89
- fragmentShader: /* glsl */`
90
- #define RAY_OFFSET 1e-4
91
-
92
- precision highp isampler2D;
93
- precision highp usampler2D;
94
- precision highp sampler2DArray;
95
- #include <common>
96
- #include <cube_uv_reflection_fragment>
97
-
98
- ${ shaderStructs }
99
- ${ shaderIntersectFunction }
100
- ${ shaderMaterialStructs }
101
- ${ shaderRandFunctions }
102
- ${ shaderUtils }
103
-
104
- uniform BVH bvh;
105
- uniform int seed;
106
- uniform float radius;
107
-
108
- varying vec3 vNorm;
109
- varying vec3 vPos;
110
-
111
- #if defined(USE_NORMALMAP) && defined(USE_TANGENT)
112
-
113
- uniform sampler2D normalMap;
114
- uniform vec2 normalScale;
115
- varying vec2 vUv;
116
- varying vec4 vTan;
117
-
118
- #endif
119
-
120
- void main() {
121
-
122
- rng_initialize( gl_FragCoord.xy, seed );
123
-
124
- // compute the flat face surface normal
125
- vec3 fdx = vec3( dFdx( vPos.x ), dFdx( vPos.y ), dFdx( vPos.z ) );
126
- vec3 fdy = vec3( dFdy( vPos.x ), dFdy( vPos.y ), dFdy( vPos.z ) );
127
- vec3 faceNormal = normalize( cross( fdx, fdy ) );
128
-
129
- // find the max component to scale the offset to account for floating point error
130
- vec3 absPoint = abs( vPos );
131
- float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) );
132
- vec3 normal = vNorm;
133
-
134
- #if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
135
-
136
- // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate
137
- // resulting in NaNs and slow path tracing.
138
- if ( length( vTan.xyz ) > 0.0 ) {
139
-
140
- vec2 uv = vUv;
141
- vec3 tangent = normalize( vTan.xyz );
142
- vec3 bitangent = normalize( cross( normal, tangent ) * vTan.w );
143
- mat3 vTBN = mat3( tangent, bitangent, normal );
144
-
145
- vec3 texNormal = texture2D( normalMap, uv ).xyz * 2.0 - 1.0;
146
- texNormal.xy *= normalScale;
147
- normal = vTBN * texNormal;
148
-
149
- }
150
-
151
- #endif
152
-
153
- normal *= gl_FrontFacing ? 1.0 : - 1.0;
154
-
155
- vec3 rayOrigin = vPos + faceNormal * ( maxPoint + 1.0 ) * RAY_OFFSET;
156
- float accumulated = 0.0;
157
- for ( int i = 0; i < SAMPLES; i ++ ) {
158
-
159
- // sample the cosine weighted hemisphere and discard the sample if it's below
160
- // the geometric surface
161
- vec3 rayDirection = getHemisphereSample( normalize( normal ), rand4().xy );
162
-
163
- // check if we hit the mesh and its within the specified radius
164
- float side = 1.0;
165
- float dist = 0.0;
166
- vec3 barycoord = vec3( 0.0 );
167
- vec3 outNormal = vec3( 0.0 );
168
- uvec4 faceIndices = uvec4( 0u );
169
-
170
- // if the ray is above the geometry surface, and it doesn't hit another surface within the specified radius then
171
- // we consider it lit
172
- if (
173
- dot( rayDirection, faceNormal ) > 0.0 &&
174
- (
175
- ! bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, outNormal, barycoord, side, dist ) ||
176
- dist > radius
177
- )
178
- ) {
179
-
180
- accumulated += 1.0;
181
-
182
- }
183
-
184
- }
185
-
186
- gl_FragColor.rgb = vec3( accumulated / float( SAMPLES ) );
187
- gl_FragColor.a = 1.0;
188
-
189
- }
190
-
191
- `
192
-
193
- } );
194
-
195
- this.setValues( parameters );
196
-
197
- }
198
-
199
- }
1
+ import { TangentSpaceNormalMap, Vector2 } from 'three';
2
+ import { MaterialBase } from './MaterialBase.js';
3
+ import { MeshBVHUniformStruct, shaderStructs, shaderIntersectFunction } from 'three-mesh-bvh';
4
+ import { shaderMaterialStructs } from '../shader/shaderStructs.js';
5
+ import { shaderUtils } from '../shader/shaderUtils.js';
6
+ import { shaderRandFunctions } from '../shader/shaderRandFunctions.js';
7
+
8
+ export class AmbientOcclusionMaterial extends MaterialBase {
9
+
10
+ get normalMap() {
11
+
12
+ return this.uniforms.normalMap.value;
13
+
14
+ }
15
+
16
+ set normalMap( v ) {
17
+
18
+ this.uniforms.normalMap.value = v;
19
+ this.setDefine( 'USE_NORMALMAP', v ? null : '' );
20
+
21
+ }
22
+
23
+ get normalMapType() {
24
+
25
+ return TangentSpaceNormalMap;
26
+
27
+ }
28
+
29
+ set normalMapType( v ) {
30
+
31
+ if ( v !== TangentSpaceNormalMap ) {
32
+
33
+ throw new Error( 'AmbientOcclusionMaterial: Only tangent space normal map are supported' );
34
+
35
+ }
36
+
37
+ }
38
+
39
+ constructor( parameters ) {
40
+
41
+ super( {
42
+
43
+ defines: {
44
+ SAMPLES: 10,
45
+ },
46
+
47
+ uniforms: {
48
+ bvh: { value: new MeshBVHUniformStruct() },
49
+ radius: { value: 1.0 },
50
+ seed: { value: 0 },
51
+
52
+ normalMap: { value: null },
53
+ normalScale: { value: new Vector2( 1, 1 ) },
54
+ },
55
+
56
+ vertexShader: /* glsl */`
57
+
58
+ varying vec3 vNorm;
59
+ varying vec3 vPos;
60
+
61
+ #if defined(USE_NORMALMAP) && defined(USE_TANGENT)
62
+
63
+ varying vec2 vUv;
64
+ varying vec4 vTan;
65
+
66
+ #endif
67
+
68
+ void main() {
69
+
70
+ vec4 mvPosition = vec4( position, 1.0 );
71
+ mvPosition = modelViewMatrix * mvPosition;
72
+ gl_Position = projectionMatrix * mvPosition;
73
+
74
+ mat3 modelNormalMatrix = transpose( inverse( mat3( modelMatrix ) ) );
75
+ vNorm = normalize( modelNormalMatrix * normal );
76
+ vPos = ( modelMatrix * vec4( position, 1.0 ) ).xyz;
77
+
78
+ #if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
79
+
80
+ vUv = uv;
81
+ vTan = tangent;
82
+
83
+ #endif
84
+
85
+ }
86
+
87
+ `,
88
+
89
+ fragmentShader: /* glsl */`
90
+ #define RAY_OFFSET 1e-4
91
+
92
+ precision highp isampler2D;
93
+ precision highp usampler2D;
94
+ precision highp sampler2DArray;
95
+ #include <common>
96
+ #include <cube_uv_reflection_fragment>
97
+
98
+ ${ shaderStructs }
99
+ ${ shaderIntersectFunction }
100
+ ${ shaderMaterialStructs }
101
+ ${ shaderRandFunctions }
102
+ ${ shaderUtils }
103
+
104
+ uniform BVH bvh;
105
+ uniform int seed;
106
+ uniform float radius;
107
+
108
+ varying vec3 vNorm;
109
+ varying vec3 vPos;
110
+
111
+ #if defined(USE_NORMALMAP) && defined(USE_TANGENT)
112
+
113
+ uniform sampler2D normalMap;
114
+ uniform vec2 normalScale;
115
+ varying vec2 vUv;
116
+ varying vec4 vTan;
117
+
118
+ #endif
119
+
120
+ void main() {
121
+
122
+ rng_initialize( gl_FragCoord.xy, seed );
123
+
124
+ // compute the flat face surface normal
125
+ vec3 fdx = vec3( dFdx( vPos.x ), dFdx( vPos.y ), dFdx( vPos.z ) );
126
+ vec3 fdy = vec3( dFdy( vPos.x ), dFdy( vPos.y ), dFdy( vPos.z ) );
127
+ vec3 faceNormal = normalize( cross( fdx, fdy ) );
128
+
129
+ // find the max component to scale the offset to account for floating point error
130
+ vec3 absPoint = abs( vPos );
131
+ float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) );
132
+ vec3 normal = vNorm;
133
+
134
+ #if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
135
+
136
+ // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate
137
+ // resulting in NaNs and slow path tracing.
138
+ if ( length( vTan.xyz ) > 0.0 ) {
139
+
140
+ vec2 uv = vUv;
141
+ vec3 tangent = normalize( vTan.xyz );
142
+ vec3 bitangent = normalize( cross( normal, tangent ) * vTan.w );
143
+ mat3 vTBN = mat3( tangent, bitangent, normal );
144
+
145
+ vec3 texNormal = texture2D( normalMap, uv ).xyz * 2.0 - 1.0;
146
+ texNormal.xy *= normalScale;
147
+ normal = vTBN * texNormal;
148
+
149
+ }
150
+
151
+ #endif
152
+
153
+ normal *= gl_FrontFacing ? 1.0 : - 1.0;
154
+
155
+ vec3 rayOrigin = vPos + faceNormal * ( maxPoint + 1.0 ) * RAY_OFFSET;
156
+ float accumulated = 0.0;
157
+ for ( int i = 0; i < SAMPLES; i ++ ) {
158
+
159
+ // sample the cosine weighted hemisphere and discard the sample if it's below
160
+ // the geometric surface
161
+ vec3 rayDirection = getHemisphereSample( normalize( normal ), rand4().xy );
162
+
163
+ // check if we hit the mesh and its within the specified radius
164
+ float side = 1.0;
165
+ float dist = 0.0;
166
+ vec3 barycoord = vec3( 0.0 );
167
+ vec3 outNormal = vec3( 0.0 );
168
+ uvec4 faceIndices = uvec4( 0u );
169
+
170
+ // if the ray is above the geometry surface, and it doesn't hit another surface within the specified radius then
171
+ // we consider it lit
172
+ if (
173
+ dot( rayDirection, faceNormal ) > 0.0 &&
174
+ (
175
+ ! bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, outNormal, barycoord, side, dist ) ||
176
+ dist > radius
177
+ )
178
+ ) {
179
+
180
+ accumulated += 1.0;
181
+
182
+ }
183
+
184
+ }
185
+
186
+ gl_FragColor.rgb = vec3( accumulated / float( SAMPLES ) );
187
+ gl_FragColor.a = 1.0;
188
+
189
+ }
190
+
191
+ `
192
+
193
+ } );
194
+
195
+ this.setValues( parameters );
196
+
197
+ }
198
+
199
+ }