Skip to content
Open
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
02d6d0f
initial example
keptsecret Feb 4, 2025
129b50e
use bxdf creation params struct
keptsecret Feb 6, 2025
74261dc
triangle and rectangle shapes
keptsecret Feb 7, 2025
ab3ae20
more sampling methods
keptsecret Feb 10, 2025
355cfec
spherical rectangle
keptsecret Feb 11, 2025
ebf8fca
merge pcg fix from upstream
keptsecret Feb 12, 2025
11180f4
fix aniso cache bug
keptsecret Feb 17, 2025
4516051
init func to modify bxdf params directly
keptsecret Feb 18, 2025
d9a00c9
bug fixes
keptsecret Feb 20, 2025
ffe9029
fix sampling bugs #2
keptsecret Feb 21, 2025
cee192e
update to master
keptsecret Feb 21, 2025
b207312
fix rank type trait for matrix/vector
keptsecret Feb 21, 2025
673f788
merge hlsl bxdfs, resolve conflict
keptsecret Feb 25, 2025
69a257d
temporary fix for dxc bug issue 7154
keptsecret Feb 25, 2025
866e6d7
some bug fixes again
keptsecret Feb 26, 2025
85e955f
fix wrong template usage
keptsecret Feb 27, 2025
3b167ab
merge changes from hlsl_bxdf
keptsecret Feb 28, 2025
19e3a35
merge master/bxdf fixes, resolve conflicts
keptsecret Mar 3, 2025
6b5bf06
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 4, 2025
7b574da
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 4, 2025
1c773d9
fix typo
keptsecret Mar 4, 2025
326c885
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 5, 2025
6132a4e
Merge branch 'revert-some-device-limits' into hlsl_path_tracer_example
keptsecret Mar 6, 2025
0bd26c7
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Mar 6, 2025
ebb1b15
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 7, 2025
7cb977d
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 7, 2025
67c525e
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Mar 10, 2025
a8f209e
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 11, 2025
e8d2ed8
fixed some func usage to nbl ver
keptsecret Mar 14, 2025
c47f446
specify template args
keptsecret Mar 17, 2025
642e46d
fix merge conflicts
keptsecret Mar 17, 2025
1137b6b
update to latest example
keptsecret Mar 17, 2025
5cd4e6c
merge math, fix conflict
keptsecret Mar 19, 2025
7e8dd81
latest example
keptsecret Mar 19, 2025
f86dd0c
Merge remote-tracking branch 'origin/intrinsics_adjustments' into hls…
keptsecret Mar 21, 2025
b154638
fix use of static const in func
keptsecret Mar 21, 2025
7892563
added more morton order stuff
keptsecret Mar 24, 2025
b21b789
latest example
keptsecret Mar 28, 2025
1f461ff
merge master, fix conflicts
keptsecret Apr 3, 2025
df2321a
merge hlsl_bxdfs, fix conflicts
keptsecret Jun 26, 2025
26adf95
latest example
keptsecret Jun 27, 2025
0d80626
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Jun 27, 2025
36910c6
latest example fixes
keptsecret Jun 30, 2025
afc3485
merge bxdf, fix conflicts
keptsecret Aug 28, 2025
19ba15d
Updated examples
Przemog1 Sep 25, 2025
7ec3f39
Created RWMC files
Przemog1 Oct 18, 2025
4dcf56a
Updated examples
Przemog1 Oct 20, 2025
dbbb30a
merge master, fix conflicts
keptsecret Nov 12, 2025
3ae69fa
updated example
keptsecret Nov 12, 2025
1f9bf16
merge iridescent_bxdf, fix conflicts (hope it's merged to master soon)
keptsecret Nov 12, 2025
4cfed1b
use new angle adder
keptsecret Nov 13, 2025
8ecfecf
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Nov 13, 2025
dc8b5bc
initialize invalid ndf return to inf, not 0
keptsecret Nov 13, 2025
434234c
derive trait from cook torrance base
keptsecret Nov 13, 2025
ffeb633
fix angle adder
keptsecret Nov 13, 2025
d75246d
optimizations to iridescent fresnel
keptsecret Nov 13, 2025
494c625
avoid repeat fresnel calc
keptsecret Nov 13, 2025
ab25c17
mix reflectance w/ transmission in getScaledReflectance
keptsecret Nov 13, 2025
2a7db14
Refactored resolve.hlsl
Przemog1 Nov 13, 2025
1acf7d6
some minor fixes to fresnel orientedEta usage
keptsecret Nov 14, 2025
72429cb
refactor usage of angle adding
keptsecret Nov 14, 2025
381bb50
temp? fix for mix_helper on floats
keptsecret Nov 14, 2025
482ef2e
merge rwmc, fix conflicts
keptsecret Nov 14, 2025
a40a025
added missing typename qualifier
keptsecret Nov 14, 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
17 changes: 17 additions & 0 deletions include/nbl/builtin/glsl/utils/morton.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ uint nbl_glsl_morton_decode2d8bComponent(in uint x)
return x;
}

