Blender V5.3
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
8#include "kernel/svm/util.h"
9
11
12/* Gradient */
13
15{
16 float x;
17 float y;
18 float z;
19
20 x = p.x;
21 y = p.y;
22 z = p.z;
23
24 if (type == NODE_BLEND_LINEAR) {
25 return x;
26 }
27 if (type == NODE_BLEND_QUADRATIC) {
28 const float r = fmaxf(x, 0.0f);
29 return r * r;
30 }
31 if (type == NODE_BLEND_EASING) {
32 const float r = fminf(fmaxf(x, 0.0f), 1.0f);
33 const float t = r * r;
34
35 return (3.0f * t - 2.0f * t * r);
36 }
37 if (type == NODE_BLEND_DIAGONAL) {
38 return (x + y) * 0.5f;
39 }
40 if (type == NODE_BLEND_RADIAL) {
41 return atan2f(y, x) / M_2PI_F + 0.5f;
42 }
43
44 /* Bias a little bit for the case where p is a unit length vector,
45 * to get exactly zero instead of a small random value depending
46 * on float precision. */
47 const float r = fmaxf(0.999999f - sqrtf(x * x + y * y + z * z), 0.0f);
48
49 if (type == NODE_BLEND_QUADRATIC_SPHERE) {
50 return r * r;
51 }
52 if (type == NODE_BLEND_SPHERICAL) {
53 return r;
54 }
55
56 return 0.0f;
57}
58
61{
62 const float3 co = stack_load_float3(stack, node.co);
63
64 float f = svm_gradient(co, node.gradient_type);
65 f = saturatef(f);
66
67 if (stack_valid(node.fac_offset)) {
68 stack_store_float(stack, node.fac_offset, f);
69 }
70 if (stack_valid(node.color_offset)) {
71 stack_store_float3(stack, node.color_offset, make_float3(f, f, f));
72 }
73}
74
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 float3 stack_load_float3(const ccl_private float *stack, const uint a)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline bool stack_valid(const uint a)
#define ccl_restrict
#define ccl_private
#define ccl_global
#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_NAMESPACE_BEGIN ccl_device float svm_gradient(const float3 p, NodeGradientType type)
Definition gradient.h:14
ccl_device_noinline void svm_node_tex_gradient(ccl_private float *ccl_restrict stack, const ccl_global SVMNodeTexGradient &ccl_restrict node)
Definition gradient.h:59
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