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
38 changes: 17 additions & 21 deletions 66_HLSLBxDFTests/app_resources/test_components.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

#include "tests_common.hlsl"

namespace nbl
{
namespace hlsl
{

template<class BxDF, bool aniso = false> // only for cook torrance bxdfs
struct TestNDF : TestBxDF<BxDF>
{
Expand Down Expand Up @@ -75,7 +70,7 @@ struct TestNDF : TestBxDF<BxDF>
}
else if (traits_t::type == bxdf::BT_BSDF)
{
if (abs<float>(s.getNdotL()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(s.getNdotL()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand All @@ -87,12 +82,13 @@ struct TestNDF : TestBxDF<BxDF>

float reflectance;
bool transmitted;
bool isNdfInfinity;
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());
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);
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_interaction, aniso_cache>(base_t::bxdf.ndf, _f, base_t::anisointer, cache);
quant_type DG1 = base_t::bxdf.ndf.template DG1<sample_t, aniso_interaction>(dq, qq, s, base_t::anisointer, isNdfInfinity);
dg1 = DG1.microfacetMeasure * hlsl::abs(cache.getVdotH() / base_t::anisointer.getNdotV());
reflectance = _f(cache.getVdotH())[0];
NdotH = cache.getAbsNdotH();
Expand All @@ -101,15 +97,18 @@ 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());
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);
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_interaction, iso_cache>(base_t::bxdf.ndf, _f, base_t::isointer, isocache);
quant_type DG1 = base_t::bxdf.ndf.template DG1<sample_t, iso_interaction>(dq, qq, s, base_t::isointer, isNdfInfinity);
dg1 = DG1.microfacetMeasure * hlsl::abs(isocache.getVdotH() / base_t::isointer.getNdotV());
reflectance = _f(isocache.getVdotH())[0];
NdotH = isocache.getAbsNdotH();
transmitted = isocache.isTransmission();
}

if (isNdfInfinity)
return BET_INVALID;

if (transmitted)
{
float eta = base_t::rc.eta.x;
Expand Down Expand Up @@ -148,7 +147,7 @@ struct TestNDF : TestBxDF<BxDF>
}
else if (traits_t::type == bxdf::BT_BSDF)
{
if (abs<float>(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand Down Expand Up @@ -181,13 +180,13 @@ struct TestNDF : TestBxDF<BxDF>

static void run(NBL_CONST_REF_ARG(STestInitParams) initparams, NBL_REF_ARG(FailureCallback) cb)
{
random::PCG32 pcg = random::PCG32::construct(initparams.state);
random::PCG32 pcg = random::PCG32::construct(initparams.halfSeed);
random::DimAdaptorRecursive<random::PCG32, 2> rand2d = random::DimAdaptorRecursive<random::PCG32, 2>::construct(pcg);
uint32_t2 state = rand2d();

this_t t;
t.init(state);
t.rc.state = initparams.state;
t.rc.halfSeed = initparams.halfSeed;
t.verbose = initparams.verbose;
t.initBxDF(t.rc);

Expand Down Expand Up @@ -322,7 +321,7 @@ struct TestCTGenerateH : TestBxDF<BxDF>
if (base_t::isointer.getNdotV() <= numeric_limits<float>::min)
return BET_INVALID;
else if (traits_t::type == bxdf::BT_BSDF)
if (abs<float>(base_t::isointer.getNdotV()) <= numeric_limits<float>::min)
if (hlsl::abs(base_t::isointer.getNdotV()) <= numeric_limits<float>::min)
return BET_INVALID;

ErrorType res = compute();
Expand All @@ -334,13 +333,13 @@ struct TestCTGenerateH : TestBxDF<BxDF>

static void run(NBL_CONST_REF_ARG(STestInitParams) initparams, NBL_REF_ARG(FailureCallback) cb)
{
random::PCG32 pcg = random::PCG32::construct(initparams.state);
random::PCG32 pcg = random::PCG32::construct(initparams.halfSeed);
random::DimAdaptorRecursive<random::PCG32, 2> rand2d = random::DimAdaptorRecursive<random::PCG32, 2>::construct(pcg);
uint32_t2 state = rand2d();

this_t t;
t.init(state);
t.rc.state = initparams.state;
t.rc.halfSeed = initparams.halfSeed;
t.numSamples = initparams.samples;
t.immediateFail = initparams.immediateFail;
t.initBxDF(t.rc);
Expand Down Expand Up @@ -376,7 +375,4 @@ struct TestCTGenerateH : TestBxDF<BxDF>
};
#endif

}
}

#endif
43 changes: 17 additions & 26 deletions 66_HLSLBxDFTests/app_resources/tests.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

#include "tests_common.hlsl"

namespace nbl
{
namespace hlsl
{

template<class BxDF, bool aniso = false>
struct TestJacobian : TestBxDF<BxDF>
{
Expand Down Expand Up @@ -69,15 +64,14 @@ struct TestJacobian : TestBxDF<BxDF>
if (!(s.isValid() && sx.isValid() && sy.isValid()))
return BET_INVALID;

// TODO: add checks with need clamp trait
if (traits_t::type == bxdf::BT_BRDF)
{
if (s.getNdotL() <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}
else if (traits_t::type == bxdf::BT_BSDF)
{
if (abs<float>(s.getNdotL()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(s.getNdotL()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand Down Expand Up @@ -115,7 +109,7 @@ struct TestJacobian : TestBxDF<BxDF>
}
else if (traits_t::type == bxdf::BT_BSDF)
{
if (abs<float>(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand Down Expand Up @@ -163,13 +157,13 @@ struct TestJacobian : TestBxDF<BxDF>

static void run(NBL_CONST_REF_ARG(STestInitParams) initparams, NBL_REF_ARG(FailureCallback) cb)
{
random::PCG32 pcg = random::PCG32::construct(initparams.state);
random::PCG32 pcg = random::PCG32::construct(initparams.halfSeed);
random::DimAdaptorRecursive<random::PCG32, 2> rand2d = random::DimAdaptorRecursive<random::PCG32, 2>::construct(pcg);
uint32_t2 state = rand2d();

this_t t;
t.init(state);
t.rc.state = initparams.state;
t.rc.halfSeed = initparams.halfSeed;
t.verbose = initparams.verbose;
t.initBxDF(t.rc);

Expand Down Expand Up @@ -245,15 +239,14 @@ struct TestReciprocity : TestBxDF<BxDF>
if (!s.isValid())
return BET_INVALID;

// TODO: add checks with need clamp trait
if (bxdf::traits<BxDF>::type == bxdf::BT_BRDF)
{
if (s.getNdotL() <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}
else if (bxdf::traits<BxDF>::type == bxdf::BT_BSDF)
{
if (abs<float>(s.getNdotL()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(s.getNdotL()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand All @@ -264,6 +257,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 Expand Up @@ -330,7 +324,7 @@ struct TestReciprocity : TestBxDF<BxDF>
}
else if (traits_t::type == bxdf::BT_BSDF)
{
if (abs<float>(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand Down Expand Up @@ -363,13 +357,13 @@ struct TestReciprocity : TestBxDF<BxDF>

static void run(NBL_CONST_REF_ARG(STestInitParams) initparams, NBL_REF_ARG(FailureCallback) cb)
{
random::PCG32 pcg = random::PCG32::construct(initparams.state);
random::PCG32 pcg = random::PCG32::construct(initparams.halfSeed);
random::DimAdaptorRecursive<random::PCG32, 2> rand2d = random::DimAdaptorRecursive<random::PCG32, 2>::construct(pcg);
uint32_t2 state = rand2d();

this_t t;
t.init(state);
t.rc.state = initparams.state;
t.rc.halfSeed = initparams.halfSeed;
t.verbose = initparams.verbose;
t.initBxDF(t.rc);

Expand Down Expand Up @@ -517,7 +511,7 @@ struct TestBucket : TestBxDF<BxDF>
}
else if (traits_t::type == bxdf::BT_BSDF)
{
if (abs<float>(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
if (hlsl::abs(base_t::isointer.getNdotV()) <= bit_cast<float>(numeric_limits<float>::min))
return BET_INVALID;
}

Expand All @@ -530,13 +524,13 @@ struct TestBucket : TestBxDF<BxDF>

static void run(NBL_CONST_REF_ARG(STestInitParams) initparams, NBL_REF_ARG(FailureCallback) cb)
{
random::PCG32 pcg = random::PCG32::construct(initparams.state);
random::PCG32 pcg = random::PCG32::construct(initparams.halfSeed);
random::DimAdaptorRecursive<random::PCG32, 2> rand2d = random::DimAdaptorRecursive<random::PCG32, 2>::construct(pcg);
uint32_t2 state = rand2d();

this_t t;
t.init(state);
t.rc.state = initparams.state;
t.rc.halfSeed = initparams.halfSeed;
t.numSamples = initparams.samples;
t.initBxDF(t.rc);

Expand Down Expand Up @@ -735,7 +729,7 @@ struct TestChi2 : TestBxDF<BxDF>

void writeToEXR()
{
std::string filename = std::format("chi2test_{}_{}.exr", base_t::rc.state, base_t::name);
std::string filename = std::format("chi2test_{}_{}.exr", base_t::rc.halfSeed, base_t::name);

int totalWidth = phiSplits;
int totalHeight = 2 * thetaSplits + 1;
Expand Down Expand Up @@ -869,7 +863,7 @@ struct TestChi2 : TestBxDF<BxDF>
cache.iso_cache.absNdotH = hlsl::abs(hlsl::dot(N, H));
cache.iso_cache.NdotH2 = cache.iso_cache.absNdotH * cache.iso_cache.absNdotH;

if (!cache.isValid(bxdf::fresnel::OrientedEtas<vector<float,1> >::create(1.f, hlsl::promote<vector<float,1> >(eta))))
if (!cache.isValid(bxdf::fresnel::OrientedEtas<hlsl::vector<float,1> >::create(1.f, hlsl::promote<hlsl::vector<float,1> >(eta))))
return 0.f;

const float32_t3 T = base_t::anisointer.getT();
Expand Down Expand Up @@ -911,7 +905,7 @@ struct TestChi2 : TestBxDF<BxDF>
if (base_t::isointer.getNdotV() <= numeric_limits<float>::min)
return BET_INVALID;
else if (traits_t::type == bxdf::BT_BSDF)
if (abs<float>(base_t::isointer.getNdotV()) <= numeric_limits<float>::min)
if (hlsl::abs(base_t::isointer.getNdotV()) <= numeric_limits<float>::min)
return BET_INVALID;

ErrorType res = compute();
Expand Down Expand Up @@ -994,13 +988,13 @@ struct TestChi2 : TestBxDF<BxDF>

static void run(NBL_CONST_REF_ARG(STestInitParams) initparams, NBL_REF_ARG(FailureCallback) cb)
{
random::PCG32 pcg = random::PCG32::construct(initparams.state);
random::PCG32 pcg = random::PCG32::construct(initparams.halfSeed);
random::DimAdaptorRecursive<random::PCG32, 2> rand2d = random::DimAdaptorRecursive<random::PCG32, 2>::construct(pcg);
uint32_t2 state = rand2d();

this_t t;
t.init(state);
t.rc.state = initparams.state;
t.rc.halfSeed = initparams.halfSeed;
t.numSamples = initparams.samples;
t.thetaSplits = initparams.thetaSplits;
t.phiSplits = initparams.phiSplits;
Expand Down Expand Up @@ -1034,7 +1028,4 @@ struct TestChi2 : TestBxDF<BxDF>
};
#endif

}
}

#endif
Loading