uint nbl_glsl_morton_decode2d32bComponent(in uint x)
{
x &= 0x55555555u;
x = (x ^ (x >> 1u)) & 0x33333333u;
x = (x ^ (x >> 2u)) & 0x0f0f0f0fu;
x = (x ^ (x >> 4u)) & 0x00ff00ffu;
x = (x ^ (x >> 8u)) & 0x0000ffffu;
x = (x ^ (x >> 16u));
return x;
}


uvec2 nbl_glsl_morton_decode2d4b(in uint x)
{
return uvec2(nbl_glsl_morton_decode2d4bComponent(x), nbl_glsl_morton_decode2d4bComponent(x >> 1u));
Expand All @@ -32,4 +44,9 @@ uvec2 nbl_glsl_morton_decode2d8b(in uint x)
return uvec2(nbl_glsl_morton_decode2d8bComponent(x), nbl_glsl_morton_decode2d8bComponent(x >> 1u));
}

uvec2 nbl_glsl_morton_decode2d32b(in uint x)
{
return uvec2(nbl_glsl_morton_decode2d32bComponent(x), nbl_glsl_morton_decode2d32bComponent(x >> 1u));
}

#endif
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/limits.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct num_base : type_identity<T>

// (TODO) think about what this means for HLSL
// identifies floating-point types that can represent the special value "quiet not-a-number" (NaN)
NBL_CONSTEXPR_STATIC_INLINE bool has_quiet_NaN = !is_integer;
NBL_CONSTEXPR_STATIC_INLINE bool has_quiet_NaN = !is_integer;
// identifies floating-point types that can represent the special value "signaling not-a-number" (NaN)
NBL_CONSTEXPR_STATIC_INLINE bool has_signaling_NaN = !is_integer;
// identifies the denormalization style used by the floating-point type
Expand Down
6 changes: 1 addition & 5 deletions include/nbl/builtin/hlsl/math/functions.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ void frisvad(NBL_CONST_REF_ARG(T) normal, NBL_REF_ARG(T) tangent, NBL_REF_ARG(T)

bool partitionRandVariable(float leftProb, NBL_REF_ARG(float) xi, NBL_REF_ARG(float) rcpChoiceProb)
{
#ifdef __HLSL_VERSION
NBL_CONSTEXPR float NEXT_ULP_AFTER_UNITY = asfloat(0x3f800001u);
#else
NBL_CONSTEXPR float32_t NEXT_ULP_AFTER_UNITY = bit_cast<float32_t>(0x3f800001u);
#endif
const float32_t NEXT_ULP_AFTER_UNITY = bit_cast<float32_t>(0x3f800001u);
Copy link
Member Author

Choose a reason for hiding this comment

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

#863 (comment)

Needs to be a struct but also with an operator() (because value can only be an int)

const bool pickRight = xi >= leftProb * NEXT_ULP_AFTER_UNITY;

// This is all 100% correct taking into account the above NEXT_ULP_AFTER_UNITY
Expand Down
68 changes: 68 additions & 0 deletions include/nbl/builtin/hlsl/math/morton.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2018-2023 - 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_MATH_MORTON_INCLUDED_
#define _NBL_BUILTIN_HLSL_MATH_MORTON_INCLUDED_

#include "nbl/builtin/hlsl/cpp_compat.hlsl"

namespace nbl
{
namespace hlsl
{
namespace math
{

namespace impl
{

template<typename T, uint32_t bitDepth>
struct MortonComponent;

template<typename T>
struct MortonComponent<T, 8u>
{
static T decode2d(T x)
{
x &= 0x55555555u;
x = (x ^ (x >> 1u)) & 0x33333333u;
x = (x ^ (x >> 2u)) & 0x0f0f0f0fu;
x = (x ^ (x >> 4u)) & 0x00ff00ffu;
return x;
}
};

template<typename T>
struct MortonComponent<T, 32u>
{
static T decode2d(T x)
{
x &= 0x55555555u;
x = (x ^ (x >> 1u)) & 0x33333333u;
x = (x ^ (x >> 2u)) & 0x0f0f0f0fu;
x = (x ^ (x >> 4u)) & 0x00ff00ffu;
x = (x ^ (x >> 8u)) & 0x0000ffffu;
x = (x ^ (x >> 16u));
return x;
}
};

}

template<typename T, uint32_t bitDepth=sizeof(T)*8u>
struct Morton
{
using vector2_type = vector<T, 2>;
using component_type = impl::MortonComponent<T, bitDepth>;

static vector2_type decode2d(T x)
{
return vector2_type(component_type::decode2d(x), component_type::decode2d(x >> 1u));
}
};

}
}
}

#endif
62 changes: 62 additions & 0 deletions include/nbl/builtin/hlsl/sampling/bilinear.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2018-2023 - 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_SAMPLING_BILINEAR_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_BILINEAR_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/limits.hlsl>
#include <nbl/builtin/hlsl/sampling/linear.hlsl>

namespace nbl
{
namespace hlsl
{
namespace sampling
{

template<typename T>
struct Bilinear
{
using scalar_type = T;
using vector2_type = vector<T, 2>;
using vector3_type = vector<T, 3>;
using vector4_type = vector<T, 4>;

static Bilinear<T> create(NBL_CONST_REF_ARG(vector4_type) bilinearCoeffs)
{
Bilinear<T> retval;
retval.bilinearCoeffs = bilinearCoeffs;
return retval;
}

vector2_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector2_type) _u)
{
vector2_type u = _u;
const vector2_type twiceAreasUnderXCurve = vector2_type(bilinearCoeffs[0] + bilinearCoeffs[1], bilinearCoeffs[2] + bilinearCoeffs[3]);
Linear<scalar_type> lineary = Linear<scalar_type>::create(twiceAreasUnderXCurve);
u.y = lineary.generate(u.y);

const vector2_type ySliceEndPoints = vector2_type(nbl::hlsl::mix(bilinearCoeffs[0], bilinearCoeffs[2], u.y), nbl::hlsl::mix(bilinearCoeffs[1], bilinearCoeffs[3], u.y));
Linear<scalar_type> linearx = Linear<scalar_type>::create(ySliceEndPoints);
u.x = linearx.generate(u.x);

rcpPdf = (twiceAreasUnderXCurve[0] + twiceAreasUnderXCurve[1]) / (4.0 * nbl::hlsl::mix(ySliceEndPoints[0], ySliceEndPoints[1], u.x));

return u;
}

scalar_type pdf(NBL_CONST_REF_ARG(vector2_type) u)
{
return 4.0 * nbl::hlsl::mix(nbl::hlsl::mix(bilinearCoeffs[0], bilinearCoeffs[1], u.x), nbl::hlsl::mix(bilinearCoeffs[2], bilinearCoeffs[3], u.x), u.y) / (bilinearCoeffs[0] + bilinearCoeffs[1] + bilinearCoeffs[2] + bilinearCoeffs[3]);
}

vector4_type bilinearCoeffs;
Copy link
Member Author

Choose a reason for hiding this comment

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

document which index/component maps to which vertex of the unit square

};

}
}
}

