-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathbasic.hlsl
More file actions
46 lines (34 loc) · 1.33 KB
/
basic.hlsl
File metadata and controls
46 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2018-2025 - 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_BASIC_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_BASIC_INCLUDED_
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/ieee754.hlsl>
namespace nbl
{
namespace hlsl
{
namespace sampling
{
template<typename T NBL_PRIMARY_REQUIRES(concepts::FloatingPointLikeScalar<T>)
struct PartitionRandVariable
{
using floating_point_type = T;
using uint_type = unsigned_integer_of_size_t<sizeof(floating_point_type)>;
bool operator()(NBL_REF_ARG(floating_point_type) xi, NBL_REF_ARG(floating_point_type) rcpChoiceProb)
{
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 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;
};
}
}
}
#endif