Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions 66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

using namespace nbl::hlsl;

using spectral_t = vector<float, 3>;
using ray_dir_info_t = bxdf::ray_dir_info::SBasic<float>;
using iso_interaction = bxdf::surface_interactions::SIsotropic<ray_dir_info_t>;
using iso_interaction = bxdf::surface_interactions::SIsotropic<ray_dir_info_t, spectral_t>;
using aniso_interaction = bxdf::surface_interactions::SAnisotropic<iso_interaction>;
using sample_t = bxdf::SLightSample<ray_dir_info_t>;
using iso_cache = bxdf::SIsotropicMicrofacetCache<float>;
using aniso_cache = bxdf::SAnisotropicMicrofacetCache<iso_cache>;
using quotient_pdf_t = sampling::quotient_and_pdf<float32_t3, float>;
using spectral_t = vector<float, 3>;

using iso_config_t = bxdf::SConfiguration<sample_t, iso_interaction, spectral_t>;
using aniso_config_t = bxdf::SConfiguration<sample_t, aniso_interaction, spectral_t>;
Expand All @@ -32,6 +32,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
bxdf::reflection::SBeckmannAnisotropic<aniso_microfacet_config_t> beckmannAnisoBRDF;
bxdf::reflection::SGGXIsotropic<iso_microfacet_config_t> ggxIsoBRDF;
bxdf::reflection::SGGXAnisotropic<aniso_microfacet_config_t> ggxAnisoBRDF;
bxdf::reflection::SIridescent<iso_microfacet_config_t> iridBRDF;

bxdf::transmission::SLambertian<iso_config_t> lambertianBSDF;
bxdf::transmission::SOrenNayar<iso_config_t> orenNayarBSDF;
Expand All @@ -42,6 +43,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
bxdf::transmission::SBeckmannDielectricAnisotropic<aniso_microfacet_config_t> beckmannAnisoBSDF;
bxdf::transmission::SGGXDielectricIsotropic<iso_microfacet_config_t> ggxIsoBSDF;
bxdf::transmission::SGGXDielectricAnisotropic<aniso_microfacet_config_t> ggxAnisoBSDF;
// bxdf::transmission::SIridescent<iso_microfacet_config_t> iridBSDF;


// do some nonsense calculations, but call all the relevant functions
Expand Down Expand Up @@ -76,6 +78,9 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
s = ggxAnisoBRDF.generate(anisointer, u.xy, cache);
L += s.L.direction;

qp = iridBRDF.quotient_and_pdf(s, anisointer, cache);
L -= qp.quotient;

qp = ggxAnisoBRDF.quotient_and_pdf(s, anisointer, cache);
L -= qp.quotient;

