Skip to content

Commit 1add8a3

Browse files
committed
minor changes to sphere sampling, rng usage
1 parent 061f7d8 commit 1add8a3

File tree

7 files changed

+35
-33
lines changed

7 files changed

+35
-33
lines changed

include/nbl/builtin/hlsl/bxdf/fresnel.hlsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
99
#include "nbl/builtin/hlsl/concepts.hlsl"
1010
#include "nbl/builtin/hlsl/numbers.hlsl"
11+
#include "nbl/builtin/hlsl/complex.hlsl"
1112
#include "nbl/builtin/hlsl/vector_utils/vector_traits.hlsl"
1213

1314
namespace nbl
@@ -316,6 +317,15 @@ struct Conductor
316317
return retval;
317318
}
318319

320+
static Conductor<T> create(NBL_CONST_REF_ARG(complex_t<T>) eta, scalar_type clampedCosTheta)
321+
{
322+
Conductor<T> retval;
323+
retval.eta = eta.real();
324+
retval.etak2 = eta.imag()*eta.imag();
325+
retval.clampedCosTheta = clampedCosTheta;
326+
return retval;
327+
}
328+
319329
T operator()()
320330
{
321331
const scalar_type cosTheta2 = clampedCosTheta * clampedCosTheta;

include/nbl/builtin/hlsl/random/dim_adaptor_recursive.hlsl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _NBL_HLSL_RANDOM_DIM_ADAPTOR_RECURSIVE_INCLUDED_
22
#define _NBL_HLSL_RANDOM_DIM_ADAPTOR_RECURSIVE_INCLUDED_
33

4+
#include <nbl/builtin/hlsl/macros.h>
45
#include "nbl/builtin/hlsl/type_traits.hlsl"
56

67
namespace nbl
@@ -17,7 +18,7 @@ struct DimAdaptorRecursive
1718
using rng_type = RNG;
1819
using return_type = vector<uint32_t, DIM>;
1920

20-
static DimAdaptorRecursive<RNG, DIM> construct(rng_type rng)
21+
static DimAdaptorRecursive<RNG, DIM> construct(NBL_REF_ARG(rng_type) rng)
2122
{
2223
DimAdaptorRecursive<RNG, DIM> retval;
2324
retval.rng = rng;
@@ -29,10 +30,7 @@ struct DimAdaptorRecursive
2930
array_set<return_type, uint32_t> setter;
3031

3132
return_type retval;
32-
#ifdef __HLSL_VERSION
33-
[unroll]
34-
#endif
35-
for (uint32_t i = 0; i < DIM; i++)
33+
NBL_UNROLL for (uint32_t i = 0; i < DIM; i++)
3634
setter(retval, i, rng());
3735
return retval;
3836
}

include/nbl/builtin/hlsl/random/lcg.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Lcg
1515
{
1616
using seed_type = uint32_t;
1717

18-
static Lcg create(NBL_CONST_REF_ARG(seed_type) _state)
18+
static Lcg create(const seed_type _state)
1919
{
2020
Lcg retval;
2121
retval.state = _state;

include/nbl/builtin/hlsl/random/pcg.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct PCG32
1515
{
1616
using seed_type = uint32_t;
1717

18-
static PCG32 construct(NBL_CONST_REF_ARG(seed_type) initialState)
18+
static PCG32 construct(const seed_type initialState)
1919
{
2020
PCG32 retval;
2121
retval.state = initialState;

include/nbl/builtin/hlsl/random/xoroshiro.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct Xoroshiro64Star
3333
using seed_type = uint32_t2;
3434

3535
// TODO: create
36-
static Xoroshiro64Star construct(NBL_CONST_REF_ARG(seed_type) initialState)
36+
static Xoroshiro64Star construct(const seed_type initialState)
3737
{
3838
Xoroshiro64StateHolder stateHolder = {initialState};
3939
return Xoroshiro64Star(stateHolder);
@@ -55,7 +55,7 @@ struct Xoroshiro64StarStar
5555
using seed_type = uint32_t2;
5656

5757
// TODO: create
58-
static Xoroshiro64StarStar construct(NBL_CONST_REF_ARG(seed_type) initialState)
58+
static Xoroshiro64StarStar construct(const seed_type initialState)
5959
{
6060
Xoroshiro64StateHolder stateHolder = {initialState};
6161
return Xoroshiro64StarStar(stateHolder);

include/nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@ struct ProjectedHemisphere
3434
return L_z * numbers::inv_pi<float>;
3535
}
3636

37-
template<typename U=T NBL_FUNC_REQUIRES(is_scalar_v<U>)
38-
static sampling::quotient_and_pdf<vector<U,1>, T> quotient_and_pdf(T L)
37+
template<typename U=vector<T,1> >
38+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(T L)
3939
{
40-
using vector_t1 = vector<U,1>;
41-
return sampling::quotient_and_pdf<vector_t1, T>::create(hlsl::promote<vector_t1>(1.0), pdf(L));
40+
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L));
4241
}
4342

44-
template<typename U=T NBL_FUNC_REQUIRES(is_scalar_v<U>)
45-
static sampling::quotient_and_pdf<vector<U,1>, T> quotient_and_pdf(vector_t3 L)
43+
template<typename U=vector<T,1> >
44+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(vector_t3 L)
4645
{
47-
using vector_t1 = vector<U,1>;
48-
return sampling::quotient_and_pdf<vector_t1, T>::create(hlsl::promote<vector_t1>(1.0), pdf(L.z));
46+
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L.z));
4947
}
5048
};
5149

@@ -72,18 +70,16 @@ struct ProjectedSphere
7270
return T(0.5) * hemisphere_t::pdf(L_z);
7371
}
7472

