Skip to content

Commit b971544

Browse files
A simple example of how to port a Microfacet BRDF to BSDF/BTDF for future reference @Crisspl
1 parent 22bd816 commit b971544

File tree

3 files changed

+119
-113
lines changed

3 files changed

+119
-113
lines changed

examples_tests/42.FragmentShaderPathTracer/common.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ void missProgram()
333333
#include <irr/builtin/glsl/bxdf/bsdf/diffuse/lambert.glsl>
334334
#include <irr/builtin/glsl/bxdf/bsdf/specular/dielectric.glsl>
335335
#include <irr/builtin/glsl/bxdf/bsdf/specular/beckmann.glsl>
336+
#include <irr/builtin/glsl/bxdf/bsdf/specular/ggx.glsl>
336337
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)
337338
{
338339
const float a = BSDFNode_getRoughness(bsdf);
@@ -353,7 +354,7 @@ irr_glsl_LightSample irr_glsl_bsdf_cos_generate(in irr_glsl_AnisotropicViewSurfa
353354
smpl = irr_glsl_ggx_cos_generate(interaction,u.xy,a,a,_cache);
354355
break;
355356
default:
356-
smpl = irr_glsl_beckmann_dielectric_cos_generate(interaction,u,a,a,monochromeEta,_cache);
357+
smpl = irr_glsl_ggx_dielectric_cos_generate(interaction,u,a,a,monochromeEta,_cache);
357358
break;
358359
}
359360
return smpl;
@@ -398,7 +399,7 @@ vec3 irr_glsl_bsdf_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample
398399
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);
399400
break;
400401
default:
401-
remainder = vec3(irr_glsl_beckmann_aniso_cos_remainder_and_pdf(pdf, _sample, interaction, _cache, monochromeEta, a,a));
402+
remainder = vec3(irr_glsl_ggx_dielectric_cos_remainder_and_pdf(pdf, _sample, interaction.isotropic, _cache.isotropic, monochromeEta, a*a));
402403
break;
403404
}
404405
}

include/irr/builtin/glsl/bxdf/bsdf/specular/beckmann.glsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ float irr_glsl_beckmann_aniso_cos_remainder_and_pdf(out float pdf, in irr_glsl_L
9696
const float BdotH2 = _cache.BdotH*_cache.BdotH;
9797
const float ndf = irr_glsl_beckmann(ax,ay,ax2,ay2, TdotH2,BdotH2,_cache.isotropic.NdotH2);
9898

99-
const float NdotL2 = _sample.NdotL*_sample.NdotL;
10099
const float TdotL2 = _sample.TdotL*_sample.TdotL;
101100
const float BdotL2 = _sample.BdotL*_sample.BdotL;
102101

@@ -113,7 +112,7 @@ float irr_glsl_beckmann_aniso_cos_remainder_and_pdf(out float pdf, in irr_glsl_L
113112
const bool transmitted = VdotHLdotH<0.0;
114113

115114
const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(VdotH));
116-
return irr_glsl_beckmann_aniso_dielectric_cos_remainder_and_pdf_wo_clamps(pdf, ndf, transmitted, NdotL2,TdotL2,BdotL2, abs(interaction.isotropic.NdotV),TdotV2,BdotV2, interaction.isotropic.NdotV_squared, VdotH,_cache.isotropic.LdotH,VdotHLdotH, reflectance,orientedEta, ax2,ay2);
115+
return irr_glsl_beckmann_aniso_dielectric_cos_remainder_and_pdf_wo_clamps(pdf, ndf, transmitted, _sample.NdotL2,TdotL2,BdotL2, abs(interaction.isotropic.NdotV),TdotV2,BdotV2, interaction.isotropic.NdotV_squared, VdotH,_cache.isotropic.LdotH,VdotHLdotH, reflectance,orientedEta, ax2,ay2);
117116
}
118117

119118

include/irr/builtin/glsl/bxdf/bsdf/specular/ggx.glsl

Lines changed: 115 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,80 @@
77
#include <irr/builtin/glsl/bxdf/brdf/specular/ggx.glsl>
88

99

