three-gpu-pathtracer 0.0.12 → 0.0.14

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 (58) hide show
  1. package/README.md +102 -7
  2. package/build/index.module.js +2891 -2065
  3. package/build/index.module.js.map +1 -1
  4. package/build/index.umd.cjs +2886 -2062
  5. package/build/index.umd.cjs.map +1 -1
  6. package/package.json +2 -1
  7. package/src/core/PathTracingRenderer.js +87 -16
  8. package/src/core/PathTracingSceneGenerator.js +1 -1
  9. package/src/core/QuiltPathTracingRenderer.js +223 -0
  10. package/src/index.js +5 -8
  11. package/src/materials/{GraphMaterial.js → debug/GraphMaterial.js} +1 -1
  12. package/src/materials/{AlphaDisplayMaterial.js → fullscreen/AlphaDisplayMaterial.js} +1 -1
  13. package/src/materials/{BlendMaterial.js → fullscreen/BlendMaterial.js} +1 -1
  14. package/src/materials/{DenoiseMaterial.js → fullscreen/DenoiseMaterial.js} +1 -1
  15. package/src/materials/{LambertPathTracingMaterial.js → pathtracing/LambertPathTracingMaterial.js} +18 -7
  16. package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +635 -0
  17. package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +179 -0
  18. package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +81 -0
  19. package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +317 -0
  20. package/src/materials/pathtracing/glsl/traceScene.glsl.js +54 -0
  21. package/src/materials/{AmbientOcclusionMaterial.js → surface/AmbientOcclusionMaterial.js} +16 -8
  22. package/src/materials/surface/FogVolumeMaterial.js +23 -0
  23. package/src/shader/bsdf/bsdfSampling.glsl.js +490 -0
  24. package/src/shader/bsdf/fog.glsl.js +23 -0
  25. package/src/shader/bsdf/ggx.glsl.js +102 -0
  26. package/src/shader/bsdf/iridescence.glsl.js +135 -0
  27. package/src/shader/bsdf/sheen.glsl.js +98 -0
  28. package/src/shader/{shaderLayerTexelFetchFunctions.js → common/arraySamplerTexelFetch.glsl.js} +1 -1
  29. package/src/shader/common/bvhAnyHit.glsl.js +76 -0
  30. package/src/shader/common/fresnel.glsl.js +98 -0
  31. package/src/shader/common/intersectShapes.glsl.js +62 -0
  32. package/src/shader/common/math.glsl.js +81 -0
  33. package/src/shader/common/utils.glsl.js +116 -0
  34. package/src/shader/{shaderRandFunctions.js → rand/pcg.glsl.js} +1 -1
  35. package/src/shader/{shaderSobolSampling.js → rand/sobol.glsl.js} +3 -3
  36. package/src/shader/sampling/equirectSampling.glsl.js +62 -0
  37. package/src/shader/sampling/lightSampling.glsl.js +223 -0
  38. package/src/shader/sampling/shapeSampling.glsl.js +86 -0
  39. package/src/shader/structs/cameraStruct.glsl.js +13 -0
  40. package/src/shader/structs/equirectStruct.glsl.js +14 -0
  41. package/src/shader/structs/fogMaterialBvh.glsl.js +62 -0
  42. package/src/shader/structs/lightsStruct.glsl.js +78 -0
  43. package/src/shader/{shaderStructs.js → structs/materialStruct.glsl.js} +5 -123
  44. package/src/uniforms/EquirectHdrInfoUniform.js +29 -11
  45. package/src/uniforms/LightsInfoUniformStruct.js +9 -4
  46. package/src/uniforms/MaterialsTexture.js +80 -3
  47. package/src/utils/BlurredEnvMapGenerator.js +2 -2
  48. package/src/utils/SobolNumberMapGenerator.js +3 -3
  49. package/src/utils/macroify.js +9 -0
  50. package/src/materials/PhysicalPathTracingMaterial.js +0 -982
  51. package/src/shader/shaderBvhAnyHit.js +0 -76
  52. package/src/shader/shaderEnvMapSampling.js +0 -58
  53. package/src/shader/shaderGGXFunctions.js +0 -100
  54. package/src/shader/shaderIridescenceFunctions.js +0 -130
  55. package/src/shader/shaderLightSampling.js +0 -229
  56. package/src/shader/shaderMaterialSampling.js +0 -506
  57. package/src/shader/shaderSheenFunctions.js +0 -98
  58. package/src/shader/shaderUtils.js +0 -361
