Skip to content

Commit c656613

Browse files
committed
yet another comments resolved
1 parent f2f3a4b commit c656613

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

include/irr/builtin/glsl/bxdf/geom/smith/common.glsl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,24 @@ float irr_glsl_smith_VNDF_pdf_wo_clamps(in float ndf, in float G1_over_2NdotV)
3030
return ndf*0.5*G1_over_2NdotV;
3131
}
3232

33-
float irr_glsl_smith_VNDF_pdf_wo_clamps(in float ndf, in float G1_over_2NdotV, in float absNdotV, in bool transmitted, in float VdotH, in float LdotH, in float VdotHLdotH, in float orientedEta, in float reflectance)
33+
float irr_glsl_smith_FVNDF_pdf_wo_clamps(in float fresnel_ndf, in float G1_over_2NdotV, in float absNdotV, in bool transmitted, in float VdotH, in float LdotH, in float VdotHLdotH, in float orientedEta)
3434
{
35-
float FNG = (transmitted ? (1.0-reflectance):reflectance)*ndf*G1_over_2NdotV;
35+
float FNG = fresnel_ndf * G1_over_2NdotV;
3636
float factor = 0.5;
3737
if (transmitted)
3838
{
39-
const float VdotH_etaLdotH = (VdotH+orientedEta*LdotH);
39+
const float VdotH_etaLdotH = (VdotH + orientedEta * LdotH);
4040
// VdotHLdotH is negative under transmission, so this factor is negative
41-
factor *= -2.0*VdotHLdotH/(VdotH_etaLdotH*VdotH_etaLdotH);
41+
factor *= -2.0 * VdotHLdotH / (VdotH_etaLdotH * VdotH_etaLdotH);
4242
}
43-
return FNG*factor;
43+
return FNG * factor;
44+
}
45+
46+
float irr_glsl_smith_VNDF_pdf_wo_clamps(in float ndf, in float G1_over_2NdotV, in float absNdotV, in bool transmitted, in float VdotH, in float LdotH, in float VdotHLdotH, in float orientedEta, in float reflectance)
47+
{
48+
float FN = (transmitted ? (1.0 - reflectance) : reflectance) * ndf;
49+
50+
return irr_glsl_smith_FVNDF_pdf_wo_clamps(FN, G1_over_2NdotV, absNdotV, transmitted, VdotH, LdotH, VdotHLdotH, orientedEta);
4451
}
4552

4653
#endif

