From ea439349dc9461f4d18eab143fe705e4cbf10c81 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Wed, 27 Aug 2025 16:29:26 +0700 Subject: [PATCH 1/8] added tests for iridescent bxdfs --- .../app_resources/test_compile.comp.hlsl | 7 ++++ 66_HLSLBxDFTests/app_resources/tests.hlsl | 35 +++++++++++++++++-- 66_HLSLBxDFTests/main.cpp | 10 +++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl index 6673a1c34..d10b8ee0b 100644 --- a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl +++ b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl @@ -31,6 +31,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID) bxdf::reflection::SBeckmannAnisotropic beckmannAnisoBRDF; bxdf::reflection::SGGXIsotropic ggxIsoBRDF; bxdf::reflection::SGGXAnisotropic ggxAnisoBRDF; + bxdf::reflection::SIridescent iridBRDF; bxdf::transmission::SLambertian lambertianBSDF; bxdf::transmission::SSmoothDielectric smoothDielectricBSDF; @@ -39,6 +40,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID) bxdf::transmission::SBeckmannDielectricAnisotropic beckmannAnisoBSDF; bxdf::transmission::SGGXDielectricIsotropic ggxIsoBSDF; bxdf::transmission::SGGXDielectricAnisotropic ggxAnisoBSDF; + bxdf::transmission::SIridescent iridBRDF; // do some nonsense calculations, but call all the relevant functions @@ -74,6 +76,11 @@ void main(uint32_t3 ID : SV_DispatchThreadID) s = ggxAnisoBRDF.generate(anisointer, u.xy, cache); L += s.L.direction; + iso_cache icache; + typename bxdf::reflection::SIridescent::query_type query6 = iridBRDF.createQuery(s, isointer); + qp = iridBRDF.quotient_and_pdf(query6, s, isointer, icache); + L -= qp.quotient; + typename bxdf::reflection::SGGXAnisotropic::query_type query1 = ggxAnisoBRDF.createQuery(s, anisointer); qp = ggxAnisoBRDF.quotient_and_pdf(query1, s, anisointer, cache); L -= qp.quotient; diff --git a/66_HLSLBxDFTests/app_resources/tests.hlsl b/66_HLSLBxDFTests/app_resources/tests.hlsl index ba388dbdb..9aa735b83 100644 --- a/66_HLSLBxDFTests/app_resources/tests.hlsl +++ b/66_HLSLBxDFTests/app_resources/tests.hlsl @@ -343,6 +343,20 @@ struct TestBxDF> : } }; +template<> +struct TestBxDF> : TestBxDFBase> +{ + using base_t = TestBxDFBase>; + + void initBxDF(SBxDFTestResources _rc) + { + base_t::bxdf = bxdf::reflection::SIridescent::create(rc.alpha.x,1600.0,hlsl::promote(1.0),hlsl::promote(1.8),hlsl::promote(rc.ior.x),hlsl::promote(rc.ior.y)); +#ifndef __HLSL_VERSION + base_t::name = "Iridescent BRDF"; +#endif + } +}; + template<> struct TestBxDF> : TestBxDFBase> { @@ -431,6 +445,21 @@ struct TestBxDF +struct TestBxDF> : TestBxDFBase> +{ + using base_t = TestBxDFBase>; + + void initBxDF(SBxDFTestResources _rc) + { + base_t::bxdf = bxdf::transmission::SIridescent::create(rc.alpha.x,1600.0,hlsl::promote(1.0),hlsl::promote(1.8),hlsl::promote(rc.ior.x)); +#ifndef __HLSL_VERSION + base_t::name = "Iridescent BSDF"; +#endif + } +}; + + template struct is_basic_brdf : bool_constant< @@ -445,7 +474,8 @@ struct is_microfacet_brdf : bool_constant< is_same>::value || is_same>::value || is_same>::value || - is_same>::value + is_same>::value || + is_same>::value > {}; template @@ -463,7 +493,8 @@ struct is_microfacet_bsdf : bool_constant< is_same>::value || is_same>::value || is_same>::value || - is_same>::value + is_same>::value || + is_same>::value > {}; template diff --git a/66_HLSLBxDFTests/main.cpp b/66_HLSLBxDFTests/main.cpp index 627b09d82..c21d52cba 100644 --- a/66_HLSLBxDFTests/main.cpp +++ b/66_HLSLBxDFTests/main.cpp @@ -66,7 +66,7 @@ struct PrintFailureCallback : FailureCallback } }; -#define FOR_EACH_BEGIN(r) std::for_each(std::execution::par_unseq, r.begin(), r.end(), [&](uint32_t i) { +#define FOR_EACH_BEGIN(r) std::for_each(std::execution::seq, r.begin(), r.end(), [&](uint32_t i) { #define FOR_EACH_END }); int main(int argc, char** argv) @@ -173,6 +173,7 @@ int main(int argc, char** argv) TestJacobian, true>::run(initparams, cb); TestJacobian, false>::run(initparams, cb); TestJacobian,true>::run(initparams, cb); + TestJacobian, false>::run(initparams, cb); TestJacobian>::run(initparams, cb); TestJacobian >::run(initparams, cb); @@ -181,6 +182,7 @@ int main(int argc, char** argv) TestJacobian, true>::run(initparams, cb); TestJacobian, false>::run(initparams, cb); TestJacobian,true>::run(initparams, cb); + TestJacobian, false>::run(initparams, cb); FOR_EACH_END @@ -197,6 +199,7 @@ int main(int argc, char** argv) TestReciprocity, true>::run(initparams, cb); TestReciprocity, false>::run(initparams, cb); TestReciprocity, true>::run(initparams, cb); + TestReciprocity, false>::run(initparams, cb); TestReciprocity>::run(initparams, cb); TestReciprocity>::run(initparams, cb); @@ -205,6 +208,7 @@ int main(int argc, char** argv) TestReciprocity, true>::run(initparams, cb); TestReciprocity, false>::run(initparams, cb); TestReciprocity, true>::run(initparams, cb); + TestReciprocity, false>::run(initparams, cb); FOR_EACH_END @@ -223,6 +227,7 @@ int main(int argc, char** argv) TestBucket, true>::run(initparams, cb); TestBucket, false>::run(initparams, cb); TestBucket, true>::run(initparams, cb); + TestBucket, false>::run(initparams, cb); TestBucket>::run(initparams, cb); //TestBucket>::run(initparams, cb); @@ -231,6 +236,7 @@ int main(int argc, char** argv) TestBucket, true>::run(initparams, cb); TestBucket, false>::run(initparams, cb); TestBucket, true>::run(initparams, cb); + TestBucket, false>::run(initparams, cb); FOR_EACH_END @@ -251,6 +257,7 @@ int main(int argc, char** argv) TestChi2, true>::run(initparams, cb); TestChi2, false>::run(initparams, cb); TestChi2, true>::run(initparams, cb); + TestChi2, false>::run(initparams, cb); TestChi2>::run(initparams, cb); //TestChi2>::run(initparams, cb); @@ -259,6 +266,7 @@ int main(int argc, char** argv) TestChi2, true>::run(initparams, cb); TestChi2, false>::run(initparams, cb); TestChi2, true>::run(initparams, cb); + TestChi2, false>::run(initparams, cb); FOR_EACH_END // test arccos angle sums From 91658e3f0737d192cafba9e073c5d67cc6eaaac6 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Thu, 28 Aug 2025 10:43:24 +0700 Subject: [PATCH 2/8] fix small typo --- 66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl index d10b8ee0b..6f48228e9 100644 --- a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl +++ b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl @@ -40,7 +40,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID) bxdf::transmission::SBeckmannDielectricAnisotropic beckmannAnisoBSDF; bxdf::transmission::SGGXDielectricIsotropic ggxIsoBSDF; bxdf::transmission::SGGXDielectricAnisotropic ggxAnisoBSDF; - bxdf::transmission::SIridescent iridBRDF; + bxdf::transmission::SIridescent iridBSDF; // do some nonsense calculations, but call all the relevant functions From 6b5f3e83ece1e279abce0efaac5cc599eaeec0bf Mon Sep 17 00:00:00 2001 From: keptsecret Date: Thu, 28 Aug 2025 15:52:54 +0700 Subject: [PATCH 3/8] forgot to set parallel execution --- 66_HLSLBxDFTests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/66_HLSLBxDFTests/main.cpp b/66_HLSLBxDFTests/main.cpp index c21d52cba..56e8e4217 100644 --- a/66_HLSLBxDFTests/main.cpp +++ b/66_HLSLBxDFTests/main.cpp @@ -66,7 +66,7 @@ struct PrintFailureCallback : FailureCallback } }; -#define FOR_EACH_BEGIN(r) std::for_each(std::execution::seq, r.begin(), r.end(), [&](uint32_t i) { +#define FOR_EACH_BEGIN(r) std::for_each(std::execution::par_unseq, r.begin(), r.end(), [&](uint32_t i) { #define FOR_EACH_END }); int main(int argc, char** argv) From 99206836d6afd6fe55735b88f4a576a0b52e10a2 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Thu, 28 Aug 2025 16:21:54 +0700 Subject: [PATCH 4/8] refactor changes to colorspace stuff --- 28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl b/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl index eaecb5d0f..07694b5cf 100644 --- a/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl +++ b/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl @@ -1,5 +1,5 @@ #include "fft_mirror_common.hlsl" -#include "nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl" +#include "nbl/builtin/hlsl/colorspace.hlsl" [[vk::binding(2, 0)]] RWTexture2DArray kernelChannels; @@ -192,7 +192,7 @@ struct PreloadedSecondAxisAccessor : MultiChannelPreloadedAccessorMirrorTradeBas if (!workgroup::SubgroupContiguousIndex()) { const vector channelWiseSums = { preloaded[0][0].real(), preloaded[1][0].real(), preloaded[2][0].real() }; - const scalar_t power = mul(vector(colorspace::scRGBtoXYZ._m10_m11_m12), channelWiseSums); + const scalar_t power = mul(vector(colorspace::scRGB::ToXYZ()._m10_m11_m12), channelWiseSums); vk::RawBufferStore(pushConstants.rowMajorBufferAddress, scalar_t(1) / power); } } From c022a23df046404efa43ff7a78e4ed080fff607a Mon Sep 17 00:00:00 2001 From: keptsecret Date: Tue, 4 Nov 2025 10:20:18 +0700 Subject: [PATCH 5/8] revert using colorspace mat --- 28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl b/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl index 07694b5cf..eaecb5d0f 100644 --- a/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl +++ b/28_FFTBloom/app_resources/kernel_fft_second_axis.hlsl @@ -1,5 +1,5 @@ #include "fft_mirror_common.hlsl" -#include "nbl/builtin/hlsl/colorspace.hlsl" +#include "nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl" [[vk::binding(2, 0)]] RWTexture2DArray kernelChannels; @@ -192,7 +192,7 @@ struct PreloadedSecondAxisAccessor : MultiChannelPreloadedAccessorMirrorTradeBas if (!workgroup::SubgroupContiguousIndex()) { const vector channelWiseSums = { preloaded[0][0].real(), preloaded[1][0].real(), preloaded[2][0].real() }; - const scalar_t power = mul(vector(colorspace::scRGB::ToXYZ()._m10_m11_m12), channelWiseSums); + const scalar_t power = mul(vector(colorspace::scRGBtoXYZ._m10_m11_m12), channelWiseSums); vk::RawBufferStore(pushConstants.rowMajorBufferAddress, scalar_t(1) / power); } } From f6371c7023d8d1f32a0b73bf946ba5b21ec12a1f Mon Sep 17 00:00:00 2001 From: keptsecret Date: Tue, 4 Nov 2025 16:10:01 +0700 Subject: [PATCH 6/8] a number of minor test fixes, disabled iridescent test temporarily --- .../app_resources/test_compile.comp.hlsl | 12 ++--- .../app_resources/test_components.hlsl | 4 +- .../app_resources/tests_common.hlsl | 8 +++ 66_HLSLBxDFTests/main.cpp | 49 ++++++++++++------- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl index c45f20c72..a98188277 100644 --- a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl +++ b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl @@ -32,7 +32,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID) bxdf::reflection::SBeckmannAnisotropic beckmannAnisoBRDF; bxdf::reflection::SGGXIsotropic ggxIsoBRDF; bxdf::reflection::SGGXAnisotropic ggxAnisoBRDF; - bxdf::reflection::SIridescent iridBRDF; + // bxdf::reflection::SIridescent iridBRDF; bxdf::transmission::SLambertian lambertianBSDF; bxdf::transmission::SOrenNayar orenNayarBSDF; @@ -43,7 +43,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID) bxdf::transmission::SBeckmannDielectricAnisotropic beckmannAnisoBSDF; bxdf::transmission::SGGXDielectricIsotropic ggxIsoBSDF; bxdf::transmission::SGGXDielectricAnisotropic ggxAnisoBSDF; - bxdf::transmission::SIridescent iridBSDF; + // bxdf::transmission::SIridescent iridBSDF; // do some nonsense calculations, but call all the relevant functions @@ -78,10 +78,10 @@ void main(uint32_t3 ID : SV_DispatchThreadID) s = ggxAnisoBRDF.generate(anisointer, u.xy, cache); L += s.L.direction; - iso_cache icache; - typename bxdf::reflection::SIridescent::query_type query6 = iridBRDF.createQuery(s, isointer); - qp = iridBRDF.quotient_and_pdf(query6, s, isointer, icache); - L -= qp.quotient; + // iso_cache icache; + // typename bxdf::reflection::SIridescent::query_type query6 = iridBRDF.createQuery(s, isointer); + // qp = iridBRDF.quotient_and_pdf(query6, s, isointer, icache); + // L -= qp.quotient; qp = ggxAnisoBRDF.quotient_and_pdf(s, anisointer, cache); L -= qp.quotient; diff --git a/66_HLSLBxDFTests/app_resources/test_components.hlsl b/66_HLSLBxDFTests/app_resources/test_components.hlsl index 9631db05d..cd2aa5cb6 100644 --- a/66_HLSLBxDFTests/app_resources/test_components.hlsl +++ b/66_HLSLBxDFTests/app_resources/test_components.hlsl @@ -90,7 +90,7 @@ struct TestNDF : TestBxDF NBL_IF_CONSTEXPR(aniso) { dg1_query_type dq = base_t::bxdf.ndf.template createDG1Query(base_t::anisointer, cache); - fresnel_type _f = bxdf::impl::getOrientedFresnel::__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::template __call(base_t::bxdf.ndf, _f, cache); quant_type DG1 = base_t::bxdf.ndf.template DG1(dq, qq, s, base_t::anisointer); dg1 = DG1.microfacetMeasure * hlsl::abs(cache.getVdotH() / base_t::anisointer.getNdotV()); @@ -101,7 +101,7 @@ struct TestNDF : TestBxDF else { dg1_query_type dq = base_t::bxdf.ndf.template createDG1Query(base_t::isointer, isocache); - fresnel_type _f = bxdf::impl::getOrientedFresnel::__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::template __call(base_t::bxdf.ndf, _f, isocache); quant_type DG1 = base_t::bxdf.ndf.template DG1(dq, qq, s, base_t::isointer); dg1 = DG1.microfacetMeasure * hlsl::abs(isocache.getVdotH() / base_t::isointer.getNdotV()); diff --git a/66_HLSLBxDFTests/app_resources/tests_common.hlsl b/66_HLSLBxDFTests/app_resources/tests_common.hlsl index c0a8d9614..c1e8e319a 100644 --- a/66_HLSLBxDFTests/app_resources/tests_common.hlsl +++ b/66_HLSLBxDFTests/app_resources/tests_common.hlsl @@ -81,6 +81,14 @@ bool checkEq(T a, T b, float32_t eps) return nbl::hlsl::all::Dimension> >(nbl::hlsl::max(_a / _b, _b / _a) <= hlsl::promote(1 + eps)); } +template<> +bool checkEq(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(_a / _b, _b / _a) <= float32_t(1 + eps); +} + template bool checkLt(T a, T b) { diff --git a/66_HLSLBxDFTests/main.cpp b/66_HLSLBxDFTests/main.cpp index 472eaa05d..a03e6ab83 100644 --- a/66_HLSLBxDFTests/main.cpp +++ b/66_HLSLBxDFTests/main.cpp @@ -193,7 +193,7 @@ int main(int argc, char** argv) TestJacobian, true>::run(initparams, cb); TestJacobian, false>::run(initparams, cb); TestJacobian,true>::run(initparams, cb); - TestJacobian, false>::run(initparams, cb); + //TestJacobian, false>::run(initparams, cb); TestJacobian>::run(initparams, cb); TestJacobian>::run(initparams, cb); @@ -204,7 +204,7 @@ int main(int argc, char** argv) TestJacobian, true>::run(initparams, cb); TestJacobian, false>::run(initparams, cb); TestJacobian,true>::run(initparams, cb); - TestJacobian, false>::run(initparams, cb); + //TestJacobian, false>::run(initparams, cb); FOR_EACH_END @@ -223,7 +223,7 @@ int main(int argc, char** argv) TestReciprocity, true>::run(initparams, cb); TestReciprocity, false>::run(initparams, cb); TestReciprocity, true>::run(initparams, cb); - TestReciprocity, false>::run(initparams, cb); + //TestReciprocity, false>::run(initparams, cb); TestReciprocity>::run(initparams, cb); TestReciprocity>::run(initparams, cb); @@ -234,7 +234,7 @@ int main(int argc, char** argv) TestReciprocity, true>::run(initparams, cb); TestReciprocity, false>::run(initparams, cb); TestReciprocity, true>::run(initparams, cb); - TestReciprocity, false>::run(initparams, cb); + //TestReciprocity, false>::run(initparams, cb); FOR_EACH_END @@ -253,7 +253,7 @@ int main(int argc, char** argv) TestBucket, true>::run(initparams, cb); TestBucket, false>::run(initparams, cb); TestBucket, true>::run(initparams, cb); - TestBucket, false>::run(initparams, cb); + //TestBucket, false>::run(initparams, cb); TestBucket>::run(initparams, cb); TestBucket>::run(initparams, cb); @@ -261,7 +261,7 @@ int main(int argc, char** argv) TestBucket, true>::run(initparams, cb); TestBucket, false>::run(initparams, cb); TestBucket, true>::run(initparams, cb); - TestBucket, false>::run(initparams, cb); + //TestBucket, false>::run(initparams, cb); FOR_EACH_END @@ -282,7 +282,7 @@ int main(int argc, char** argv) TestChi2, true>::run(initparams, cb); TestChi2, false>::run(initparams, cb); TestChi2, true>::run(initparams, cb); - TestChi2, false>::run(initparams, cb); + //TestChi2, false>::run(initparams, cb); TestChi2>::run(initparams, cb); TestChi2>::run(initparams, cb); @@ -290,7 +290,7 @@ int main(int argc, char** argv) TestChi2, true>::run(initparams, cb); TestChi2, false>::run(initparams, cb); TestChi2, true>::run(initparams, cb); - TestChi2, false>::run(initparams, cb); + //TestChi2, false>::run(initparams, cb); FOR_EACH_END #if 0 @@ -338,22 +338,35 @@ int main(int argc, char** argv) // test arccos angle sums { Xoroshiro64Star rng = Xoroshiro64Star::construct(uint32_t2(4, 2)); + math::sincos_accumulator angle_adder; + + auto Sin = [&](const float cosA) -> float + { + return nbl::hlsl::sqrt(1.f - cosA * cosA); + }; + for (uint32_t i = 0; i < 10; i++) { - const float a = rng() * numbers::pi; - const float b = rng() * numbers::pi; - const float c = rng() * numbers::pi; - const float d = rng() * numbers::pi; + const float a = ConvertToFloat01::__call(rng()) * 2.f - 1.f; + const float b = ConvertToFloat01::__call(rng()) * 2.f - 1.f; + const float c = ConvertToFloat01::__call(rng()) * 2.f - 1.f; + const float d = ConvertToFloat01::__call(rng()) * 2.f - 1.f; const float exAB = acos(a) + acos(b); - float res = math::getSumofArccosAB(a, b); - if (res != exAB) - fprintf(stderr, "[ERROR] math::getSumofArccosAB failed! expected %f, got %f\n", exAB, res); + angle_adder = math::sincos_accumulator::create(a, Sin(a)); + angle_adder.addCosine(b, Sin(b)); + float res = angle_adder.getSumofArccos(); + if (!checkEq(res, exAB, 1e-3)) + fprintf(stderr, "[ERROR] angle adding (2 angles) failed! expected %f, got %f\n", exAB, res); const float exABCD = exAB + acos(c) + acos(d); - res = math::getSumofArccosABCD(a, b, c, d); - if (res != exABCD) - fprintf(stderr, "[ERROR] math::getSumofArccosABCD failed! expected %f, got %f\n", exABCD, res); + angle_adder = math::sincos_accumulator::create(a, Sin(a)); + angle_adder.addCosine(b, Sin(b)); + angle_adder.addCosine(c, Sin(c)); + angle_adder.addCosine(d, Sin(d)); + res = angle_adder.getSumofArccos(); + if (!checkEq(res, exABCD, 1e-3)) + fprintf(stderr, "[ERROR] angle adding (4 angles) failed! expected %f, got %f\n", exABCD, res); } } From 9d79107b8798f86b857ecb1f169cb6018d80b357 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Thu, 6 Nov 2025 16:41:42 +0700 Subject: [PATCH 7/8] refactor new interaction template --- .../app_resources/test_compile.comp.hlsl | 4 +-- 66_HLSLBxDFTests/app_resources/tests.hlsl | 1 + .../app_resources/tests_common.hlsl | 34 ++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl index a98188277..16236ce63 100644 --- a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl +++ b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl @@ -8,14 +8,14 @@ using namespace nbl::hlsl; +using spectral_t = vector; using ray_dir_info_t = bxdf::ray_dir_info::SBasic; -using iso_interaction = bxdf::surface_interactions::SIsotropic; +using iso_interaction = bxdf::surface_interactions::SIsotropic; using aniso_interaction = bxdf::surface_interactions::SAnisotropic; using sample_t = bxdf::SLightSample; using iso_cache = bxdf::SIsotropicMicrofacetCache; using aniso_cache = bxdf::SAnisotropicMicrofacetCache; using quotient_pdf_t = sampling::quotient_and_pdf; -using spectral_t = vector; using iso_config_t = bxdf::SConfiguration; using aniso_config_t = bxdf::SConfiguration; diff --git a/66_HLSLBxDFTests/app_resources/tests.hlsl b/66_HLSLBxDFTests/app_resources/tests.hlsl index 9011aa2e5..62d65f1ad 100644 --- a/66_HLSLBxDFTests/app_resources/tests.hlsl +++ b/66_HLSLBxDFTests/app_resources/tests.hlsl @@ -264,6 +264,7 @@ struct TestReciprocity : TestBxDF 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(); diff --git a/66_HLSLBxDFTests/app_resources/tests_common.hlsl b/66_HLSLBxDFTests/app_resources/tests_common.hlsl index c1e8e319a..eff94bce9 100644 --- a/66_HLSLBxDFTests/app_resources/tests_common.hlsl +++ b/66_HLSLBxDFTests/app_resources/tests_common.hlsl @@ -46,14 +46,14 @@ namespace nbl namespace hlsl { +using spectral_t = vector; using ray_dir_info_t = bxdf::ray_dir_info::SBasic; -using iso_interaction = bxdf::surface_interactions::SIsotropic; +using iso_interaction = bxdf::surface_interactions::SIsotropic; using aniso_interaction = bxdf::surface_interactions::SAnisotropic; using sample_t = bxdf::SLightSample; using iso_cache = bxdf::SIsotropicMicrofacetCache; using aniso_cache = bxdf::SAnisotropicMicrofacetCache; using quotient_pdf_t = sampling::quotient_and_pdf; -using spectral_t = vector; using iso_config_t = bxdf::SConfiguration; using aniso_config_t = bxdf::SConfiguration; @@ -192,6 +192,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); } @@ -449,34 +450,40 @@ struct TestBxDF> : TestBxD namespace reciprocity_test_impl { -template) +template && concepts::FloatingPointLikeVectorial) struct SIsotropic { + using this_t = SIsotropic; 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 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 retval; + this_t retval; retval.V = normalizedV; retval.N = normalizedN; retval.NdotV = nbl::hlsl::dot(retval.N, retval.V.getDirection()); retval.NdotV2 = retval.NdotV * retval.NdotV; + retval.luminosityContributionHint = hlsl::promote(1.0); + retval.throughputWeights = hlsl::promote(1.0); return retval; } template) - static SIsotropic copy(NBL_CONST_REF_ARG(I) other) + static this_t copy(NBL_CONST_REF_ARG(I) other) { - SIsotropic 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; } @@ -489,12 +496,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(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) @@ -506,6 +521,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; + using spectral_type = typename isotropic_interaction_type::spectral_type; // WARNING: Changed since GLSL, now arguments need to be normalized! static this_t create( @@ -559,6 +575,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; } @@ -607,7 +625,7 @@ struct CustomIsoMicrofacetConfiguration; +using rectest_iso_interaction = reciprocity_test_impl::SIsotropic; using rectest_aniso_interaction = reciprocity_test_impl::SAnisotropic; using rectest_iso_microfacet_config_t = reciprocity_test_impl::CustomIsoMicrofacetConfiguration; using rectest_aniso_microfacet_config_t = bxdf::SMicrofacetConfiguration; From a20e33d2b6d2c54bf44baeb8545d4fa0575ede12 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Fri, 7 Nov 2025 16:17:08 +0700 Subject: [PATCH 8/8] enable tests for iridescent bxdf --- .../app_resources/test_compile.comp.hlsl | 8 ++-- .../app_resources/tests_common.hlsl | 38 ++++++++++++++++++- 66_HLSLBxDFTests/main.cpp | 18 ++++----- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl index 16236ce63..68fe8b633 100644 --- a/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl +++ b/66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl @@ -32,7 +32,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID) bxdf::reflection::SBeckmannAnisotropic beckmannAnisoBRDF; bxdf::reflection::SGGXIsotropic ggxIsoBRDF; bxdf::reflection::SGGXAnisotropic ggxAnisoBRDF; - // bxdf::reflection::SIridescent iridBRDF; + bxdf::reflection::SIridescent iridBRDF; bxdf::transmission::SLambertian lambertianBSDF; bxdf::transmission::SOrenNayar orenNayarBSDF; @@ -78,10 +78,8 @@ void main(uint32_t3 ID : SV_DispatchThreadID) s = ggxAnisoBRDF.generate(anisointer, u.xy, cache); L += s.L.direction; - // iso_cache icache; - // typename bxdf::reflection::SIridescent::query_type query6 = iridBRDF.createQuery(s, isointer); - // qp = iridBRDF.quotient_and_pdf(query6, s, isointer, icache); - // L -= qp.quotient; + qp = iridBRDF.quotient_and_pdf(s, anisointer, cache); + L -= qp.quotient; qp = ggxAnisoBRDF.quotient_and_pdf(s, anisointer, cache); L -= qp.quotient; diff --git a/66_HLSLBxDFTests/app_resources/tests_common.hlsl b/66_HLSLBxDFTests/app_resources/tests_common.hlsl index eff94bce9..89d3bcf71 100644 --- a/66_HLSLBxDFTests/app_resources/tests_common.hlsl +++ b/66_HLSLBxDFTests/app_resources/tests_common.hlsl @@ -139,6 +139,9 @@ struct SBxDFTestResources retval.alpha.y = ConvertToFloat01::__call(retval.rng()); retval.eta = ConvertToFloat01::__call(rng_vec2()) * hlsl::promote(1.5) + hlsl::promote(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::__call(retval.rng()) * 2400.0f + 100.0f; + retval.etaThinFilm = ConvertToFloat01::__call(retval.rng()) * 0.5 + 1.1f; // range [1.1,1.6] return retval; } @@ -155,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 @@ -324,6 +331,21 @@ struct TestBxDF> : } }; +template<> +struct TestBxDF> : TestBxDFBase> +{ + using base_t = TestBxDFBase>; + + 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(1.0),hlsl::promote(_rc.etaThinFilm),hlsl::promote(_rc.eta.x),hlsl::promote(_rc.eta.y)); +#ifndef __HLSL_VERSION + base_t::name = "Iridescent BRDF"; +#endif + } +}; + template<> struct TestBxDF> : TestBxDFBase> { @@ -363,7 +385,6 @@ struct TestBxDF> : TestB { using spectral_type = typename base_t::bxdf_t::spectral_type; base_t::bxdf.fresnel = bxdf::fresnel::Dielectric::create(bxdf::fresnel::OrientedEtas::create(base_t::isointer.getNdotV(bxdf::BxDFClampMode::BCM_ABS), hlsl::promote(_rc.eta.x))); - base_t::bxdf.luminosityContributionHint = _rc.luma_coeff; #ifndef __HLSL_VERSION base_t::name = "Thin smooth dielectric BSDF"; #endif @@ -447,6 +468,21 @@ struct TestBxDF> : TestBxD } }; +template +struct TestBxDF> : TestBxDFBase> +{ + using base_t = TestBxDFBase>; + + 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(1.0),hlsl::promote(_rc.etaThinFilm),hlsl::promote(_rc.eta.x)); +#ifndef __HLSL_VERSION + base_t::name = "Iridescent BSDF"; +#endif + } +}; + namespace reciprocity_test_impl { diff --git a/66_HLSLBxDFTests/main.cpp b/66_HLSLBxDFTests/main.cpp index a03e6ab83..876965875 100644 --- a/66_HLSLBxDFTests/main.cpp +++ b/66_HLSLBxDFTests/main.cpp @@ -193,7 +193,7 @@ int main(int argc, char** argv) TestJacobian, true>::run(initparams, cb); TestJacobian, false>::run(initparams, cb); TestJacobian,true>::run(initparams, cb); - //TestJacobian, false>::run(initparams, cb); + TestJacobian, false>::run(initparams, cb); TestJacobian>::run(initparams, cb); TestJacobian>::run(initparams, cb); @@ -204,7 +204,7 @@ int main(int argc, char** argv) TestJacobian, true>::run(initparams, cb); TestJacobian, false>::run(initparams, cb); TestJacobian,true>::run(initparams, cb); - //TestJacobian, false>::run(initparams, cb); + TestJacobian, false>::run(initparams, cb); FOR_EACH_END @@ -213,7 +213,7 @@ int main(int argc, char** argv) auto rReciprocity = std::ranges::views::iota(0u, runs); FOR_EACH_BEGIN(rReciprocity) STestInitParams initparams{ .logInfo = logInfo }; - initparams.state = 3; + initparams.state = i; initparams.verbose = testconfigs["TestReciprocity"]["verbose"]; TestReciprocity>::run(initparams, cb); @@ -223,7 +223,7 @@ int main(int argc, char** argv) TestReciprocity, true>::run(initparams, cb); TestReciprocity, false>::run(initparams, cb); TestReciprocity, true>::run(initparams, cb); - //TestReciprocity, false>::run(initparams, cb); + TestReciprocity, false>::run(initparams, cb); TestReciprocity>::run(initparams, cb); TestReciprocity>::run(initparams, cb); @@ -234,7 +234,7 @@ int main(int argc, char** argv) TestReciprocity, true>::run(initparams, cb); TestReciprocity, false>::run(initparams, cb); TestReciprocity, true>::run(initparams, cb); - //TestReciprocity, false>::run(initparams, cb); + //TestReciprocity, false>::run(initparams, cb); // viewing angle changes result? FOR_EACH_END @@ -253,7 +253,7 @@ int main(int argc, char** argv) TestBucket, true>::run(initparams, cb); TestBucket, false>::run(initparams, cb); TestBucket, true>::run(initparams, cb); - //TestBucket, false>::run(initparams, cb); + TestBucket, false>::run(initparams, cb); TestBucket>::run(initparams, cb); TestBucket>::run(initparams, cb); @@ -261,7 +261,7 @@ int main(int argc, char** argv) TestBucket, true>::run(initparams, cb); TestBucket, false>::run(initparams, cb); TestBucket, true>::run(initparams, cb); - //TestBucket, false>::run(initparams, cb); + TestBucket, false>::run(initparams, cb); FOR_EACH_END @@ -282,7 +282,7 @@ int main(int argc, char** argv) TestChi2, true>::run(initparams, cb); TestChi2, false>::run(initparams, cb); TestChi2, true>::run(initparams, cb); - //TestChi2, false>::run(initparams, cb); + TestChi2, false>::run(initparams, cb); TestChi2>::run(initparams, cb); TestChi2>::run(initparams, cb); @@ -290,7 +290,7 @@ int main(int argc, char** argv) TestChi2, true>::run(initparams, cb); TestChi2, false>::run(initparams, cb); TestChi2, true>::run(initparams, cb); - //TestChi2, false>::run(initparams, cb); + TestChi2, false>::run(initparams, cb); FOR_EACH_END #if 0