diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-13 23:22:15 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-13 23:22:15 +0300 |
commit | 313b78928970a82ab547b07f21f04fc032491ca1 (patch) | |
tree | 465c6aec1df0c6b8b0894a238fd4792dd3977dc9 /intern/cycles/kernel/svm/svm_clamp.h | |
parent | 42798a5ca16154c9ecaf5a2359bd0b4fbe9dec94 (diff) |
Shading: Add Clamp node to Cycles and EEVEE.
This patch adds a new node that clamps a value between a maximum and
a minimum values.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D5476
Diffstat (limited to 'intern/cycles/kernel/svm/svm_clamp.h')
-rw-r--r-- | intern/cycles/kernel/svm/svm_clamp.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/intern/cycles/kernel/svm/svm_clamp.h b/intern/cycles/kernel/svm/svm_clamp.h new file mode 100644 index 00000000000..5ff4a599028 --- /dev/null +++ b/intern/cycles/kernel/svm/svm_clamp.h @@ -0,0 +1,41 @@ +/* + * Copyright 2011-2013 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CCL_NAMESPACE_BEGIN + +/* Clamp Node */ + +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) +{ + uint min_stack_offset, max_stack_offset; + decode_node_uchar4(parameters_stack_offsets, &min_stack_offset, &max_stack_offset, NULL, NULL); + + uint4 defaults = read_node(kg, offset); + + float value = stack_load_float(stack, value_stack_offset); + float min = stack_load_float_default(stack, min_stack_offset, defaults.x); + float max = stack_load_float_default(stack, max_stack_offset, defaults.y); + + stack_store_float(stack, result_stack_offset, clamp(value, min, max)); +} + +CCL_NAMESPACE_END |