#endif
27 changes: 27 additions & 0 deletions include/nbl/builtin/hlsl/sampling/box_muller_transform.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2018-2023 - 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_BOX_MULLER_TRANSFORM_INCLUDED_
#define _NBL_BUILTIN_HLSL_BOX_MULLER_TRANSFORM_INCLUDED_

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

namespace nbl
{
namespace hlsl
{

template<typename T>
vector<T,2> boxMullerTransform(vector<T,2> xi, T stddev)
{
T sinPhi, cosPhi;
math::sincos<T>(2.0 * numbers::pi<float> * xi.y - numbers::pi<float>, sinPhi, cosPhi);
return vector<T,2>(cosPhi, sinPhi) * nbl::hlsl::sqrt(-2.0 * nbl::hlsl::log(xi.x)) * stddev;
}
Comment on lines +11 to +22
Copy link
Member Author

Choose a reason for hiding this comment

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

turn into struct with stddev as a member, also don't forget the sampling namespace


}
}

#endif
45 changes: 45 additions & 0 deletions include/nbl/builtin/hlsl/sampling/linear.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (C) 2018-2023 - 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_SAMPLING_LINEAR_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_LINEAR_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/limits.hlsl>

namespace nbl
{
namespace hlsl
{
namespace sampling
{

template<typename T>
struct Linear
{
using scalar_type = T;
using vector2_type = vector<T, 2>;

static Linear<T> create(NBL_CONST_REF_ARG(vector2_type) linearCoeffs)
Copy link
Member Author

Choose a reason for hiding this comment

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

need to document that they're start and end importance values

{
Linear<T> retval;
retval.linearCoeffs = linearCoeffs;
return retval;
}

scalar_type generate(scalar_type u)
{
const scalar_type rcpDiff = 1.0 / (linearCoeffs[0] - linearCoeffs[1]);
const vector2_type squaredCoeffs = linearCoeffs * linearCoeffs;
return nbl::hlsl::abs(rcpDiff) < numeric_limits<scalar_type>::max ? (linearCoeffs[0] - nbl::hlsl::sqrt(nbl::hlsl::mix(squaredCoeffs[0], squaredCoeffs[1], u))) * rcpDiff : u;
}

vector2_type linearCoeffs;
Comment on lines +27 to +38
Copy link
Member Author

@devshgraphicsprogramming devshgraphicsprogramming Nov 12, 2025

Choose a reason for hiding this comment

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

your members should be what can be precomputed from generate without knowing u so:

