Files
test/intern/cycles/kernel/svm/hsv.h
William Leeson 7b1c5712f8 Cycles: Replace saturate with saturatef
saturate is depricated in favour of __saturatef this replaces saturate
with __saturatef on CUDA by createing a saturatef function which replaces
all instances of saturate and are hooked up to the correct function on all
platforms.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D13010
2021-10-27 14:05:46 +02:00

62 lines
2.1 KiB
C

/*
* 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.
*/
#pragma once
CCL_NAMESPACE_BEGIN
ccl_device_noinline void svm_node_hsv(KernelGlobals kg,
ccl_private ShaderData *sd,
ccl_private float *stack,
uint4 node)
{
uint in_color_offset, fac_offset, out_color_offset;
uint hue_offset, sat_offset, val_offset;
svm_unpack_node_uchar3(node.y, &in_color_offset, &fac_offset, &out_color_offset);
svm_unpack_node_uchar3(node.z, &hue_offset, &sat_offset, &val_offset);
float fac = stack_load_float(stack, fac_offset);
float3 in_color = stack_load_float3(stack, in_color_offset);
float3 color = in_color;
float hue = stack_load_float(stack, hue_offset);
float sat = stack_load_float(stack, sat_offset);
float val = stack_load_float(stack, val_offset);
color = rgb_to_hsv(color);
/* Remember: `fmodf` doesn't work for negative numbers here. */
color.x = fmodf(color.x + hue + 0.5f, 1.0f);
color.y = saturatef(color.y * sat);
color.z *= val;
color = hsv_to_rgb(color);
color.x = fac * color.x + (1.0f - fac) * in_color.x;
color.y = fac * color.y + (1.0f - fac) * in_color.y;
color.z = fac * color.z + (1.0f - fac) * in_color.z;
/* Clamp color to prevent negative values caused by over saturation. */
color.x = max(color.x, 0.0f);
color.y = max(color.y, 0.0f);
color.z = max(color.z, 0.0f);
if (stack_valid(out_color_offset))
stack_store_float3(stack, out_color_offset, color);
}
CCL_NAMESPACE_END