Blender  V2.93
svm_clamp.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* Clamp Node */
20 
21 ccl_device void svm_node_clamp(KernelGlobals *kg,
22  ShaderData *sd,
23  float *stack,
24  uint value_stack_offset,
25  uint parameters_stack_offsets,
26  uint result_stack_offset,
27  int *offset)
28 {
29  uint min_stack_offset, max_stack_offset, type;
30  svm_unpack_node_uchar3(parameters_stack_offsets, &min_stack_offset, &max_stack_offset, &type);
31 
32  uint4 defaults = read_node(kg, offset);
33 
34  float value = stack_load_float(stack, value_stack_offset);
35  float min = stack_load_float_default(stack, min_stack_offset, defaults.x);
36  float max = stack_load_float_default(stack, max_stack_offset, defaults.y);
37 
38  if (type == NODE_CLAMP_RANGE && (min > max)) {
39  stack_store_float(stack, result_stack_offset, clamp(value, max, min));
40  }
41  else {
42  stack_store_float(stack, result_stack_offset, clamp(value, min, max));
43  }
44 }
45 
unsigned int uint
Definition: BLI_sys_types.h:83
@ 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_device_inline uint4 read_node(KernelGlobals *kg, int *offset)
ccl_device_inline float stack_load_float_default(float *stack, uint a, uint value)
ccl_device_inline float stack_load_float(float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, uint *x, uint *y, uint *z)
ccl_device_inline void stack_store_float(float *stack, uint a, float f)
#define ccl_device
#define CCL_NAMESPACE_END
ShaderData
#define min(a, b)
Definition: sort.c:51
CCL_NAMESPACE_BEGIN ccl_device void svm_node_clamp(KernelGlobals *kg, ShaderData *sd, float *stack, uint value_stack_offset, uint parameters_stack_offsets, uint result_stack_offset, int *offset)
Definition: svm_clamp.h:21
float max
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util_math.h:283