Blender V5.3
eevee_transform.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
8
9#pragma once
10
12
13#ifndef GPU_SHADER
14namespace blender::eevee {
15#endif
16
21 /* The transform is stored transposed for compactness. */
25
26#ifndef GPU_SHADER
27 Transform() = default;
29 : x(tx[0][0], tx[1][0], tx[2][0], tx[3][0]),
30 y(tx[0][1], tx[1][1], tx[2][1], tx[3][1]),
31 z(tx[0][2], tx[1][2], tx[2][2], tx[3][2])
32 {
33 }
34
35 operator float4x4() const
36 {
37 return float4x4(float4(x.x, y.x, z.x, 0.0f),
38 float4(x.y, y.y, z.y, 0.0f),
39 float4(x.z, y.z, z.z, 0.0f),
40 float4(x.w, y.w, z.w, 1.0f));
41 }
42#endif
43
44 float3 x_axis() const
45 {
46 return float3(x.x, y.x, z.x);
47 }
48 float3 y_axis() const
49 {
50 return float3(x.y, y.y, z.y);
51 }
52 float3 z_axis() const
53 {
54 return float3(x.z, y.z, z.z);
55 }
57 {
58 return float3(x.w, y.w, z.w);
59 }
60};
61
63{
64 return float4x4(float4(t.x.x, t.y.x, t.z.x, 0.0f),
65 float4(t.x.y, t.y.y, t.z.y, 0.0f),
66 float4(t.x.z, t.y.z, t.z.z, 0.0f),
67 float4(t.x.w, t.y.w, t.z.w, 1.0f));
68}
69
71{
72 Transform t;
73 t.x = float4(m[0][0], m[1][0], m[2][0], m[3][0]);
74 t.y = float4(m[0][1], m[1][1], m[2][1], m[3][1]);
75 t.z = float4(m[0][2], m[1][2], m[2][2], m[3][2]);
76 return t;
77}
78
79#ifdef GPU_SHADER
80static inline bool transform_equal(Transform a, Transform b)
81{
82 return all(equal(a.x, b.x)) && all(equal(a.y, b.y)) && all(equal(a.z, b.z));
83}
84#endif
85
86static inline float3 transform_point(Transform t, float3 point)
87{
88 return float4(point, 1.0f) * float3x4(t.x, t.y, t.z);
89}
90
91static inline float3 transform_direction(Transform t, float3 direction)
92{
93 return direction * float3x3(float3(t.x.x, t.x.y, t.x.z),
94 float3(t.y.x, t.y.y, t.y.z),
95 float3(t.z.x, t.z.y, t.z.z));
96}
97
99{
100 return float3x3(float3(t.x.x, t.x.y, t.x.z),
101 float3(t.y.x, t.y.y, t.y.z),
102 float3(t.z.x, t.z.y, t.z.z)) *
103 direction;
104}
105
106/* Assumes the transform has unit scale. */
108{
109 return float3x3(float3(t.x.x, t.x.y, t.x.z),
110 float3(t.y.x, t.y.y, t.y.z),
111 float3(t.z.x, t.z.y, t.z.z)) *
112 (point - t.location());
113}
114
115#ifndef GPU_SHADER
116} // namespace blender::eevee
117#endif
#define host_shared
bool all(VecOp< bool, D >) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
static float3 transform_point_inversed(Transform t, float3 point)
static Transform transform_from_matrix(float4x4 m)
static float3 transform_direction(Transform t, float3 direction)
static float3 transform_direction_transposed(Transform t, float3 direction)
static float3 transform_point(Transform t, float3 point)
static float4x4 transform_to_matrix(Transform t)
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 4 > float3x4
VecBase< float, 4 > float4
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
Transform(const float4x4 &tx)