three-gpu-pathtracer 0.0.20 → 0.0.21

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 (75) hide show
  1. package/README.md +111 -464
  2. package/build/index.module.js +5691 -5312
  3. package/build/index.module.js.map +1 -1
  4. package/build/index.umd.cjs +5369 -5003
  5. package/build/index.umd.cjs.map +1 -1
  6. package/package.json +12 -6
  7. package/src/core/PathTracingRenderer.js +59 -46
  8. package/src/core/PathTracingSceneGenerator.js +245 -10
  9. package/src/core/WebGLPathTracer.js +472 -0
  10. package/src/core/utils/BakedGeometry.js +35 -0
  11. package/src/core/utils/BufferAttributeUtils.js +64 -0
  12. package/src/{utils → core/utils}/GeometryPreparationUtils.js +35 -35
  13. package/src/core/utils/MeshDiff.js +102 -0
  14. package/src/core/utils/StaticGeometryGenerator.js +285 -0
  15. package/src/core/utils/convertToStaticGeometry.js +344 -0
  16. package/src/core/utils/mergeGeometries.js +218 -0
  17. package/src/core/utils/sceneUpdateUtils.js +96 -0
  18. package/src/index.d.ts +274 -0
  19. package/src/index.js +4 -20
  20. package/src/materials/MaterialBase.js +4 -0
  21. package/src/materials/fullscreen/ClampedInterpolationMaterial.js +112 -0
  22. package/src/materials/fullscreen/DenoiseMaterial.js +4 -0
  23. package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +73 -76
  24. package/src/materials/pathtracing/glsl/{attenuateHit.glsl.js → attenuate_hit_function.glsl.js} +1 -1
  25. package/src/materials/pathtracing/glsl/{cameraUtils.glsl.js → camera_util_functions.glsl.js} +1 -1
  26. package/src/materials/pathtracing/glsl/{directLightContribution.glsl.js → direct_light_contribution_function.glsl.js} +1 -1
  27. package/src/materials/pathtracing/glsl/{getSurfaceRecord.glsl.js → get_surface_record_function.glsl.js} +1 -1
  28. package/src/materials/pathtracing/glsl/index.js +6 -0
  29. package/src/materials/pathtracing/glsl/{renderStructs.glsl.js → render_structs.glsl.js} +1 -1
  30. package/src/materials/pathtracing/glsl/{traceScene.glsl.js → trace_scene_function.glsl.js} +1 -3
  31. package/src/materials/surface/AmbientOcclusionMaterial.js +8 -8
  32. package/src/objects/PhysicalSpotLight.js +2 -2
  33. package/src/shader/bsdf/{bsdfSampling.glsl.js → bsdf_functions.glsl.js} +19 -72
  34. package/src/shader/bsdf/{fog.glsl.js → fog_functions.glsl.js} +1 -1
  35. package/src/shader/bsdf/{ggx.glsl.js → ggx_functions.glsl.js} +1 -1
  36. package/src/shader/bsdf/index.js +5 -0
  37. package/src/shader/bsdf/{iridescence.glsl.js → iridescence_functions.glsl.js} +1 -1
  38. package/src/shader/bsdf/{sheen.glsl.js → sheen_functions.glsl.js} +1 -1
  39. package/src/shader/bvh/index.js +2 -0
  40. package/src/shader/{structs/fogMaterialBvh.glsl.js → bvh/inside_fog_volume_function.glsl.js} +1 -1
  41. package/src/shader/{common/bvhAnyHit.glsl.js → bvh/ray_any_hit_function.glsl.js} +1 -1
  42. package/src/shader/common/{fresnel.glsl.js → fresnel_functions.glsl.js} +1 -1
  43. package/src/shader/common/index.js +5 -0
  44. package/src/shader/common/{math.glsl.js → math_functions.glsl.js} +1 -1
  45. package/src/shader/common/{intersectShapes.glsl.js → shape_intersection_functions.glsl.js} +1 -1
  46. package/src/shader/common/{arraySamplerTexelFetch.glsl.js → texture_sample_functions.glsl.js} +1 -1
  47. package/src/shader/common/{utils.glsl.js → util_functions.glsl.js} +1 -1
  48. package/src/shader/rand/index.js +3 -0
  49. package/src/shader/rand/pcg.glsl.js +1 -1
  50. package/src/shader/rand/sobol.glsl.js +4 -4
  51. package/src/shader/rand/{stratifiedTexture.glsl.js → stratified.glsl.js} +7 -2
  52. package/src/shader/sampling/{equirectSampling.glsl.js → equirect_sampling_functions.glsl.js} +1 -2
  53. package/src/shader/sampling/index.js +3 -0
  54. package/src/shader/sampling/{lightSampling.glsl.js → light_sampling_functions.glsl.js} +3 -3
  55. package/src/shader/sampling/{shapeSampling.glsl.js → shape_sampling_functions.glsl.js} +1 -1
  56. package/src/shader/structs/{cameraStruct.glsl.js → camera_struct.glsl.js} +1 -1
  57. package/src/shader/structs/{equirectStruct.glsl.js → equirect_struct.glsl.js} +1 -1
  58. package/src/shader/structs/index.js +5 -0
  59. package/src/shader/structs/{lightsStruct.glsl.js → lights_struct.glsl.js} +1 -1
  60. package/src/shader/structs/{materialStruct.glsl.js → material_struct.glsl.js} +2 -2
  61. package/src/shader/structs/surface_record_struct.glsl.js +63 -0
  62. package/src/uniforms/EquirectHdrInfoUniform.js +16 -11
  63. package/src/uniforms/LightsInfoUniformStruct.js +21 -10
  64. package/src/uniforms/MaterialsTexture.js +27 -86
  65. package/src/uniforms/RenderTarget2DArray.js +60 -20
  66. package/src/utils/BlurredEnvMapGenerator.js +12 -5
  67. package/src/utils/SobolNumberMapGenerator.js +3 -3
  68. package/src/utils/bufferToHash.js +22 -0
  69. package/src/core/DynamicPathTracingSceneGenerator.js +0 -164
  70. package/src/core/MaterialReducer.js +0 -256
  71. package/src/materials/pathtracing/LambertPathTracingMaterial.js +0 -297
  72. package/src/uniforms/IESProfilesTexture.js +0 -100
  73. package/src/uniforms/utils.js +0 -30
  74. package/src/utils/IESLoader.js +0 -327
  75. package/src/workers/PathTracingSceneWorker.js +0 -52
