Cycles: svn merge -r36495:36747 https://svn.blender.org/svnroot/bf-blender/trunk...
[blender-staging.git] / intern / cycles / kernel / svm / svm_image.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 __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y)
22 {
23         float4 r;
24
25         /* not particularly proud of this massive switch, what are the
26            alternatives?
27            - use a single big 1D texture, and do our own lookup/filtering
28            - group by size and use a 3d texture, performance impact
29            - group into larger texture with some padding for correct lerp
30
31            also note that cuda has 128 textures limit, we use 100 now, since
32            we still need some for other storage */
33
34         switch(id) {
35                 case 0: r = kernel_tex_image_interp(__tex_image_000, x, y); break;
36                 case 1: r = kernel_tex_image_interp(__tex_image_001, x, y); break;
37                 case 2: r = kernel_tex_image_interp(__tex_image_002, x, y); break;
38                 case 3: r = kernel_tex_image_interp(__tex_image_003, x, y); break;
39                 case 4: r = kernel_tex_image_interp(__tex_image_004, x, y); break;
40                 case 5: r = kernel_tex_image_interp(__tex_image_005, x, y); break;
41                 case 6: r = kernel_tex_image_interp(__tex_image_006, x, y); break;
42                 case 7: r = kernel_tex_image_interp(__tex_image_007, x, y); break;
43                 case 8: r = kernel_tex_image_interp(__tex_image_008, x, y); break;
44                 case 9: r = kernel_tex_image_interp(__tex_image_009, x, y); break;
45                 case 10: r = kernel_tex_image_interp(__tex_image_010, x, y); break;
46                 case 11: r = kernel_tex_image_interp(__tex_image_011, x, y); break;
47                 case 12: r = kernel_tex_image_interp(__tex_image_012, x, y); break;
48                 case 13: r = kernel_tex_image_interp(__tex_image_013, x, y); break;
49                 case 14: r = kernel_tex_image_interp(__tex_image_014, x, y); break;
50                 case 15: r = kernel_tex_image_interp(__tex_image_015, x, y); break;
51                 case 16: r = kernel_tex_image_interp(__tex_image_016, x, y); break;
52                 case 17: r = kernel_tex_image_interp(__tex_image_017, x, y); break;
53                 case 18: r = kernel_tex_image_interp(__tex_image_018, x, y); break;
54                 case 19: r = kernel_tex_image_interp(__tex_image_019, x, y); break;
55                 case 20: r = kernel_tex_image_interp(__tex_image_020, x, y); break;
56                 case 21: r = kernel_tex_image_interp(__tex_image_021, x, y); break;
57                 case 22: r = kernel_tex_image_interp(__tex_image_022, x, y); break;
58                 case 23: r = kernel_tex_image_interp(__tex_image_023, x, y); break;
59                 case 24: r = kernel_tex_image_interp(__tex_image_024, x, y); break;
60                 case 25: r = kernel_tex_image_interp(__tex_image_025, x, y); break;
61                 case 26: r = kernel_tex_image_interp(__tex_image_026, x, y); break;
62                 case 27: r = kernel_tex_image_interp(__tex_image_027, x, y); break;
63                 case 28: r = kernel_tex_image_interp(__tex_image_028, x, y); break;
64                 case 29: r = kernel_tex_image_interp(__tex_image_029, x, y); break;
65                 case 30: r = kernel_tex_image_interp(__tex_image_030, x, y); break;
66                 case 31: r = kernel_tex_image_interp(__tex_image_031, x, y); break;
67                 case 32: r = kernel_tex_image_interp(__tex_image_032, x, y); break;
68                 case 33: r = kernel_tex_image_interp(__tex_image_033, x, y); break;
69                 case 34: r = kernel_tex_image_interp(__tex_image_034, x, y); break;
70                 case 35: r = kernel_tex_image_interp(__tex_image_035, x, y); break;
71                 case 36: r = kernel_tex_image_interp(__tex_image_036, x, y); break;
72                 case 37: r = kernel_tex_image_interp(__tex_image_037, x, y); break;
73                 case 38: r = kernel_tex_image_interp(__tex_image_038, x, y); break;
74                 case 39: r = kernel_tex_image_interp(__tex_image_039, x, y); break;
75                 case 40: r = kernel_tex_image_interp(__tex_image_040, x, y); break;
76                 case 41: r = kernel_tex_image_interp(__tex_image_041, x, y); break;
77                 case 42: r = kernel_tex_image_interp(__tex_image_042, x, y); break;
78                 case 43: r = kernel_tex_image_interp(__tex_image_043, x, y); break;
79                 case 44: r = kernel_tex_image_interp(__tex_image_044, x, y); break;
80                 case 45: r = kernel_tex_image_interp(__tex_image_045, x, y); break;
81                 case 46: r = kernel_tex_image_interp(__tex_image_046, x, y); break;
82                 case 47: r = kernel_tex_image_interp(__tex_image_047, x, y); break;
83                 case 48: r = kernel_tex_image_interp(__tex_image_048, x, y); break;
84                 case 49: r = kernel_tex_image_interp(__tex_image_049, x, y); break;
85                 case 50: r = kernel_tex_image_interp(__tex_image_050, x, y); break;
86                 case 51: r = kernel_tex_image_interp(__tex_image_051, x, y); break;
87                 case 52: r = kernel_tex_image_interp(__tex_image_052, x, y); break;
88                 case 53: r = kernel_tex_image_interp(__tex_image_053, x, y); break;
89                 case 54: r = kernel_tex_image_interp(__tex_image_054, x, y); break;
90                 case 55: r = kernel_tex_image_interp(__tex_image_055, x, y); break;
91                 case 56: r = kernel_tex_image_interp(__tex_image_056, x, y); break;
92                 case 57: r = kernel_tex_image_interp(__tex_image_057, x, y); break;
93                 case 58: r = kernel_tex_image_interp(__tex_image_058, x, y); break;
94                 case 59: r = kernel_tex_image_interp(__tex_image_059, x, y); break;
95                 case 60: r = kernel_tex_image_interp(__tex_image_060, x, y); break;
96                 case 61: r = kernel_tex_image_interp(__tex_image_061, x, y); break;
97                 case 62: r = kernel_tex_image_interp(__tex_image_062, x, y); break;
98                 case 63: r = kernel_tex_image_interp(__tex_image_063, x, y); break;
99                 case 64: r = kernel_tex_image_interp(__tex_image_064, x, y); break;
100                 case 65: r = kernel_tex_image_interp(__tex_image_065, x, y); break;
101                 case 66: r = kernel_tex_image_interp(__tex_image_066, x, y); break;
102                 case 67: r = kernel_tex_image_interp(__tex_image_067, x, y); break;
103                 case 68: r = kernel_tex_image_interp(__tex_image_068, x, y); break;
104                 case 69: r = kernel_tex_image_interp(__tex_image_069, x, y); break;
105                 case 70: r = kernel_tex_image_interp(__tex_image_070, x, y); break;
106                 case 71: r = kernel_tex_image_interp(__tex_image_071, x, y); break;
107                 case 72: r = kernel_tex_image_interp(__tex_image_072, x, y); break;
108                 case 73: r = kernel_tex_image_interp(__tex_image_073, x, y); break;
109                 case 74: r = kernel_tex_image_interp(__tex_image_074, x, y); break;
110                 case 75: r = kernel_tex_image_interp(__tex_image_075, x, y); break;
111                 case 76: r = kernel_tex_image_interp(__tex_image_076, x, y); break;
112                 case 77: r = kernel_tex_image_interp(__tex_image_077, x, y); break;
113                 case 78: r = kernel_tex_image_interp(__tex_image_078, x, y); break;
114                 case 79: r = kernel_tex_image_interp(__tex_image_079, x, y); break;
115                 case 80: r = kernel_tex_image_interp(__tex_image_080, x, y); break;
116                 case 81: r = kernel_tex_image_interp(__tex_image_081, x, y); break;
117                 case 82: r = kernel_tex_image_interp(__tex_image_082, x, y); break;
118                 case 83: r = kernel_tex_image_interp(__tex_image_083, x, y); break;
119                 case 84: r = kernel_tex_image_interp(__tex_image_084, x, y); break;
120                 case 85: r = kernel_tex_image_interp(__tex_image_085, x, y); break;
121                 case 86: r = kernel_tex_image_interp(__tex_image_086, x, y); break;
122                 case 87: r = kernel_tex_image_interp(__tex_image_087, x, y); break;
123                 case 88: r = kernel_tex_image_interp(__tex_image_088, x, y); break;
124                 case 89: r = kernel_tex_image_interp(__tex_image_089, x, y); break;
125                 case 90: r = kernel_tex_image_interp(__tex_image_090, x, y); break;
126                 case 91: r = kernel_tex_image_interp(__tex_image_091, x, y); break;
127                 case 92: r = kernel_tex_image_interp(__tex_image_092, x, y); break;
128                 case 93: r = kernel_tex_image_interp(__tex_image_093, x, y); break;
129                 case 94: r = kernel_tex_image_interp(__tex_image_094, x, y); break;
130                 case 95: r = kernel_tex_image_interp(__tex_image_095, x, y); break;
131                 case 96: r = kernel_tex_image_interp(__tex_image_096, x, y); break;
132                 case 97: r = kernel_tex_image_interp(__tex_image_097, x, y); break;
133                 case 98: r = kernel_tex_image_interp(__tex_image_098, x, y); break;
134                 case 99: r = kernel_tex_image_interp(__tex_image_099, x, y); break;
135                 default: 
136                         kernel_assert(0);
137                         return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
138         }
139
140         return r;
141 }
142
143 __device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
144 {
145         uint id = node.y;
146         uint co_offset, out_offset, srgb;
147
148         decode_node_uchar4(node.z, &co_offset, &out_offset, &srgb, NULL);
149
150         float3 co = stack_load_float3(stack, co_offset);
151         float4 f = svm_image_texture(kg, id, co.x, co.y);
152         float3 r = make_float3(f.x, f.y, f.z);
153
154         if(srgb)
155                 r = color_srgb_to_scene_linear(r);
156
157         stack_store_float3(stack, out_offset, r);
158 }
159
160 __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
161 {
162         uint id = node.y;
163         uint co_offset, out_offset, srgb;
164
165         decode_node_uchar4(node.z, &co_offset, &out_offset, &srgb, NULL);
166
167         float3 co = stack_load_float3(stack, co_offset);
168         float u = (atan2f(co.y, co.x) + M_PI_F)/(2*M_PI_F);
169         float v = atan2f(co.z, hypotf(co.x, co.y))/M_PI_F + 0.5f;
170         float4 f = svm_image_texture(kg, id, u, v);
171         float3 r = make_float3(f.x, f.y, f.z);
172
173         if(srgb)
174                 r = color_srgb_to_scene_linear(r);
175
176         stack_store_float3(stack, out_offset, r);
177 }
178
179 CCL_NAMESPACE_END
180