Blender V5.3
gpu_shader_material_vector_math.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
10{
11 /* Match the safe normalize function in Cycles by defaulting to float3(0.0f) */
12 float length_sqr = dot(a, a);
13 return (length_sqr > 1e-35f) ? a * inversesqrt(length_sqr) : float3(0.0f);
14}
15
16[[node]]
18 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
19{
20 outVector = a + b;
21}
22
23[[node]]
25 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
26{
27 outVector = a - b;
28}
29
30[[node]]
32 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
33{
34 outVector = a * b;
35}
36
37[[node]]
39 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
40{
41 outVector = safe_divide(a, b);
42}
43
44/* `a / a` folded to 1 (see #162948). */
45[[node]]
47 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
48{
49 outVector = float3(notEqual(a, float3(0.0f)));
50}
51
52[[node]]
54 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
55{
56 outVector = cross(a, b);
57}
58
59[[node]]
61 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
62{
63 float lenSquared = dot(b, b);
64 outVector = (lenSquared != 0.0f) ? (dot(a, b) / lenSquared) * b : float3(0.0f);
65}
66
67[[node]]
69 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
70{
71 outVector = reflect(a, vector_math_safe_normalize(b));
72}
73
74[[node]]
76 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 & /*outVector*/, float &outValue)
77{
78 outValue = dot(a, b);
79}
80
81[[node]]
83 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 & /*outVector*/, float &outValue)
84{
85 outValue = distance(a, b);
86}
87
88[[node]]
90 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 & /*outVector*/, float &outValue)
91{
92 outValue = length(a);
93}
94
95[[node]]
97 float3 a, float3 /*b*/, float3 /*c*/, float scale, float3 &outVector, float & /*outValue*/)
98{
99 outVector = a * scale;
100}
101
102[[node]]
104 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
105{
106 outVector = a;
107 /* Safe version of normalize(a). */
108 float lenSquared = dot(a, a);
109 if (lenSquared > 0.0f) {
110 outVector *= inversesqrt(lenSquared);
111 }
112}
113
114[[node]]
116 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
117{
118 outVector = floor(safe_divide(a, b)) * b;
119}
120
121/* `floor(a / a) * a` folded to `a` (see #162948). */
122[[node]]
124 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
125{
126 outVector = a;
127}
128
129[[node]]
131 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
132{
133 outVector = floor(a);
134}
135
136[[node]]
138 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
139{
140 outVector = ceil(a);
141}
142
143[[node]]
145 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
146{
147 outVector = compatible_mod(a, b);
148}
149
150[[node]]
152 float3 a, float3 b, float3 c, float /*scale*/, float3 &outVector, float & /*outValue*/)
153{
154 outVector = wrap(a, b, c);
155}
156
157[[node]]
159 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
160{
161 outVector = fract(a);
162}
163
164[[node]]
166 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
167{
168 outVector = abs(a);
169}
170
171[[node]]
173 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
174{
175 outVector = compatible_pow(a, b);
176}
177
178[[node]]
180 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
181{
182 outVector = sign(a);
183}
184
185[[node]]
187 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
188{
189 outVector = floor(a + 0.5f);
190}
191
192[[node]]
194 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
195{
196 outVector = min(a, b);
197}
198
199[[node]]
201 float3 a, float3 b, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
202{
203 outVector = max(a, b);
204}
205
206[[node]]
208 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
209{
210 outVector = sin(a);
211}
212
213[[node]]
215 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
216{
217 outVector = cos(a);
218}
219
220[[node]]
222 float3 a, float3 /*b*/, float3 /*c*/, float /*scale*/, float3 &outVector, float & /*outValue*/)
223{
224 outVector = tan(a);
225}
226
227[[node]]
229 float3 a, float3 b, float3 /*c*/, float scale, float3 &outVector, float & /*outValue*/)
230{
231 outVector = refract(a, vector_math_safe_normalize(b), scale);
232}
233
234[[node]]
236 float3 a, float3 b, float3 c, float /*scale*/, float3 &outVector, float & /*outValue*/)
237{
238 outVector = faceforward(a, b, c);
239}
240
241[[node]]
243 float3 a, float3 b, float3 c, float /*scale*/, float3 &outVector, float & /*outValue*/)
244{
245 outVector = a * b + c;
246}
btScalar max
VecBase< bool, D > notEqual(VecOp< T, D >, VecOp< T, D >) RET
#define tan
#define sin
T fract(T) RET
VecBase< T, D > refract(VecOp< T, D >, VecOp< T, D >, float) RET
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
#define cos
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T sign(T) RET
VecBase< T, D > faceforward(VecOp< T, D >, VecOp< T, D >, VecOp< T, D >) RET
constexpr T inversesqrt(T) RET
#define abs
#define floor
float distance(float, float) RET
#define ceil
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float length(VecOp< float, D >) RET
void vector_math_multiply_add(float3 a, float3 b, float3 c, float, float3 &outVector, float &)
void vector_math_snap(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_length(float3 a, float3, float3, float, float3 &, float &outValue)
void vector_math_multiply(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_scale(float3 a, float3, float3, float scale, float3 &outVector, float &)
void vector_math_round(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_minimum(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_cross(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_distance(float3 a, float3 b, float3, float, float3 &, float &outValue)
void vector_math_divide(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_refract(float3 a, float3 b, float3, float scale, float3 &outVector, float &)
void vector_math_normalize(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_divide_self(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_tangent(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_sine(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_cosine(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_dot(float3 a, float3 b, float3, float, float3 &, float &outValue)
void vector_math_sign(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_ceil(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_absolute(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_floor(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_fraction(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_wrap(float3 a, float3 b, float3 c, float, float3 &outVector, float &)
void vector_math_subtract(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_reflect(float3 a, float3 b, float3, float, float3 &outVector, float &)
float3 vector_math_safe_normalize(float3 a)
void vector_math_power(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_modulo(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_maximum(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_snap_self(float3 a, float3, float3, float, float3 &outVector, float &)
void vector_math_add(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_project(float3 a, float3 b, float3, float, float3 &outVector, float &)
void vector_math_faceforward(float3 a, float3 b, float3 c, float, float3 &outVector, float &)
float3x3 scale(float3x3 mat, float2 scale)
float wrap(float a, float b, float c)
float safe_divide(float a, float b)
float compatible_pow(float x, float y)
float compatible_mod(float a, float b)
#define min(a, b)
Definition sort.cc:38