three-gpu-pathtracer 0.0.7 → 0.0.9

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