Blender V2.61 - r43446

svm_wave.h

Go to the documentation of this file.
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 /* Marble */
00022 
00023 __device_noinline float svm_wave(NodeWoodType type, float3 p, float scale, float detail, float distortion, float dscale)
00024 {
00025     float w, n;
00026 
00027     p *= scale;
00028 
00029     if(type == NODE_WAVE_BANDS)
00030         n= (p.x + p.x + p.z)*10.0f;
00031     else /* if(type == NODE_WAVE_RINGS) */
00032         n= len(p)*20.0f;
00033     
00034     if(distortion != 0.0f)
00035         n += distortion * noise_turbulence(p*dscale, NODE_NOISE_PERLIN, detail, 0);
00036 
00037     w = noise_wave(NODE_WAVE_SINE, n);
00038 
00039     return w;
00040 }
00041 
00042 __device void svm_node_tex_wave(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
00043 {
00044     uint4 node2 = read_node(kg, offset);
00045 
00046     uint type;
00047     uint co_offset, scale_offset, detail_offset, dscale_offset, distortion_offset, color_offset, fac_offset;
00048 
00049     decode_node_uchar4(node.y, &type, &color_offset, &fac_offset, &dscale_offset);
00050     decode_node_uchar4(node.z, &co_offset, &scale_offset, &detail_offset, &distortion_offset);
00051 
00052     float3 co = stack_load_float3(stack, co_offset);
00053     float scale = stack_load_float_default(stack, scale_offset, node2.x);
00054     float detail = stack_load_float_default(stack, detail_offset, node2.y);
00055     float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
00056     float dscale = stack_load_float_default(stack, dscale_offset, node2.w);
00057 
00058     float f = svm_wave((NodeWoodType)type, co, scale, detail, distortion, dscale);
00059 
00060     if(stack_valid(fac_offset)) stack_store_float(stack, fac_offset, f);
00061     if(stack_valid(color_offset)) stack_store_float3(stack, color_offset, make_float3(f, f, f));
00062 }
00063 
00064 CCL_NAMESPACE_END
00065