Expand Down
4 changes: 2 additions & 2 deletions 66_HLSLBxDFTests/app_resources/test_components.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct TestNDF : TestBxDF<BxDF>
NBL_IF_CONSTEXPR(aniso)
{
dg1_query_type dq = base_t::bxdf.ndf.template createDG1Query<aniso_interaction, aniso_cache>(base_t::anisointer, cache);
fresnel_type _f = bxdf::impl::getOrientedFresnel<fresnel_type, base_t::bxdf_t::IsBSDF>::__call(base_t::bxdf.fresnel, base_t::anisointer.getNdotV());
fresnel_type _f = base_t::bxdf_t::getOrientedFresnel(base_t::bxdf.fresnel, base_t::anisointer.getNdotV());
quant_query_type qq = bxdf::impl::quant_query_helper<ndf_type, fresnel_type, base_t::bxdf_t::IsBSDF>::template __call<aniso_cache>(base_t::bxdf.ndf, _f, cache);
quant_type DG1 = base_t::bxdf.ndf.template DG1<sample_t, aniso_interaction>(dq, qq, s, base_t::anisointer);
dg1 = DG1.microfacetMeasure * hlsl::abs(cache.getVdotH() / base_t::anisointer.getNdotV());
Expand All @@ -101,7 +101,7 @@ struct TestNDF : TestBxDF<BxDF>
else
{
dg1_query_type dq = base_t::bxdf.ndf.template createDG1Query<iso_interaction, iso_cache>(base_t::isointer, isocache);
fresnel_type _f = bxdf::impl::getOrientedFresnel<fresnel_type, base_t::bxdf_t::IsBSDF>::__call(base_t::bxdf.fresnel, base_t::isointer.getNdotV());
fresnel_type _f = base_t::bxdf_t::getOrientedFresnel(base_t::bxdf.fresnel, base_t::isointer.getNdotV());
quant_query_type qq = bxdf::impl::quant_query_helper<ndf_type, fresnel_type, base_t::bxdf_t::IsBSDF>::template __call<iso_cache>(base_t::bxdf.ndf, _f, isocache);
quant_type DG1 = base_t::bxdf.ndf.template DG1<sample_t, iso_interaction>(dq, qq, s, base_t::isointer);
dg1 = DG1.microfacetMeasure * hlsl::abs(isocache.getVdotH() / base_t::isointer.getNdotV());
Expand Down
1 change: 1 addition & 0 deletions 66_HLSLBxDFTests/app_resources/tests.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ struct TestReciprocity : TestBxDF<BxDF>
rec_s = sample_t::createFromTangentSpace(rec_localL, anisointer.getFromTangentSpace());

rec_isointer = iso_interaction_t::create(rec_V, base_t::rc.N);
rec_isointer.luminosityContributionHint = isointer.luminosityContributionHint;
rec_anisointer = aniso_interaction_t::create(rec_isointer, base_t::rc.T, base_t::rc.B);
rec_cache = cache;
rec_cache.iso_cache.VdotH = cache.iso_cache.getLdotH();
Expand Down
80 changes: 71 additions & 9 deletions 66_HLSLBxDFTests/app_resources/tests_common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ namespace nbl
namespace hlsl
{

using spectral_t = vector<float, 3>;
using ray_dir_info_t = bxdf::ray_dir_info::SBasic<float>;
using iso_interaction = bxdf::surface_interactions::SIsotropic<ray_dir_info_t>;
using iso_interaction = bxdf::surface_interactions::SIsotropic<ray_dir_info_t, spectral_t>;
using aniso_interaction = bxdf::surface_interactions::SAnisotropic<iso_interaction>;
using sample_t = bxdf::SLightSample<ray_dir_info_t>;
using iso_cache = bxdf::SIsotropicMicrofacetCache<float>;
using aniso_cache = bxdf::SAnisotropicMicrofacetCache<iso_cache>;
using quotient_pdf_t = sampling::quotient_and_pdf<float32_t3, float>;
using spectral_t = vector<float, 3>;

using iso_config_t = bxdf::SConfiguration<sample_t, iso_interaction, spectral_t>;
using aniso_config_t = bxdf::SConfiguration<sample_t, aniso_interaction, spectral_t>;
Expand Down Expand Up @@ -81,6 +81,14 @@ bool checkEq(T a, T b, float32_t eps)
return nbl::hlsl::all<vector<bool, vector_traits<T>::Dimension> >(nbl::hlsl::max<T>(_a / _b, _b / _a) <= hlsl::promote<T>(1 + eps));
}

template<>
bool checkEq<float32_t>(float32_t a, float32_t b, float32_t eps)
{
float32_t _a = hlsl::abs(a);
float32_t _b = hlsl::abs(b);
return nbl::hlsl::max<float32_t>(_a / _b, _b / _a) <= float32_t(1 + eps);
}

template<typename T>
bool checkLt(T a, T b)
{
Expand Down Expand Up @@ -131,6 +139,9 @@ struct SBxDFTestResources
retval.alpha.y = ConvertToFloat01<uint32_t>::__call(retval.rng());
retval.eta = ConvertToFloat01<uint32_t2>::__call(rng_vec2()) * hlsl::promote<float32_t2>(1.5) + hlsl::promote<float32_t2>(1.1); // range [1.1,2.6], also only do eta = eta/1.0 (air)
retval.luma_coeff = float32_t3(0.2126, 0.7152, 0.0722); // luma coefficients for Rec. 709

retval.Dinc = ConvertToFloat01<uint32_t>::__call(retval.rng()) * 2400.0f + 100.0f;
retval.etaThinFilm = ConvertToFloat01<uint32_t>::__call(retval.rng()) * 0.5 + 1.1f; // range [1.1,1.6]
return retval;
}

Expand All @@ -147,6 +158,10 @@ struct SBxDFTestResources
float32_t2 alpha;
float32_t2 eta; // (eta, etak)
float32_t3 luma_coeff;

// thin film stuff;
float Dinc; // in nm [100, 2500]
float etaThinFilm;
};

struct STestInitParams
Expand Down Expand Up @@ -184,6 +199,7 @@ struct TestBase
rc = SBxDFTestResources::create(seed);

isointer = iso_interaction::create(rc.V, rc.N);
isointer.luminosityContributionHint = rc.luma_coeff;
anisointer = aniso_interaction::create(isointer, rc.T, rc.B);
}