10-
float irr_glsl_ggx_height_correlated_aniso_cos_eval_DG_wo_clamps(in float NdotH2, in float TdotH2, in float BdotH2, in float maxNdotL, in float NdotL2, in float TdotL2, in float BdotL2, in float maxNdotV, in float NdotV2, in float TdotV2, in float BdotV2, in float ax, in float ax2, in float ay, in float ay2)
10+
float irr_glsl_ggx_height_correlated_aniso_dielectric_cos_eval_wo_clamps(
11+
in float NdotH2, in float TdotH2, in float BdotH2,
12+
in float absNdotL, in float NdotL2, in float TdotL2, in float BdotL2,
13+
in float absNdotV, in float NdotV2, in float TdotV2, in float BdotV2,
14+
in bool transmitted, in float VdotH, in float LdotH, in float VdotHLdotH,
15+
in float orientedEta, in float orientedEta2,
16+
in float ax, in float ax2, in float ay, in float ay2)
1117
{
12-
float NG = irr_glsl_ggx_aniso(TdotH2,BdotH2,NdotH2, ax, ay, ax2, ay2);
13-
if (ax>FLT_MIN || ay>FLT_MIN)
14-
{
15-
NG *= irr_glsl_ggx_smith_correlated_wo_numerator(
16-
maxNdotV, TdotV2, BdotV2, NdotV2,
17-
maxNdotL, TdotL2, BdotL2, NdotL2,
18-
ax2, ay2
19-
);
20-
}
21-
22-
return NG;
23-
}
24-
25-
vec3 irr_glsl_ggx_height_correlated_aniso_cos_eval_wo_clamps(in float NdotH2, in float TdotH2, in float BdotH2, in float maxNdotL, in float NdotL2, in float TdotL2, in float BdotL2, in float maxNdotV, in float NdotV2, in float TdotV2, in float BdotV2, in float VdotH, in mat2x3 ior, in float ax, in float ax2, in float ay, in float ay2)
26-
{
27-
float NG_already_in_reflective_dL_measure = irr_glsl_ggx_height_correlated_aniso_cos_eval_DG_wo_clamps(NdotH2,TdotH2,BdotH2,maxNdotL,NdotL2,TdotL2,BdotL2,maxNdotV,NdotV2,TdotV2,BdotV2,ax,ax2,ay,ay2);
18+
float NG_already_in_reflective_dL_measure = irr_glsl_ggx_height_correlated_aniso_cos_eval_DG_wo_clamps(NdotH2,TdotH2,BdotH2,absNdotL,NdotL2,TdotL2,BdotL2,absNdotV,NdotV2,TdotV2,BdotV2,ax,ax2,ay,ay2);
19+
20+
const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(VdotH));
2821

29-
vec3 fr = irr_glsl_fresnel_conductor(ior[0], ior[1], VdotH);
30-
return fr*irr_glsl_ggx_microfacet_to_light_measure_transform(NG_already_in_reflective_dL_measure,maxNdotL);
22+
return reflectance*irr_glsl_ggx_microfacet_to_light_measure_transform(NG_already_in_reflective_dL_measure,absNdotL,transmitted,VdotH,LdotH,VdotHLdotH,orientedEta);
3123
}
3224

33-
vec3 irr_glsl_ggx_height_correlated_aniso_cos_eval(in irr_glsl_LightSample _sample, in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in irr_glsl_AnisotropicMicrofacetCache _cache, in mat2x3 ior, in float ax, in float ay)
25+
// before calling you must ensure that `irr_glsl_AnisotropicMicrofacetCache` is valid (if a given V vector can "see" the L vector)
26+
float irr_glsl_ggx_height_correlated_aniso_dielectric_cos_eval(in irr_glsl_LightSample _sample, in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in irr_glsl_AnisotropicMicrofacetCache _cache, in float eta, in float ax, in float ay)
3427
{
35-
if (_sample.NdotL>FLT_MIN && interaction.isotropic.NdotV>FLT_MIN)
36-
{
37-
const float TdotH2 = _cache.TdotH*_cache.TdotH;
38-
const float BdotH2 = _cache.BdotH*_cache.BdotH;
39-
40-
const float TdotL2 = _sample.TdotL*_sample.TdotL;
41-
const float BdotL2 = _sample.BdotL*_sample.BdotL;
42-
43-
const float TdotV2 = interaction.TdotV*interaction.TdotV;
44-
const float BdotV2 = interaction.BdotV*interaction.BdotV;
45-
return irr_glsl_ggx_height_correlated_aniso_cos_eval_wo_clamps(_cache.isotropic.NdotH2, TdotH2, BdotH2, _sample.NdotL,_sample.NdotL2,TdotL2,BdotL2, interaction.isotropic.NdotV,interaction.isotropic.NdotV_squared,TdotV2,BdotV2, _cache.isotropic.VdotH, ior, ax,ax*ax,ay,ay*ay);
46-
}
47-
else
48-
return vec3(0.0);
49-
}
28+
const float TdotH2 = _cache.TdotH*_cache.TdotH;
29+
const float BdotH2 = _cache.BdotH*_cache.BdotH;
5030

