Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f71610b
Created concepts for samplers, added quotient_and_pdf variants to sat…
karimsayedre Feb 18, 2026
0e0b0ad
revert bad formatting for hlsl sampling headers
karimsayedre Feb 25, 2026
3574d83
Separate warp sample types from quotient_and_pdf, add sample density …
karimsayedre Feb 25, 2026
168ca4d
merge master, fix conflicts
keptsecret Mar 2, 2026
f1493ed
changes to linear, bilinear, box muller for pdf and backward pdf
keptsecret Jan 20, 2026
5933fe0
changes to solid angle method name, simplified a lot of code in spher…
keptsecret Jan 21, 2026
3ac7b83
removed redundant/unused variables from spherical triangle sample
keptsecret Jan 22, 2026
4ed1cbc
spherical rectangle stores origin, extent, basis and takes observer i…
keptsecret Jan 22, 2026
65ef4b3
added compressed spherical rectangle, comments for info of implementa…
keptsecret Jan 22, 2026
7fc8281
minor fixes to spherical rectangle stuff
keptsecret Feb 25, 2026
855dac4
spherical rectangle constructor for same rectangle and observer
keptsecret Mar 2, 2026
468031f
spherical rectangle create only from compressed, minor fix for spheri…
keptsecret Mar 2, 2026
0f143a0
reduced duplicate methods to only ones matching (close to) concept in…
keptsecret Mar 2, 2026
fb0e8a5
spherical rect generate don't divide by extents, let user do that
keptsecret Mar 2, 2026
ab5ee78
store only needed members from tri
keptsecret Mar 3, 2026
17c85ba
forward/backward pdfs for spherical triangle/rectangle, projected sph…
keptsecret Mar 3, 2026
d95cfa7
copied over fixed linear sampling because merge fucked up, added forw…
keptsecret Mar 3, 2026
0bb7b39
add forward pdf, generate inverse to bilinear
keptsecret Mar 4, 2026
89f6d5f
uniform hemi/sphere samplign make static methods private, added metho…
keptsecret Mar 4, 2026
e07ebc1
cosine hemi/sphere sampling make static methods private, added method…
keptsecret Mar 4, 2026
c4e63b3
box muller transform add forward pdf, generate wasn't merged from pt …
keptsecret Mar 4, 2026
c064b29
`approx_compare` uses abs then relative comparison, better sampler co…
karimsayedre Mar 5, 2026
d254d7a
Merge branch 'master' into sampler-concepts
karimsayedre Mar 5, 2026
5bc073f
Merge branch 'master' into sampler-concepts
karimsayedre Mar 6, 2026
d2114f8
fixes after merge
karimsayedre Mar 7, 2026
4f390b4
Merge remote-tracking branch 'origin/sampling_refactor_for_pt' into s…
karimsayedre Mar 7, 2026
743575f
update `examples_tests`
karimsayedre Mar 7, 2026
4d266ec
All samplers now conform to concepts
karimsayedre Mar 13, 2026
86fa3f6
Added alias table and cumulative prbability builders and samplers
karimsayedre Mar 17, 2026
6c79011
Merge branch 'master' into sampler-concepts
karimsayedre Mar 17, 2026
254404b
update examples_tests
karimsayedre Mar 17, 2026
2fa32a7
Merge branch 'master' into sampler-concepts
karimsayedre Mar 17, 2026
c61a63c
Merge branch 'master' into sampler-concepts
karimsayedre Mar 17, 2026
b720bc0
Merge branch 'master' into sampler-concepts
karimsayedre Mar 18, 2026
1fb987a
addressing comments in concepts.hlsl
karimsayedre Mar 18, 2026
fc7e174
address comments in concepts.hlsl
karimsayedre Mar 19, 2026
38f73af
Merge branch 'master' into sampler-concepts
devshgraphicsprogramming Mar 20, 2026
04d5a30
Merge branch 'master' into sampler-concepts
karimsayedre Mar 23, 2026
edc3c3e
addressed more comments
karimsayedre Mar 23, 2026
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
7 changes: 7 additions & 0 deletions include/nbl/builtin/hlsl/sampling/bilinear.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ struct Bilinear
using vector3_type = vector<T, 3>;
using vector4_type = vector<T, 4>;

