Blender V5.3
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
8
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
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. */
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}
float2 octahedral_mirror_repeat_uv(float2 uv)
float2 octahedral_uv_from_direction(float3 co)
float3 octahedral_uv_to_direction(float2 co)
T fract(T) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T sign(T) RET
#define abs
#define floor
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float x
float y
float z
Definition sky_math.h:136