Blender V4.5
sepcomb_hsv.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
7#include "kernel/svm/util.h"
8
9#include "util/color.h"
10
12
14 ccl_private ShaderData *sd,
15 ccl_private float *stack,
16 const uint hue_in,
17 const uint saturation_in,
18 const uint value_in,
19 int offset)
20{
21 const uint4 node1 = read_node(kg, &offset);
22 const uint color_out = node1.y;
23
24 const float hue = stack_load_float(stack, hue_in);
25 const float saturation = stack_load_float(stack, saturation_in);
26 const float value = stack_load_float(stack, value_in);
27
28 /* Combine, and convert back to RGB */
29 const float3 color = hsv_to_rgb(make_float3(hue, saturation, value));
30
31 if (stack_valid(color_out)) {
32 stack_store_float3(stack, color_out, color);
33 }
34 return offset;
35}
36
38 ccl_private ShaderData *sd,
39 ccl_private float *stack,
40 const uint color_in,
41 const uint hue_out,
42 const uint saturation_out,
43 int offset)
44{
45 const uint4 node1 = read_node(kg, &offset);
46 const uint value_out = node1.y;
47
48 float3 color = stack_load_float3(stack, color_in);
49
50 /* Convert to HSV */
51 color = rgb_to_hsv(color);
52
53 if (stack_valid(hue_out)) {
54 stack_store_float(stack, hue_out, color.x);
55 }
56 if (stack_valid(saturation_out)) {
57 stack_store_float(stack, saturation_out, color.y);
58 }
59 if (stack_valid(value_out)) {
60 stack_store_float(stack, value_out, color.z);
61 }
62 return offset;
63}
64
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
unsigned int uint
ccl_device_inline float stack_load_float(const ccl_private float *stack, const uint a)
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *const offset)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline bool stack_valid(const uint a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
CCL_NAMESPACE_BEGIN ccl_device_noinline int svm_node_combine_hsv(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint hue_in, const uint saturation_in, const uint value_in, int offset)
Definition sepcomb_hsv.h:13
ccl_device_noinline int svm_node_separate_hsv(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint color_in, const uint hue_out, const uint saturation_out, int offset)
Definition sepcomb_hsv.h:37
float z
Definition sky_float3.h:27
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
uint y
Definition types_uint4.h:13