// BijectiveSampler concept types
using domain_type = vector2_type;
using codomain_type = vector2_type;
using density_type = scalar_type;
using sample_type = codomain_and_rcpPdf<codomain_type, density_type>;
using inverse_sample_type = domain_and_rcpPdf<domain_type, density_type>;

static Bilinear<T> create(const vector4_type bilinearCoeffs)
{
Bilinear<T> retval;
Expand Down
48 changes: 27 additions & 21 deletions include/nbl/builtin/hlsl/sampling/box_muller_transform.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@

#include "nbl/builtin/hlsl/math/functions.hlsl"
#include "nbl/builtin/hlsl/numbers.hlsl"
#include "nbl/builtin/hlsl/sampling/quotient_and_pdf.hlsl"

namespace nbl
{
namespace hlsl
{
namespace sampling
{

template<typename T NBL_PRIMARY_REQUIRES(concepts::FloatingPointLikeScalar<T>)
struct BoxMullerTransform
{
using scalar_type = T;
using vector2_type = vector<T,2>;

vector2_type operator()(const vector2_type xi)
namespace hlsl
{
scalar_type sinPhi, cosPhi;
math::sincos<scalar_type>(2.0 * numbers::pi<scalar_type> * xi.y - numbers::pi<scalar_type>, sinPhi, cosPhi);
return vector2_type(cosPhi, sinPhi) * nbl::hlsl::sqrt(-2.0 * nbl::hlsl::log(xi.x)) * stddev;
namespace sampling
{

template <typename T NBL_PRIMARY_REQUIRES(concepts::FloatingPointLikeScalar<T>) struct BoxMullerTransform
{
using scalar_type = T;
using vector2_type = vector<T, 2>;

// BackwardDensitySampler concept types
using domain_type = vector2_type;
using codomain_type = vector2_type;
using density_type = scalar_type;
using sample_type = codomain_and_rcpPdf<codomain_type, density_type>;

vector2_type operator()(const vector2_type xi)
{
scalar_type sinPhi, cosPhi;
math::sincos<scalar_type>(2.0 * numbers::pi<scalar_type> * xi.y - numbers::pi<scalar_type>, sinPhi, cosPhi);
return vector2_type(cosPhi, sinPhi) * nbl::hlsl::sqrt(-2.0 * nbl::hlsl::log(xi.x)) * stddev;
}

T stddev;
};

}
}

T stddev;
};

}
}
}

#endif
170 changes: 170 additions & 0 deletions include/nbl/builtin/hlsl/sampling/concepts.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#ifndef _NBL_BUILTIN_HLSL_SAMPLING_CONCEPTS_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_CONCEPTS_INCLUDED_

#include <nbl/builtin/hlsl/concepts.hlsl>

namespace nbl
{
namespace hlsl
{
namespace sampling
{
namespace concepts
{

// ============================================================================
// BasicSampler
//
// The simplest sampler: maps domain -> codomain.
//
// Required types:
// domain_type - the input space (e.g. float for 1D, float2 for 2D)
// codomain_type - the output space (e.g. float3 for directions)
//
// Required methods:
// codomain_type generate(domain_type u)
// ============================================================================

#define NBL_CONCEPT_NAME BasicSampler
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (sampler, T)
#define NBL_CONCEPT_PARAM_1 (u, typename T::domain_type)
NBL_CONCEPT_BEGIN(2)
#define sampler NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::domain_type))
((NBL_CONCEPT_REQ_TYPE)(T::codomain_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.generate(u)), ::nbl::hlsl::is_same_v, typename T::codomain_type))
);
#undef u
#undef sampler
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

// ============================================================================
// TractableSampler
//
// A sampler whose density can be computed analytically in the forward
// (sampling) direction. The generate method returns the sample bundled
// with its density to avoid redundant computation.
//
// Required types:
// domain_type - the input space
// codomain_type - the output space
// density_type - the density type (typically scalar)
// sample_type - bundled return of generate, should be one of:
// codomain_and_rcpPdf<codomain_type, density_type> (preferred)
// codomain_and_pdf<codomain_type, density_type>
//
// Required methods:
// sample_type generate(domain_type u) - sample + density
// density_type forwardPdf(domain_type u) - density only
// ============================================================================

#define NBL_CONCEPT_NAME TractableSampler
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (sampler, T)
#define NBL_CONCEPT_PARAM_1 (u, typename T::domain_type)
NBL_CONCEPT_BEGIN(2)
#define sampler NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::domain_type))
((NBL_CONCEPT_REQ_TYPE)(T::codomain_type))
((NBL_CONCEPT_REQ_TYPE)(T::density_type))
((NBL_CONCEPT_REQ_TYPE)(T::sample_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.generate(u)), ::nbl::hlsl::is_same_v, typename T::sample_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.forwardPdf(u)), ::nbl::hlsl::is_same_v, typename T::density_type))
);
#undef u
#undef sampler
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

