-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathconcentric_mapping.hlsl
More file actions
53 lines (44 loc) · 1.17 KB
/
concentric_mapping.hlsl
File metadata and controls
53 lines (44 loc) · 1.17 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
47
48
49
50
51
52
53
// 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_CONCENTRIC_MAPPING_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_CONCENTRIC_MAPPING_INCLUDED_
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
#include "nbl/builtin/hlsl/tgmath.hlsl"
#include "nbl/builtin/hlsl/math/functions.hlsl"
namespace nbl
{
namespace hlsl
{
namespace sampling
{
template<typename T>
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);
vector<T, 2> p;
if (hlsl::all<vector<bool, 2> >(glsl::equal(u, hlsl::promote<vector<T, 2> >(0.0))))
p = hlsl::promote<vector<T, 2> >(0.0);
else
{
T r;
T theta;
if (abs<T>(u.x) > abs<T>(u.y))
{
r = u.x;
theta = 0.25 * numbers::pi<T> * (u.y / u.x);
}
else
{
r = u.y;
theta = 0.5 * numbers::pi<T> - 0.25 * numbers::pi<T> * (u.x / u.y);
}
p = r * vector<T, 2>(cos<T>(theta), sin<T>(theta));
}
return p;
}
} // namespace sampling
} // namespace hlsl
} // namespace nbl
#endif