Blender V4.5
clamp.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/* Clamp Node */
12
14 ccl_private ShaderData *sd,
15 ccl_private float *stack,
16 const uint value_stack_offset,
17 const uint parameters_stack_offsets,
18 const uint result_stack_offset,
19 int offset)
20{
21 uint min_stack_offset;
22 uint max_stack_offset;
23 uint type;
24 svm_unpack_node_uchar3(parameters_stack_offsets, &min_stack_offset, &max_stack_offset, &type);
25
26 const uint4 defaults = read_node(kg, &offset);
27
28 const float value = stack_load_float(stack, value_stack_offset);
29 const float min = stack_load_float_default(stack, min_stack_offset, defaults.x);
30 const float max = stack_load_float_default(stack, max_stack_offset, defaults.y);
31
32 if (type == NODE_CLAMP_RANGE && (min > max)) {
33 stack_store_float(stack, result_stack_offset, clamp(value, max, min));
34 }
35 else {
36 stack_store_float(stack, result_stack_offset, clamp(value, min, max));
37 }
38 return offset;
39}
40
unsigned int uint
@ NODE_CLAMP_RANGE
CCL_NAMESPACE_BEGIN ccl_device_noinline int svm_node_clamp(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint value_stack_offset, const uint parameters_stack_offsets, const uint result_stack_offset, int offset)
Definition clamp.h:13
ccl_device_inline float stack_load_float(const ccl_private float *stack, const uint a)
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *const offset)
ccl_device_inline float stack_load_float_default(const ccl_private float *stack, const uint a, const uint value)
ccl_device_forceinline void svm_unpack_node_uchar3(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
constexpr T clamp(T, U, U) RET
#define min(a, b)
Definition sort.cc:36
uint x
Definition types_uint4.h:13
uint y
Definition types_uint4.h:13
max
Definition text_draw.cc:251