Blender  V3.3
clamp.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /* Clamp Node */
9 
12  ccl_private float *stack,
13  uint value_stack_offset,
14  uint parameters_stack_offsets,
15  uint result_stack_offset,
16  int offset)
17 {
18  uint min_stack_offset, max_stack_offset, type;
19  svm_unpack_node_uchar3(parameters_stack_offsets, &min_stack_offset, &max_stack_offset, &type);
20 
21  uint4 defaults = read_node(kg, &offset);
22 
23  float value = stack_load_float(stack, value_stack_offset);
24  float min = stack_load_float_default(stack, min_stack_offset, defaults.x);
25  float max = stack_load_float_default(stack, max_stack_offset, defaults.y);
26 
27  if (type == NODE_CLAMP_RANGE && (min > max)) {
28  stack_store_float(stack, result_stack_offset, clamp(value, max, min));
29  }
30  else {
31  stack_store_float(stack, result_stack_offset, clamp(value, min, max));
32  }
33  return offset;
34 }
35 
unsigned int uint
Definition: BLI_sys_types.h:67
@ NODE_CLAMP_RANGE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
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:10
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
const KernelGlobalsCPU *ccl_restrict KernelGlobals
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
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
Definition: kernel/types.h:925
T clamp(const T &a, const T &min, const T &max)
#define min(a, b)
Definition: sort.c:35
uint x
Definition: types_uint4.h:15
uint y
Definition: types_uint4.h:15
float max