Blender
V5.3
source
blender
draw
engines
eevee
shaders
eevee_octahedron_lib.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
12
float2
octahedral_uv_from_direction
(
float3
co)
13
{
14
/* Projection onto octahedron. */
15
co /=
dot
(
float3
(1.0f),
abs
(co));
16
17
/* Out-folding of the downward faces. */
18
if
(co.
z
< 0.0f) {
19
float2
sign
=
step
(0.0f, co.xy) * 2.0f - 1.0f;
20
co.xy = (1.0f -
abs
(co.yx)) *
sign
;
21
}
22
23
/* Mapping to [0;1]^2 texture space. */
24
float2
uvs = co.xy * (0.5f) + 0.5f;
25
26
return
uvs;
27
}
28
29
float3
octahedral_uv_to_direction
(
float2
co)
30
{
31
/* Change range to between [-1..1] */
32
co = co * 2.0f - 1.0f;
33
34
float2
abs_co =
abs
(co);
35
float3
v =
float3
(co, 1.0f - (abs_co.
x
+ abs_co.
y
));
36
37
if
(abs_co.
x
+ abs_co.
y
> 1.0f) {
38
v.xy = (
abs
(co.yx) - 1.0f) * -
sign
(co.xy);
39
}
40
41
return
v;
42
}
43
44
/* Mirror the UV if they are not on the diagonal or unit UV squares.
45
* Doesn't extend outside of [-1..2] range. But this is fine since we use it only for borders. */
46
float2
octahedral_mirror_repeat_uv
(
float2
uv)
47
{
48
float2
m =
abs
(uv - 0.5f) + 0.5f;
49
float2
f =
floor
(m);
50
float
x
= f.
x
- f.
y
;
51
if
(
x
!= 0.0f) {
52
uv.xy = 1.0f - uv.xy;
53
}
54
return
fract
(uv);
55
}
octahedral_mirror_repeat_uv
float2 octahedral_mirror_repeat_uv(float2 uv)
Definition
eevee_octahedron_lib.bsl.hh:46
octahedral_uv_from_direction
float2 octahedral_uv_from_direction(float3 co)
Definition
eevee_octahedron_lib.bsl.hh:12
octahedral_uv_to_direction
float3 octahedral_uv_to_direction(float2 co)
Definition
eevee_octahedron_lib.bsl.hh:29
gpu_shader_compat.hh
fract
T fract(T) RET
dot
float dot(VecOp< float, D >, VecOp< float, D >) RET
sign
constexpr T sign(T) RET
abs
#define abs
Definition
gpu_shader_cxx_builtin.hh:104
floor
#define floor
Definition
gpu_shader_cxx_builtin.hh:108
step
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
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
float3
Definition
sky_math.h:135
float3::z
float z
Definition
sky_math.h:136
Generated on
for Blender by
doxygen
1.18.0