@@ -1,506 +0,0 @@
1
- import { shaderGGXFunctions } from './shaderGGXFunctions.js';
2
- import { shaderSheenFunctions } from './shaderSheenFunctions.js';
3
- import { shaderIridescenceFunctions } from './shaderIridescenceFunctions.js';
4
-
5
- /*
6
- wi : incident vector or light vector (pointing toward the light)
7
- wo : outgoing vector or view vector (pointing towards the camera)
8
- wh : computed half vector from wo and wi
9
- Eval : Get the color and pdf for a direction
10
- Sample : Get the direction, color, and pdf for a sample
11
- eta : Greek character used to denote the "ratio of ior"
12
- f0 : Amount of light reflected when looking at a surface head on - "fresnel 0"
13
- */
14
-
15
- export const shaderMaterialSampling = /* glsl */`
16
-
17
- struct SurfaceRec {
18
- vec3 normal;
19
- vec3 faceNormal;
20
- bool frontFace;
21
- float roughness;
22
- float filteredRoughness;
23
- float metalness;
24
- vec3 color;
25
- vec3 emission;
26
- float transmission;
27
- bool thinFilm;
28
- float ior;
29
- float eta;
30
- float f0;
31
- float clearcoat;
32
- float clearcoatRoughness;
33
- float filteredClearcoatRoughness;
34
- vec3 sheenColor;
35
- float sheenRoughness;
36
- float iridescence;
37
- float iridescenceIor;
38
- float iridescenceThickness;
39
- vec3 specularColor;
40
- float specularIntensity;
41
- vec3 attenuationColor;
42
- float attenuationDistance;
43
- };
44
-
45
- struct SampleRec {
46
- float specularPdf;
47
- float pdf;
48
- vec3 direction;
49
- vec3 clearcoatDirection;
50
- vec3 color;
51
- };
52
-
53
- ${ shaderGGXFunctions }
54
- ${ shaderSheenFunctions }
55
- ${ shaderIridescenceFunctions }
56
-
57
- float disneyFresnel( SurfaceRec surf, vec3 wo, vec3 wi, vec3 wh ) {
58
-
59
- float dotHV = dot( wo, wh );
60
- float dotHL = dot( wi, wh );
61
-
62
- // TODO: some model-viewer test models look better when surf.eta is set to a non 1.5 eta here here?
63
- // and the furnace test seems to pass when it === 1.0
64
- // float dielectricFresnel = dielectricFresnel( abs( dotHV ), surf.eta );
65
- float dielectricFresnel = dielectricFresnel( abs( dotHV ), 1.0 / 1.1 );
66
- float metallicFresnel = schlickFresnel( dotHL, surf.f0 );
67
-
68
- return mix( dielectricFresnel, metallicFresnel, surf.metalness );
69
-
70
- }
71
-
72
- // diffuse
73
- float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRec surf, out vec3 color ) {
74
-
75
- // https://schuttejoe.github.io/post/disneybsdf/
76
- float fl = schlickFresnel( wi.z, 0.0 );
77
- float fv = schlickFresnel( wo.z, 0.0 );
78
-
79
- float metalFactor = ( 1.0 - surf.metalness );
80
- float transFactor = ( 1.0 - surf.transmission );
81
- float rr = 0.5 + 2.0 * surf.roughness * fl * fl;
82
- float retro = rr * ( fl + fv + fl * fv * ( rr - 1.0f ) );
83
- float lambert = ( 1.0f - 0.5f * fl ) * ( 1.0f - 0.5f * fv );
84
-
85
- // TODO: subsurface approx?
86
-
87
- float FM = disneyFresnel( surf, wo, wi, wh );
88
-
89
- color = ( 1.0 - FM ) * transFactor * metalFactor * wi.z * surf.color * ( retro + lambert ) / PI;
90
- return wi.z / PI;
91
-
92
- }
93
-
94
- vec3 diffuseDirection( vec3 wo, SurfaceRec surf ) {
95
-
96
- vec3 lightDirection = sampleSphere( sobol2( 11 ) );
97
- lightDirection.z += 1.0;
98
- lightDirection = normalize( lightDirection );
99
-
100
- return lightDirection;
101
-
102
- }
103
-
104
- // specular
105
- float specularEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRec surf, out vec3 color ) {
106
-
107
- // if roughness is set to 0 then D === NaN which results in black pixels
108
- float metalness = surf.metalness;
109
- float filteredRoughness = surf.filteredRoughness;
110
-
111
- float eta = surf.eta;
112
- float f0 = surf.f0;
113
- float G = ggxShadowMaskG2( wi, wo, filteredRoughness );
114
- float D = ggxDistribution( wh, filteredRoughness );
115
- float FM = disneyFresnel( surf, wo, wi, wh );
116
- float cosTheta = min( wo.z, 1.0 );
117
- float sinTheta = sqrt( 1.0 - cosTheta * cosTheta );
118
- bool cannotRefract = eta * sinTheta > 1.0;
119
- if ( cannotRefract ) {
120
-
121
- FM = 1.0;
122
-
123
- }
124
-
125
- vec3 metalColor = surf.color;
126
- vec3 dielectricColor = f0 * surf.specularColor;
127
- vec3 specColor = mix( dielectricColor, metalColor, surf.metalness );
128
-
129
- vec3 iridescenceF = evalIridescence( 1.0, surf.iridescenceIor, dot( wi, wh ), surf.iridescenceThickness, vec3( f0 ) );
130
- vec3 iridescenceMix = mix( vec3( FM ), iridescenceF, surf.iridescence );
131
- vec3 F = mix( specColor, vec3( 1.0 ), iridescenceMix );
132
-
133
- color = mix( surf.specularIntensity, 1.0, surf.metalness ) * wi.z * F * G * D / ( 4.0 * abs( wi.z * wo.z ) );
134
-
135
- // PDF
136
- // See 14.1.1 Microfacet BxDFs in https://www.pbr-book.org/
137
- float incidentTheta = acos( wo.z );
138
- float G1 = ggxShadowMaskG1( incidentTheta, filteredRoughness );
139
- float ggxPdf = D * G1 * max( 0.0, abs( dot( wo, wh ) ) ) / abs ( wo.z );
140
- return ggxPdf / ( 4.0 * dot( wo, wh ) );
141
-
142
- }
143
-
144
- vec3 specularDirection( vec3 wo, SurfaceRec surf ) {
145
-
146
- // sample ggx vndf distribution which gives a new normal
147
- float filteredRoughness = surf.filteredRoughness;
148
- vec3 halfVector = ggxDirection(
149
- wo,
150
- vec2( filteredRoughness ),
151
- sobol2( 12 )
152
- );
153
-
154
- // apply to new ray by reflecting off the new normal
155
- return - reflect( wo, halfVector );
156
-
157
- }
158
-
159
-
160
- // transmission
161
- /*
162
- float transmissionEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRec surf, out vec3 color ) {
163
-
164
- // See section 4.2 in https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf
165
-
166
- float filteredRoughness = surf.filteredRoughness;
167
- float eta = surf.eta;
168
- bool frontFace = surf.frontFace;
169
- bool thinFilm = surf.thinFilm;
170
-
171
- vec3 col = thinFilm || frontFace ? surf.color : vec3( 1.0 );
172
- color = surf.transmission * col;
173
-
174
- float denom = pow( eta * dot( wi, wh ) + dot( wo, wh ), 2.0 );
175
- return ggxPDF( wo, wh, filteredRoughness ) / denom;
176
-
177
- }
178
-
179
- vec3 transmissionDirection( vec3 wo, SurfaceRec surf ) {
180
-
181
- float filteredRoughness = surf.filteredRoughness;
182
- float eta = surf.eta;
183
- bool frontFace = surf.frontFace;
184
-
185
- // sample ggx vndf distribution which gives a new normal
186
- vec3 halfVector = ggxDirection(
187
- wo,
188
- vec2( filteredRoughness ),
189
- sobol2( 13 )
190
- );
191
-
192
-
193
- // TODO: support thin film
194
- vec3 lightDirection = refract( normalize( - wo ), halfVector, eta );
195
- return normalize( lightDirection );
196
-
197
- }
198
- */
199
-
200
- // TODO: This is just using a basic cosine-weighted specular distribution with an
201
- // incorrect PDF value at the moment. Update it to correctly use a GGX distribution
202
- float transmissionEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRec surf, out vec3 color ) {
203
-
204
- // only attenuate the color if it's on the way in
205
- vec3 col = surf.thinFilm || surf.frontFace ? surf.color : vec3( 1.0 );
206
- color = surf.transmission * col;
207
-
208
- // PDF
209
- float eta = surf.eta;
210
- float f0 = surf.f0;
211
- float cosTheta = min( wo.z, 1.0 );
212
- float sinTheta = sqrt( 1.0 - cosTheta * cosTheta );
213
- float reflectance = schlickFresnel( cosTheta, f0 );
214
- bool cannotRefract = eta * sinTheta > 1.0;
215
- if ( cannotRefract ) {
216
-
217
- return 0.0;
218
-
219
- }
220
-
221
- return 1.0 / ( 1.0 - reflectance );
222
-
223
- }
224
-
225
- vec3 transmissionDirection( vec3 wo, SurfaceRec surf ) {
226
-
227
- float roughness = surf.roughness;
228
- float eta = surf.eta;
229
- vec3 halfVector = normalize( vec3( 0.0, 0.0, 1.0 ) + sampleSphere( sobol2( 13 ) ) * roughness );
230
- vec3 lightDirection = refract( normalize( - wo ), halfVector, eta );
231
-
232
- if ( surf.thinFilm ) {
233
-
234
- lightDirection = - refract( normalize( - lightDirection ), - vec3( 0.0, 0.0, 1.0 ), 1.0 / eta );
235
-
236
- }
237
- return normalize( lightDirection );
238
-
239
- }
240
-
241
- // clearcoat
242
- float clearcoatEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRec surf, inout vec3 color ) {
243
-
244
- float ior = 1.5;
245
- float f0 = iorRatioToF0( ior );
246
- bool frontFace = surf.frontFace;
247
- float filteredClearcoatRoughness = surf.filteredClearcoatRoughness;
248
-
249
- float eta = frontFace ? 1.0 / ior : ior;
250
- float G = ggxShadowMaskG2( wi, wo, filteredClearcoatRoughness );
251
- float D = ggxDistribution( wh, filteredClearcoatRoughness );
252
- float F = schlickFresnel( dot( wi, wh ), f0 );
253
- float cosTheta = min( wo.z, 1.0 );
254
- float sinTheta = sqrt( 1.0 - cosTheta * cosTheta );
255
- bool cannotRefract = eta * sinTheta > 1.0;
256
- if ( cannotRefract ) {
257
-
258
- F = 1.0;
259
-
260
- }
261
-
262
- float fClearcoat = F * D * G / ( 4.0 * abs( wi.z * wo.z ) );
263
- color = color * ( 1.0 - surf.clearcoat * F ) + fClearcoat * surf.clearcoat * wi.z;
264
-
265
- // PDF
266
- // See equation (27) in http://jcgt.org/published/0003/02/03/
267
- return ggxPDF( wo, wh, filteredClearcoatRoughness ) / ( 4.0 * dot( wi, wh ) );
268
-
269
- }
270
-
271
- vec3 clearcoatDirection( vec3 wo, SurfaceRec surf ) {
272
-
273
- // sample ggx vndf distribution which gives a new normal
274
- float filteredClearcoatRoughness = surf.filteredClearcoatRoughness;
275
- vec3 halfVector = ggxDirection(
276
- wo,
277
- vec2( filteredClearcoatRoughness ),
278
- sobol2( 14 )
279
- );
280
-
281
- // apply to new ray by reflecting off the new normal
282
- return - reflect( wo, halfVector );
283
-
284
- }
285
-
286
- // sheen
287
- vec3 sheenColor( vec3 wo, vec3 wi, vec3 wh, SurfaceRec surf ) {
288
-
289
- float cosThetaO = saturateCos( wo.z );
290
- float cosThetaI = saturateCos( wi.z );
291
- float cosThetaH = wh.z;
292
-
293
- float D = velvetD( cosThetaH, surf.sheenRoughness );
294
- float G = velvetG( cosThetaO, cosThetaI, surf.sheenRoughness );
295
-
296
- // See equation (1) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
297
- vec3 color = surf.sheenColor;
298
- color *= D * G / ( 4.0 * abs( cosThetaO * cosThetaI ) );
299
- color *= wi.z;
300
-
301
- return color;
302
-
303
- }
304
-
305
- // bsdf
306
- void getLobeWeights(
307
- vec3 wo, vec3 wi, vec3 wh, vec3 clearcoatWo, SurfaceRec surf,
308
- out float diffuseWeight, out float specularWeight, out float transmissionWeight, out float clearcoatWeight
309
- ) {
310
-
311
- float metalness = surf.metalness;
312
- float transmission = surf.transmission;
313
-
314
- float eta = surf.eta;
315
- float f0 = surf.f0;
316
- float cosTheta = min( wo.z, 1.0 );
317
- float sinTheta = sqrt( 1.0 - cosTheta * cosTheta );
318
-
319
- // TODO: does "cannot refract" belong in disney fresnel?
320
- float reflectance = disneyFresnel( surf, wo, wi, wh );
321
- bool cannotRefract = eta * sinTheta > 1.0;
322
- if ( cannotRefract ) {
323
-
324
- reflectance = 1.0;
325
-
326
- }
327
-
328
- float transSpecularProb = mix( max( 0.25, reflectance ), 1.0, metalness );
329
- float diffSpecularProb = 0.5 + 0.5 * metalness;
330
-
331
- diffuseWeight = ( 1.0 - transmission ) * ( 1.0 - diffSpecularProb );
332
- specularWeight = transmission * transSpecularProb + ( 1.0 - transmission ) * diffSpecularProb;
333
- transmissionWeight = transmission * ( 1.0 - transSpecularProb );
334
- clearcoatWeight = surf.clearcoat * schlickFresnel( clearcoatWo.z, 0.04 );
335
-
336
- float totalWeight = diffuseWeight + specularWeight + transmissionWeight + clearcoatWeight;
337
- diffuseWeight /= totalWeight;
338
- specularWeight /= totalWeight;
339
- transmissionWeight /= totalWeight;
340
- clearcoatWeight /= totalWeight;
341
- }
342
-
343
- float bsdfEval(
344
- vec3 wo, vec3 clearcoatWo, vec3 wi, vec3 clearcoatWi, SurfaceRec surf,
345
- float diffuseWeight, float specularWeight, float transmissionWeight, float clearcoatWeight, out float specularPdf, out vec3 color
346
- ) {
347
-
348
- float metalness = surf.metalness;
349
- float transmission = surf.transmission;
350
-
351
- float eta = surf.eta;
352
- float f0 = surf.f0;
353
- float cosTheta = min( wo.z, 1.0 );
354
- float sinTheta = sqrt( 1.0 - cosTheta * cosTheta );
355
- float reflectance = schlickFresnel( cosTheta, f0 );
356
- bool cannotRefract = eta * sinTheta > 1.0;
357
- if ( cannotRefract ) {
358
-
359
- reflectance = 1.0;
360
-
361
- }
362
-
363
- float spdf = 0.0;
364
- float dpdf = 0.0;
365
- float tpdf = 0.0;
366
- float cpdf = 0.0;
367
- color = vec3( 0.0 );
368
-
369
- vec3 halfVector = getHalfVector( wi, wo, surf.eta );
370
-
371
- // diffuse
372
- if ( diffuseWeight > 0.0 && wi.z > 0.0 ) {
373
-
374
- dpdf = diffuseEval( wo, wi, halfVector, surf, color );
375
- color *= 1.0 - surf.transmission;
376
-
377
- }
378
-
379
- // ggx specular
380
- if ( specularWeight > 0.0 && wi.z > 0.0 ) {
381
-
382
- vec3 outColor;
383
- spdf = specularEval( wo, wi, getHalfVector( wi, wo ), surf, outColor );
384
- color += outColor;
385
-
386
- }
387
-
388
- // transmission
389
- if ( transmissionWeight > 0.0 && wi.z < 0.0 ) {
390
-
391
- tpdf = transmissionEval( wo, wi, halfVector, surf, color );
392
-
393
- }
394
-
395
- // sheen
396
- color *= sheenAlbedoScaling( wo, wi, surf );
397
- color += sheenColor( wo, wi, halfVector, surf );
398
-
399
- // clearcoat
400
- if ( clearcoatWi.z >= 0.0 && clearcoatWeight > 0.0 ) {
401
-
402
- vec3 clearcoatHalfVector = getHalfVector( clearcoatWo, clearcoatWi );
403
- cpdf = clearcoatEval( clearcoatWo, clearcoatWi, clearcoatHalfVector, surf, color );
404
-
405
- }
406
-
407
- float pdf =
408
- dpdf * diffuseWeight
409
- + spdf * specularWeight
410
- + tpdf * transmissionWeight
411
- + cpdf * clearcoatWeight;
412
-
413
- // retrieve specular rays for the shadows flag
414
- specularPdf = spdf * specularWeight + cpdf * clearcoatWeight;
415
-
416
- return pdf;
417
-
418
- }
419
-
420
- float bsdfResult( vec3 wo, vec3 clearcoatWo, vec3 wi, vec3 clearcoatWi, SurfaceRec surf, out vec3 color ) {
421
-
422
- vec3 wh = getHalfVector( wo, wi, surf.eta );
423
- float diffuseWeight;
424
- float specularWeight;
425
- float transmissionWeight;
426
- float clearcoatWeight;
427
- getLobeWeights( wo, wi, wh, clearcoatWo, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight );
428
-
429
- float specularPdf;
430
- return bsdfEval( wo, clearcoatWo, wi, clearcoatWi, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight, specularPdf, color );
431
-
432
- }
433
-
434
- SampleRec bsdfSample( vec3 wo, vec3 clearcoatWo, mat3 normalBasis, mat3 invBasis, mat3 clearcoatNormalBasis, mat3 clearcoatInvBasis, SurfaceRec surf ) {
435
-
436
- float diffuseWeight;
437
- float specularWeight;
438
- float transmissionWeight;
439
- float clearcoatWeight;
440
- // using normal and basically-reflected ray since we don't have proper half vector here
441
- getLobeWeights( wo, wo, vec3( 0, 0, 1 ), clearcoatWo, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight );
442
-
443
- float pdf[4];
444
- pdf[0] = diffuseWeight;
445
- pdf[1] = specularWeight;
446
- pdf[2] = transmissionWeight;
447
- pdf[3] = clearcoatWeight;
448
-
449
- float cdf[4];
450
- cdf[0] = pdf[0];
451
- cdf[1] = pdf[1] + cdf[0];
452
- cdf[2] = pdf[2] + cdf[1];
453
- cdf[3] = pdf[3] + cdf[2];
454
-
455
- if( cdf[3] != 0.0 ) {
456
-
457
- float invMaxCdf = 1.0 / cdf[3];
458
- cdf[0] *= invMaxCdf;
459
- cdf[1] *= invMaxCdf;
460
- cdf[2] *= invMaxCdf;
461
- cdf[3] *= invMaxCdf;
462
-
463
- } else {
464
-
465
- cdf[0] = 1.0;
466
- cdf[1] = 0.0;
467
- cdf[2] = 0.0;
468
- cdf[3] = 0.0;
469
-
470
- }
471
-
472
- vec3 wi;
473
- vec3 clearcoatWi;
474
-
475
- float r = sobol( 15 );
476
- if ( r <= cdf[0] ) { // diffuse
477
-
478
- wi = diffuseDirection( wo, surf );
479
- clearcoatWi = normalize( clearcoatInvBasis * normalize( normalBasis * wi ) );
480
-
481
- } else if ( r <= cdf[1] ) { // specular
482
-
483
- wi = specularDirection( wo, surf );
484
- clearcoatWi = normalize( clearcoatInvBasis * normalize( normalBasis * wi ) );
485
-
486
- } else if ( r <= cdf[2] ) { // transmission / refraction
487
-
488
- wi = transmissionDirection( wo, surf );
489
- clearcoatWi = normalize( clearcoatInvBasis * normalize( normalBasis * wi ) );
490
-
491
- } else if ( r <= cdf[3] ) { // clearcoat
492
-
493
- clearcoatWi = clearcoatDirection( clearcoatWo, surf );
494
- wi = normalize( invBasis * normalize( clearcoatNormalBasis * clearcoatWi ) );
495
-
496
- }
497
-
498
- SampleRec result;
499
- result.pdf = bsdfEval( wo, clearcoatWo, wi, clearcoatWi, surf, diffuseWeight, specularWeight, transmissionWeight, clearcoatWeight, result.specularPdf, result.color );
500
- result.direction = wi;
501
- result.clearcoatDirection = clearcoatWi;
502
-
503
- return result;
504
-
505
- }
506
- `;
@@ -1,98 +0,0 @@
1
- export const shaderSheenFunctions = /* glsl */`
2
-
3
- // See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
4
- float velvetD( float cosThetaH, float roughness ) {
5
-
6
- float alpha = max( roughness, 0.07 );
7
- alpha = alpha * alpha;
8
-
9
- float invAlpha = 1.0 / alpha;
10
-
11
- float sqrCosThetaH = cosThetaH * cosThetaH;
12
- float sinThetaH = max( 1.0 - sqrCosThetaH, 0.001 );
13
-
14
- return ( 2.0 + invAlpha ) * pow( sinThetaH, 0.5 * invAlpha ) / ( 2.0 * PI );
15
-
16
- }
17
-
18
- float velvetParamsInterpolate( int i, float oneMinusAlphaSquared ) {
19
-
20
- const float p0[5] = float[5]( 25.3245, 3.32435, 0.16801, -1.27393, -4.85967 );
21
- const float p1[5] = float[5]( 21.5473, 3.82987, 0.19823, -1.97760, -4.32054 );
22
-
23
- return mix( p1[i], p0[i], oneMinusAlphaSquared );
24
-
25
- }
26
-
27
- float velvetL( float x, float alpha ) {
28
-
29
- float oneMinusAlpha = 1.0 - alpha;
30
- float oneMinusAlphaSquared = oneMinusAlpha * oneMinusAlpha;
31
-
32
- float a = velvetParamsInterpolate( 0, oneMinusAlphaSquared );
33
- float b = velvetParamsInterpolate( 1, oneMinusAlphaSquared );
34
- float c = velvetParamsInterpolate( 2, oneMinusAlphaSquared );
35
- float d = velvetParamsInterpolate( 3, oneMinusAlphaSquared );
36
- float e = velvetParamsInterpolate( 4, oneMinusAlphaSquared );
37
-
38
- return a / ( 1.0 + b * pow( abs( x ), c ) ) + d * x + e;
39
-
40
- }
41
-
42
- // See equation (3) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
43
- float velvetLambda( float cosTheta, float alpha ) {
44
-
45
- return abs( cosTheta ) < 0.5 ? exp( velvetL( cosTheta, alpha ) ) : exp( 2.0 * velvetL( 0.5, alpha ) - velvetL( 1.0 - cosTheta, alpha ) );
46
-
47
- }
48
-
49
- // See Section 3, Shadowing Term, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
50
- float velvetG( float cosThetaO, float cosThetaI, float roughness ) {
51
-
52
- float alpha = max( roughness, 0.07 );
53
- alpha = alpha * alpha;
54
-
55
- return 1.0 / ( 1.0 + velvetLambda( cosThetaO, alpha ) + velvetLambda( cosThetaI, alpha ) );
56
-
57
- }
58
-
59
- float directionalAlbedoSheen( float cosTheta, float alpha ) {
60
-
61
- cosTheta = saturate( cosTheta );
62
-
63
- float c = 1.0 - cosTheta;
64
- float c3 = c * c * c;
65
-
66
- return 0.65584461 * c3 + 1.0 / ( 4.16526551 + exp( -7.97291361 * sqrt( alpha ) + 6.33516894 ) );
67
-
68
- }
69
-
70
- float sheenAlbedoScaling( vec3 wo, vec3 wi, SurfaceRec surf ) {
71
-
72
- float alpha = max( surf.sheenRoughness, 0.07 );
73
- alpha = alpha * alpha;
74
-
75
- float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b );
76
-
77
- float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha );
78
- float eWi = directionalAlbedoSheen( saturateCos( wi.z ), alpha );
79
-
80
- return min( 1.0 - maxSheenColor * eWo, 1.0 - maxSheenColor * eWi );
81
-
82
- }
83
-
84
- // See Section 5, Layering, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
85
- float sheenAlbedoScaling( vec3 wo, SurfaceRec surf ) {
86
-
87
- float alpha = max( surf.sheenRoughness, 0.07 );
88
- alpha = alpha * alpha;
89
-
90
- float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b );
91
-
92
- float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha );
93
-
94
- return 1.0 - maxSheenColor * eWo;
95
-
96
- }
97
-
98
- `;