@@ -668,14 +668,14 @@ void instr_eval_and_pdf_execute(in instr_t instr, in MC_precomputed_t precomp, i
668
668
pdf = irr_glsl_smith_VNDF_pdf_wo_clamps(ndf_val, G1_over_2NdotV);
669
669
float remainder_scalar_part = G2_over_G1;
670
670
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);
672
672
vec3 fr;
673
673
#ifdef OP_CONDUCTOR
674
674
if (op == OP_CONDUCTOR)
675
675
fr = irr_glsl_fresnel_conductor(ior[0 ], ior[1 ], VdotH);
676
676
else
677
677
#endif
678
- fr = irr_glsl_fresnel_dielectric_common(ior2[ 0 ] , VdotH);
678
+ fr = vec3 ( irr_glsl_fresnel_dielectric_common(eta * eta , VdotH) );
679
679
680
680
float eval_scalar_part = remainder_scalar_part * pdf;
681
681
@@ -860,8 +860,8 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
860
860
const float NdotV = irr_glsl_conditionalAbsOrMax(is_bsdf, currInteraction.inner.isotropic.NdotV, 0.0 );
861
861
const bool positiveNdotV = (NdotV > FLT_MIN);
862
862
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 );
865
865
uint ndf = instr_getNDF(instr);
866
866
irr_glsl_LightSample s;
867
867
@@ -910,13 +910,15 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
910
910
out_microfacet.inner = irr_glsl_calcAnisotropicMicrofacetCache(currInteraction.inner, s);
911
911
finalizeMicrofacet(out_microfacet);
912
912
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);
914
914
localPdf *= is_bsdf ? 0.5 : 1.0 ;
915
915
} else
916
916
#endif
917
917
#if defined(OP_CONDUCTOR) || defined(OP_DIELECTRIC)
918
918
if (op_hasSpecular(op))
919
919
{
920
+ localPdf = 1.0 ;
921
+
920
922
const float TdotV2 = currInteraction.inner.TdotV * currInteraction.inner.TdotV;
921
923
const float BdotV2 = currInteraction.inner.BdotV * currInteraction.inner.BdotV;
922
924
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
959
961
const float VdotH_clamp = is_bsdf ? VdotH : max (VdotH, 0.0 );
960
962
vec3 fr;
961
963
bool refraction = false;
964
+ float eta = colorToScalar(ior[0 ]);
965
+ float rcpEta = 1.0 / eta;
962
966
#ifdef OP_CONDUCTOR
963
967
if (op == OP_CONDUCTOR)
964
968
{
965
969
fr = irr_glsl_fresnel_conductor(ior[0 ], ior[1 ], VdotH_clamp);
966
- rem * = fr;
970
+ rem = fr;
967
971
}
968
972
else
969
973
#endif
970
974
{
971
- fr = irr_glsl_fresnel_dielectric_common(ior2[ 0 ] , VdotH_clamp);
975
+ fr = vec3 ( irr_glsl_fresnel_dielectric_common(eta * eta , VdotH_clamp) );
972
976
973
977
const float refractionProb = colorToScalar(fr);
974
978
float rcpChoiceProb;
975
979
refraction = irr_glsl_partitionRandVariable(refractionProb, u.z, rcpChoiceProb);
976
980
localPdf /= rcpChoiceProb;
981
+ rem = vec3 (1.0 );
977
982
}
978
- float eta = colorToScalar(ior[0 ]);
979
- float rcpEta = 1.0 / eta;
980
983
981
984
out_microfacet.inner = irr_glsl_calcAnisotropicMicrofacetCache(refraction, localV, localH, localL, rcpEta, rcpEta* rcpEta);
982
985
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
1022
1025
1023
1026
const float LdotH = out_microfacet.inner.isotropic.LdotH;
1024
1027
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 ;
1027
1028
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);
1029
1031
} else
1030
1032
#endif
1031
1033
{} // empty braces for `else`
0 commit comments