Expand Down Expand Up @@ -315,6 +331,21 @@ struct TestBxDF<bxdf::reflection::SGGXAnisotropic<aniso_microfacet_config_t>> :
}
};

template<>
struct TestBxDF<bxdf::reflection::SIridescent<iso_microfacet_config_t>> : TestBxDFBase<bxdf::reflection::SIridescent<iso_microfacet_config_t>>
{
using base_t = TestBxDFBase<bxdf::reflection::SIridescent<iso_microfacet_config_t>>;

void initBxDF(SBxDFTestResources _rc)
{
base_t::bxdf.ndf = base_t::bxdf_t::ndf_type::create(_rc.alpha.x);
base_t::bxdf.fresnel = base_t::bxdf_t::fresnel_type::create(_rc.Dinc,hlsl::promote<float32_t3>(1.0),hlsl::promote<float32_t3>(_rc.etaThinFilm),hlsl::promote<float32_t3>(_rc.eta.x),hlsl::promote<float32_t3>(_rc.eta.y));
#ifndef __HLSL_VERSION
base_t::name = "Iridescent BRDF";
#endif
}
};

template<>
struct TestBxDF<bxdf::transmission::SOrenNayar<iso_config_t>> : TestBxDFBase<bxdf::transmission::SOrenNayar<iso_config_t>>
{
Expand Down Expand Up @@ -354,7 +385,6 @@ struct TestBxDF<bxdf::transmission::SThinSmoothDielectric<iso_config_t>> : TestB
{
using spectral_type = typename base_t::bxdf_t::spectral_type;
base_t::bxdf.fresnel = bxdf::fresnel::Dielectric<spectral_type>::create(bxdf::fresnel::OrientedEtas<spectral_type>::create(base_t::isointer.getNdotV(bxdf::BxDFClampMode::BCM_ABS), hlsl::promote<spectral_type>(_rc.eta.x)));
base_t::bxdf.luminosityContributionHint = _rc.luma_coeff;
#ifndef __HLSL_VERSION
base_t::name = "Thin smooth dielectric BSDF";
#endif
Expand Down Expand Up @@ -438,37 +468,58 @@ struct TestBxDF<bxdf::transmission::SGGXDielectricAnisotropic<Config>> : TestBxD
}
};

template<class Config>
struct TestBxDF<bxdf::transmission::SIridescent<Config>> : TestBxDFBase<bxdf::transmission::SIridescent<Config>>
{
using base_t = TestBxDFBase<bxdf::transmission::SIridescent<Config>>;

void initBxDF(SBxDFTestResources _rc)
{
base_t::bxdf.ndf = base_t::bxdf_t::ndf_type::create(_rc.alpha.x);
base_t::bxdf.fresnel = base_t::bxdf_t::fresnel_type::create(_rc.Dinc,hlsl::promote<float32_t3>(1.0),hlsl::promote<float32_t3>(_rc.etaThinFilm),hlsl::promote<float32_t3>(_rc.eta.x));
#ifndef __HLSL_VERSION
base_t::name = "Iridescent BSDF";
#endif
}
};