  • rcpDiff
  • squaredCoeffs

and obviously keep linearCoeffs[0]

Actually you could precompute squaredCoeffs[1]-squaredCoeffs[0] to turn mix into u*diff+base

};

}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (C) 2018-2023 - 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_SAMPLING_PROJECTED_SPHERICAL_TRIANGLE_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_PROJECTED_SPHERICAL_TRIANGLE_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/limits.hlsl>
#include <nbl/builtin/hlsl/math/functions.hlsl>
#include <nbl/builtin/hlsl/sampling/bilinear.hlsl>
#include <nbl/builtin/hlsl/sampling/spherical_triangle.hlsl>

namespace nbl
{
namespace hlsl
{
namespace sampling
{

template<typename T>
struct ProjectedSphericalTriangle
{
using scalar_type = T;
using vector2_type = vector<T, 2>;
using vector3_type = vector<T, 3>;
using vector4_type = vector<T, 4>;

static ProjectedSphericalTriangle<T> create(NBL_CONST_REF_ARG(shapes::SphericalTriangle<T>) tri)
{
ProjectedSphericalTriangle<T> retval;
retval.tri = tri;
return retval;
}

vector4_type computeBilinearPatch(NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF)
{
const scalar_type minimumProjSolidAngle = 0.0;

matrix<T, 3, 3> m = matrix<T, 3, 3>(tri.vertex0, tri.vertex1, tri.vertex2);
const vector3_type bxdfPdfAtVertex = math::conditionalAbsOrMax(isBSDF, nbl::hlsl::mul(m, receiverNormal), (vector3_type)minimumProjSolidAngle);

return bxdfPdfAtVertex.yyxz;
}

vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, scalar_type solidAngle, NBL_CONST_REF_ARG(vector3_type) cos_vertices, NBL_CONST_REF_ARG(vector3_type) sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF, NBL_CONST_REF_ARG(vector2_type) _u)
{
vector2_type u;
// pre-warp according to proj solid angle approximation
vector4_type patch = computeBilinearPatch(receiverNormal, isBSDF);
Bilinear<scalar_type> bilinear = Bilinear<scalar_type>::create(patch);
u = bilinear.generate(rcpPdf, u);

// now warp the points onto a spherical triangle
const vector3_type L = sphtri.generate(solidAngle, cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c, u);
rcpPdf *= solidAngle;

return L;
}

vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF, NBL_CONST_REF_ARG(vector2_type) u)
{
scalar_type cos_a, cos_c, csc_b, csc_c;
vector3_type cos_vertices, sin_vertices;
const scalar_type solidAngle = tri.solidAngleOfTriangle(cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c);
return generate(rcpPdf, solidAngle, cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c, receiverNormal, isBSDF, u);
}

scalar_type pdf(scalar_type solidAngle, NBL_CONST_REF_ARG(vector3_type) cos_vertices, NBL_CONST_REF_ARG(vector3_type) sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool receiverWasBSDF, NBL_CONST_REF_ARG(vector3_type) L)
{
scalar_type pdf;
const vector2_type u = sphtri.generateInverse(pdf, solidAngle, cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c, L);

vector4_type patch = computeBilinearPatch(receiverNormal, receiverWasBSDF);
Bilinear<scalar_type> bilinear = Bilinear<scalar_type>::create(patch);
return pdf * bilinear.pdf(u);
}

scalar_type pdf(NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool receiverWasBSDF, NBL_CONST_REF_ARG(vector3_type) L)
{
scalar_type pdf;
const vector2_type u = sphtri.generateInverse(pdf, L);

vector4_type patch = computeBilinearPatch(receiverNormal, receiverWasBSDF);
Bilinear<scalar_type> bilinear = Bilinear<scalar_type>::create(patch);
return pdf * bilinear.pdf(u);
}

shapes::SphericalTriangle<T> tri;
sampling::SphericalTriangle<T> sphtri;
};

}
}
}

#endif
Loading
Loading