Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4fd9d59
minor fixes to interaction, microfacet cache in common.hlsl
keptsecret Sep 1, 2025
3c4a1d5
added delta distribution bxdfs
keptsecret Sep 1, 2025
1eac170
added oren nayar bsdf
keptsecret Sep 1, 2025
be844a5
fixes to smooth dielectric bsdf
keptsecret Sep 2, 2025
5f9f746
redone bxdf concepts
keptsecret Sep 2, 2025
349d6b2
don't take sample u by reference
keptsecret Sep 2, 2025
5b6bb6e
added a reflectTransmit to ray dir type
keptsecret Sep 2, 2025
4f31580
fix thin dielectric scatter func
keptsecret Sep 3, 2025
e2357fc
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret Sep 8, 2025
3d418bb
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret Sep 10, 2025
34ae295
change microfacet bxdf concept
keptsecret Sep 12, 2025
906d3ec
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret Sep 15, 2025
1099d60
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret Sep 16, 2025
c194f4e
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret Sep 18, 2025
d80f5ca
minor oren nayar changes to store A2 and AB
keptsecret Sep 18, 2025
5dd4956
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret Sep 19, 2025
d4c61bd
minor fixes to concept, iso cachce
keptsecret Sep 19, 2025
68c8123
removed create from lambertian, delta dis bc they do nothing
keptsecret Sep 19, 2025
a0dbcc2
added macro for bxdf type aliases
keptsecret Sep 19, 2025
b0c41f7
oren nayar create changes
keptsecret Sep 19, 2025
7e086f4
fix more oren nayar bugs
keptsecret Sep 19, 2025
6488ba4
fix delta distribution generate
keptsecret Sep 19, 2025
75ef607
reverted __rec_pi_factored_out_wo_clamps removal in oren nayar
keptsecret Sep 19, 2025
906d437
moved lambertian and oren nayar logic into a base class
keptsecret Sep 19, 2025
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
73 changes: 73 additions & 0 deletions include/nbl/builtin/hlsl/bxdf/base/lambertian.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_BUILTIN_HLSL_BXDF_BASE_LAMBERTIAN_INCLUDED_
#define _NBL_BUILTIN_HLSL_BXDF_BASE_LAMBERTIAN_INCLUDED_

#include "nbl/builtin/hlsl/bxdf/common.hlsl"
#include "nbl/builtin/hlsl/bxdf/config.hlsl"
#include "nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl"

namespace nbl
{
namespace hlsl
{
namespace bxdf
{
namespace base
{

template<class Config, bool IsBSDF NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>)
struct SLambertianBase
{
using this_t = SLambertianBase<Config, IsBSDF>;
BXDF_CONFIG_TYPE_ALIASES(Config);

NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = conditional_value<IsBSDF, BxDFClampMode, BxDFClampMode::BCM_ABS, BxDFClampMode::BCM_MAX>::value;

spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
{
return hlsl::promote<spectral_type>(_sample.getNdotL(_clamp) * numbers::inv_pi<scalar_type> * hlsl::mix(1.0, 0.5, IsBSDF));
}

sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
{
// static_assert(!IsBSDF);
ray_dir_info_type L;
L.direction = sampling::ProjectedHemisphere<scalar_type>::generate(u);
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}

sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u)
{
// static_assert(IsBSDF);
ray_dir_info_type L;
L.direction = sampling::ProjectedSphere<scalar_type>::generate(u);
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}
Comment on lines +33 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is flaky, template the generate on the vector type and REQUIRE that vector_type==conditional_t<IsBSDF,vector3_type,vector2_type)


scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
{
if (IsBSDF)
return sampling::ProjectedSphere<scalar_type>::pdf(_sample.getNdotL(_clamp));
else
return sampling::ProjectedHemisphere<scalar_type>::pdf(_sample.getNdotL(_clamp));
}

quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
{
sampling::quotient_and_pdf<monochrome_type, scalar_type> qp;
if (IsBSDF)
qp = sampling::ProjectedSphere<scalar_type>::template quotient_and_pdf(_sample.getNdotL(_clamp));
else
qp = sampling::ProjectedHemisphere<scalar_type>::template quotient_and_pdf(_sample.getNdotL(_clamp));
return quotient_pdf_type::create(qp.quotient[0], qp.pdf);
}
};

}
}
}
}

