Skip to content

Commit b0c41f7

Browse files
committed
oren nayar create changes
1 parent a0dbcc2 commit b0c41f7

File tree

3 files changed

+15
-30
lines changed

3 files changed

+15
-30
lines changed

include/nbl/builtin/hlsl/bxdf/common.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ struct SIsotropicMicrofacetCache
521521
retval.LdotH = retval.VdotH;
522522
retval.absNdotH = NdotLplusVdotL * oriented_LplusV_rcpLen;
523523
retval.NdotH2 = retval.absNdotH * retval.absNdotH;
524-
LplusV_rcpLen = oriented_LplusV_rcpLen;
524+
LplusV_rcpLen = unoriented_LplusV_rcpLen;
525525

526526
return retval;
527527
}

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,24 @@ struct SOrenNayar
3838
scalar_type VdotL;
3939
};
4040

41-
static this_t create(scalar_type A)
41+
static this_t create(NBL_CONST_REF_ARG(creation_type) params)
4242
{
4343
this_t retval;
44-
retval.A2 = A * 0.5;
44+
retval.A2 = params.A * 0.5;
4545
retval.AB = vector2_type(1.0, 0.0) + vector2_type(-0.5, 0.45) * vector2_type(retval.A2, retval.A2) / vector2_type(retval.A2 + 0.33, retval.A2 + 0.09);
4646
return retval;
4747
}
48-
static this_t create(NBL_CONST_REF_ARG(creation_type) params)
49-
{
50-
return create(params.A);
51-
}
5248

53-
scalar_type __rec_pi_factored_out_wo_clamps(scalar_type VdotL, scalar_type maxNdotL, scalar_type maxNdotV)
54-
{
55-
scalar_type C = 1.0 / max<scalar_type>(maxNdotL, maxNdotV);
56-
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - maxNdotL * maxNdotV, 0.0);
57-
return (AB.x + AB.y * cos_phi_sin_theta * C);
58-
}
5949
template<typename Query>
6050
spectral_type __eval(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
6151
{
6252
scalar_type NdotL = _sample.getNdotL(_clamp);
63-
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * __rec_pi_factored_out_wo_clamps(query.getVdotL(), NdotL, interaction.getNdotV(_clamp)));
64-
}
53+
scalar_type NdotV = interaction.getNdotV(_clamp);
54+
scalar_type C = 1.0 / max<scalar_type>(NdotL, NdotV);
6555

56+
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - NdotL * NdotV, 0.0);
57+
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * (AB.x + AB.y * cos_phi_sin_theta * C));
58+
}
6659
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
6760
{
6861
SQuery query;

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,24 @@ struct SOrenNayar
3838
scalar_type VdotL;
3939
};
4040

41-
static this_t create(scalar_type A)
41+
static this_t create(NBL_CONST_REF_ARG(creation_type) params)
4242
{
4343
this_t retval;
44-
retval.A2 = A * 0.5;
44+
retval.A2 = params.A * 0.5;
4545
retval.AB = vector2_type(1.0, 0.0) + vector2_type(-0.5, 0.45) * vector2_type(retval.A2, retval.A2) / vector2_type(retval.A2 + 0.33, retval.A2 + 0.09);
4646
return retval;
4747
}
48-
static this_t create(NBL_CONST_REF_ARG(creation_type) params)
49-
{
50-
return create(params.A);
51-
}
5248

53-
scalar_type __rec_pi_factored_out_wo_clamps(scalar_type VdotL, scalar_type maxNdotL, scalar_type maxNdotV)
54-
{
55-
scalar_type C = 1.0 / max<scalar_type>(maxNdotL, maxNdotV);
56-
57-
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - maxNdotL * maxNdotV, 0.0);
58-
return (AB.x + AB.y * cos_phi_sin_theta * C);
59-
}
6049
template<typename Query>
6150
spectral_type __eval(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
6251
{
6352
scalar_type NdotL = _sample.getNdotL(_clamp);
64-
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * 0.5 * __rec_pi_factored_out_wo_clamps(query.getVdotL(), NdotL, interaction.getNdotV(_clamp)));
65-
}
53+
scalar_type NdotV = interaction.getNdotV(_clamp);
54+
scalar_type C = 1.0 / max<scalar_type>(NdotL, NdotV);
6655

56+
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - NdotL * NdotV, 0.0);
57+
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * 0.5 * (AB.x + AB.y * cos_phi_sin_theta * C));
58+
}
6759
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
6860
{
6961
SQuery query;

0 commit comments

Comments
 (0)