// ============================================================================
// BackwardDensitySampler
//
// Extends TractableSampler with the ability to evaluate the PDF given
// a codomain value (i.e. without knowing the original domain input).
//
// Required methods (in addition to TractableSampler):
// density_type backwardPdf(codomain_type v)
// ============================================================================

#define NBL_CONCEPT_NAME BackwardDensitySampler
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (sampler, T)
#define NBL_CONCEPT_PARAM_1 (u, typename T::domain_type)
#define NBL_CONCEPT_PARAM_2 (v, typename T::codomain_type)
NBL_CONCEPT_BEGIN(3)
#define sampler NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define v NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::domain_type))
((NBL_CONCEPT_REQ_TYPE)(T::codomain_type))
((NBL_CONCEPT_REQ_TYPE)(T::density_type))
((NBL_CONCEPT_REQ_TYPE)(T::sample_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.generate(u)), ::nbl::hlsl::is_same_v, typename T::sample_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.forwardPdf(u)), ::nbl::hlsl::is_same_v, typename T::density_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.backwardPdf(v)), ::nbl::hlsl::is_same_v, typename T::density_type))
);
#undef v
#undef u
#undef sampler
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

// ============================================================================
// BijectiveSampler
//
// The mapping domain <-> codomain is bijective (1:1), so it can be
// inverted. Extends BackwardDensitySampler with invertGenerate.
//
// Because the mapping is bijective, the Jacobian of the inverse is
// the reciprocal of the Jacobian of the forward mapping:
// backwardPdf(v) == 1.0 / forwardPdf(invertGenerate(v).value)
//
// Required types (in addition to BackwardDensitySampler):
// inverse_sample_type - bundled return of invertGenerate, should be
// one of:
// domain_and_rcpPdf<domain_type, density_type> (preferred)
// domain_and_pdf<domain_type, density_type>
//
// Required methods (in addition to BackwardDensitySampler):
// inverse_sample_type invertGenerate(codomain_type v)
// ============================================================================

#define NBL_CONCEPT_NAME BijectiveSampler
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (sampler, T)
#define NBL_CONCEPT_PARAM_1 (u, typename T::domain_type)
#define NBL_CONCEPT_PARAM_2 (v, typename T::codomain_type)
NBL_CONCEPT_BEGIN(3)
#define sampler NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define v NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::domain_type))
((NBL_CONCEPT_REQ_TYPE)(T::codomain_type))
((NBL_CONCEPT_REQ_TYPE)(T::density_type))
((NBL_CONCEPT_REQ_TYPE)(T::sample_type))
((NBL_CONCEPT_REQ_TYPE)(T::inverse_sample_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.generate(u)), ::nbl::hlsl::is_same_v, typename T::sample_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.forwardPdf(u)), ::nbl::hlsl::is_same_v, typename T::density_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.backwardPdf(v)), ::nbl::hlsl::is_same_v, typename T::density_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((sampler.invertGenerate(v)), ::nbl::hlsl::is_same_v, typename T::inverse_sample_type))
);
#undef v
#undef u
#undef sampler
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

} // namespace concepts
} // namespace sampling
} // namespace hlsl
} // namespace nbl

#endif // _NBL_BUILTIN_HLSL_SAMPLING_CONCEPTS_INCLUDED_
Loading
Loading