Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
121 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
b3f6d55
Fixed `ResolveAccessor` concept
Przemog1 Nov 14, 2025
cf6760e
minor fixes to spherical rect, latest example
keptsecret Nov 17, 2025
4a283ba
quaternion struct, renamed spherical tri/rect shapes
keptsecret Nov 18, 2025
0305948
make PartitionRandVar in struct and templated
keptsecret Nov 18, 2025
3134254
precompute values in linear, bilinear sampling; make box muller a struct
keptsecret Nov 18, 2025
8d744a9
precompute cos_sides, csc_sides in shape spherical_tri
keptsecret Nov 19, 2025
2a22cb6
merge new rwmc fix
keptsecret Nov 19, 2025
8292707
fix spherical tri precompute
keptsecret Nov 20, 2025
563e072
latest example
keptsecret Nov 25, 2025
4abbacf
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Nov 25, 2025
229929d
update examples
Erfan-Ahmadi Nov 25, 2025
495924c
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Nov 26, 2025
27fd427
make rwmc accumulator match concept
keptsecret Nov 26, 2025
12cac68
took 1transformation_matrix_utils.hlsl` from Arek's `cameraz` branch
karimsayedre Nov 26, 2025
438aeb5
Merge remote-tracking branch 'origin/hlsl_path_tracer_example' into i…
karimsayedre Nov 26, 2025
d125a0e
pack rwmc params to half 2x16
keptsecret Nov 27, 2025
1ccc4c4
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Nov 27, 2025
aa716ee
merge imguizmo-lights, fix conflicts
keptsecret Nov 28, 2025
8a6939f
latest example
keptsecret Nov 28, 2025
fbfde73
change quaternion struct name to match what it will be
keptsecret Dec 2, 2025
856f828
merge master, fix conflicts
keptsecret Dec 2, 2025
07918be
Merge branch 'master' into hlsl_path_tracer_example_no_quat
keptsecret Dec 4, 2025
37d5c5a
removed temp fix for mix_helper require
keptsecret Dec 4, 2025
6971906
fixes more nan problems + a few bugs in iridescent fresnel
keptsecret Dec 5, 2025
cb68928
fixes iridescent fresnel under transmission
keptsecret Dec 5, 2025
76ed66c
fix wrong get refraction eta in iridescent transmission
keptsecret Dec 5, 2025
4a8f4dc
quantized sequence packing data
keptsecret Dec 8, 2025
b8688be
templated quantized sequence
keptsecret Dec 9, 2025
2146003
Merge branch 'master' into hlsl_path_tracer_example_no_quat
keptsecret Dec 9, 2025
38bbf04
latest example
keptsecret Dec 9, 2025
fae7a80
quantized sequence decode
keptsecret Dec 9, 2025
e23538c
quantized sequence get/set values by index, simplify decode func spec…
keptsecret Dec 10, 2025
6e9160e
quantized sequence encode should right shift input, changed scramble …
keptsecret Dec 10, 2025
6f0d012
added decode variant for scramble before decode
keptsecret Dec 11, 2025
3d53866
Merge branch 'master' into hlsl_path_tracer_example_no_quat
keptsecret Dec 11, 2025
c6462d1
some minor fixes to quantized sequence set, decode
keptsecret Dec 12, 2025
a30f083
fix quantized sequence mask being too small, assert conditions
keptsecret Dec 15, 2025
073a9f3
merge master, fix conflicts
keptsecret Dec 15, 2025
7d16cb2
fixed problems from merging master
keptsecret Dec 15, 2025
965e028
fix decode scramble key, shifting discard bits in quantization
keptsecret Dec 15, 2025
cfd5500
fix z component storing too many bits in quantized sequence in vec2 d…
keptsecret Dec 15, 2025
53ff444
mix_helper requirements include bool vectors
keptsecret Dec 16, 2025
5055713
fix iridescent oriented eta bug
keptsecret Dec 16, 2025
3f3b5c9
partitionRandVar stores leftProb, fix minor bugs
keptsecret Dec 16, 2025
db454c0
plain const for vector types
keptsecret Dec 16, 2025
c353ab3
fixes to iridescent fresnel, moved getOrientedEtaRcp to dielectric fr…
keptsecret Dec 16, 2025
04f1c76
adjust mix_helper calling select requirements
keptsecret Dec 16, 2025
94a778f
restore regular triangle stuff, refactor usage
keptsecret Dec 16, 2025
9e4a16c
minor changes to rwmc usage
keptsecret Dec 16, 2025
62c79b4
remove storing texture inside local var of ResolveAccessorAdaptor
keptsecret Dec 16, 2025
5075c63
removed accessor, user should provide accessor that matches concept
keptsecret Dec 16, 2025
90007e6
fix formatting, name
keptsecret Dec 16, 2025
3d36c13
added more things to precompute
keptsecret Dec 16, 2025
62f2c99
changes to splatting params precompute for the last time
keptsecret Dec 16, 2025
f3f60c6
check that eta type of dielectric fresnels should be monochrome
keptsecret Dec 16, 2025
b4d957d
Change `Compile flag error` to `Compile flag warning`
devshgraphicsprogramming Dec 16, 2025
dfcae2d
Merge remote-tracking branch 'remotes/origin/master' into hlsl_path_t…
devshgraphicsprogramming Dec 16, 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
5 changes: 3 additions & 2 deletions include/nbl/builtin/hlsl/bxdf/base/cook_torrance_base.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ struct SCookTorrance
const scalar_type NdotV = localV.z;

fresnel_type _f = __getOrientedFresnel(fresnel, NdotV);
fresnel::OrientedEtaRcps<monochrome_type> rcpEta = _f.getOrientedEtaRcps();
fresnel::OrientedEtaRcps<monochrome_type> rcpEta = _f.getRefractionOrientedEtaRcps();

const vector3_type upperHemisphereV = ieee754::flipSignIfRHSNegative<vector3_type>(localV, hlsl::promote<vector3_type>(NdotV));
const vector3_type localH = ndf.generateH(upperHemisphereV, u.xy);
Expand All @@ -304,7 +304,8 @@ struct SCookTorrance
scalar_type rcpChoiceProb;
scalar_type z = u.z;
sampling::PartitionRandVariable<scalar_type> partitionRandVariable;
bool transmitted = partitionRandVariable(reflectance, z, rcpChoiceProb);
partitionRandVariable.leftProb = reflectance;
bool transmitted = partitionRandVariable(z, rcpChoiceProb);

const scalar_type LdotH = hlsl::mix(VdotH, ieee754::copySign(hlsl::sqrt(rcpEta.value2[0]*VdotH*VdotH + scalar_type(1.0) - rcpEta.value2[0]), -VdotH), transmitted);
bool valid;
Expand Down
51 changes: 26 additions & 25 deletions include/nbl/builtin/hlsl/bxdf/fresnel.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ NBL_CONCEPT_BEGIN(2)
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
((NBL_CONCEPT_REQ_TYPE)(T::vector_type))
((NBL_CONCEPT_REQ_TYPE)(T::eta_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((fresnel(cosTheta)), ::nbl::hlsl::is_same_v, typename T::vector_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((fresnel.getOrientedEtaRcps()), ::nbl::hlsl::is_same_v, OrientedEtaRcps<typename T::eta_type>))
);
#undef cosTheta
#undef fresnel
Expand All @@ -331,7 +329,9 @@ NBL_CONCEPT_BEGIN(2)
#define cosTheta NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(Fresnel, T))
((NBL_CONCEPT_REQ_TYPE)(T::eta_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((fresnel.getRefractionOrientedEta()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((fresnel.getRefractionOrientedEtaRcps()), ::nbl::hlsl::is_same_v, OrientedEtaRcps<typename T::eta_type>))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((fresnel.getReorientedFresnel(cosTheta)), ::nbl::hlsl::is_same_v, T))
);
#undef cosTheta
Expand Down Expand Up @@ -362,7 +362,7 @@ struct Schlick
return F0 + (1.0 - F0) * x*x*x*x*x;
}

OrientedEtaRcps<eta_type> getOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
OrientedEtaRcps<eta_type> getRefractionOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
{
const eta_type sqrtF0 = hlsl::sqrt(F0);
OrientedEtaRcps<eta_type> rcpEta;
Expand Down Expand Up @@ -424,13 +424,13 @@ struct Conductor
return (rs2 + rp2) * hlsl::promote<T>(0.5);
}

OrientedEtaRcps<eta_type> getOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
{
OrientedEtaRcps<eta_type> rcpEta;
rcpEta.value = hlsl::promote<eta_type>(1.0) / eta;
rcpEta.value2 = rcpEta.value * rcpEta.value;
return rcpEta;
}
// OrientedEtaRcps<eta_type> getRefractionOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
// {
// OrientedEtaRcps<eta_type> rcpEta;
// rcpEta.value = hlsl::promote<eta_type>(1.0) / eta;
// rcpEta.value2 = rcpEta.value * rcpEta.value;
// return rcpEta;
// }

T eta;
T etak2;
Expand Down Expand Up @@ -484,7 +484,7 @@ struct Dielectric
// default to monochrome, but it is possible to have RGB fresnel without dispersion fixing the refraction Eta
// to be something else than the etas used to compute RGB reflectance or some sort of interpolation of them
scalar_type getRefractionOrientedEta() NBL_CONST_MEMBER_FUNC { return orientedEta.value[0]; }
OrientedEtaRcps<T> getOrientedEtaRcps() NBL_CONST_MEMBER_FUNC { return orientedEta.getReciprocals(); }
OrientedEtaRcps<eta_type> getRefractionOrientedEtaRcps() NBL_CONST_MEMBER_FUNC { return orientedEta.getReciprocals(); }

Dielectric<T> getReorientedFresnel(const scalar_type NdotI) NBL_CONST_MEMBER_FUNC
{
Expand Down Expand Up @@ -548,8 +548,6 @@ struct iridescent_helper
static T __call(const vector_type _D, const vector_type ior1, const vector_type ior2, const vector_type ior3, const vector_type iork3,
const vector_type eta12, const vector_type eta23, const vector_type etak23, const scalar_type clampedCosTheta)
{
const vector_type wavelengths = vector_type(Colorspace::wavelength_R, Colorspace::wavelength_G, Colorspace::wavelength_B);

const scalar_type cosTheta_1 = clampedCosTheta;
vector_type R12p, R23p, R12s, R23s;
vector_type cosTheta_2;
Expand Down Expand Up @@ -589,7 +587,6 @@ struct iridescent_helper

// Optical Path Difference
const vector_type D = _D * cosTheta_2;
const vector_type Dphi = hlsl::promote<vector_type>(2.0 * numbers::pi<scalar_type>) * D / wavelengths;

vector_type phi21p, phi21s, phi23p, phi23s, r123s, r123p, Rs;
vector_type I = hlsl::promote<vector_type>(0.0);
Expand Down Expand Up @@ -635,7 +632,7 @@ struct iridescent_helper
I += Cm*Sm;
}

return hlsl::max(colorspace::scRGB::FromXYZ(I) * hlsl::promote<vector_type>(0.5), hlsl::promote<vector_type>(0.0));
return hlsl::max(Colorspace::FromXYZ(I) * hlsl::promote<vector_type>(0.5), hlsl::promote<vector_type>(0.0));
}
};

Expand All @@ -652,6 +649,7 @@ struct iridescent_base
vector_type iork3;
vector_type eta12; // outside (usually air 1.0) -> thin-film IOR
vector_type eta23; // thin-film -> base material IOR
vector_type eta13;
};
}

Expand Down Expand Up @@ -688,6 +686,7 @@ struct Iridescent<T, false, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoi
retval.eta12 = params.ior2/params.ior1;
retval.eta23 = params.ior3/params.ior2;
retval.etak23 = params.iork3/params.ior2;
retval.eta13 = params.ior3/params.ior1;
return retval;
}

Expand All @@ -697,13 +696,13 @@ struct Iridescent<T, false, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoi
base_type::eta12, base_type::eta23, getEtak23(), clampedCosTheta);
}

OrientedEtaRcps<eta_type> getOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
{
OrientedEtaRcps<eta_type> rcpEta;
rcpEta.value = hlsl::promote<eta_type>(1.0) / base_type::eta23;
rcpEta.value2 = rcpEta.value * rcpEta.value;
return rcpEta;
}
// OrientedEtaRcps<eta_type> getRefractionOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
// {
// OrientedEtaRcps<eta_type> rcpEta;
// rcpEta.value = hlsl::promote<eta_type>(1.0) / base_type::eta13;
// rcpEta.value2 = rcpEta.value * rcpEta.value;
// return rcpEta;
// }

vector_type getEtak23() NBL_CONST_MEMBER_FUNC
{
Expand Down Expand Up @@ -743,6 +742,7 @@ struct Iridescent<T, true, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoin
retval.ior3 = params.ior3;
retval.eta12 = params.ior2/params.ior1;
retval.eta23 = params.ior3/params.ior2;
retval.eta13 = params.ior3/params.ior1;
return retval;
}

Expand All @@ -752,11 +752,11 @@ struct Iridescent<T, true, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoin
base_type::eta12, base_type::eta23, getEtak23(), clampedCosTheta);
}

scalar_type getRefractionOrientedEta() NBL_CONST_MEMBER_FUNC { return base_type::ior3[0] / base_type::ior1[0]; }
OrientedEtaRcps<eta_type> getOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
scalar_type getRefractionOrientedEta() NBL_CONST_MEMBER_FUNC { return base_type::eta13[0]; }
OrientedEtaRcps<eta_type> getRefractionOrientedEtaRcps() NBL_CONST_MEMBER_FUNC
{
OrientedEtaRcps<eta_type> rcpEta;
rcpEta.value = base_type::ior1[0] / base_type::ior3[0];
rcpEta.value = hlsl::promote<eta_type>(1.0) / hlsl::promote<eta_type>(base_type::eta13[0]);
rcpEta.value2 = rcpEta.value * rcpEta.value;
return rcpEta;
}
Expand All @@ -771,6 +771,7 @@ struct Iridescent<T, true, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoin
orientedFresnel.ior3 = hlsl::mix(base_type::ior3, base_type::ior1, flip);
orientedFresnel.eta12 = hlsl::mix(base_type::eta12, hlsl::promote<vector_type>(1.0)/base_type::eta23, flip);
orientedFresnel.eta23 = hlsl::mix(base_type::eta23, hlsl::promote<vector_type>(1.0)/base_type::eta12, flip);
orientedFresnel.eta13 = hlsl::mix(base_type::eta13, hlsl::promote<vector_type>(1.0)/base_type::eta13, flip);
return orientedFresnel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ struct SSmoothDielectric

scalar_type rcpChoiceProb;
sampling::PartitionRandVariable<scalar_type> partitionRandVariable;
bool transmitted = partitionRandVariable(reflectance, u.z, rcpChoiceProb);
partitionRandVariable.leftProb = reflectance;
bool transmitted = partitionRandVariable(u.z, rcpChoiceProb);

ray_dir_info_type V = interaction.getV();
Refract<scalar_type> r = Refract<scalar_type>::create(V.getDirection(), interaction.getN());
Expand Down Expand Up @@ -128,7 +129,8 @@ struct SThinSmoothDielectric
scalar_type rcpChoiceProb;
scalar_type z = u.z;
sampling::PartitionRandVariable<scalar_type> partitionRandVariable;
const bool transmitted = partitionRandVariable(reflectionProb, z, rcpChoiceProb);
partitionRandVariable.leftProb = reflectionProb;
const bool transmitted = partitionRandVariable(z, rcpChoiceProb);
remainderMetadata = hlsl::mix(reflectance, hlsl::promote<spectral_type>(1.0) - reflectance, transmitted) * rcpChoiceProb;

ray_dir_info_type V = interaction.getV();
Expand Down
12 changes: 7 additions & 5 deletions include/nbl/builtin/hlsl/sampling/basic.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ template<typename T NBL_PRIMARY_REQUIRES(concepts::FloatingPointLikeScalar<T>)
struct PartitionRandVariable
{
using floating_point_type = T;
using uint_type = typename unsigned_integer_of_size<sizeof(floating_point_type)>::type;
using uint_type = unsigned_integer_of_size_t<sizeof(floating_point_type)>;

bool operator()(floating_point_type leftProb, NBL_REF_ARG(floating_point_type) xi, NBL_REF_ARG(floating_point_type) rcpChoiceProb)
bool operator()(NBL_REF_ARG(floating_point_type) xi, NBL_REF_ARG(floating_point_type) rcpChoiceProb)
{
const floating_point_type NEXT_ULP_AFTER_UNITY = bit_cast<floating_point_type>(bit_cast<uint_type>(floating_point_type(1.0)) + uint_type(1u));
const bool pickRight = xi >= leftProb * NEXT_ULP_AFTER_UNITY;
const floating_point_type NextULPAfterUnity = bit_cast<floating_point_type>(bit_cast<uint_type>(floating_point_type(1.0)) + uint_type(1u));
const bool pickRight = xi >= leftProb * NextULPAfterUnity;

// This is all 100% correct taking into account the above NEXT_ULP_AFTER_UNITY
// This is all 100% correct taking into account the above NextULPAfterUnity
xi -= pickRight ? leftProb : floating_point_type(0.0);

rcpChoiceProb = floating_point_type(1.0) / (pickRight ? (floating_point_type(1.0) - leftProb) : leftProb);
xi *= rcpChoiceProb;

return pickRight;
}

floating_point_type leftProb;
};


Expand Down
12 changes: 6 additions & 6 deletions include/nbl/builtin/hlsl/sampling/bilinear.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ struct Bilinear
using vector3_type = vector<T, 3>;
using vector4_type = vector<T, 4>;

static Bilinear<T> create(NBL_CONST_REF_ARG(vector4_type) bilinearCoeffs)
static Bilinear<T> create(const vector4_type bilinearCoeffs)
{
Bilinear<T> retval;
retval.bilinearCoeffs = bilinearCoeffs;
retval.twiceAreasUnderXCurve = vector2_type(bilinearCoeffs[0] + bilinearCoeffs[1], bilinearCoeffs[2] + bilinearCoeffs[3]);
return retval;
}

vector2_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector2_type) _u)
vector2_type generate(NBL_REF_ARG(scalar_type) rcpPdf, const vector2_type _u)
{
vector2_type u = _u;
vector2_type u;
Linear<scalar_type> lineary = Linear<scalar_type>::create(twiceAreasUnderXCurve);
u.y = lineary.generate(u.y);
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);
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)
scalar_type pdf(const 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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct BoxMullerTransform
using scalar_type = T;
using vector2_type = vector<T,2>;

vector2_type operator()(vector2_type xi)
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);
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/sampling/concentric_mapping.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace sampling
{

template<typename T>
vector<T,2> concentricMapping(vector<T,2> _u)
vector<T,2> concentricMapping(const vector<T,2> _u)
{
//map [0;1]^2 to [-1;1]^2
vector<T,2> u = 2.0f * _u - hlsl::promote<vector<T,2> >(1.0);
Expand Down
10 changes: 5 additions & 5 deletions include/nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ struct ProjectedHemisphere
using vector_t2 = vector<T, 2>;
using vector_t3 = vector<T, 3>;

static vector_t3 generate(vector_t2 _sample)
static vector_t3 generate(const vector_t2 _sample)
{
vector_t2 p = concentricMapping<T>(_sample * T(0.99999) + T(0.000005));
T z = hlsl::sqrt<T>(hlsl::max<T>(T(0.0), T(1.0) - p.x * p.x - p.y * p.y));
return vector_t3(p.x, p.y, z);
}

static T pdf(T L_z)
static T pdf(const T L_z)
{
return L_z * numbers::inv_pi<float>;
}

template<typename U=vector<T,1> >
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(T L)
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(const T L)
{
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L));
}

template<typename U=vector<T,1> >
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(vector_t3 L)
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(const vector_t3 L)
{
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L.z));
}
Expand Down Expand Up @@ -77,7 +77,7 @@ struct ProjectedSphere
}

template<typename U=vector<T,1> >
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(vector_t3 L)
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(const vector_t3 L)
{
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L.z));
}
Expand Down
4 changes: 2 additions & 2 deletions include/nbl/builtin/hlsl/sampling/linear.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Linear
using scalar_type = T;
using vector2_type = vector<T, 2>;

static Linear<T> create(NBL_CONST_REF_ARG(vector2_type) linearCoeffs) // start and end importance values (start, end)
static Linear<T> create(const vector2_type linearCoeffs) // start and end importance values (start, end)
{
Linear<T> retval;
retval.linearCoeffStart = linearCoeffs[0];
Expand All @@ -32,7 +32,7 @@ struct Linear
return retval;
}

scalar_type generate(scalar_type u)
scalar_type generate(const scalar_type u)
{
return hlsl::mix(u, (linearCoeffStart - hlsl::sqrt(squaredCoeffStart + u * squaredCoeffDiff)) * rcpDiff, hlsl::abs(rcpDiff) < numeric_limits<scalar_type>::max);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ struct ProjectedSphericalTriangle
return retval;
}

vector4_type computeBilinearPatch(NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF)
vector4_type computeBilinearPatch(const 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);
const vector3_type bxdfPdfAtVertex = math::conditionalAbsOrMax(isBSDF, nbl::hlsl::mul(m, receiverNormal), hlsl::promote<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)
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, scalar_type solidAngle, const vector3_type cos_vertices, const vector3_type sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, const vector3_type receiverNormal, bool isBSDF, const 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);
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);
Expand All @@ -58,15 +58,15 @@ struct ProjectedSphericalTriangle
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)
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, const vector3_type receiverNormal, bool isBSDF, const 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(scalar_type solidAngle, const vector3_type cos_vertices, const vector3_type sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, const vector3_type receiverNormal, bool receiverWasBSDF, const 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);
Expand All @@ -76,7 +76,7 @@ struct ProjectedSphericalTriangle
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 vector3_type receiverNormal, bool receiverWasBSDF, const vector3_type L)
{
scalar_type pdf;
const vector2_type u = sphtri.generateInverse(pdf, L);
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/sampling/spherical_rectangle.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct SphericalRectangle
return retval;
}

vector2_type generate(NBL_CONST_REF_ARG(vector2_type) rectangleExtents, NBL_CONST_REF_ARG(vector2_type) uv, NBL_REF_ARG(scalar_type) S)
vector2_type generate(const vector2_type rectangleExtents, const vector2_type uv, NBL_REF_ARG(scalar_type) S)
{
const vector4_type denorm_n_z = vector4_type(-rect.r0.y, rect.r0.x + rectangleExtents.x, rect.r0.y + rectangleExtents.y, -rect.r0.x);
const vector4_type n_z = denorm_n_z / hlsl::sqrt<vector4_type>(hlsl::promote<vector4_type>(rect.r0.z * rect.r0.z) + denorm_n_z * denorm_n_z);
Expand Down
Loading
Loading