Blender V4.3
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
8
9/* Clamp Node */
10
13 ccl_private float *stack,
14 uint value_stack_offset,
15 uint parameters_stack_offsets,
16 uint result_stack_offset,
17 int offset)
18{
19 uint min_stack_offset, max_stack_offset, type;
20 svm_unpack_node_uchar3(parameters_stack_offsets, &min_stack_offset, &max_stack_offset, &type);
21
22 uint4 defaults = read_node(kg, &offset);
23
24 float value = stack_load_float(stack, value_stack_offset);
25 float min = stack_load_float_default(stack, min_stack_offset, defaults.x);
26 float max = stack_load_float_default(stack, max_stack_offset, defaults.y);
27
28 if (type == NODE_CLAMP_RANGE && (min > max)) {
29 stack_store_float(stack, result_stack_offset, clamp(value, max, min));
30 }
31 else {
32 stack_store_float(stack, result_stack_offset, clamp(value, min, max));
33 }
34 return offset;
35}
36
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, uint value_stack_offset, uint parameters_stack_offsets, uint result_stack_offset, int offset)
Definition clamp.h:11
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *offset)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_inline float stack_load_float_default(ccl_private float *stack, uint a, uint value)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
ShaderData
#define min(a, b)
Definition sort.c:32
uint x
Definition types_uint4.h:15
uint y
Definition types_uint4.h:15
ccl_device_inline int clamp(int a, int mn, int mx)
Definition util/math.h:379