@@ -867,7 +867,7 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
867
867
const bool is_bsdf = ! op_isBRDF(op) && ! is_coat;
868
868
const vec3 albedo = params_getReflectance(params);
869
869
870
- float pdf = 1.0 ;
870
+ float localPdf = 1.0 ;
871
871
vec3 rem = vec3 (1.0 );
872
872
uint ndf = instr_getNDF(instr);
873
873
irr_glsl_LightSample s;
@@ -881,7 +881,7 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
881
881
s = irr_glsl_createLightSample(- precomp.V, - 1.0 , currInteraction.T, currInteraction.B, currInteraction.isotropic.N);
882
882
out_microfacet = irr_glsl_calcAnisotropicMicrofacetCache(currInteraction, s);
883
883
rem = vec3 (1.0 );
884
- pdf = irr_glsl_FLT_INF;
884
+ localPdf = irr_glsl_FLT_INF;
885
885
} else
886
886
#endif
887
887
#ifdef OP_THINDIELECTRIC
@@ -890,7 +890,7 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
890
890
const vec3 luminosityContributionHint = CIE_XYZ_Luma_Y_coeffs;
891
891
s = irr_glsl_thin_smooth_dielectric_cos_generate(currInteraction, u, ior2[0 ], luminosityContributionHint);
892
892
out_microfacet = irr_glsl_calcAnisotropicMicrofacetCache(currInteraction, s);
893
- rem = irr_glsl_thin_smooth_dielectric_cos_remainder_and_pdf(pdf , s, currInteraction.isotropic, ior2[0 ], luminosityContributionHint);
893
+ rem = irr_glsl_thin_smooth_dielectric_cos_remainder_and_pdf(localPdf , s, currInteraction.isotropic, ior2[0 ], luminosityContributionHint);
894
894
} else
895
895
#endif
896
896
#if defined(OP_DIFFUSE) || defined(OP_DIFFTRANS)
@@ -908,8 +908,8 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
908
908
s = irr_glsl_createLightSampleTangentSpace(localV, localL, tangentFrame);
909
909
out_microfacet = irr_glsl_calcAnisotropicMicrofacetCache(currInteraction, s);
910
910
911
- rem *= albedo* irr_glsl_oren_nayar_cos_remainder_and_pdf(pdf , s, currInteraction.isotropic, ax2);
912
- pdf *= is_bsdf ? 0.5 : 1.0 ;
911
+ rem *= albedo* irr_glsl_oren_nayar_cos_remainder_and_pdf(localPdf , s, currInteraction.isotropic, ax2);
912
+ localPdf *= is_bsdf ? 0.5 : 1.0 ;
913
913
} else
914
914
#endif
915
915
#if defined(OP_CONDUCTOR) || defined(OP_DIELECTRIC)
@@ -953,7 +953,7 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
953
953
END_CASES
954
954
955
955
vec3 localL;
956
- float VdotH = dot (localH, localV);
956
+ const float VdotH = dot (localH, localV);
957
957
vec3 fr;
958
958
bool refraction = false;
959
959
#ifdef OP_CONDUCTOR
@@ -970,7 +970,7 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
970
970
const float refractionProb = colorToScalar(fr);
971
971
float rcpChoiceProb;
972
972
refraction = irr_glsl_partitionRandVariable(refractionProb, u.z, rcpChoiceProb);
973
- pdf /= rcpChoiceProb;
973
+ localPdf /= rcpChoiceProb;
974
974
}
975
975
float eta = colorToScalar(ior[0 ]);
976
976
float rcpEta = 1.0 / eta;
@@ -1017,14 +1017,18 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
1017
1017
{}
1018
1018
END_CASES
1019
1019
1020
+ const float LdotH = out_microfacet.isotropic.LdotH;
1021
+ const float VdotHLdotH = VdotH * LdotH;
1022
+ // a trick, pdf was already multiplied by transmission/reflection choice probability above
1023
+ const float reflectance = refraction ? 0.0 : 1.0 ;
1020
1024
rem *= G2_over_G1;
1021
- pdf *= irr_glsl_smith_VNDF_pdf_wo_clamps(ndf_val, G1_over_2NdotV);
1025
+ localPdf *= irr_glsl_smith_VNDF_pdf_wo_clamps(ndf_val, G1_over_2NdotV, NdotV, refraction, VdotH, LdotH, VdotHLdotH, eta, reflectance );
1022
1026
} else
1023
1027
#endif
1024
1028
{} // empty braces for `else`
1025
1029
1026
1030
out_remainder = rem;
1027
- out_pdf *= pdf ;
1031
+ out_pdf *= localPdf ;
1028
1032
1029
1033
return s;
1030
1034
}
0 commit comments