namespace reciprocity_test_impl
{
template<class RayDirInfo NBL_PRIMARY_REQUIRES(bxdf::ray_dir_info::Basic<RayDirInfo>)
template<class RayDirInfo, class Spectrum NBL_PRIMARY_REQUIRES(bxdf::ray_dir_info::Basic<RayDirInfo> && concepts::FloatingPointLikeVectorial<Spectrum>)
struct SIsotropic
{
using this_t = SIsotropic<RayDirInfo, Spectrum>;
using ray_dir_info_type = RayDirInfo;
using scalar_type = typename RayDirInfo::scalar_type;
using vector3_type = typename RayDirInfo::vector3_type;
using spectral_type = Spectrum;

// WARNING: Changed since GLSL, now arguments need to be normalized!
static SIsotropic<RayDirInfo> create(NBL_CONST_REF_ARG(RayDirInfo) normalizedV, const vector3_type normalizedN)
static this_t create(NBL_CONST_REF_ARG(RayDirInfo) normalizedV, const vector3_type normalizedN)
{
SIsotropic<RayDirInfo> retval;
this_t retval;
retval.V = normalizedV;
retval.N = normalizedN;
retval.NdotV = nbl::hlsl::dot<vector3_type>(retval.N, retval.V.getDirection());
retval.NdotV2 = retval.NdotV * retval.NdotV;
retval.luminosityContributionHint = hlsl::promote<spectral_type>(1.0);
retval.throughputWeights = hlsl::promote<spectral_type>(1.0);

return retval;
}

template<typename I NBL_FUNC_REQUIRES(bxdf::surface_interactions::Isotropic<I>)
static SIsotropic<RayDirInfo> copy(NBL_CONST_REF_ARG(I) other)
static this_t copy(NBL_CONST_REF_ARG(I) other)
{
SIsotropic<RayDirInfo> retval;
this_t retval;
retval.V = other.getV();
retval.N = other.getN();
retval.NdotV = other.getNdotV();
retval.NdotV2 = other.getNdotV2();
retval.pathOrigin = bxdf::PathOrigin::PO_SENSOR;
retval.luminosityContributionHint = other.luminosityContributionHint;
retval.throughputWeights = other.throughputWeights;
return retval;
}

Expand All @@ -481,12 +532,20 @@ struct SIsotropic
scalar_type getNdotV2() NBL_CONST_MEMBER_FUNC { return NdotV2; }

bxdf::PathOrigin getPathOrigin() NBL_CONST_MEMBER_FUNC { return pathOrigin; }
spectral_type getLuminosityContributionHint() NBL_CONST_MEMBER_FUNC { return luminosityContributionHint; }
spectral_type getPrefixThroughputWeights() NBL_CONST_MEMBER_FUNC
{
spectral_type prefixThroughputWeights = luminosityContributionHint * throughputWeights;
return prefixThroughputWeights / math::lpNorm<spectral_type,1>(prefixThroughputWeights);
}

RayDirInfo V;
vector3_type N;
scalar_type NdotV;
scalar_type NdotV2;
bxdf::PathOrigin pathOrigin;
spectral_type luminosityContributionHint;
spectral_type throughputWeights; // product of all quotients so far
};

template<class IsotropicInteraction NBL_PRIMARY_REQUIRES(bxdf::surface_interactions::Isotropic<IsotropicInteraction>)
Expand All @@ -498,6 +557,7 @@ struct SAnisotropic
using scalar_type = typename ray_dir_info_type::scalar_type;
using vector3_type = typename ray_dir_info_type::vector3_type;
using matrix3x3_type = matrix<scalar_type, 3, 3>;
using spectral_type = typename isotropic_interaction_type::spectral_type;

// WARNING: Changed since GLSL, now arguments need to be normalized!
static this_t create(
Expand Down Expand Up @@ -551,6 +611,8 @@ struct SAnisotropic
scalar_type getNdotV(bxdf::BxDFClampMode _clamp = bxdf::BxDFClampMode::BCM_NONE) NBL_CONST_MEMBER_FUNC { return isotropic.getNdotV(_clamp); }
scalar_type getNdotV2() NBL_CONST_MEMBER_FUNC { return isotropic.getNdotV2(); }
bxdf::PathOrigin getPathOrigin() NBL_CONST_MEMBER_FUNC { return isotropic.getPathOrigin(); }
spectral_type getLuminosityContributionHint() NBL_CONST_MEMBER_FUNC { return isotropic.getLuminosityContributionHint(); }
spectral_type getPrefixThroughputWeights() NBL_CONST_MEMBER_FUNC { return isotropic.getPrefixThroughputWeights(); }

vector3_type getT() NBL_CONST_MEMBER_FUNC { return T; }
vector3_type getB() NBL_CONST_MEMBER_FUNC { return B; }
Expand Down Expand Up @@ -599,7 +661,7 @@ struct CustomIsoMicrofacetConfiguration<LS,Interaction,MicrofacetCache,Spectrum
};
}

using rectest_iso_interaction = reciprocity_test_impl::SIsotropic<ray_dir_info_t>;
using rectest_iso_interaction = reciprocity_test_impl::SIsotropic<ray_dir_info_t, spectral_t>;
using rectest_aniso_interaction = reciprocity_test_impl::SAnisotropic<rectest_iso_interaction>;
using rectest_iso_microfacet_config_t = reciprocity_test_impl::CustomIsoMicrofacetConfiguration<sample_t, rectest_iso_interaction, iso_cache, spectral_t>;
using rectest_aniso_microfacet_config_t = bxdf::SMicrofacetConfiguration<sample_t, rectest_aniso_interaction, aniso_cache, spectral_t>;
Expand Down
Loading