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 /* Checker */ 00022 00023 __device_noinline float svm_checker(float3 p, float scale) 00024 { 00025 p *= scale; 00026 00027 /* avoid precision issues on unit coordinates */ 00028 p.x = (p.x + 0.00001f)*0.9999f; 00029 p.y = (p.y + 0.00001f)*0.9999f; 00030 p.z = (p.z + 0.00001f)*0.9999f; 00031 00032 int xi = (int)fabsf(floorf(p.x)); 00033 int yi = (int)fabsf(floorf(p.y)); 00034 int zi = (int)fabsf(floorf(p.z)); 00035 00036 return ((xi % 2 == yi % 2) == (zi % 2))? 1.0f: 0.0f; 00037 } 00038 00039 __device void svm_node_tex_checker(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) 00040 { 00041 uint co_offset, color1_offset, color2_offset, scale_offset; 00042 uint color_offset, fac_offset; 00043 00044 decode_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &scale_offset); 00045 decode_node_uchar4(node.z, &color_offset, &fac_offset, NULL, NULL); 00046 00047 float3 co = stack_load_float3(stack, co_offset); 00048 float3 color1 = stack_load_float3(stack, color1_offset); 00049 float3 color2 = stack_load_float3(stack, color2_offset); 00050 float scale = stack_load_float_default(stack, scale_offset, node.w); 00051 00052 float f = svm_checker(co, scale); 00053 00054 if(stack_valid(color_offset)) 00055 stack_store_float3(stack, color_offset, (f == 1.0f)? color1: color2); 00056 if(stack_valid(fac_offset)) 00057 stack_store_float(stack, fac_offset, f); 00058 } 00059 00060 CCL_NAMESPACE_END 00061