@@ -0,0 +1,112 @@
1
+ import { ShaderMaterial } from 'three';
2
+
3
+ // Material that tone maps a texture before performing interpolation to prevent
4
+ // unexpected high values during texture stretching interpolation.
5
+ // Emulates browser image stretching
6
+ export class ClampedInterpolationMaterial extends ShaderMaterial {
7
+
8
+ get map() {
9
+
10
+ return this.uniforms.map.value;
11
+
12
+ }
13
+
14
+ set map( v ) {
15
+
16
+ this.uniforms.map.value = v;
17
+
18
+ }
19
+
20
+ get opacity() {
21
+
22
+ return this.uniforms.opacity.value;
23
+
24
+ }
25
+
26
+ set opacity( v ) {
27
+
28
+ if ( this.uniforms ) {
29
+
30
+ this.uniforms.opacity.value = v;
31
+
32
+ }
33
+
34
+ }
35
+
36
+ constructor( params ) {
37
+
38
+ super( {
39
+ uniforms: {
40
+
41
+ map: { value: null },
42
+ opacity: { value: 1 },
43
+
44
+ },
45
+
46
+ vertexShader: /* glsl */`
47
+ varying vec2 vUv;
48
+ void main() {
49
+
50
+ vUv = uv;
51
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
52
+
53
+ }
54
+ `,
55
+
56
+ fragmentShader: /* glsl */`
57
+ uniform sampler2D map;
58
+ uniform float opacity;
59
+ varying vec2 vUv;
60
+
61
+ vec4 clampedTexelFatch( sampler2D map, ivec2 px, int lod ) {
62
+
63
+ vec4 res = texelFetch( map, ivec2( px.x, px.y ), 0 );
64
+
65
+ #if defined( TONE_MAPPING )
66
+
67
+ res.xyz = toneMapping( res.xyz );
68
+
69
+ #endif
70
+
71
+ return linearToOutputTexel( res );
72
+
73
+ }
74
+
75
+ void main() {
76
+
77
+ vec2 size = vec2( textureSize( map, 0 ) );
78
+ vec2 pxUv = vUv * size;
79
+ vec2 pxCurr = floor( pxUv );
80
+ vec2 pxFrac = fract( pxUv ) - 0.5;
81
+ vec2 pxOffset;
82
+ pxOffset.x = pxFrac.x > 0.0 ? 1.0 : - 1.0;
83
+ pxOffset.y = pxFrac.y > 0.0 ? 1.0 : - 1.0;
84
+
85
+ vec2 pxNext = clamp( pxOffset + pxCurr, vec2( 0.0 ), size - 1.0 );
86
+ vec2 alpha = abs( pxFrac );
87
+
88
+ vec4 p1 = mix(
89
+ clampedTexelFatch( map, ivec2( pxCurr.x, pxCurr.y ), 0 ),
90
+ clampedTexelFatch( map, ivec2( pxNext.x, pxCurr.y ), 0 ),
91
+ alpha.x
92
+ );
93
+
94
+ vec4 p2 = mix(
95
+ clampedTexelFatch( map, ivec2( pxCurr.x, pxNext.y ), 0 ),
96
+ clampedTexelFatch( map, ivec2( pxNext.x, pxNext.y ), 0 ),
97
+ alpha.x
98
+ );
99
+
100
+ gl_FragColor = mix( p1, p2, alpha.y );
101
+ gl_FragColor.a *= opacity;
102
+ #include <premultiplied_alpha_fragment>
103
+
104
+ }
105
+ `
106
+ } );
107
+
108
+ this.setValues( params );
109
+
110
+ }
111
+
112
+ }
@@ -28,6 +28,7 @@ export class DenoiseMaterial extends MaterialBase {
28
28
  kSigma: { value: 1.0 },
29
29
 
30
30
  map: { value: null },
31
+ opacity: { value: 1 },
31
32
 
32
33
  },