75-
template<typename U=T NBL_FUNC_REQUIRES(is_scalar_v<U>)
76-
static sampling::quotient_and_pdf<vector<U,1>, T> quotient_and_pdf(T L)
73+
template<typename U=vector<T,1> >
74+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(T L)
7775
{
78-
using vector_t1 = vector<U,1>;
79-
return sampling::quotient_and_pdf<vector_t1, T>::create(hlsl::promote<vector_t1>(1.0), pdf(L));
76+
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L));
8077
}
8178

82-
template<typename U=T NBL_FUNC_REQUIRES(is_scalar_v<U>)
83-
static sampling::quotient_and_pdf<vector<U,1>, T> quotient_and_pdf(vector_t3 L)
79+
template<typename U=vector<T,1> >
80+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(vector_t3 L)
8481
{
85-
using vector_t1 = vector<U,1>;
86-
return sampling::quotient_and_pdf<vector_t1, T>::create(hlsl::promote<vector_t1>(1.0), pdf(L.z));
82+
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L.z));
8783
}
8884
};
8985

include/nbl/builtin/hlsl/sampling/uniform_spheres.hlsl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ struct UniformHemisphere
3636
return T(1.0) / (T(2.0) * numbers::pi<T>);
3737
}
3838

39-
template<typename U=T NBL_FUNC_REQUIRES(is_scalar_v<U>)
40-
static quotient_and_pdf<vector<U,1>, T> quotient_and_pdf()
39+
template<typename U=vector<T,1> >
40+
static quotient_and_pdf<U, T> quotient_and_pdf()
4141
{
42-
using vector_t1 = vector<U,1>;
43-
return quotient_and_pdf<vector_t1, T>::create(hlsl::promote<vector_t1>(1.0), pdf());
42+
return quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf());
4443
}
4544
};
4645

@@ -63,11 +62,10 @@ struct UniformSphere
6362
return T(1.0) / (T(4.0) * numbers::pi<T>);
6463
}
6564

66-
template<typename U=T NBL_FUNC_REQUIRES(is_scalar_v<U>)
67-
static quotient_and_pdf<vector<U,1>, T> quotient_and_pdf()
65+
template<typename U=vector<T,1> >
66+
static quotient_and_pdf<U, T> quotient_and_pdf()
6867
{
69-
using vector_t1 = vector<U,1>;
70-
return quotient_and_pdf<vector_t1, T>::create(hlsl::promote<vector_t1>(1.0), pdf());
68+
return quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf());
7169
}
7270
};
7371
}

0 commit comments

Comments
 (0)