Integer socket support in Cycles. Int values are already supported natively in OSL...
[blender.git] / intern / cycles / kernel / svm / svm_convert.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 CCL_NAMESPACE_BEGIN
20
21 /* Conversion Nodes */
22
23 __device void svm_node_convert(ShaderData *sd, float *stack, uint type, uint from, uint to)
24 {
25         switch(type) {
26                 case NODE_CONVERT_FI: {
27                         float f = stack_load_float(stack, from);
28                         stack_store_int(stack, to, (int)f);
29                         break;
30                 }
31                 case NODE_CONVERT_FV: {
32                         float f = stack_load_float(stack, from);
33                         stack_store_float3(stack, to, make_float3(f, f, f));
34                         break;
35                 }
36                 case NODE_CONVERT_CF: {
37                         float3 f = stack_load_float3(stack, from);
38                         float g = linear_rgb_to_gray(f);
39                         stack_store_float(stack, to, g);
40                         break;
41                 }
42                 case NODE_CONVERT_CI: {
43                         float3 f = stack_load_float3(stack, from);
44                         int i = (int)linear_rgb_to_gray(f);
45                         stack_store_int(stack, to, i);
46                         break;
47                 }
48                 case NODE_CONVERT_VF: {
49                         float3 f = stack_load_float3(stack, from);
50                         float g = (f.x + f.y + f.z)*(1.0f/3.0f);
51                         stack_store_float(stack, to, g);
52                         break;
53                 }
54                 case NODE_CONVERT_VI: {
55                         float3 f = stack_load_float3(stack, from);
56                         int i = (f.x + f.y + f.z)*(1.0f/3.0f);
57                         stack_store_int(stack, to, i);
58                         break;
59                 }
60                 case NODE_CONVERT_IF: {
61                         float f = (float)stack_load_int(stack, from);
62                         stack_store_float(stack, to, f);
63                         break;
64                 }
65                 case NODE_CONVERT_IV: {
66                         float f = (float)stack_load_int(stack, from);
67                         stack_store_float3(stack, to, make_float3(f, f, f));
68                         break;
69                 }
70         }
71 }
72
73 CCL_NAMESPACE_END
74