Blender V5.0
gradient.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "kernel/svm/util.h"
8
10
11/* Gradient */
12
14{
15 float x;
16 float y;
17 float z;
18
19 x = p.x;
20 y = p.y;
21 z = p.z;
22
23 if (type == NODE_BLEND_LINEAR) {
24 return x;
25 }
26 if (type == NODE_BLEND_QUADRATIC) {
27 const float r = fmaxf(x, 0.0f);
28 return r * r;
29 }
30 if (type == NODE_BLEND_EASING) {
31 const float r = fminf(fmaxf(x, 0.0f), 1.0f);
32 const float t = r * r;
33
34 return (3.0f * t - 2.0f * t * r);
35 }
36 if (type == NODE_BLEND_DIAGONAL) {
37 return (x + y) * 0.5f;
38 }
39 if (type == NODE_BLEND_RADIAL) {
40 return atan2f(y, x) / M_2PI_F + 0.5f;
41 }
42
43 /* Bias a little bit for the case where p is a unit length vector,
44 * to get exactly zero instead of a small random value depending
45 * on float precision. */
46 const float r = fmaxf(0.999999f - sqrtf(x * x + y * y + z * z), 0.0f);
47
48 if (type == NODE_BLEND_QUADRATIC_SPHERE) {
49 return r * r;
50 }
51 if (type == NODE_BLEND_SPHERICAL) {
52 return r;
53 }
54
55 return 0.0f;
56}
57
59{
60 uint type;
61 uint co_offset;
62 uint color_offset;
63 uint fac_offset;
64
65 svm_unpack_node_uchar4(node.y, &type, &co_offset, &fac_offset, &color_offset);
66
67 const float3 co = stack_load_float3(stack, co_offset);
68
69 float f = svm_gradient(co, (NodeGradientType)type);
70 f = saturatef(f);
71
72 if (stack_valid(fac_offset)) {
73 stack_store_float(stack, fac_offset, f);
74 }
75 if (stack_valid(color_offset)) {
76 stack_store_float3(stack, color_offset, make_float3(f, f, f));
77 }
78}
79
unsigned int uint
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_forceinline void svm_unpack_node_uchar4(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
ccl_device_inline bool stack_valid(const uint a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
#define saturatef(x)
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_noinline void svm_node_tex_gradient(ccl_private float *stack, const uint4 node)
Definition gradient.h:58
CCL_NAMESPACE_BEGIN ccl_device float svm_gradient(const float3 p, NodeGradientType type)
Definition gradient.h:13
NodeGradientType
@ NODE_BLEND_QUADRATIC
@ NODE_BLEND_DIAGONAL
@ NODE_BLEND_EASING
@ NODE_BLEND_RADIAL
@ NODE_BLEND_SPHERICAL
@ NODE_BLEND_QUADRATIC_SPHERE
@ NODE_BLEND_LINEAR
#define sqrtf
#define ccl_device
#define M_2PI_F
#define fmaxf
#define fminf
#define atan2f
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
uint y
Definition types_uint4.h:13