31+
const float TdotL2 = _sample.TdotL*_sample.TdotL;
32+
const float BdotL2 = _sample.BdotL*_sample.BdotL;
5133

52-
float irr_glsl_ggx_height_correlated_cos_eval_DG_wo_clamps(in float NdotH2, in float maxNdotL, in float NdotL2, in float maxNdotV, in float NdotV2, in float a2)
53-
{
54-
float NG = irr_glsl_ggx_trowbridge_reitz(a2, NdotH2);
55-
if (a2>FLT_MIN)
56-
NG *= irr_glsl_ggx_smith_correlated_wo_numerator(maxNdotV, NdotV2, maxNdotL, NdotL2, a2);
34+
const float TdotV2 = interaction.TdotV*interaction.TdotV;
35+
const float BdotV2 = interaction.BdotV*interaction.BdotV;
5736

58-
return NG;
37+
const float VdotH = _cache.isotropic.VdotH;
38+
39+
float orientedEta, dummy;
40+
const bool backside = irr_glsl_getOrientedEtas(orientedEta, dummy, VdotH, eta);
41+
const float orientedEta2 = orientedEta*orientedEta;
42+
43+
const float VdotHLdotH = VdotH*_cache.isotropic.LdotH;
44+
const bool transmitted = VdotHLdotH<0.0;
45+
46+
return irr_glsl_ggx_height_correlated_aniso_dielectric_cos_eval_wo_clamps(
47+
_cache.isotropic.NdotH2,TdotH2,BdotH2,
48+
abs(_sample.NdotL),_sample.NdotL2,TdotL2,BdotL2,
49+
abs(interaction.isotropic.NdotV),interaction.isotropic.NdotV_squared,TdotV2,BdotV2,
50+
transmitted,VdotH,_cache.isotropic.LdotH,VdotHLdotH,orientedEta,orientedEta2,
51+
ax,ax*ax,ay,ay*ay
52+
);
5953
}
6054

61-
vec3 irr_glsl_ggx_height_correlated_cos_eval_wo_clamps(in float NdotH2, in float maxNdotL, in float NdotL2, in float maxNdotV, in float NdotV2, in float VdotH, in mat2x3 ior, in float a2)
62-
{
63-
float NG_already_in_reflective_dL_measure = irr_glsl_ggx_height_correlated_cos_eval_DG_wo_clamps(NdotH2, maxNdotL, NdotL2, maxNdotV, NdotV2, a2);
6455

65-
vec3 fr = irr_glsl_fresnel_conductor(ior[0], ior[1], VdotH);
56+
float irr_glsl_ggx_height_correlated_dielectric_cos_eval_wo_clamps(
57+
in float NdotH2, in float absNdotL, in float NdotL2,
58+
in float absNdotV, in float NdotV2,
59+
in bool transmitted, in float VdotH, in float LdotH, in float VdotHLdotH,
60+
in float orientedEta, in float orientedEta2, in float a2)
61+
{
62+
const float NG_already_in_reflective_dL_measure = irr_glsl_ggx_height_correlated_cos_eval_DG_wo_clamps(NdotH2, absNdotL, NdotL2, absNdotV, NdotV2, a2);
63+
64+
const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(VdotH));
6665

67-
return fr*irr_glsl_ggx_microfacet_to_light_measure_transform(NG_already_in_reflective_dL_measure,maxNdotL);
66+
return reflectance*irr_glsl_ggx_microfacet_to_light_measure_transform(NG_already_in_reflective_dL_measure,absNdotL,transmitted,VdotH,LdotH,VdotHLdotH,orientedEta);
6867
}
6968

