Skip to content

Created concepts for samplers, added quotient_and_pdf variants to satisfy the concepts#1001

Open
karimsayedre wants to merge 1 commit intomasterfrom
sampler-concepts
Open

Created concepts for samplers, added quotient_and_pdf variants to satisfy the concepts#1001
karimsayedre wants to merge 1 commit intomasterfrom
sampler-concepts

Conversation

@karimsayedre
Copy link
Contributor

@karimsayedre karimsayedre commented Feb 18, 2026

Examples PR

Notes:

  • The quotient_and_pdf() methods in UniformHemisphere, UniformSphere, ProjectedHemisphere, and ProjectedSphere shadow the struct type sampling::quotient_and_pdf<Q, P> from quotient_and_pdf.hlsl. DXC can't resolve the return type because the method name takes precedence over the struct name during lookup. Fixed by fully qualifying with ::nbl::hlsl::sampling::quotient_and_pdf<U, T>.
  • Obv. there's some refactoring to be done to satisfy all the concepts, so for not Basic (Level1) samplers are concept tested

Comment on lines +14 to +17
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
{

Choose a reason for hiding this comment

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

no indent for namespaces

Comment on lines +19 to +20
template <typename T NBL_PRIMARY_REQUIRES(concepts::FloatingPointLikeScalar<T>) struct BoxMullerTransform
{

Choose a reason for hiding this comment

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

fix the indents and template + requires is always on its own line

Comment on lines +6 to +15
namespace nbl
{
namespace hlsl
{
namespace sampling
{
namespace concepts
{

// ============================================================================

Choose a reason for hiding this comment

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

no indends for namespaces

((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))
Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming Feb 19, 2026

Choose a reason for hiding this comment

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

I'd also check that sample_type has a pdf or rpdf and value method (can do a separate concept SampleWithPDF and SampleWithRcpPDF)

// Required types:
// domain_type - the input space
// codomain_type - the output space
// density_type - the density type (typically scalar)

Choose a reason for hiding this comment

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

density will always be scalar

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

// ============================================================================
// BackwardDensitySampler

Choose a reason for hiding this comment

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

we need a better name like ResamplableSampler

#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)

Choose a reason for hiding this comment

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

sampler is a HLSL keyword, replace with _sampler throughout the file

// 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):

Choose a reason for hiding this comment

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

if it extends then you can simply put a clause that checks TractableSampler<T>, see how Anisotropic and Isotropic build on top of each other in the BxDF concepts

}
namespace sampling
{

Choose a reason for hiding this comment

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

watch out for indents

Comment on lines -20 to -22
struct quotient_and_pdf
{
using this_t = quotient_and_pdf<Q, P>;

Choose a reason for hiding this comment

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

we really need this type, its necessary for BxDFs and without it you'd murder it, quotient_and_pdf is meant for importance sampling a function f(x) proportional to its value

The struct here stores quotient = f(sample)/forwardPdf(sample) and shouldn't be abused for anything else

you need something else for warps (which is what you're doing), which means a new header

Undo changes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments