Blender
V5.3
source
blender
gpu
shaders
common
gpu_shader_math_fast.bsl.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#pragma once
6
7
#include "
gpu_shader_compat.hh
"
8
#include "
gpu_shader_math_constants.bsl.hh
"
9
10
/* [Drobot2014a] Low Level Optimizations for GCN. */
11
float
sqrt_fast
(
float
v)
12
{
13
return
intBitsToFloat
(0x1fbd1df5 + (
floatBitsToInt
(v) >> 1));
14
}
15
float2
sqrt_fast
(
float2
v)
16
{
17
return
intBitsToFloat
(0x1fbd1df5 + (
floatBitsToInt
(v) >> 1));
18
}
19
20
/* [Eberly2014] GPGPU Programming for Games and Science. */
21
float
acos_fast
(
float
v)
22
{
23
float
res = -0.156583f *
abs
(v) +
M_PI_2
;
24
res *=
sqrt_fast
(1.0f -
abs
(v));
25
return
(v >= 0) ? res :
M_PI
- res;
26
}
27
float2
acos_fast
(
float2
v)
28
{
29
float2
res = -0.156583f *
abs
(v) +
M_PI_2
;
30
res *=
sqrt_fast
(1.0f -
abs
(v));
31
v.x = (v.x >= 0) ? res.
x
:
M_PI
- res.
x
;
32
v.y = (v.y >= 0) ? res.
y
:
M_PI
- res.
y
;
33
return
v;
34
}
35
36
float
atan_fast
(
float
x
)
37
{
38
float
a =
abs
(
x
);
39
float
k = a > 1.0f ? (1.0f / a) : a;
40
float
s = 1.0f - (1.0f - k);
/* Crush denormals. */
41
float
t = s * s;
42
/* http://mathforum.org/library/drmath/view/62672.html
43
* Examined 4278190080 values of atan:
44
* 2.36864877 avg ULP diff, 302 max ULP, 6.55651e-06f max error // (with denormals)
45
* Examined 4278190080 values of atan:
46
* 171160502 avg ULP diff, 855638016 max ULP, 6.55651e-06f max error // (crush denormals)
47
*/
48
float
r = s *
fma
(0.43157974f, t, 1.0f) /
fma
(
fma
(0.05831938f, t, 0.76443945f), t, 1.0f);
49
if
(a > 1.0f) {
50
r = 1.57079632679489661923f - r;
51
}
52
return
(
x
< 0.0f) ? -r : r;
53
}
M_PI_2
#define M_PI_2
Definition
BLI_math_constants.hh:27
M_PI
#define M_PI
Definition
BLI_math_constants.hh:21
gpu_shader_compat.hh
floatBitsToInt
VecBase< int, D > floatBitsToInt(VecOp< float, D >) RET
intBitsToFloat
VecBase< float, D > intBitsToFloat(VecOp< int, D >) RET
abs
#define abs
Definition
gpu_shader_cxx_builtin.hh:104
fma
#define fma
Definition
gpu_shader_cxx_builtin.hh:109
gpu_shader_math_constants.bsl.hh
atan_fast
float atan_fast(float x)
Definition
gpu_shader_math_fast.bsl.hh:36
sqrt_fast
float sqrt_fast(float v)
Definition
gpu_shader_math_fast.bsl.hh:11
acos_fast
float acos_fast(float v)
Definition
gpu_shader_math_fast.bsl.hh:21
x
uint x
Definition
kernel/device/gpu/kernel.h:142
float2
Definition
types_float2.h:13
float2::x
float x
Definition
types_float2.h:14
float2::y
float y
Definition
types_float2.h:14
Generated on
for Blender by
doxygen
1.18.0