Skip to content

Commit 7e086f4

Browse files
committed
fix more oren nayar bugs
1 parent b0c41f7 commit 7e086f4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

include/nbl/builtin/hlsl/bxdf/reflection/oren_nayar.hlsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct SOrenNayar
5353
scalar_type NdotV = interaction.getNdotV(_clamp);
5454
scalar_type C = 1.0 / max<scalar_type>(NdotL, NdotV);
5555

56-
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - NdotL * NdotV, 0.0);
56+
scalar_type cos_phi_sin_theta = max<scalar_type>(query.getVdotL() - NdotL * NdotV, 0.0);
5757
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * (AB.x + AB.y * cos_phi_sin_theta * C));
5858
}
5959
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
@@ -88,7 +88,13 @@ struct SOrenNayar
8888
quotient_pdf_type __quotient_and_pdf(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
8989
{
9090
scalar_type _pdf = pdf(_sample);
91-
scalar_type q = __rec_pi_factored_out_wo_clamps(query.getVdotL(), _sample.getNdotL(_clamp), interaction.getNdotV(_clamp));
91+
92+
scalar_type NdotL = _sample.getNdotL(_clamp);
93+
scalar_type NdotV = interaction.getNdotV(_clamp);
94+
scalar_type C = 1.0 / max<scalar_type>(NdotL, NdotV);
95+
96+
scalar_type cos_phi_sin_theta = max<scalar_type>(query.getVdotL() - NdotL * NdotV, 0.0);
97+
scalar_type q = AB.x + AB.y * cos_phi_sin_theta * C;
9298
return quotient_pdf_type::create(q, _pdf);
9399
}
94100
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)

include/nbl/builtin/hlsl/bxdf/transmission/oren_nayar.hlsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct SOrenNayar
5353
scalar_type NdotV = interaction.getNdotV(_clamp);
5454
scalar_type C = 1.0 / max<scalar_type>(NdotL, NdotV);
5555

56-
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - NdotL * NdotV, 0.0);
56+
scalar_type cos_phi_sin_theta = max<scalar_type>(query.getVdotL() - NdotL * NdotV, 0.0);
5757
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * 0.5 * (AB.x + AB.y * cos_phi_sin_theta * C));
5858
}
5959
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
@@ -87,7 +87,13 @@ struct SOrenNayar
8787
quotient_pdf_type __quotient_and_pdf(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
8888
{
8989
scalar_type _pdf = pdf(_sample);
90-
scalar_type q = __rec_pi_factored_out_wo_clamps(query.getVdotL(), _sample.getNdotL(_clamp), interaction.getNdotV(_clamp));
90+
91+
scalar_type NdotL = _sample.getNdotL(_clamp);
92+
scalar_type NdotV = interaction.getNdotV(_clamp);
93+
scalar_type C = 1.0 / max<scalar_type>(NdotL, NdotV);
94+
95+
scalar_type cos_phi_sin_theta = max<scalar_type>(query.getVdotL() - NdotL * NdotV, 0.0);
96+
scalar_type q = AB.x + AB.y * cos_phi_sin_theta * C;
9197
return quotient_pdf_type::create(q, _pdf);
9298
}
9399
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)

0 commit comments

Comments
 (0)