@@ -142,10 +142,6 @@ float irr_glsl_ggx_pdf_wo_clamps(in float NdotH2, in float maxNdotV, in float Nd
142
142
143
143
return irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, maxNdotV);
144
144
}
145
- float irr_glsl_ggx_pdf(in irr_glsl_IsotropicViewSurfaceInteraction i, irr_glsl_IsotropicMicrofacetCache h, in float a2)
146
- {
147
- return irr_glsl_ggx_pdf_wo_clamps(h.NdotH2, max (i.NdotV, 0.0 ), i.NdotV_squared, a2);
148
- }
149
145
150
146
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)
151
147
{
@@ -154,16 +150,6 @@ float irr_glsl_ggx_pdf_wo_clamps(in float NdotH2, in float TdotH2, in float Bdot
154
150
155
151
return irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, maxNdotV);
156
152
}
157
- float irr_glsl_ggx_pdf(in irr_glsl_AnisotropicViewSurfaceInteraction i, irr_glsl_AnisotropicMicrofacetCache h, in float ax, in float ay, in float ax2, in float ay2)
158
- {
159
- float TdotH2 = h.TdotH* h.TdotH;
160
- float BdotH2 = h.BdotH* h.BdotH;
161
- float maxNdotV = max (0.0 ,i.isotropic.NdotV);
162
- float NdotV2 = i.isotropic.NdotV_squared;
163
- float TdotV2 = i.TdotV* i.TdotV;
164
- float BdotV2 = i.BdotV* i.BdotV;
165
- return irr_glsl_ggx_pdf_wo_clamps(h.isotropic.NdotH2, TdotH2, BdotH2, maxNdotV, NdotV2, TdotV2, BdotV2, ax, ay, ax2, ay2);
166
- }
167
153
168
154
169
155
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)
@@ -179,18 +165,20 @@ vec3 irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, i
179
165
180
166
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)
181
167
{
168
+ const float one_minus_a2 = 1.0 - a2;
169
+ const float ndf = irr_glsl_ggx_trowbridge_reitz(a2, _cache.NdotH2);
170
+ const float devsh_v = irr_glsl_smith_ggx_devsh_part(interaction.NdotV_squared, a2, one_minus_a2);
171
+ pdf = irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, interaction.NdotV);
172
+ vec3 rem = vec3 (0.0 );
182
173
if (_sample.NdotL> FLT_MIN && interaction.NdotV> FLT_MIN)
183
174
{
184
- const float ndf = irr_glsl_ggx_trowbridge_reitz(a2, _cache.NdotH2);
185
175
const vec3 reflectance = irr_glsl_fresnel_conductor(ior[0 ], ior[1 ], _cache.VdotH);
176
+ const float G2_over_G1 = irr_glsl_ggx_smith_G2_over_G1_devsh(_sample.NdotL, _sample.NdotL2, interaction.NdotV, devsh_v, a2, one_minus_a2);
186
177
187
- return irr_glsl_ggx_cos_remainder_and_pdf_wo_clamps(pdf, ndf, _sample.NdotL, _sample.NdotL2, interaction.NdotV, interaction.NdotV_squared, reflectance, a2);
188
- }
189
- else
190
- {
191
- pdf = irr_glsl_ggx_pdf(interaction,_cache,a2);
192
- return vec3 (0.0 );
178
+ rem = reflectance * G2_over_G1;
193
179
}
180
+
181
+ return rem;
194
182
}
195
183
196
184
@@ -210,29 +198,36 @@ vec3 irr_glsl_ggx_aniso_cos_remainder_and_pdf_wo_clamps(out float pdf, in float
210
198
211
199
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)
212
200
{
201
+ const float ax2 = ax * ax;
202
+ const float ay2 = ay * ay;
203
+
204
+ const float TdotV2 = interaction.TdotV * interaction.TdotV;
205
+ const float BdotV2 = interaction.BdotV * interaction.BdotV;
206
+ const float NdotV2 = interaction.isotropic.NdotV_squared;
207
+
208
+ const float TdotH2 = _cache.TdotH * _cache.TdotH;
209
+ const float BdotH2 = _cache.BdotH * _cache.BdotH;
210
+
211
+ const float devsh_v = irr_glsl_smith_ggx_devsh_part(TdotV2, BdotV2, NdotV2, ax2, ay2);
212
+ const float ndf = irr_glsl_ggx_aniso(TdotH2, BdotH2, _cache.isotropic.NdotH2, ax, ay, ax2, ay2);
213
+ pdf = irr_glsl_ggx_pdf_wo_clamps(ndf, devsh_v, interaction.isotropic.NdotV);
214
+ vec3 rem = vec3 (0.0 );
213
215
if (_sample.NdotL> FLT_MIN && interaction.isotropic.NdotV> FLT_MIN)
214
216
{
215
- const float TdotH2 = _cache.TdotH* _cache.TdotH;
216
- const float BdotH2 = _cache.BdotH* _cache.BdotH;
217
-
218
217
const float TdotL2 = _sample.TdotL* _sample.TdotL;
219
218
const float BdotL2 = _sample.BdotL* _sample.BdotL;
220
219
221
- const float TdotV2 = interaction.TdotV* interaction.TdotV;
222
- const float BdotV2 = interaction.BdotV* interaction.BdotV;
223
-
224
- const float ax2 = ax* ax;
225
- const float ay2 = ay* ay;
226
- const float ndf = irr_glsl_ggx_aniso(TdotH2,BdotH2,_cache.isotropic.NdotH2, ax, ay, ax2, ay2);
227
220
const vec3 reflectance = irr_glsl_fresnel_conductor(ior[0 ], ior[1 ], _cache.isotropic.VdotH);
221
+ const float G2_over_G1 = irr_glsl_ggx_smith_G2_over_G1_devsh(
222
+ _sample.NdotL, TdotL2, BdotL2, _sample.NdotL2,
223
+ interaction.isotropic.NdotV, devsh_v,
224
+ ax2, ay2
225
+ );
228
226
229
- 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);
230
- }
231
- else
232
- {
233
- pdf = irr_glsl_ggx_pdf(interaction, _cache, ax, ay, ax* ax, ay* ay);
234
- return vec3 (0.0 );
227
+ rem = reflectance * G2_over_G1;
235
228
}
229
+
230
+ return rem;
236
231
}
237
232
238
233
#endif
0 commit comments