70-
vec3 irr_glsl_ggx_height_correlated_cos_eval(in irr_glsl_LightSample _sample, in irr_glsl_IsotropicViewSurfaceInteraction interaction, in irr_glsl_IsotropicMicrofacetCache _cache, in mat2x3 ior, in float a2)
69+
// before calling you must ensure that `irr_glsl_AnisotropicMicrofacetCache` is valid (if a given V vector can "see" the L vector)
70+
float irr_glsl_ggx_height_correlated_dielectric_cos_eval(in irr_glsl_LightSample _sample, in irr_glsl_IsotropicViewSurfaceInteraction interaction, in irr_glsl_IsotropicMicrofacetCache _cache, in float eta, in float a2)
7171
{
72-
if (_sample.NdotL>FLT_MIN && interaction.NdotV>FLT_MIN)
73-
return irr_glsl_ggx_height_correlated_cos_eval_wo_clamps(_cache.NdotH2,max(_sample.NdotL,0.0),_sample.NdotL2, max(interaction.NdotV,0.0), interaction.NdotV_squared, _cache.VdotH,ior,a2);
74-
else
75-
return vec3(0.0);
72+
float orientedEta, dummy;
73+
const bool backside = irr_glsl_getOrientedEtas(orientedEta, dummy, _cache.VdotH, eta);
74+
const float orientedEta2 = orientedEta*orientedEta;
75+
76+
const float VdotHLdotH = _cache.VdotH*_cache.LdotH;
77+
const bool transmitted = VdotHLdotH<0.0;
78+
79+
return irr_glsl_ggx_height_correlated_dielectric_cos_eval_wo_clamps(
80+
_cache.NdotH2,abs(_sample.NdotL),_sample.NdotL2,
81+
abs(interaction.NdotV),interaction.NdotV_squared,
82+
transmitted,_cache.VdotH,_cache.LdotH,VdotHLdotH,orientedEta,orientedEta2,a2
83+
);
7684
}
7785

7886

@@ -108,98 +116,96 @@ irr_glsl_LightSample irr_glsl_ggx_dielectric_cos_generate(in irr_glsl_Anisotropi
108116
return irr_glsl_ggx_dielectric_cos_generate_wo_clamps(localV,backside,upperHemisphereV,m, u,ax,ay, rcpOrientedEta,orientedEta*orientedEta,rcpOrientedEta*rcpOrientedEta,_cache);
109117
}
110118

111-
#if 0
112-
// TODO
113-
float irr_glsl_ggx_pdf_wo_clamps(in float ndf, in float devsh_v, in float maxNdotV)
119+
120+
121+
float irr_glsl_ggx_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float ndf, in float devsh_v, in float absNdotV, in float VdotH, in float LdotH, in float VdotHLdotH, in float orientedEta)
114122
{
115-
return irr_glsl_smith_VNDF_pdf_wo_clamps(ndf,irr_glsl_GGXSmith_G1_wo_numerator(maxNdotV,devsh_v),);
123+
return irr_glsl_smith_VNDF_pdf_wo_clamps(ndf,irr_glsl_GGXSmith_G1_wo_numerator(absNdotV,devsh_v),absNdotV,transmitted,VdotH,LdotH,VdotHLdotH,orientedEta,reflectance);
116124
}
117-
float irr_glsl_ggx_pdf_wo_clamps(in float NdotH2, in float maxNdotV, in float NdotV2, in float a2)
125+
float irr_glsl_ggx_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float NdotH2, in float absNdotV, in float NdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float a2, in float orientedEta)
118126
{
119127
const float ndf = irr_glsl_ggx_trowbridge_reitz(a2, NdotH2);
120128
const float devsh_v = irr_glsl_smith_ggx_devsh_part(NdotV2, a2, 1.0-a2);
121129

122-
return irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, maxNdotV);
130+
return irr_glsl_ggx_dielectric_pdf_wo_clamps(transmitted,reflectance, ndf,devsh_v, absNdotV, VdotH,LdotH,VdotHLdotH, orientedEta);
123131
}
124132

125-
float irr_glsl_ggx_pdf_wo_clamps(in float NdotH2, in float TdotH2, in float BdotH2, in float maxNdotV, in float NdotV2, in float TdotV2, in float BdotV2, in float ax, in float ay, in float ax2, in float ay2)
133+
float irr_glsl_ggx_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float NdotH2, in float TdotH2, in float BdotH2, in float absNdotV, in float NdotV2, in float TdotV2, in float BdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float ax, in float ay, in float ax2, in float ay2, in float orientedEta)
126134
{
127135
const float ndf = irr_glsl_ggx_aniso(TdotH2,BdotH2,NdotH2, ax, ay, ax2, ay2);
128136
const float devsh_v = irr_glsl_smith_ggx_devsh_part(TdotV2, BdotV2, NdotV2, ax2, ay2);
129137

130-
return irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, maxNdotV);
138+
return irr_glsl_ggx_dielectric_pdf_wo_clamps(transmitted,reflectance, ndf,devsh_v, absNdotV, VdotH,LdotH,VdotHLdotH, orientedEta);
131139
}
132140

