Blender V5.3
gpu_shader_math_matrix_normalize.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
9
10/* -------------------------------------------------------------------- */
13
14/* Needs to be defined for correct overloading. */
15#if defined(GPU_OPENGL) || defined(GPU_METAL)
17{
18 return a * inversesqrt(length_squared(a));
19}
21{
22 return a * inversesqrt(length_squared(a));
23}
25{
26 return a * inversesqrt(length_squared(a));
27}
28#endif
29
33#if 0 /* Remove unused variants as they are slow down compilation. */
35{
37 ret[0] = normalize(mat[0].xy);
38 ret[1] = normalize(mat[1].xy);
39 return ret;
40}
42{
44 ret[0] = normalize(mat[0].xyz);
45 ret[1] = normalize(mat[1].xyz);
46 return ret;
47}
49{
51 ret[0] = normalize(mat[0].xyzw);
52 ret[1] = normalize(mat[1].xyzw);
53 return ret;
54}
56{
58 ret[0] = normalize(mat[0].xy);
59 ret[1] = normalize(mat[1].xy);
60 ret[2] = normalize(mat[2].xy);
61 return ret;
62}
63#endif
65{
66 float3x3 ret;
67 ret[0] = normalize(mat[0].xyz);
68 ret[1] = normalize(mat[1].xyz);
69 ret[2] = normalize(mat[2].xyz);
70 return ret;
71}
72#if 0 /* Remove unused variants as they are slow down compilation. */
74{
76 ret[0] = normalize(mat[0].xyzw);
77 ret[1] = normalize(mat[1].xyzw);
78 ret[2] = normalize(mat[2].xyzw);
79 return ret;
80}
82{
84 ret[0] = normalize(mat[0].xy);
85 ret[1] = normalize(mat[1].xy);
86 ret[2] = normalize(mat[2].xy);
87 ret[3] = normalize(mat[3].xy);
88 return ret;
89}
91{
93 ret[0] = normalize(mat[0].xyz);
94 ret[1] = normalize(mat[1].xyz);
95 ret[2] = normalize(mat[2].xyz);
96 ret[3] = normalize(mat[3].xyz);
97 return ret;
98}
99#endif
101{
102 float4x4 ret;
103 ret[0] = normalize(mat[0].xyzw);
104 ret[1] = normalize(mat[1].xyzw);
105 ret[2] = normalize(mat[2].xyzw);
106 ret[3] = normalize(mat[3].xyzw);
107 return ret;
108}
109
114#if 0 /* Remove unused variants as they are slow down compilation. */
116{
117 float size_x = 0.0f, size_y = 0.0f;
119 ret[0] = normalize_and_get_length(mat[0], size_x);
120 ret[1] = normalize_and_get_length(mat[1], size_y);
121 r_size = float2(size_x, size_y);
122 return ret;
123}
125{
126 float size_x = 0.0f, size_y = 0.0f;
128 ret[0] = normalize_and_get_length(mat[0], size_x);
129 ret[1] = normalize_and_get_length(mat[1], size_y);
130 r_size = float2(size_x, size_y);
131 return ret;
132}
134{
135 float size_x = 0.0f, size_y = 0.0f;
137 ret[0] = normalize_and_get_length(mat[0], size_x);
138 ret[1] = normalize_and_get_length(mat[1], size_y);
139 r_size = float2(size_x, size_y);
140 return ret;
141}
143{
144 float size_x = 0.0f, size_y = 0.0f, size_z = 0.0f;
146 ret[0] = normalize_and_get_length(mat[0], size_x);
147 ret[1] = normalize_and_get_length(mat[1], size_y);
148 ret[2] = normalize_and_get_length(mat[2], size_z);
149 r_size = float3(size_x, size_y, size_z);
150 return ret;
151}
152#endif
154{
155 float size_x = 0.0f, size_y = 0.0f, size_z = 0.0f;
156 float3x3 ret;
157 ret[0] = normalize_and_get_length(mat[0], size_x);
158 ret[1] = normalize_and_get_length(mat[1], size_y);
159 ret[2] = normalize_and_get_length(mat[2], size_z);
160 r_size = float3(size_x, size_y, size_z);
161 return ret;
162}
163#if 0 /* Remove unused variants as they are slow down compilation. */
165{
166 float size_x = 0.0f, size_y = 0.0f, size_z = 0.0f;
168 ret[0] = normalize_and_get_length(mat[0], size_x);
169 ret[1] = normalize_and_get_length(mat[1], size_y);
170 ret[2] = normalize_and_get_length(mat[2], size_z);
171 r_size = float3(size_x, size_y, size_z);
172 return ret;
173}
175{
176 float size_x = 0.0f, size_y = 0.0f, size_z = 0.0f, size_w = 0.0f;
178 ret[0] = normalize_and_get_length(mat[0], size_x);
179 ret[1] = normalize_and_get_length(mat[1], size_y);
180 ret[2] = normalize_and_get_length(mat[2], size_z);
181 ret[3] = normalize_and_get_length(mat[3], size_w);
182 r_size = float4(size_x, size_y, size_z, size_w);
183 return ret;
184}
186{
187 float size_x = 0.0f, size_y = 0.0f, size_z = 0.0f, size_w = 0.0f;
189 ret[0] = normalize_and_get_length(mat[0], size_x);
190 ret[1] = normalize_and_get_length(mat[1], size_y);
191 ret[2] = normalize_and_get_length(mat[2], size_z);
192 ret[3] = normalize_and_get_length(mat[3], size_w);
193 r_size = float4(size_x, size_y, size_z, size_w);
194 return ret;
195}
196#endif
198{
199 float size_x = 0.0f, size_y = 0.0f, size_z = 0.0f, size_w = 0.0f;
200 float4x4 ret;
201 ret[0] = normalize_and_get_length(mat[0], size_x);
202 ret[1] = normalize_and_get_length(mat[1], size_y);
203 ret[2] = normalize_and_get_length(mat[2], size_z);
204 ret[3] = normalize_and_get_length(mat[3], size_w);
205 r_size = float4(size_x, size_y, size_z, size_w);
206 return ret;
207}
208
VecBase< float, D > normalize(VecOp< float, D >) RET
constexpr T inversesqrt(T) RET
MatBase< 3, 2 > float3x2
MatBase< 2, 3 > float2x3
MatBase< 4, 3 > float4x3
float3x3 normalize_and_get_size(float3x3 mat, float3 &r_size)
VecT normalize_and_get_length(VecT vector, float &out_length)
float length_squared(VecT a)
MatBase< float, 2, 2 > float2x2
MatBase< float, 4, 4 > float4x4
MatBase< float, 2, 4 > float2x4
MatBase< float, 3, 4 > float3x4
MatBase< float, 4, 2 > float4x2