Blender V5.3
gpu_shader_material_tex_gradient.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
9
10float calc_gradient(float3 p, int gradient_type)
11{
12 float x, y, z;
13 x = p.x;
14 y = p.y;
15 z = p.z;
16 if (gradient_type == 0) { /* linear */
17 return x;
18 }
19 if (gradient_type == 1) { /* quadratic */
20 float r = max(x, 0.0f);
21 return r * r;
22 }
23 if (gradient_type == 2) { /* easing */
24 float r = min(max(x, 0.0f), 1.0f);
25 float t = r * r;
26 return (3.0f * t - 2.0f * t * r);
27 }
28 if (gradient_type == 3) { /* diagonal */
29 return (x + y) * 0.5f;
30 }
31 if (gradient_type == 4) { /* radial */
32 return atan(y, x) / (M_PI * 2) + 0.5f;
33 }
34 /* Bias a little bit for the case where p is a unit length vector,
35 * to get exactly zero instead of a small random value depending
36 * on float precision. */
37 float r = max(0.999999f - sqrt(x * x + y * y + z * z), 0.0f);
38 if (gradient_type == 5) { /* quadratic sphere */
39 return r * r;
40 }
41 if (gradient_type == 6) { /* sphere */
42 return r;
43 }
44 return 0.0f;
45}
46
47[[node]]
48void node_tex_gradient(float3 co, float gradient_type, float4 &color, float &fac)
49{
50 float f = calc_gradient(co, int(gradient_type));
51 f = clamp(f, 0.0f, 1.0f);
52
53 color = float4(f, f, f, 1.0f);
54 fac = f;
55}
#define M_PI
btScalar max
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
#define atan
#define sqrt
constexpr T clamp(T, U, U) RET
void node_tex_gradient(float3 co, float gradient_type, float4 &color, float &fac)
float calc_gradient(float3 p, int gradient_type)
#define min(a, b)
Definition sort.cc:38
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136