Blender V5.0
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
5#pragma once
6
8
9#ifndef GPU_SHADER
10namespace blender::eevee {
11#endif
12
16struct Transform {
17 /* The transform is stored transposed for compactness. */
19
20#ifndef GPU_SHADER
21 Transform() = default;
23 : x(tx[0][0], tx[1][0], tx[2][0], tx[3][0]),
24 y(tx[0][1], tx[1][1], tx[2][1], tx[3][1]),
25 z(tx[0][2], tx[1][2], tx[2][2], tx[3][2])
26 {
27 }
28
29 operator float4x4() const
30 {
31 return float4x4(float4(x.x, y.x, z.x, 0.0f),
32 float4(x.y, y.y, z.y, 0.0f),
33 float4(x.z, y.z, z.z, 0.0f),
34 float4(x.w, y.w, z.w, 1.0f));
35 }
36#endif
37};
38
40{
41 return float4x4(float4(t.x.x, t.y.x, t.z.x, 0.0f),
42 float4(t.x.y, t.y.y, t.z.y, 0.0f),
43 float4(t.x.z, t.y.z, t.z.z, 0.0f),
44 float4(t.x.w, t.y.w, t.z.w, 1.0f));
45}
46
48{
49 Transform t;
50 t.x = float4(m[0][0], m[1][0], m[2][0], m[3][0]);
51 t.y = float4(m[0][1], m[1][1], m[2][1], m[3][1]);
52 t.z = float4(m[0][2], m[1][2], m[2][2], m[3][2]);
53 return t;
54}
55
57{
58 return float3(t.x.x, t.y.x, t.z.x);
59}
61{
62 return float3(t.x.y, t.y.y, t.z.y);
63}
65{
66 return float3(t.x.z, t.y.z, t.z.z);
67}
69{
70 return float3(t.x.w, t.y.w, t.z.w);
71}
72
73#ifdef GPU_SHADER
74static inline bool transform_equal(Transform a, Transform b)
75{
76 return all(equal(a.x, b.x)) && all(equal(a.y, b.y)) && all(equal(a.z, b.z));
77}
78#endif
79
80static inline float3 transform_point(Transform t, float3 point)
81{
82 return float4(point, 1.0f) * float3x4(t.x, t.y, t.z);
83}
84
85static inline float3 transform_direction(Transform t, float3 direction)
86{
87 return direction * float3x3(float3(t.x.x, t.x.y, t.x.z),
88 float3(t.y.x, t.y.y, t.y.z),
89 float3(t.z.x, t.z.y, t.z.z));
90}
91
93{
94 return float3x3(float3(t.x.x, t.x.y, t.x.z),
95 float3(t.y.x, t.y.y, t.y.z),
96 float3(t.z.x, t.z.y, t.z.z)) *
97 direction;
98}
99
100/* Assumes the transform has unit scale. */
102{
103 return float3x3(float3(t.x.x, t.x.y, t.x.z),
104 float3(t.y.x, t.y.y, t.y.z),
105 float3(t.z.x, t.z.y, t.z.z)) *
106 (point - transform_location(t));
107}
108
109#ifndef GPU_SHADER
110} // namespace blender::eevee
111#endif
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 float3 transform_x_axis(Transform t)
static Transform transform_from_matrix(float4x4 m)
static float3 transform_direction_transposed(Transform t, float3 direction)
static float3 transform_z_axis(Transform t)
static float3 transform_y_axis(Transform t)
static float4x4 transform_to_matrix(Transform t)
static float3 transform_location(Transform t)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 4 > float3x4
VecBase< float, 4 > float4
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
float4 y
Definition transform.h:23
float4 x
Definition transform.h:23
float4 z
Definition transform.h:23
Transform(const float4x4 &tx)