#endif
115 changes: 115 additions & 0 deletions include/nbl/builtin/hlsl/bxdf/base/oren_nayar.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_BUILTIN_HLSL_BXDF_BASE_OREN_NAYAR_INCLUDED_
#define _NBL_BUILTIN_HLSL_BXDF_BASE_OREN_NAYAR_INCLUDED_

#include "nbl/builtin/hlsl/bxdf/common.hlsl"
#include "nbl/builtin/hlsl/bxdf/config.hlsl"
#include "nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl"

namespace nbl
{
namespace hlsl
{
namespace bxdf
{
namespace base
{

template<class Config, bool IsBSDF NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>)
struct SOrenNayarBase
{
using this_t = SOrenNayarBase<Config, IsBSDF>;
BXDF_CONFIG_TYPE_ALIASES(Config);

NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = conditional_value<IsBSDF, BxDFClampMode, BxDFClampMode::BCM_ABS, BxDFClampMode::BCM_MAX>::value;

struct SCreationParams
{
scalar_type A;
};
using creation_type = SCreationParams;

struct SQuery
{
scalar_type getVdotL() NBL_CONST_MEMBER_FUNC { return VdotL; }
scalar_type VdotL;
};

static this_t create(NBL_CONST_REF_ARG(creation_type) params)
{
this_t retval;
retval.A2 = params.A * 0.5;
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);
return retval;
}

scalar_type __rec_pi_factored_out_wo_clamps(scalar_type VdotL, scalar_type clampedNdotL, scalar_type clampedNdotV)
{
scalar_type C = 1.0 / max<scalar_type>(clampedNdotL, clampedNdotV);
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - clampedNdotL * clampedNdotV, 0.0);
return (AB.x + AB.y * cos_phi_sin_theta * C);
}
template<typename Query>
spectral_type __eval(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
{
scalar_type NdotL = _sample.getNdotL(_clamp);
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * hlsl::mix(1.0, 0.5, IsBSDF) * __rec_pi_factored_out_wo_clamps(query.getVdotL(), NdotL, interaction.getNdotV(_clamp)));
}

spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
{
SQuery query;
query.VdotL = hlsl::dot(interaction.getV().getDirection(), _sample.getL().getDirection());
return __eval<SQuery>(query, _sample, interaction);
}

sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
{
// static_assert(!IsBSDF);
ray_dir_info_type L;
L.direction = sampling::ProjectedHemisphere<scalar_type>::generate(u);
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}

sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u)
{
// static_assert(IsBSDF);
ray_dir_info_type L;
L.direction = sampling::ProjectedSphere<scalar_type>::generate(u);
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}
Comment on lines +68 to +82

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as for the lambertian


scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
{
if (IsBSDF)
return sampling::ProjectedSphere<scalar_type>::pdf(_sample.getNdotL(_clamp));
else
return sampling::ProjectedHemisphere<scalar_type>::pdf(_sample.getNdotL(_clamp));
}

template<typename Query>
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)
{
scalar_type _pdf = pdf(_sample);
scalar_type q = __rec_pi_factored_out_wo_clamps(query.getVdotL(), _sample.getNdotL(_clamp), interaction.getNdotV(_clamp));
return quotient_pdf_type::create(q, _pdf);
}
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
{
SQuery query;
query.VdotL = hlsl::dot(interaction.getV().getDirection(), _sample.getL().getDirection());
return __quotient_and_pdf<SQuery>(query, _sample, interaction);
}

scalar_type A2;
vector2_type AB;
};

}
}
}
}

#endif
Loading
Loading