133141

134142

135-
vec3 irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, in float maxNdotL, in float NdotL2, in float maxNdotV, in float NdotV2, in vec3 reflectance, in float a2)
143+
float irr_glsl_ggx_dielectric_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, in bool transmitted, in float absNdotL, in float NdotL2, in float absNdotV, in float NdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float reflectance, in float orientedEta, in float a2)
136144
{
137145
const float one_minus_a2 = 1.0 - a2;
138146
const float devsh_v = irr_glsl_smith_ggx_devsh_part(NdotV2, a2, one_minus_a2);
139-
pdf = irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, maxNdotV);
140-
141-
const float G2_over_G1 = irr_glsl_ggx_smith_G2_over_G1_devsh(maxNdotL, NdotL2, maxNdotV, devsh_v, a2, one_minus_a2);
147+
pdf = irr_glsl_ggx_dielectric_pdf_wo_clamps(transmitted,reflectance, ndf,devsh_v, absNdotV, VdotH,LdotH,VdotHLdotH, orientedEta);
142148

143-
return reflectance * G2_over_G1;
149+
return irr_glsl_ggx_smith_G2_over_G1_devsh(absNdotL, NdotL2, absNdotV, devsh_v, a2, one_minus_a2);
144150
}
145151

146-
vec3 irr_glsl_ggx_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample _sample, in irr_glsl_IsotropicViewSurfaceInteraction interaction, in irr_glsl_IsotropicMicrofacetCache _cache, in mat2x3 ior, in float a2)
152+
float irr_glsl_ggx_dielectric_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample _sample, in irr_glsl_IsotropicViewSurfaceInteraction interaction, in irr_glsl_IsotropicMicrofacetCache _cache, in float eta, in float a2)
147153
{
148-
if (_sample.NdotL>FLT_MIN && interaction.NdotV>FLT_MIN)
149-
{
150-
const float ndf = irr_glsl_ggx_trowbridge_reitz(a2, _cache.NdotH2);
151-
const vec3 reflectance = irr_glsl_fresnel_conductor(ior[0], ior[1], _cache.VdotH);
152-
153-
return irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(pdf, ndf, _sample.NdotL, _sample.NdotL2, interaction.NdotV, interaction.NdotV_squared, reflectance, a2);
154-
}
155-
else
156-
{
157-
pdf = 0.0;
158-
return vec3(0.0);
159-
}
154+
const float ndf = irr_glsl_ggx_trowbridge_reitz(a2, _cache.NdotH2);
155+
156+
float orientedEta, dummy;
157+
const bool backside = irr_glsl_getOrientedEtas(orientedEta, dummy, _cache.VdotH, eta);
158+
const float orientedEta2 = orientedEta*orientedEta;
159+
160+
const float VdotHLdotH = _cache.VdotH*_cache.LdotH;
161+
const bool transmitted = VdotHLdotH<0.0;
162+
163+
const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(_cache.VdotH));
164+
165+
const float absNdotV = abs(interaction.NdotV);
166+
return irr_glsl_ggx_dielectric_cos_remainder_and_pdf_wo_clamps(pdf,ndf,transmitted, abs(_sample.NdotL),_sample.NdotL2, absNdotV,interaction.NdotV_squared, _cache.VdotH,_cache.LdotH,VdotHLdotH, reflectance,orientedEta, a2);
160167
}
161168

162169

163-
vec3 irr_glsl_ggx_aniso_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, in float maxNdotL, in float NdotL2, in float TdotL2, in float BdotL2, in float maxNdotV, in float TdotV2, in float BdotV2, in float NdotV2, in vec3 reflectance, in float ax2,in float ay2)
170+
float irr_glsl_ggx_aniso_dielectric_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, in bool transmitted, in float absNdotL, in float NdotL2, in float TdotL2, in float BdotL2, in float absNdotV, in float TdotV2, in float BdotV2, in float NdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float reflectance, in float orientedEta, in float ax2,in float ay2)
164171
{
165172
const float devsh_v = irr_glsl_smith_ggx_devsh_part(TdotV2, BdotV2, NdotV2, ax2, ay2);
166-
pdf = irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, maxNdotV);
173+
pdf = irr_glsl_ggx_dielectric_pdf_wo_clamps(transmitted,reflectance, ndf,devsh_v, absNdotV, VdotH,LdotH,VdotHLdotH, orientedEta);
167174

