1
1
// basic settings
2
2
#define MAX_DEPTH 8
3
- #define SAMPLES 128
3
+ #define SAMPLES 32
4
4
5
5
// firefly and variance reduction techniques
6
6
// #define KILL_DIFFUSE_SPECULAR_PATHS
@@ -158,10 +158,6 @@ float BSDFNode_getRoughness(in BSDFNode node)
158
158
{
159
159
return uintBitsToFloat(node.data[1 ].w);
160
160
}
161
- vec3 BSDFNode_getReflectance(in BSDFNode node)
162
- {
163
- return uintBitsToFloat(node.data[0 ].rgb);
164
- }
165
161
vec3 BSDFNode_getRealEta(in BSDFNode node)
166
162
{
167
163
return uintBitsToFloat(node.data[0 ].rgb);
@@ -174,6 +170,15 @@ mat2x3 BSDFNode_getEta(in BSDFNode node)
174
170
{
175
171
return mat2x3 (BSDFNode_getRealEta(node),BSDFNode_getImaginaryEta(node));
176
172
}
173
+ #include < irr/ builtin/ glsl/ bxdf/ fresnel.glsl>
174
+ vec3 BSDFNode_getReflectance(in BSDFNode node, in float VdotH)
175
+ {
176
+ const vec3 albedoOrRealIoR = uintBitsToFloat(node.data[0 ].rgb);
177
+ if (BSDFNode_isNotDiffuse(node))
178
+ return irr_glsl_fresnel_conductor(albedoOrRealIoR, BSDFNode_getImaginaryEta(node), VdotH);
179
+ else
180
+ return albedoOrRealIoR;
181
+ }
177
182
178
183
float BSDFNode_getMISWeight(in BSDFNode bsdf)
179
184
{
@@ -198,7 +203,7 @@ BSDFNode bsdfs[BSDF_COUNT] = {
198
203
{{uvec4 (floatBitsToUint(vec3 (1.02 ,1.02 ,1.3 )),CONDUCTOR_OP),floatBitsToUint(vec4 (1.0 ,1.0 ,2.0 ,0.0 ))}},
199
204
{{uvec4 (floatBitsToUint(vec3 (1.02 ,1.3 ,1.02 )),CONDUCTOR_OP),floatBitsToUint(vec4 (1.0 ,2.0 ,1.0 ,0.0 ))}},
200
205
{{uvec4 (floatBitsToUint(vec3 (1.02 ,1.3 ,1.02 )),CONDUCTOR_OP),floatBitsToUint(vec4 (1.0 ,2.0 ,1.0 ,0.15 ))}},
201
- {{uvec4 (floatBitsToUint(vec3 (1.4 ,1.45 ,1.5 )),DIELECTRIC_OP),floatBitsToUint(vec4 (0.0 ,0.0 ,0.0 ,0.0 ))}}
206
+ {{uvec4 (floatBitsToUint(vec3 (1.4 ,1.45 ,1.5 )),DIELECTRIC_OP),floatBitsToUint(vec4 (0.0 ,0.0 ,0.0 ,0.05 ))}}
202
207
};
203
208
204
209
@@ -323,91 +328,82 @@ void missProgram()
323
328
}
324
329
325
330
#include < irr/ builtin/ glsl/ bxdf/ brdf/ diffuse/ oren_nayar.glsl>
331
+ #include < irr/ builtin/ glsl/ bxdf/ brdf/ specular/ beckmann.glsl>
326
332
#include < irr/ builtin/ glsl/ bxdf/ brdf/ specular/ ggx.glsl>
327
- #include < irr/ builtin/ glsl/ bxdf/ bsdf/ specular/ dielectric.glsl>
328
- irr_glsl_BxDFSample irr_glsl_bsdf_cos_generate(in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in vec3 u, in BSDFNode bsdf, in vec3 luminosityContributionHint)
333
+ #include < irr/ builtin/ glsl/ bxdf/ bsdf/ diffuse/ lambert.glsl>
334
+ // #include <irr/builtin/glsl/bxdf/bsdf/specular/dielectric.glsl>
335
+ // #include <irr/builtin/glsl/bxdf/bsdf/specular/beckmann.glsl>
336
+ irr_glsl_LightSample irr_glsl_bsdf_cos_generate(in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in vec3 u, in BSDFNode bsdf, in float monochromeEta, out irr_glsl_AnisotropicMicrofacetCache _cache)
329
337
{
330
338
const float a = BSDFNode_getRoughness(bsdf);
331
339
const mat2x3 ior = BSDFNode_getEta(bsdf);
332
340
333
- irr_glsl_BxDFSample smpl;
341
+ irr_glsl_LightSample smpl;
342
+ irr_glsl_AnisotropicMicrofacetCache dummy;
334
343
switch (BSDFNode_getType(bsdf))
335
344
{
336
345
case DIFFUSE_OP:
337
346
smpl = irr_glsl_oren_nayar_cos_generate(interaction,u.xy,a* a);
338
347
break ;
339
348
case CONDUCTOR_OP:
340
- smpl = irr_glsl_ggx_cos_generate(interaction,u.xy,a,a);
349
+ smpl = irr_glsl_ggx_cos_generate(interaction,u.xy,a,a,_cache );
341
350
break ;
342
351
default :
343
- {
344
- const float _eta = dot (ior[0 ],luminosityContributionHint);
345
- smpl = irr_glsl_smooth_dielectric_cos_generate(interaction,u,_eta);
346
- }
352
+ smpl = irr_glsl_beckmann_cos_generate(interaction,u.xy,a,a,_cache);
353
+ // smpl = irr_glsl_beckmann_dielectric_cos_generate(interaction,u,a,a,monochromeEta,_cache);
347
354
break ;
348
355
}
349
356
return smpl;
350
357
}
351
358
352
- vec3 irr_glsl_bsdf_cos_remainder_and_pdf(out float pdf, in irr_glsl_BxDFSample _sample, in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in BSDFNode bsdf, in vec3 luminosityContributionHint )
359
+ vec3 irr_glsl_bsdf_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample _sample, in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in BSDFNode bsdf, in float monochromeEta, in irr_glsl_AnisotropicMicrofacetCache _cache )
353
360
{
354
- const vec3 reflectance = BSDFNode_getReflectance(bsdf);
355
- const float a = max (BSDFNode_getRoughness(bsdf),0.01 ); // TODO: @Crisspl 0-roughness still doesn't work! Also Beckmann has a weird dark rim instead as fresnel!?
356
- const float a2 = a* a;
357
-
358
- const mat2x3 ior = BSDFNode_getEta(bsdf);
359
-
360
- const float NdotH2 = _sample.NdotH* _sample.NdotH;
361
- const float NdotL2 = _sample.NdotL* _sample.NdotL;
362
-
363
- const float VdotL = dot (interaction.isotropic.V.dir,_sample.L);
361
+ // are V and L on opposite sides of the surface?
364
362
const bool transmitted = irr_glsl_isTransmissionPath(interaction.isotropic.NdotV,_sample.NdotL);
365
363
364
+ // is the BSDF or BRDF, if it is then we make the dot products `abs` before `max(,0.0)`
366
365
const bool transmissive = BSDFNode_isBSDF(bsdf);
367
- const float clampedNdotL = irr_glsl_conditionalAbsOrMax(transmissive,_sample.NdotL,0.0 );
368
- const float clampedNdotV = irr_glsl_conditionalAbsOrMax(transmissive,interaction.isotropic.NdotV,0.0 );
369
366
370
- float rcpOrientedEta, orientedEta2, rcpOrientedEta2;
371
- const bool viewerInsideMedium = irr_glsl_getOrientedEtas(rcpOrientedEta,orientedEta2,rcpOrientedEta2,interaction.isotropic.NdotV,dot (ior[0 ],luminosityContributionHint));
367
+ // obtain stuff for transmissive parts of BSDFs
368
+ float orientedEta, rcpOrientedEta;
369
+ const bool viewerInsideMedium = irr_glsl_getOrientedEtas(orientedEta,rcpOrientedEta,interaction.isotropic.NdotV,monochromeEta);
372
370
373
- vec3 remainder; // TODO should just return a 0.0 remainder if NdotV<FLT_MIN and BSDF is not transmissive
374
- switch (BSDFNode_getType(bsdf) )
371
+ vec3 remainder;
372
+ if (transmissive || ! transmitted )
375
373
{
376
- case DIFFUSE_OP:
377
- remainder = reflectance* irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(pdf,a* a,VdotL,clampedNdotL,clampedNdotV);
378
- break ;
379
- case CONDUCTOR_OP:
380
- remainder = irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(pdf,irr_glsl_ggx_trowbridge_reitz(a2,NdotH2),clampedNdotL,NdotL2,clampedNdotV,interaction.isotropic.NdotV_squared,_sample.VdotH,ior,a2);
381
- break ;
382
- default :
383
- remainder = vec3 (irr_glsl_smooth_dielectric_cos_remainder_and_pdf(pdf, transmitted, rcpOrientedEta2));
384
- break ;
385
- }
386
- return remainder;
387
- }
374
+ //
375
+ const mat2x3 ior = BSDFNode_getEta(bsdf);
376
+ const vec3 reflectance = BSDFNode_getReflectance(bsdf,_cache.isotropic.VdotH);
388
377
378
+ //
379
+ const float VdotL = dot (interaction.isotropic.V.dir,_sample.L);
389
380
390
- #define GeneratorSample irr_glsl_BxDFSample
391
- #define irr_glsl_LightSample irr_glsl_BxDFSample
392
- irr_glsl_LightSample irr_glsl_createLightSample(in vec3 L, in irr_glsl_AnisotropicViewSurfaceInteraction interaction)
393
- {
394
- irr_glsl_BxDFSample s;
395
- s.L = L;
381
+ // is the BSDF or BRDF, if it is then we make the dot products `abs` before `max(,0.0)`
382
+ const float clampedNdotL = irr_glsl_conditionalAbsOrMax(transmissive,_sample.NdotL,0.0 );
383
+ const float clampedNdotV = irr_glsl_conditionalAbsOrMax(transmissive,interaction.isotropic.NdotV,0.0 );
396
384
397
- s.TdotL = dot (interaction.T,L);
398
- s.BdotL = dot (interaction.B,L);
399
- s.NdotL = dot (interaction.isotropic.N,L);
400
-
401
- float VdotL = dot (interaction.isotropic.V.dir,L);
402
- float LplusV_rcpLen = inversesqrt (2.0 + 2.0 * VdotL);
385
+ //
386
+ const float a = max (BSDFNode_getRoughness(bsdf),0.01 ); // TODO: @Crisspl 0-roughness still doesn't work! Also Beckmann has a weird dark rim instead as fresnel!?
387
+ const float a2 = a* a;
403
388
404
- s.TdotH = (interaction.TdotV+ s.TdotL)* LplusV_rcpLen;
405
- s.BdotH = (interaction.BdotV+ s.BdotL)* LplusV_rcpLen;
406
- s.NdotH = (interaction.isotropic.NdotV+ s.NdotL)* LplusV_rcpLen;
407
-
408
- s.VdotH = LplusV_rcpLen+ LplusV_rcpLen* VdotL;
409
-
410
- return s;
389
+ switch (BSDFNode_getType(bsdf))
390
+ {
391
+ case DIFFUSE_OP:
392
+ remainder = reflectance* irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(pdf,a* a,VdotL,clampedNdotL,clampedNdotV);
393
+ break ;
394
+ case CONDUCTOR_OP:
395
+ remainder = irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(pdf,irr_glsl_ggx_trowbridge_reitz(a2,_cache.isotropic.NdotH2),clampedNdotL,_sample.NdotL2,clampedNdotV,interaction.isotropic.NdotV_squared,reflectance,a2);
396
+ break ;
397
+ default :
398
+ remainder = irr_glsl_beckmann_cos_remainder_and_pdf_wo_clamps(pdf,irr_glsl_beckmann(a2,_cache.isotropic.NdotH2),_sample.NdotL2,clampedNdotV,interaction.isotropic.NdotV_squared,reflectance,a2);
399
+ // remainder = vec3(irr_glsl_lambertian_transmitter_cos_remainder_and_pdf(pdf,_sample));
400
+ // remainder = vec3(irr_glsl_beckmann_dielectric_cos_remainder_and_pdf(pdf, _sample, interaction.isotropic, monochromeEta, a2));
401
+ break ;
402
+ }
403
+ }
404
+ else
405
+ remainder = vec3 (0.0 );
406
+ return remainder;
411
407
}
412
408
413
409
layout (constant_id = 0 ) const int MAX_DEPTH_LOG2 = 0 ;
0 commit comments