Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 CCL_NAMESPACE_BEGIN 00020 00021 __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) 00022 { 00023 float4 r; 00024 00025 /* not particularly proud of this massive switch, what are the 00026 alternatives? 00027 - use a single big 1D texture, and do our own lookup/filtering 00028 - group by size and use a 3d texture, performance impact 00029 - group into larger texture with some padding for correct lerp 00030 00031 also note that cuda has 128 textures limit, we use 100 now, since 00032 we still need some for other storage */ 00033 00034 #ifdef __KERNEL_OPENCL__ 00035 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f); /* todo */ 00036 #else 00037 switch(id) { 00038 case 0: r = kernel_tex_image_interp(__tex_image_000, x, y); break; 00039 case 1: r = kernel_tex_image_interp(__tex_image_001, x, y); break; 00040 case 2: r = kernel_tex_image_interp(__tex_image_002, x, y); break; 00041 case 3: r = kernel_tex_image_interp(__tex_image_003, x, y); break; 00042 case 4: r = kernel_tex_image_interp(__tex_image_004, x, y); break; 00043 case 5: r = kernel_tex_image_interp(__tex_image_005, x, y); break; 00044 case 6: r = kernel_tex_image_interp(__tex_image_006, x, y); break; 00045 case 7: r = kernel_tex_image_interp(__tex_image_007, x, y); break; 00046 case 8: r = kernel_tex_image_interp(__tex_image_008, x, y); break; 00047 case 9: r = kernel_tex_image_interp(__tex_image_009, x, y); break; 00048 case 10: r = kernel_tex_image_interp(__tex_image_010, x, y); break; 00049 case 11: r = kernel_tex_image_interp(__tex_image_011, x, y); break; 00050 case 12: r = kernel_tex_image_interp(__tex_image_012, x, y); break; 00051 case 13: r = kernel_tex_image_interp(__tex_image_013, x, y); break; 00052 case 14: r = kernel_tex_image_interp(__tex_image_014, x, y); break; 00053 case 15: r = kernel_tex_image_interp(__tex_image_015, x, y); break; 00054 case 16: r = kernel_tex_image_interp(__tex_image_016, x, y); break; 00055 case 17: r = kernel_tex_image_interp(__tex_image_017, x, y); break; 00056 case 18: r = kernel_tex_image_interp(__tex_image_018, x, y); break; 00057 case 19: r = kernel_tex_image_interp(__tex_image_019, x, y); break; 00058 case 20: r = kernel_tex_image_interp(__tex_image_020, x, y); break; 00059 case 21: r = kernel_tex_image_interp(__tex_image_021, x, y); break; 00060 case 22: r = kernel_tex_image_interp(__tex_image_022, x, y); break; 00061 case 23: r = kernel_tex_image_interp(__tex_image_023, x, y); break; 00062 case 24: r = kernel_tex_image_interp(__tex_image_024, x, y); break; 00063 case 25: r = kernel_tex_image_interp(__tex_image_025, x, y); break; 00064 case 26: r = kernel_tex_image_interp(__tex_image_026, x, y); break; 00065 case 27: r = kernel_tex_image_interp(__tex_image_027, x, y); break; 00066 case 28: r = kernel_tex_image_interp(__tex_image_028, x, y); break; 00067 case 29: r = kernel_tex_image_interp(__tex_image_029, x, y); break; 00068 case 30: r = kernel_tex_image_interp(__tex_image_030, x, y); break; 00069 case 31: r = kernel_tex_image_interp(__tex_image_031, x, y); break; 00070 case 32: r = kernel_tex_image_interp(__tex_image_032, x, y); break; 00071 case 33: r = kernel_tex_image_interp(__tex_image_033, x, y); break; 00072 case 34: r = kernel_tex_image_interp(__tex_image_034, x, y); break; 00073 case 35: r = kernel_tex_image_interp(__tex_image_035, x, y); break; 00074 case 36: r = kernel_tex_image_interp(__tex_image_036, x, y); break; 00075 case 37: r = kernel_tex_image_interp(__tex_image_037, x, y); break; 00076 case 38: r = kernel_tex_image_interp(__tex_image_038, x, y); break; 00077 case 39: r = kernel_tex_image_interp(__tex_image_039, x, y); break; 00078 case 40: r = kernel_tex_image_interp(__tex_image_040, x, y); break; 00079 case 41: r = kernel_tex_image_interp(__tex_image_041, x, y); break; 00080 case 42: r = kernel_tex_image_interp(__tex_image_042, x, y); break; 00081 case 43: r = kernel_tex_image_interp(__tex_image_043, x, y); break; 00082 case 44: r = kernel_tex_image_interp(__tex_image_044, x, y); break; 00083 case 45: r = kernel_tex_image_interp(__tex_image_045, x, y); break; 00084 case 46: r = kernel_tex_image_interp(__tex_image_046, x, y); break; 00085 case 47: r = kernel_tex_image_interp(__tex_image_047, x, y); break; 00086 case 48: r = kernel_tex_image_interp(__tex_image_048, x, y); break; 00087 case 49: r = kernel_tex_image_interp(__tex_image_049, x, y); break; 00088 case 50: r = kernel_tex_image_interp(__tex_image_050, x, y); break; 00089 case 51: r = kernel_tex_image_interp(__tex_image_051, x, y); break; 00090 case 52: r = kernel_tex_image_interp(__tex_image_052, x, y); break; 00091 case 53: r = kernel_tex_image_interp(__tex_image_053, x, y); break; 00092 case 54: r = kernel_tex_image_interp(__tex_image_054, x, y); break; 00093 case 55: r = kernel_tex_image_interp(__tex_image_055, x, y); break; 00094 case 56: r = kernel_tex_image_interp(__tex_image_056, x, y); break; 00095 case 57: r = kernel_tex_image_interp(__tex_image_057, x, y); break; 00096 case 58: r = kernel_tex_image_interp(__tex_image_058, x, y); break; 00097 case 59: r = kernel_tex_image_interp(__tex_image_059, x, y); break; 00098 case 60: r = kernel_tex_image_interp(__tex_image_060, x, y); break; 00099 case 61: r = kernel_tex_image_interp(__tex_image_061, x, y); break; 00100 case 62: r = kernel_tex_image_interp(__tex_image_062, x, y); break; 00101 case 63: r = kernel_tex_image_interp(__tex_image_063, x, y); break; 00102 case 64: r = kernel_tex_image_interp(__tex_image_064, x, y); break; 00103 case 65: r = kernel_tex_image_interp(__tex_image_065, x, y); break; 00104 case 66: r = kernel_tex_image_interp(__tex_image_066, x, y); break; 00105 case 67: r = kernel_tex_image_interp(__tex_image_067, x, y); break; 00106 case 68: r = kernel_tex_image_interp(__tex_image_068, x, y); break; 00107 case 69: r = kernel_tex_image_interp(__tex_image_069, x, y); break; 00108 case 70: r = kernel_tex_image_interp(__tex_image_070, x, y); break; 00109 case 71: r = kernel_tex_image_interp(__tex_image_071, x, y); break; 00110 case 72: r = kernel_tex_image_interp(__tex_image_072, x, y); break; 00111 case 73: r = kernel_tex_image_interp(__tex_image_073, x, y); break; 00112 case 74: r = kernel_tex_image_interp(__tex_image_074, x, y); break; 00113 case 75: r = kernel_tex_image_interp(__tex_image_075, x, y); break; 00114 case 76: r = kernel_tex_image_interp(__tex_image_076, x, y); break; 00115 case 77: r = kernel_tex_image_interp(__tex_image_077, x, y); break; 00116 case 78: r = kernel_tex_image_interp(__tex_image_078, x, y); break; 00117 case 79: r = kernel_tex_image_interp(__tex_image_079, x, y); break; 00118 case 80: r = kernel_tex_image_interp(__tex_image_080, x, y); break; 00119 case 81: r = kernel_tex_image_interp(__tex_image_081, x, y); break; 00120 case 82: r = kernel_tex_image_interp(__tex_image_082, x, y); break; 00121 case 83: r = kernel_tex_image_interp(__tex_image_083, x, y); break; 00122 case 84: r = kernel_tex_image_interp(__tex_image_084, x, y); break; 00123 case 85: r = kernel_tex_image_interp(__tex_image_085, x, y); break; 00124 case 86: r = kernel_tex_image_interp(__tex_image_086, x, y); break; 00125 case 87: r = kernel_tex_image_interp(__tex_image_087, x, y); break; 00126 case 88: r = kernel_tex_image_interp(__tex_image_088, x, y); break; 00127 case 89: r = kernel_tex_image_interp(__tex_image_089, x, y); break; 00128 case 90: r = kernel_tex_image_interp(__tex_image_090, x, y); break; 00129 case 91: r = kernel_tex_image_interp(__tex_image_091, x, y); break; 00130 case 92: r = kernel_tex_image_interp(__tex_image_092, x, y); break; 00131 case 93: r = kernel_tex_image_interp(__tex_image_093, x, y); break; 00132 case 94: r = kernel_tex_image_interp(__tex_image_094, x, y); break; 00133 case 95: r = kernel_tex_image_interp(__tex_image_095, x, y); break; 00134 case 96: r = kernel_tex_image_interp(__tex_image_096, x, y); break; 00135 case 97: r = kernel_tex_image_interp(__tex_image_097, x, y); break; 00136 case 98: r = kernel_tex_image_interp(__tex_image_098, x, y); break; 00137 case 99: r = kernel_tex_image_interp(__tex_image_099, x, y); break; 00138 default: 00139 kernel_assert(0); 00140 return make_float4(0.0f, 0.0f, 0.0f, 0.0f); 00141 } 00142 #endif 00143 00144 return r; 00145 } 00146 00147 __device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) 00148 { 00149 uint id = node.y; 00150 uint co_offset, out_offset, alpha_offset, srgb; 00151 00152 decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); 00153 00154 float3 co = stack_load_float3(stack, co_offset); 00155 float4 f = svm_image_texture(kg, id, co.x, co.y); 00156 float3 r = make_float3(f.x, f.y, f.z); 00157 00158 if(srgb) { 00159 r.x = color_srgb_to_scene_linear(r.x); 00160 r.y = color_srgb_to_scene_linear(r.y); 00161 r.z = color_srgb_to_scene_linear(r.z); 00162 } 00163 00164 if(stack_valid(out_offset)) 00165 stack_store_float3(stack, out_offset, r); 00166 if(stack_valid(alpha_offset)) 00167 stack_store_float(stack, alpha_offset, f.w); 00168 } 00169 00170 __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) 00171 { 00172 uint id = node.y; 00173 uint co_offset, out_offset, alpha_offset, srgb; 00174 00175 decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); 00176 00177 float3 co = stack_load_float3(stack, co_offset); 00178 float u = (atan2f(co.y, co.x) + M_PI_F)/(2*M_PI_F); 00179 float v = atan2f(co.z, hypotf(co.x, co.y))/M_PI_F + 0.5f; 00180 float4 f = svm_image_texture(kg, id, u, v); 00181 float3 r = make_float3(f.x, f.y, f.z); 00182 00183 if(srgb) { 00184 r.x = color_srgb_to_scene_linear(r.x); 00185 r.y = color_srgb_to_scene_linear(r.y); 00186 r.z = color_srgb_to_scene_linear(r.z); 00187 } 00188 00189 if(stack_valid(out_offset)) 00190 stack_store_float3(stack, out_offset, r); 00191 if(stack_valid(alpha_offset)) 00192 stack_store_float(stack, alpha_offset, f.w); 00193 } 00194 00195 CCL_NAMESPACE_END 00196