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 /* Voronoi */ 00022 00023 __device_noinline float4 svm_voronoi(NodeVoronoiColoring coloring, float scale, float3 p) 00024 { 00025 /* compute distance and point coordinate of 4 nearest neighbours */ 00026 float da[4]; 00027 float3 pa[4]; 00028 00029 voronoi(p*scale, NODE_VORONOI_DISTANCE_SQUARED, 1.0f, da, pa); 00030 00031 /* output */ 00032 float fac; 00033 float3 color; 00034 00035 if(coloring == NODE_VORONOI_INTENSITY) { 00036 fac = fabsf(da[0]); 00037 color = make_float3(fac, fac, fac); 00038 } 00039 else { 00040 color = cellnoise_color(pa[0]); 00041 fac= average(color); 00042 } 00043 00044 return make_float4(color.x, color.y, color.z, fac); 00045 } 00046 00047 __device void svm_node_tex_voronoi(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) 00048 { 00049 uint coloring = node.y; 00050 uint scale_offset, co_offset, fac_offset, color_offset; 00051 00052 decode_node_uchar4(node.z, &scale_offset, &co_offset, &fac_offset, &color_offset); 00053 00054 float3 co = stack_load_float3(stack, co_offset); 00055 float scale = stack_load_float_default(stack, scale_offset, node.w); 00056 00057 float4 result = svm_voronoi((NodeVoronoiColoring)coloring, scale, co); 00058 float3 color = make_float3(result.x, result.y, result.z); 00059 float f = result.w; 00060 00061 if(stack_valid(fac_offset)) stack_store_float(stack, fac_offset, f); 00062 if(stack_valid(color_offset)) stack_store_float3(stack, color_offset, color); 00063 } 00064 00065 CCL_NAMESPACE_END 00066