include/irr/builtin/material_compiler/glsl/common.glsl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -668,14 +668,14 @@ void instr_eval_and_pdf_execute(in instr_t instr, in MC_precomputed_t precomp, i
668668
pdf = irr_glsl_smith_VNDF_pdf_wo_clamps(ndf_val, G1_over_2NdotV);
669669
float remainder_scalar_part = G2_over_G1;
670670

671-
const float VdotH = is_bsdf ? microfacet.inner.isotropic.VdotH : max(microfacet.inner.isotropic.VdotH, 0.0);
671+
const float VdotH = abs(microfacet.inner.isotropic.VdotH);
672672
vec3 fr;
673673
#ifdef OP_CONDUCTOR
674674
if (op == OP_CONDUCTOR)
675675
fr = irr_glsl_fresnel_conductor(ior[0], ior[1], VdotH);
676676
else
677677
#endif
678-
fr = irr_glsl_fresnel_dielectric_common(ior2[0], VdotH);
678+
fr = vec3(irr_glsl_fresnel_dielectric_common(eta*eta, VdotH));
679679

680680
float eval_scalar_part = remainder_scalar_part * pdf;
681681

@@ -860,8 +860,8 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
860860
const float NdotV = irr_glsl_conditionalAbsOrMax(is_bsdf, currInteraction.inner.isotropic.NdotV, 0.0);
861861
const bool positiveNdotV = (NdotV > FLT_MIN);
862862

863-
float localPdf = positiveNdotV ? 1.0 : 0.0;
864-
vec3 rem = positiveNdotV ? vec3(1.0) : vec3(0.0);
863+
float localPdf = 0.0;
864+
vec3 rem = vec3(0.0);
865865
uint ndf = instr_getNDF(instr);
866866
irr_glsl_LightSample s;
867867

@@ -910,13 +910,15 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
910910
out_microfacet.inner = irr_glsl_calcAnisotropicMicrofacetCache(currInteraction.inner, s);
911911
finalizeMicrofacet(out_microfacet);
912912

913-
rem *= albedo*irr_glsl_oren_nayar_cos_remainder_and_pdf(localPdf, s, currInteraction.inner.isotropic, ax2);
913+
rem = albedo*irr_glsl_oren_nayar_cos_remainder_and_pdf(localPdf, s, currInteraction.inner.isotropic, ax2);
914914
localPdf *= is_bsdf ? 0.5 : 1.0;
915915
} else
916916
#endif
917917
#if defined(OP_CONDUCTOR) || defined(OP_DIELECTRIC)
918918
if (op_hasSpecular(op))
919919
{
920+
localPdf = 1.0;
921+
920922
const float TdotV2 = currInteraction.inner.TdotV * currInteraction.inner.TdotV;
921923
const float BdotV2 = currInteraction.inner.BdotV * currInteraction.inner.BdotV;
922924
const float NdotV2 = currInteraction.inner.isotropic.NdotV_squared;
@@ -959,24 +961,25 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
959961
const float VdotH_clamp = is_bsdf ? VdotH : max(VdotH, 0.0);
960962
vec3 fr;
961963
bool refraction = false;
964+
float eta = colorToScalar(ior[0]);
965+
float rcpEta = 1.0 / eta;
962966
#ifdef OP_CONDUCTOR
963967
if (op == OP_CONDUCTOR)
964968
{
965969
fr = irr_glsl_fresnel_conductor(ior[0], ior[1], VdotH_clamp);
966-
rem *= fr;
970+
rem = fr;
967971
}
968972
else
969973
#endif
970974
{
971-
fr = irr_glsl_fresnel_dielectric_common(ior2[0], VdotH_clamp);
975+
fr = vec3(irr_glsl_fresnel_dielectric_common(eta*eta, VdotH_clamp));
972976

973977
const float refractionProb = colorToScalar(fr);
974978
float rcpChoiceProb;
975979
refraction = irr_glsl_partitionRandVariable(refractionProb, u.z, rcpChoiceProb);
976980
localPdf /= rcpChoiceProb;
981+
rem = vec3(1.0);
977982
}
978-
float eta = colorToScalar(ior[0]);
979-
float rcpEta = 1.0/eta;
980983

981984
out_microfacet.inner = irr_glsl_calcAnisotropicMicrofacetCache(refraction, localV, localH, localL, rcpEta, rcpEta*rcpEta);
982985
s = irr_glsl_createLightSampleTangentSpace(localV, localL, tangentFrame);
@@ -1022,10 +1025,9 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
10221025

10231026
const float LdotH = out_microfacet.inner.isotropic.LdotH;
10241027
const float VdotHLdotH = VdotH * LdotH;
1025-
// a trick, pdf was already multiplied by transmission/reflection choice probability above
1026-
const float reflectance = refraction ? 0.0 : 1.0;
10271028
rem *= G2_over_G1;
1028-
localPdf *= irr_glsl_smith_VNDF_pdf_wo_clamps(ndf_val, G1_over_2NdotV, NdotV, refraction, VdotH, LdotH, VdotHLdotH, eta, reflectance);
1029+
// note: at this point localPdf is already multiplied by transmission/reflection choice probability
1030+
localPdf *= irr_glsl_smith_FVNDF_pdf_wo_clamps(ndf_val, G1_over_2NdotV, NdotV, refraction, VdotH, LdotH, VdotHLdotH, eta);
10291031
} else
10301032
#endif
10311033
{} //empty braces for `else`

0 commit comments

Comments
 (0)