Blender V2.61 - r43446

svm_noisetex.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 /* Clouds */
00022 
00023 __device_inline void svm_noise(float3 p, float scale, float detail, float distortion, float *fac, float3 *color)
00024 {
00025     NodeNoiseBasis basis = NODE_NOISE_PERLIN;
00026     int hard = 0;
00027 
00028     p *= scale;
00029 
00030     if(distortion != 0.0f) {
00031         float3 r, offset = make_float3(13.5f, 13.5f, 13.5f);
00032 
00033         r.x = noise_basis(p + offset, basis) * distortion;
00034         r.y = noise_basis(p, basis) * distortion;
00035         r.z = noise_basis(p - offset, basis) * distortion;
00036 
00037         p += r;
00038     }
00039 
00040     *fac = noise_turbulence(p, basis, detail, hard);
00041     *color = make_float3(*fac,
00042         noise_turbulence(make_float3(p.y, p.x, p.z), basis, detail, hard),
00043         noise_turbulence(make_float3(p.y, p.z, p.x), basis, detail, hard));
00044 }
00045 
00046 __device void svm_node_tex_noise(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
00047 {
00048     uint co_offset, scale_offset, detail_offset, distortion_offset, fac_offset, color_offset;
00049 
00050     decode_node_uchar4(node.y, &co_offset, &scale_offset, &detail_offset, &distortion_offset);
00051 
00052     uint4 node2 = read_node(kg, offset);
00053 
00054     float scale = stack_load_float_default(stack, scale_offset, node2.x);
00055     float detail = stack_load_float_default(stack, detail_offset, node2.y);
00056     float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
00057     float3 co = stack_load_float3(stack, co_offset);
00058 
00059     float3 color;
00060     float f;
00061 
00062     svm_noise(co, scale, detail, distortion, &f, &color);
00063 
00064     decode_node_uchar4(node.z, &color_offset, &fac_offset, NULL, NULL);
00065 
00066     if(stack_valid(fac_offset))
00067         stack_store_float(stack, fac_offset, f);
00068     if(stack_valid(color_offset))
00069         stack_store_float3(stack, color_offset, color);
00070 }
00071 
00072 CCL_NAMESPACE_END
00073