Blender  V2.93
svm_sepcomb_hsv.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 ccl_device void svm_node_combine_hsv(KernelGlobals *kg,
20  ShaderData *sd,
21  float *stack,
22  uint hue_in,
23  uint saturation_in,
24  uint value_in,
25  int *offset)
26 {
27  uint4 node1 = read_node(kg, offset);
28  uint color_out = node1.y;
29 
30  float hue = stack_load_float(stack, hue_in);
31  float saturation = stack_load_float(stack, saturation_in);
32  float value = stack_load_float(stack, value_in);
33 
34  /* Combine, and convert back to RGB */
35  float3 color = hsv_to_rgb(make_float3(hue, saturation, value));
36 
37  if (stack_valid(color_out))
38  stack_store_float3(stack, color_out, color);
39 }
40 
41 ccl_device void svm_node_separate_hsv(KernelGlobals *kg,
42  ShaderData *sd,
43  float *stack,
44  uint color_in,
45  uint hue_out,
46  uint saturation_out,
47  int *offset)
48 {
49  uint4 node1 = read_node(kg, offset);
50  uint value_out = node1.y;
51 
52  float3 color = stack_load_float3(stack, color_in);
53 
54  /* Convert to HSV */
55  color = rgb_to_hsv(color);
56 
57  if (stack_valid(hue_out))
58  stack_store_float(stack, hue_out, color.x);
59  if (stack_valid(saturation_out))
60  stack_store_float(stack, saturation_out, color.y);
61  if (stack_valid(value_out))
62  stack_store_float(stack, value_out, color.z);
63 }
64 
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
Definition: math_color.c:229
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition: math_color.c:31
unsigned int uint
Definition: BLI_sys_types.h:83
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(float *stack, uint a)
ccl_device_inline uint4 read_node(KernelGlobals *kg, int *offset)
ccl_device_inline float stack_load_float(float *stack, uint a)
ccl_device_inline void stack_store_float3(float *stack, uint a, float3 f)
ccl_device_inline void stack_store_float(float *stack, uint a, float f)
ccl_device_inline bool stack_valid(uint a)
#define ccl_device
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
ShaderData
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
CCL_NAMESPACE_BEGIN ccl_device void svm_node_combine_hsv(KernelGlobals *kg, ShaderData *sd, float *stack, uint hue_in, uint saturation_in, uint value_in, int *offset)
ccl_device void svm_node_separate_hsv(KernelGlobals *kg, ShaderData *sd, float *stack, uint color_in, uint hue_out, uint saturation_out, int *offset)