33
34
 
@@ -65,6 +66,7 @@ export class DenoiseMaterial extends MaterialBase {
65
66
  uniform float sigma;
66
67
  uniform float threshold;
67
68
  uniform float kSigma;
69
+ uniform float opacity;
68
70
 
69
71
  varying vec2 vUv;
70
72
 
@@ -129,6 +131,8 @@ export class DenoiseMaterial extends MaterialBase {
129
131
  #include <colorspace_fragment>
130
132
  #include <premultiplied_alpha_fragment>
131
133
 
134
+ gl_FragColor.a *= opacity;
135
+
132
136
  }
133
137
 
134
138
  `
@@ -1,4 +1,4 @@
1
- import { Matrix4, Vector2 } from 'three';
1
+ import { ClampToEdgeWrapping, HalfFloatType, Matrix4, Vector2 } from 'three';
2
2
  import { MaterialBase } from '../MaterialBase.js';
3
3
  import {
4
4
  MeshBVHUniformStruct, UIntVertexAttributeTexture,
@@ -9,49 +9,23 @@ import {
9
9
  import { PhysicalCameraUniform } from '../../uniforms/PhysicalCameraUniform.js';
10
10
  import { EquirectHdrInfoUniform } from '../../uniforms/EquirectHdrInfoUniform.js';
11
11
  import { LightsInfoUniformStruct } from '../../uniforms/LightsInfoUniformStruct.js';
12
- import { IESProfilesTexture } from '../../uniforms/IESProfilesTexture.js';
13
12
  import { AttributesTextureArray } from '../../uniforms/AttributesTextureArray.js';
14
13
  import { MaterialsTexture } from '../../uniforms/MaterialsTexture.js';
15
14
  import { RenderTarget2DArray } from '../../uniforms/RenderTarget2DArray.js';
16
-
17
- // glsl
18
- import { cameraStructGLSL } from '../../shader/structs/cameraStruct.glsl.js';
19
- import { equirectStructGLSL } from '../../shader/structs/equirectStruct.glsl.js';
20
- import { lightsStructGLSL } from '../../shader/structs/lightsStruct.glsl.js';
21
- import { materialStructGLSL } from '../../shader/structs/materialStruct.glsl.js';
22
- import { fogMaterialBvhGLSL } from '../../shader/structs/fogMaterialBvh.glsl.js';
23
-
24
- // material sampling
25
- import { bsdfSamplingGLSL } from '../../shader/bsdf/bsdfSampling.glsl.js';
26
- import { fogGLSL } from '../../shader/bsdf/fog.glsl.js';
27
-
28
- // sampling
29
- import { equirectSamplingGLSL } from '../../shader/sampling/equirectSampling.glsl.js';
30
- import { lightSamplingGLSL } from '../../shader/sampling/lightSampling.glsl.js';
31
- import { shapeSamplingGLSL } from '../../shader/sampling/shapeSampling.glsl.js';
32
-
33
- // common glsl
34
- import { intersectShapesGLSL } from '../../shader/common/intersectShapes.glsl.js';
35
- import { mathGLSL } from '../../shader/common/math.glsl.js';
36
- import { utilsGLSL } from '../../shader/common/utils.glsl.js';
37
- import { fresnelGLSL } from '../../shader/common/fresnel.glsl.js';
38
- import { arraySamplerTexelFetchGLSL } from '../../shader/common/arraySamplerTexelFetch.glsl.js';
39
-
40
- // random glsl
41
- import { pcgGLSL } from '../../shader/rand/pcg.glsl.js';
42
- import { sobolCommonGLSL, sobolSamplingGLSL } from '../../shader/rand/sobol.glsl.js';
43
-
44
- // path tracer utils
45
- import { renderStructsGLSL } from './glsl/renderStructs.glsl.js';
46
- import { cameraUtilsGLSL } from './glsl/cameraUtils.glsl.js';
47
- import { attenuateHitGLSL } from './glsl/attenuateHit.glsl.js';
48
- import { traceSceneGLSL } from './glsl/traceScene.glsl.js';
49
- import { getSurfaceRecordGLSL } from './glsl/getSurfaceRecord.glsl.js';
50
- import { directLightContributionGLSL } from './glsl/directLightContribution.glsl.js';
51
- import { stratifiedTextureGLSL } from '../../shader/rand/stratifiedTexture.glsl.js';
52
15
  import { StratifiedSamplesTexture } from '../../uniforms/StratifiedSamplesTexture.js';
53
16
  import { BlueNoiseTexture } from '../../textures/BlueNoiseTexture.js';
54
17
 
18
+ // general glsl
19
+ import * as StructsGLSL from '../../shader/structs/index.js';
20
+ import * as SamplingGLSL from '../../shader/sampling/index.js';
21
+ import * as CommonGLSL from '../../shader/common/index.js';
22
+ import * as RandomGLSL from '../../shader/rand/index.js';
23
+ import * as BSDFGLSL from '../../shader/bsdf/index.js';
24
+ import * as PTBVHGLSL from '../../shader/bvh/index.js';
25
+
26
+ // path tracer glsl
27
+ import * as RenderGLSL from './glsl/index.js';
28
+
55
29
  export class PhysicalPathTracingMaterial extends MaterialBase {
56
30
 
57
31
  onBeforeRender() {
@@ -95,32 +69,46 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
95
69
  },
96
70
 
97
71
  uniforms: {
98
- resolution: { value: new Vector2() },
99
72
 
73
+ // path trace uniforms
74
+ resolution: { value: new Vector2() },
75
+ opacity: { value: 1 },
100
76
  bounces: { value: 10 },
101
77
  transmissiveBounces: { value: 10 },
78
+ filterGlossyFactor: { value: 0 },
79
+
80
+ // camera uniforms
102
81
  physicalCamera: { value: new PhysicalCameraUniform() },
82
+ cameraWorldMatrix: { value: new Matrix4() },
83
+ invProjectionMatrix: { value: new Matrix4() },
103
84
 
85
+ // scene uniforms
104
86
  bvh: { value: new MeshBVHUniformStruct() },
105
87
  attributesArray: { value: new AttributesTextureArray() },
106
88
  materialIndexAttribute: { value: new UIntVertexAttributeTexture() },
107
89
  materials: { value: new MaterialsTexture() },
108
90
  textures: { value: new RenderTarget2DArray().texture },
91
+
92
+ // light uniforms
109
93
  lights: { value: new LightsInfoUniformStruct() },
110
- iesProfiles: { value: new IESProfilesTexture().texture },
111
- cameraWorldMatrix: { value: new Matrix4() },
112
- invProjectionMatrix: { value: new Matrix4() },
113
- backgroundBlur: { value: 0.0 },
94
+ iesProfiles: { value: new RenderTarget2DArray( 360, 180, {
95
+ type: HalfFloatType,
96
+ wrapS: ClampToEdgeWrapping,
97
+ wrapT: ClampToEdgeWrapping,
98
+ } ).texture },
114
99
  environmentIntensity: { value: 1.0 },
115
100
  environmentRotation: { value: new Matrix4() },
116
101
  envMapInfo: { value: new EquirectHdrInfoUniform() },
102
+
103
+ // background uniforms
104
+ backgroundBlur: { value: 0.0 },
117
105
  backgroundMap: { value: null },
106
+ backgroundAlpha: { value: 1.0 },
107
+ backgroundIntensity: { value: 1.0 },
108
+ backgroundRotation: { value: new Matrix4() },
118
109
 
110
+ // randomness uniforms
119
111
  seed: { value: 0 },
120
- opacity: { value: 1 },
121
- filterGlossyFactor: { value: 0.0 },
122
-
123
- backgroundAlpha: { value: 1.0 },
124
112
  sobolTexture: { value: null },
125
113
  stratifiedTexture: { value: new StratifiedSamplesTexture() },
126
114
  stratifiedOffsetTexture: { value: new BlueNoiseTexture( 64, 1 ) },
@@ -157,21 +145,22 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
157
145
  ${ BVHShaderGLSL.bvh_ray_functions }
158
146
 
159
147
  // uniform structs
160
- ${ cameraStructGLSL }
161
- ${ lightsStructGLSL }
162
- ${ equirectStructGLSL }
163
- ${ materialStructGLSL }
148
+ ${ StructsGLSL.camera_struct }
149
+ ${ StructsGLSL.lights_struct }
150
+ ${ StructsGLSL.equirect_struct }
151
+ ${ StructsGLSL.material_struct }
152
+ ${ StructsGLSL.surface_record_struct }
164
153
 
165
154
  // random
166
155
  #if RANDOM_TYPE == 2 // Stratified List
167
156
 
168
- ${ stratifiedTextureGLSL }
157
+ ${ RandomGLSL.stratified_functions }
169
158
 
170
159
  #elif RANDOM_TYPE == 1 // Sobol
171
160
 
172
- ${ pcgGLSL }
173
- ${ sobolCommonGLSL }
174
- ${ sobolSamplingGLSL }
161
+ ${ RandomGLSL.pcg_functions }
162
+ ${ RandomGLSL.sobol_common }
163
+ ${ RandomGLSL.sobol_functions }
175
164
 
176
165
  #define rand(v) sobol(v)
177
166
  #define rand2(v) sobol2(v)
@@ -180,7 +169,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
180
169
 
181
170
  #else // PCG
182
171
 
183
- ${ pcgGLSL }
172
+ ${ RandomGLSL.pcg_functions }
184
173
 
185
174
  // Using the sobol functions seems to break the the compiler on MacOS
186
175
  // - specifically the "sobolReverseBits" function.
@@ -196,11 +185,11 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
196
185
  #endif
197
186
 
198
187
  // common
199
- ${ arraySamplerTexelFetchGLSL }
200
- ${ fresnelGLSL }
201
- ${ utilsGLSL }
202
- ${ mathGLSL }
203
- ${ intersectShapesGLSL }
188
+ ${ CommonGLSL.texture_sample_functions }
189
+ ${ CommonGLSL.fresnel_functions }
190
+ ${ CommonGLSL.util_functions }
191
+ ${ CommonGLSL.math_functions }
192
+ ${ CommonGLSL.shape_intersection_functions }
204
193
 
205
194
  // environment
206
195
  uniform EquirectHdrInfo envMapInfo;
@@ -217,6 +206,8 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
217
206
  #if FEATURE_BACKGROUND_MAP
218
207
 
219
208
  uniform sampler2D backgroundMap;
209
+ uniform mat4 backgroundRotation;
210
+ uniform float backgroundIntensity;
220
211
 
221
212
  #endif
222
213
 
@@ -254,12 +245,16 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
254
245
  float lightsDenom;
255
246
 
256
247
  // sampling
257
- ${ fogMaterialBvhGLSL }
258
- ${ shapeSamplingGLSL }
259
- ${ bsdfSamplingGLSL }
260
- ${ equirectSamplingGLSL }
261
- ${ lightSamplingGLSL }
262
- ${ fogGLSL }
248
+ ${ SamplingGLSL.shape_sampling_functions }
249
+ ${ SamplingGLSL.equirect_functions }
250
+ ${ SamplingGLSL.light_sampling_functions }
251
+
252
+ ${ PTBVHGLSL.inside_fog_volume_function }
253
+ ${ BSDFGLSL.ggx_functions }
254
+ ${ BSDFGLSL.sheen_functions }
255
+ ${ BSDFGLSL.iridescence_functions }
256
+ ${ BSDFGLSL.fog_functions }
257
+ ${ BSDFGLSL.bsdf_functions }
263
258
 
264
259
  float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
265
260
 
@@ -275,26 +270,28 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
275
270
 
276
271
  vec3 sampleBackground( vec3 direction, vec2 uv ) {
277
272
 
278
- vec3 sampleDir = normalize( direction + sampleHemisphere( direction, uv ) * 0.5 * backgroundBlur );
273
+ vec3 sampleDir = sampleHemisphere( direction, uv ) * 0.5 * backgroundBlur;
279
274
 
280
275
  #if FEATURE_BACKGROUND_MAP
281
276
 
282
- return sampleEquirectColor( backgroundMap, sampleDir );
277
+ sampleDir = normalize( mat3( backgroundRotation ) * direction + sampleDir );
278
+ return backgroundIntensity * sampleEquirectColor( backgroundMap, sampleDir );
283
279
 
284
280
  #else
285
281
 
282
+ sampleDir = normalize( envRotation3x3 * direction + sampleDir );
286
283
  return environmentIntensity * sampleEquirectColor( envMapInfo.map, sampleDir );
287
284
 
288
285
  #endif
289
286
 
290
287
  }
291
288
 
292
- ${ renderStructsGLSL }
293
- ${ cameraUtilsGLSL }
294
- ${ traceSceneGLSL }
295
- ${ attenuateHitGLSL }
296
- ${ directLightContributionGLSL }
297
- ${ getSurfaceRecordGLSL }
289
+ ${ RenderGLSL.render_structs }
290
+ ${ RenderGLSL.camera_util_functions }
291
+ ${ RenderGLSL.trace_scene_function }
292
+ ${ RenderGLSL.attenuate_hit_function }
293
+ ${ RenderGLSL.direct_light_contribution_function }
294
+ ${ RenderGLSL.get_surface_record_function }
298
295
 
299
296
  void main() {
300
297
 
@@ -381,7 +378,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
381
378
 
382
379
  if ( state.firstRay || state.transmissiveRay ) {
383
380
 
384
- gl_FragColor.rgb += sampleBackground( envRotation3x3 * ray.direction, rand2( 2 ) ) * state.throughputColor;
381
+ gl_FragColor.rgb += sampleBackground( ray.direction, rand2( 2 ) ) * state.throughputColor;
385
382
  gl_FragColor.a = backgroundAlpha;
386
383
 
387
384
  } else {
@@ -1,4 +1,4 @@
1
- export const attenuateHitGLSL = /* glsl */`
1
+ export const attenuate_hit_function = /* glsl */`
2
2
 
3
3
  // step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
4
4
  // returns true if a solid surface was hit
@@ -1,4 +1,4 @@
1
- export const cameraUtilsGLSL = /* glsl */`
1
+ export const camera_util_functions = /* glsl */`
2
2
 
3
3
  vec3 ndcToRayOrigin( vec2 coord ) {
4
4
 
@@ -1,4 +1,4 @@
1
- export const directLightContributionGLSL = /*glsl*/`
1
+ export const direct_light_contribution_function = /*glsl*/`
2
2
 
3
3
  vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- export const getSurfaceRecordGLSL = /* glsl */`
2
+ export const get_surface_record_function = /* glsl */`
3
3
 
4
4
  #define SKIP_SURFACE 0
5
5
  #define HIT_SURFACE 1
@@ -0,0 +1,6 @@
1
+ export * from './attenuate_hit_function.glsl.js';
2
+ export * from './camera_util_functions.glsl.js';
3
+ export * from './direct_light_contribution_function.glsl.js';
4
+ export * from './get_surface_record_function.glsl.js';
5
+ export * from './render_structs.glsl.js';
6
+ export * from './trace_scene_function.glsl.js';
@@ -1,4 +1,4 @@
1
- export const renderStructsGLSL = /* glsl */`
1
+ export const render_structs = /* glsl */`
2
2
 
3
3
  struct Ray {
4
4
 
@@ -1,4 +1,4 @@
1
- export const traceSceneGLSL = /* glsl */`
1
+ export const trace_scene_function = /* glsl */`
2
2
 
3
3
  #define NO_HIT 0
4
4
  #define SURFACE_HIT 1
@@ -9,9 +9,7 @@ export const traceSceneGLSL = /* glsl */`
9
9
  // So global variables like 'lights' and 'bvh' were moved out of the function parameters.
10
10
  // For more information, refer to: https://github.com/gkjohnson/three-gpu-pathtracer/pull/457
11
11
  int traceScene(
12
-
13
12
  Ray ray, Material fogMaterial, inout SurfaceHit surfaceHit
14
-
15
13
  ) {
16
14
 
17
15
  int result = NO_HIT;
@@ -2,9 +2,9 @@ import { TangentSpaceNormalMap, Vector2 } from 'three';
2
2
  import { MaterialBase } from '../MaterialBase.js';
3
3
  import { MeshBVHUniformStruct, BVHShaderGLSL } from 'three-mesh-bvh';
4
4
 
5
- import { materialStructGLSL } from '../../shader/structs/materialStruct.glsl.js';
6
- import { shapeSamplingGLSL } from '../../shader/sampling/shapeSampling.glsl.js';
7
- import { pcgGLSL } from '../../shader/rand/pcg.glsl.js';
5
+ import * as StructsGLSL from '../../shader/structs/index.js';
6
+ import * as SamplingGLSL from '../../shader/sampling/index.js';
7
+ import * as RandomGLSL from '../../shader/rand/index.js';
8
8
 
9
9
  export class AmbientOcclusionMaterial extends MaterialBase {
10
10
 
@@ -59,7 +59,7 @@ export class AmbientOcclusionMaterial extends MaterialBase {
59
59
  varying vec3 vNorm;
60
60
  varying vec3 vPos;
61
61
 
62
- #if defined(USE_NORMALMAP) && defined(USE_TANGENT)
62
+ #if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
63
63
 
64
64
  varying vec2 vUv;
65
65
  varying vec4 vTan;
@@ -102,13 +102,13 @@ export class AmbientOcclusionMaterial extends MaterialBase {
102
102
  ${ BVHShaderGLSL.bvh_ray_functions }
103
103
 
104
104
  // uniform structs
105
- ${ materialStructGLSL }
105
+ ${ StructsGLSL.material_struct }
106
106
 
107
107
  // rand
108
- ${ pcgGLSL }
108
+ ${ RandomGLSL.pcg_functions }
109
109
 
110
110
  // common
111
- ${ shapeSamplingGLSL }
111
+ ${ SamplingGLSL.shape_sampling_functions }
112
112
 
113
113
  uniform BVH bvh;
114
114
  uniform int seed;
@@ -167,7 +167,7 @@ export class AmbientOcclusionMaterial extends MaterialBase {
167
167
 
168
168
  // sample the cosine weighted hemisphere and discard the sample if it's below
169
169
  // the geometric surface
170
- vec3 rayDirection = sampleHemisphere( normalize( normal ), rand4().xy );
170
+ vec3 rayDirection = sampleHemisphere( normalize( normal ), pcgRand4().xy );
171
171
 
172
172
  // check if we hit the mesh and its within the specified radius
173
173
  float side = 1.0;
@@ -6,7 +6,7 @@ export class PhysicalSpotLight extends SpotLight {
6
6
 
7
7
  super( ...args );
8
8
 
9
- this.iesTexture = null;
9
+ this.iesMap = null;
10
10
  this.radius = 0;
11
11
 
12
12
  }
@@ -15,7 +15,7 @@ export class PhysicalSpotLight extends SpotLight {
15
15
 
16
16
  super.copy( source, recursive );
17
17
 
18
- this.iesTexture = source.iesTexture;
18
+ this.iesMap = source.iesMap;
19
19
  this.radius = source.radius;
20
20
 
21
21
  return this;
@@ -1,7 +1,3 @@
1
- import { ggxGLSL } from './ggx.glsl.js';
2
- import { sheenGLSL } from './sheen.glsl.js';
3
- import { iridescenceGLSL } from './iridescence.glsl.js';
4
-
5
1
  /*
6
2
  wi : incident vector or light vector (pointing toward the light)
7
3
  wo : outgoing vector or view vector (pointing towards the camera)
@@ -13,71 +9,7 @@ f0 : Amount of light reflected when looking at a surface head on - "fresnel
13
9
  f90 : Amount of light reflected at grazing angles
14
10
  */
15
11
 
16
- export const bsdfSamplingGLSL = /* glsl */`
17
-
18
- struct SurfaceRecord {
19
-
20
- // surface type
21
- bool volumeParticle;
22
-
23
- // geometry
24
- vec3 faceNormal;
25
- bool frontFace;
26
- vec3 normal;
27
- mat3 normalBasis;
28
- mat3 normalInvBasis;
29
-
30
- // cached properties
31
- float eta;
32
- float f0;
33
-
34
- // material
35
- float roughness;
36
- float filteredRoughness;
37
- float metalness;
38
- vec3 color;
39
- vec3 emission;
40
-
41
- // transmission
42
- float ior;
43
- float transmission;
44
- bool thinFilm;
45
- vec3 attenuationColor;
46
- float attenuationDistance;
47
-
48
- // clearcoat
49
- vec3 clearcoatNormal;
50
- mat3 clearcoatBasis;
51
- mat3 clearcoatInvBasis;
52
- float clearcoat;
53
- float clearcoatRoughness;
54
- float filteredClearcoatRoughness;
55
-
56
- // sheen
57
- float sheen;
58
- vec3 sheenColor;
59
- float sheenRoughness;
60
-
61
- // iridescence
62
- float iridescence;
63
- float iridescenceIor;
64
- float iridescenceThickness;
65
-
66
- // specular
67
- vec3 specularColor;
68
- float specularIntensity;
69
- };
70
-
71
- struct ScatterRecord {
72
- float specularPdf;
73
- float pdf;
74
- vec3 direction;
75
- vec3 color;
76
- };
77
-
78
- ${ ggxGLSL }
79
- ${ sheenGLSL }
80
- ${ iridescenceGLSL }
12
+ export const bsdf_functions = /* glsl */`
81
13
 
82
14
  // diffuse
83
15
  float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
@@ -209,14 +141,29 @@ export const bsdfSamplingGLSL = /* glsl */`
209
141
 
210
142
  // PDF
211
143
  // float F = evaluateFresnelWeight( dot( wo, wh ), surf.eta, surf.f0 );
212
- float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
213
- if ( F >= 1.0 ) {
144
+ // float F = disneyFresnel( wo, wi, wh, surf.f0, surf.eta, surf.metalness );
145
+ // if ( F >= 1.0 ) {
146
+
147
+ // return 0.0;
148
+
149
+ // }
150
+
151
+ // return 1.0 / ( 1.0 - F );
152
+
153
+ // reverted to previous to transmission. The above was causing black pixels
154
+ float eta = surf.eta;
155
+ float f0 = surf.f0;
156
+ float cosTheta = min( wo.z, 1.0 );
157
+ float sinTheta = sqrt( 1.0 - cosTheta * cosTheta );
158
+ float reflectance = schlickFresnel( cosTheta, f0 );
159
+ bool cannotRefract = eta * sinTheta > 1.0;
160
+ if ( cannotRefract ) {
214
161
 
215
162
  return 0.0;
216
163
 
217
164
  }
218
165
 
219
- return 1.0 / ( 1.0 - F );
166
+ return 1.0 / ( 1.0 - reflectance );
220
167
 
221
168
  }
222
169
 
@@ -1,4 +1,4 @@
1
- export const fogGLSL = /* glsl */`
1
+ export const fog_functions = /* glsl */`
2
2
 
3
3
  // returns the hit distance given the material density
4
4
  float intersectFogVolume( Material material, float u ) {
@@ -1,4 +1,4 @@
1
- export const ggxGLSL = /* glsl */`
1
+ export const ggx_functions = /* glsl */`
2
2
 
3
3
  // The GGX functions provide sampling and distribution information for normals as output so
4
4
  // in order to get probability of scatter direction the half vector must be computed and provided.
@@ -0,0 +1,5 @@
1
+ export * from './bsdf_functions.glsl.js';
2
+ export * from './fog_functions.glsl.js';
3
+ export * from './ggx_functions.glsl.js';
4
+ export * from './iridescence_functions.glsl.js';
5
+ export * from './sheen_functions.glsl.js';
@@ -1,4 +1,4 @@
1
- export const iridescenceGLSL = /* glsl */`
1
+ export const iridescence_functions = /* glsl */`
2
2
 
3
3
  // XYZ to sRGB color space
4
4
  const mat3 XYZ_TO_REC709 = mat3(
@@ -1,4 +1,4 @@
1
- export const sheenGLSL = /* glsl */`
1
+ export const sheen_functions = /* glsl */`
2
2
 
3
3
  // See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
4
4
  float velvetD( float cosThetaH, float roughness ) {
@@ -0,0 +1,2 @@
1
+ export * from './inside_fog_volume_function.glsl.js';
2
+ export * from './ray_any_hit_function.glsl.js';
@@ -1,4 +1,4 @@
1
- export const fogMaterialBvhGLSL = /* glsl */`
1
+ export const inside_fog_volume_function = /* glsl */`
2
2
 
3
3
  #ifndef FOG_CHECK_ITERATIONS
4
4
  #define FOG_CHECK_ITERATIONS 30