168-
const float G2_over_G1 = irr_glsl_ggx_smith_G2_over_G1_devsh(
169-
maxNdotL, TdotL2,BdotL2,NdotL2,
170-
maxNdotV, devsh_v,
175+
return irr_glsl_ggx_smith_G2_over_G1_devsh(
176+
absNdotL, TdotL2,BdotL2,NdotL2,
177+
absNdotV, devsh_v,
171178
ax2, ay2
172179
);
173-
174-
return reflectance * G2_over_G1;
175180
}
176181

177-
vec3 irr_glsl_ggx_aniso_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample _sample, in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in irr_glsl_AnisotropicMicrofacetCache _cache, in mat2x3 ior, in float ax, in float ay)
182+
float irr_glsl_ggx_aniso_dielectric_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample _sample, in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in irr_glsl_AnisotropicMicrofacetCache _cache, in float eta, in float ax, in float ay)
178183
{
179-
if (_sample.NdotL>FLT_MIN && interaction.isotropic.NdotV>FLT_MIN)
180-
{
181-
const float TdotH2 = _cache.TdotH*_cache.TdotH;
182-
const float BdotH2 = _cache.BdotH*_cache.BdotH;
183-
184-
const float TdotL2 = _sample.TdotL*_sample.TdotL;
185-
const float BdotL2 = _sample.BdotL*_sample.BdotL;
186-
187-
const float TdotV2 = interaction.TdotV*interaction.TdotV;
188-
const float BdotV2 = interaction.BdotV*interaction.BdotV;
189-
190-
const float ax2 = ax*ax;
191-
const float ay2 = ay*ay;
192-
const float ndf = irr_glsl_ggx_aniso(TdotH2,BdotH2,_cache.isotropic.NdotH2, ax, ay, ax2, ay2);
193-
const vec3 reflectance = irr_glsl_fresnel_conductor(ior[0], ior[1], _cache.isotropic.VdotH);
194-
195-
return irr_glsl_ggx_aniso_cos_remainder_and_pdf_wo_clamps(pdf, ndf, _sample.NdotL, _sample.NdotL2, TdotL2, BdotL2, interaction.isotropic.NdotV, TdotV2, BdotV2, interaction.isotropic.NdotV_squared, reflectance, ax2, ay2);
196-
}
197-
else
198-
{
199-
pdf = 0.0;
200-
return vec3(0.0);
201-
}
184+
const float ax2 = ax*ax;
185+
const float ay2 = ay*ay;
186+
const float TdotH2 = _cache.TdotH*_cache.TdotH;
187+
const float BdotH2 = _cache.BdotH*_cache.BdotH;
188+
const float ndf = irr_glsl_ggx_aniso(TdotH2,BdotH2,_cache.isotropic.NdotH2, ax, ay, ax2, ay2);
189+
190+
const float TdotL2 = _sample.TdotL*_sample.TdotL;
191+
const float BdotL2 = _sample.BdotL*_sample.BdotL;
192+
193+
const float TdotV2 = interaction.TdotV*interaction.TdotV;
194+
const float BdotV2 = interaction.BdotV*interaction.BdotV;
195+
196+
const float VdotH = _cache.isotropic.VdotH;
197+
198+
float orientedEta, dummy;
199+
const bool backside = irr_glsl_getOrientedEtas(orientedEta, dummy, VdotH, eta);
200+
const float orientedEta2 = orientedEta*orientedEta;
201+
202+
const float VdotHLdotH = VdotH*_cache.isotropic.LdotH;
203+
const bool transmitted = VdotHLdotH<0.0;
204+
205+
const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(VdotH));
206+
207+
const float absNdotV = abs(interaction.isotropic.NdotV);
208+
return irr_glsl_ggx_aniso_dielectric_cos_remainder_and_pdf_wo_clamps(pdf,ndf,transmitted, abs(_sample.NdotL),_sample.NdotL2,TdotL2,BdotL2, absNdotV,TdotV2,BdotV2,interaction.isotropic.NdotV_squared, VdotH,_cache.isotropic.LdotH,VdotHLdotH, reflectance,orientedEta, ax2,ay2);
202209
}
203-
#endif
204210

205211
#endif

0 commit comments

Comments
 (0)