diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-07 01:05:58 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-07 01:05:58 +0400 |
commit | fb56dbc2afc7c8b6ffc24406ed82cbcbff090da3 (patch) | |
tree | 5832366c7147ad6ebc858312ac106b5d1571b5e5 /source/blender/nodes | |
parent | 3bf96250cde08ab9ad717819114b48ccb11c2d5d (diff) |
Cycles: procedural texture nodes reorganization. This will break existing files
using them, but rather do it now that I have the chance still. Highlights:
* Wood and Marble merged into a single Wave texture
* Clouds + Distorted Noise merged into new Noise node
* Blend renamed to Gradient
* Stucci removed, was mostly useful for old bump
* Noise removed, will come back later, didn't actually work yet
* Depth setting is now Detail socket, which accepts float values
* Scale socket instead of Size socket
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/Textures
Diffstat (limited to 'source/blender/nodes')
15 files changed, 326 insertions, 817 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 8ee67fc4f9a..1847fcb8add 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -135,7 +135,7 @@ set(SRC shader/nodes/node_shader_bsdf_velvet.c shader/nodes/node_shader_emission.c shader/nodes/node_shader_fresnel.c - shader/nodes/node_shader_blend_weight.c + shader/nodes/node_shader_layer_weight.c shader/nodes/node_shader_geometry.c shader/nodes/node_shader_holdout.c shader/nodes/node_shader_volume_transparent.c @@ -147,20 +147,16 @@ set(SRC shader/nodes/node_shader_output_material.c shader/nodes/node_shader_output_texture.c shader/nodes/node_shader_output_world.c - shader/nodes/node_shader_tex_blend.c - shader/nodes/node_shader_tex_clouds.c + shader/nodes/node_shader_tex_gradient.c shader/nodes/node_shader_tex_coord.c - shader/nodes/node_shader_tex_distnoise.c - shader/nodes/node_shader_tex_image.c shader/nodes/node_shader_tex_environment.c + shader/nodes/node_shader_tex_image.c shader/nodes/node_shader_tex_magic.c - shader/nodes/node_shader_tex_marble.c shader/nodes/node_shader_tex_musgrave.c shader/nodes/node_shader_tex_noise.c shader/nodes/node_shader_tex_sky.c - shader/nodes/node_shader_tex_stucci.c shader/nodes/node_shader_tex_voronoi.c - shader/nodes/node_shader_tex_wood.c + shader/nodes/node_shader_tex_wave.c shader/nodes/node_shader_noise.h shader/node_shader_tree.c shader/node_shader_util.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 8f6a6e527f2..52d5f2f5e9c 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -75,7 +75,7 @@ void register_node_type_sh_attribute(ListBase *lb); void register_node_type_sh_geometry(ListBase *lb); void register_node_type_sh_light_path(ListBase *lb); void register_node_type_sh_fresnel(ListBase *lb); -void register_node_type_sh_blend_weight(ListBase *lb); +void register_node_type_sh_layer_weight(ListBase *lb); void register_node_type_sh_tex_coord(ListBase *lb); void register_node_type_sh_background(ListBase *lb); @@ -102,15 +102,11 @@ void register_node_type_sh_tex_image(ListBase *lb); void register_node_type_sh_tex_environment(ListBase *lb); void register_node_type_sh_tex_sky(ListBase *lb); void register_node_type_sh_tex_voronoi(ListBase *lb); -void register_node_type_sh_tex_blend(ListBase *lb); +void register_node_type_sh_tex_gradient(ListBase *lb); void register_node_type_sh_tex_magic(ListBase *lb); -void register_node_type_sh_tex_marble(ListBase *lb); -void register_node_type_sh_tex_clouds(ListBase *lb); -void register_node_type_sh_tex_wood(ListBase *lb); +void register_node_type_sh_tex_wave(ListBase *lb); void register_node_type_sh_tex_musgrave(ListBase *lb); void register_node_type_sh_tex_noise(ListBase *lb); -void register_node_type_sh_tex_stucci(ListBase *lb); -void register_node_type_sh_tex_distnoise(ListBase *lb); #endif diff --git a/source/blender/nodes/shader/nodes/node_shader_blend_weight.c b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c index f214f765abf..79e5728fab6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_blend_weight.c +++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c @@ -1,5 +1,5 @@ /** - * $Id: node_shader_blend_weight.c 32517 2010-10-16 14:32:17Z campbellbarton $ + * $Id: node_shader_layer_weight.c 32517 2010-10-16 14:32:17Z campbellbarton $ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -29,40 +29,41 @@ #include "../node_shader_util.h" -/* **************** BlendWeight ******************** */ -static bNodeSocketTemplate sh_node_blend_weight_in[]= { +/* **************** Layer Weight ******************** */ + +static bNodeSocketTemplate sh_node_layer_weight_in[]= { { SOCK_FLOAT, 1, "Blend", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } }; -static bNodeSocketTemplate sh_node_blend_weight_out[]= { +static bNodeSocketTemplate sh_node_layer_weight_out[]= { { SOCK_FLOAT, 0, "Fresnel", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { SOCK_FLOAT, 0, "Facing", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } }; -static void node_shader_exec_blend_weight(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_layer_weight(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { } -static int node_shader_gpu_blend_weight(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out)) +static int node_shader_gpu_layer_weight(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out)) { return 0; } /* node type definition */ -void register_node_type_sh_blend_weight(ListBase *lb) +void register_node_type_sh_layer_weight(ListBase *lb) { static bNodeType ntype; - node_type_base(&ntype, SH_NODE_BLEND_WEIGHT, "Blend Weight", NODE_CLASS_INPUT, 0); + node_type_base(&ntype, SH_NODE_LAYER_WEIGHT, "Layer Weight", NODE_CLASS_INPUT, 0); node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_blend_weight_in, sh_node_blend_weight_out); + node_type_socket_templates(&ntype, sh_node_layer_weight_in, sh_node_layer_weight_out); node_type_size(&ntype, 150, 60, 200); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, node_shader_exec_blend_weight); - node_type_gpu(&ntype, node_shader_gpu_blend_weight); + node_type_exec(&ntype, node_shader_exec_layer_weight); + node_type_gpu(&ntype, node_shader_gpu_layer_weight); nodeRegisterType(lb, &ntype); }; diff --git a/source/blender/nodes/shader/nodes/node_shader_noise.h b/source/blender/nodes/shader/nodes/node_shader_noise.h index 44aa8f6bb41..7f633820124 100644 --- a/source/blender/nodes/shader/nodes/node_shader_noise.h +++ b/source/blender/nodes/shader/nodes/node_shader_noise.h @@ -444,14 +444,17 @@ MINLINE float noise_wave(int wave, float a) /* Turbulence */ -MINLINE float noise_turbulence(float p[3], int basis, int octaves, int hard) +MINLINE float noise_turbulence(float p[3], int basis, float octaves, int hard) { float fscale = 1.0f; float amp = 1.0f; float sum = 0.0f; - int i; + float rmd; + int i, n; + + octaves = CLAMPIS(octaves, 0.0f, 16.0f); - for(i = 0; i <= octaves; i++) { + for(i = 0; i <= (int)octaves; i++) { float pscale[3] = {fscale*p[0], fscale*p[1], fscale*p[2]}; float t = noise_basis(pscale, basis); @@ -463,7 +466,28 @@ MINLINE float noise_turbulence(float p[3], int basis, int octaves, int hard) fscale *= 2.0f; } - sum *= ((float)(1 << octaves)/(float)((1 << (octaves+1)) - 1)); + rmd = octaves - floor(octaves); + + if(rmd != 0.0f) { + float pscale[3] = {fscale*p[0], fscale*p[1], fscale*p[2]}; + float t = noise_basis(pscale, basis); + float sum2; + + if(hard) + t = fabsf(2.0f*t - 1.0f); + + sum2 = sum + t*amp; + + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + sum2 *= ((float)(1 << (n+1))/(float)((1 << (n+2)) - 1)); + + return (1.0f - rmd)*sum + rmd*sum2; + } + else { + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + return sum; + } + return sum; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_clouds.c b/source/blender/nodes/shader/nodes/node_shader_tex_clouds.c deleted file mode 100644 index 12f117995bc..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_clouds.c +++ /dev/null @@ -1,123 +0,0 @@ -/** - * $Id: node_shader_output.c 32517 2010-10-16 14:32:17Z campbellbarton $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "../node_shader_util.h" -#include "node_shader_noise.h" - -static float clouds(int basis, int hard, int depth, float size, float vec[3], float color[3]) -{ - float p[3], pg[3], pb[3]; - - mul_v3_v3fl(p, vec, 1.0f/size); - - pg[0]= p[1]; - pg[1]= p[0]; - pg[2]= p[2]; - - pb[0]= p[1]; - pb[1]= p[2]; - pb[2]= p[0]; - - color[0]= noise_turbulence(p, basis, depth, hard); - color[1]= noise_turbulence(pg, basis, depth, hard); - color[2]= noise_turbulence(pb, basis, depth, hard); - - return color[0]; -} - -/* **************** CLOUDS ******************** */ - -static bNodeSocketTemplate sh_node_tex_clouds_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_tex_clouds_out[]= { - { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_init_tex_clouds(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) -{ - NodeTexClouds *tex = MEM_callocN(sizeof(NodeTexClouds), "NodeTexClouds"); - default_tex_mapping(&tex->base.tex_mapping); - default_color_mapping(&tex->base.color_mapping); - tex->basis = SHD_NOISE_PERLIN; - tex->hard = 0; - tex->depth = 2; - - node->storage = tex; -} - -static void node_shader_exec_tex_clouds(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - ShaderCallData *scd= (ShaderCallData*)data; - NodeTexClouds *tex= (NodeTexClouds*)node->storage; - bNodeSocket *vecsock = node->inputs.first; - float vec[3], size; - - if(vecsock->link) - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - else - copy_v3_v3(vec, scd->co); - - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - - out[1]->vec[0]= clouds(tex->basis, tex->hard, tex->depth, size, vec, out[0]->vec); -} - -static int node_shader_gpu_tex_clouds(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - if(!in[0].link) - in[0].link = GPU_attribute(CD_ORCO, ""); - - node_shader_gpu_tex_mapping(mat, node, in, out); - - return GPU_stack_link(mat, "node_tex_clouds", in, out); -} - -/* node type definition */ -void register_node_type_sh_tex_clouds(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_TEX_CLOUDS, "Clouds Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_tex_clouds_in, sh_node_tex_clouds_out); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, node_shader_init_tex_clouds); - node_type_storage(&ntype, "NodeTexClouds", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_tex_clouds); - node_type_gpu(&ntype, node_shader_gpu_tex_clouds); - - nodeRegisterType(lb, &ntype); -}; - diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_distnoise.c b/source/blender/nodes/shader/nodes/node_shader_tex_distnoise.c deleted file mode 100644 index 56a87949fc7..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_distnoise.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - * $Id: node_shader_output.c 32517 2010-10-16 14:32:17Z campbellbarton $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "../node_shader_util.h" -#include "node_shader_noise.h" - -static float distorted_noise(float vec[3], float size, int basis, int distortion_basis, float distortion) -{ - float p[3], r[3], p_offset[3], p_noffset[3]; - float offset[3] = {13.5f, 13.5f, 13.5f}; - - mul_v3_v3fl(p, vec, 1.0f/size); - add_v3_v3v3(p_offset, p, offset); - sub_v3_v3v3(p_noffset, p, offset); - - r[0] = noise_basis(p_offset, basis) * distortion; - r[1] = noise_basis(p, basis) * distortion; - r[2] = noise_basis(p_noffset, basis) * distortion; - - add_v3_v3(p, r); - - return noise_basis(p, distortion_basis); /* distorted-domain noise */ -} - -/* **************** OUTPUT ******************** */ - -static bNodeSocketTemplate sh_node_tex_distnoise_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Distortion", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_tex_distnoise_out[]= { - { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_init_tex_distorted_noise(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) -{ - NodeTexDistortedNoise *tex = MEM_callocN(sizeof(NodeTexDistortedNoise), "NodeTexDistortedNoise"); - default_tex_mapping(&tex->base.tex_mapping); - default_color_mapping(&tex->base.color_mapping); - tex->basis = SHD_NOISE_PERLIN; - tex->distortion_basis = SHD_NOISE_PERLIN; - - node->storage = tex; -} - -static void node_shader_exec_tex_distnoise(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - ShaderCallData *scd= (ShaderCallData*)data; - NodeTexDistortedNoise *tex= (NodeTexDistortedNoise*)node->storage; - bNodeSocket *vecsock = node->inputs.first; - float vec[3], size, distortion; - - if(vecsock->link) - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - else - copy_v3_v3(vec, scd->co); - - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - nodestack_get_vec(&distortion, SOCK_FLOAT, in[2]); - - out[0]->vec[0]= distorted_noise(vec, size, tex->basis, tex->distortion_basis, distortion); -} - -static int node_shader_gpu_tex_distnoise(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - if(!in[0].link) - in[0].link = GPU_attribute(CD_ORCO, ""); - - node_shader_gpu_tex_mapping(mat, node, in, out); - - return GPU_stack_link(mat, "node_tex_distnoise", in, out); -} - -/* node type definition */ -void register_node_type_sh_tex_distnoise(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_TEX_DISTNOISE, "Distorted Noise Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_tex_distnoise_in, sh_node_tex_distnoise_out); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, node_shader_init_tex_distorted_noise); - node_type_storage(&ntype, "NodeTexDistortedNoise", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_tex_distnoise); - node_type_gpu(&ntype, node_shader_gpu_tex_distnoise); - - nodeRegisterType(lb, &ntype); -}; - diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_blend.c b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c index 50bafede2aa..71269ba85b6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_blend.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * The Original Code is Copyright (C) 2005 Blender Foundation. + * The Original Code is Copyright (C) 2005 Gradienter Foundation. * All rights reserved. * * The Original Code is: all of this file. @@ -29,18 +29,12 @@ #include "../node_shader_util.h" -static float blend(float p[3], int type, int axis) +static float gradient(float p[3], int type) { float x, y; - if(axis == SHD_BLEND_VERTICAL) { - x= p[1]; - y= p[0]; - } - else { - x= p[0]; - y= p[1]; - } + x= p[0]; + y= p[1]; if(type == SHD_BLEND_LINEAR) { return (1.0f + x)/2.0f; @@ -75,65 +69,71 @@ static float blend(float p[3], int type, int axis) /* **************** BLEND ******************** */ -static bNodeSocketTemplate sh_node_tex_blend_in[]= { +static bNodeSocketTemplate sh_node_tex_gradient_in[]= { { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, { -1, 0, "" } }; -static bNodeSocketTemplate sh_node_tex_blend_out[]= { +static bNodeSocketTemplate sh_node_tex_gradient_out[]= { + { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } }; -static void node_shader_init_tex_blend(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) { - NodeTexBlend *tex = MEM_callocN(sizeof(NodeTexBlend), "NodeTexBlend"); + NodeTexGradient *tex = MEM_callocN(sizeof(NodeTexGradient), "NodeTexGradient"); default_tex_mapping(&tex->base.tex_mapping); default_color_mapping(&tex->base.color_mapping); - tex->progression = SHD_BLEND_LINEAR; - tex->axis = SHD_BLEND_HORIZONTAL; + tex->gradient_type = SHD_BLEND_LINEAR; node->storage = tex; } -static void node_shader_exec_tex_blend(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +static void node_shader_exec_tex_gradient(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { ShaderCallData *scd= (ShaderCallData*)data; - NodeTexBlend *tex= (NodeTexBlend*)node->storage; + NodeTexGradient *tex= (NodeTexGradient*)node->storage; bNodeSocket *vecsock = node->inputs.first; - float vec[3]; + float vec[3], fac; if(vecsock->link) nodestack_get_vec(vec, SOCK_VECTOR, in[0]); else copy_v3_v3(vec, scd->co); - out[0]->vec[0]= blend(vec, tex->progression, tex->axis); + fac= gradient(vec, tex->gradient_type); + CLAMP(fac, 0.0f, 1.0f); + + out[0]->vec[0]= fac; + out[0]->vec[1]= fac; + out[0]->vec[2]= fac; + out[1]->vec[0]= fac; } -static int node_shader_gpu_tex_blend(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { if(!in[0].link) in[0].link = GPU_attribute(CD_ORCO, ""); node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_blend", in, out); + return GPU_stack_link(mat, "node_tex_gradient", in, out); } /* node type definition */ -void register_node_type_sh_tex_blend(ListBase *lb) +void register_node_type_sh_tex_gradient(ListBase *lb) { static bNodeType ntype; - node_type_base(&ntype, SH_NODE_TEX_BLEND, "Blend Texture", NODE_CLASS_TEXTURE, 0); + node_type_base(&ntype, SH_NODE_TEX_GRADIENT, "Gradient Texture", NODE_CLASS_TEXTURE, 0); node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_tex_blend_in, sh_node_tex_blend_out); + node_type_socket_templates(&ntype, sh_node_tex_gradient_in, sh_node_tex_gradient_out); node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, node_shader_init_tex_blend); - node_type_storage(&ntype, "NodeTexBlend", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_tex_blend); - node_type_gpu(&ntype, node_shader_gpu_tex_blend); + node_type_init(&ntype, node_shader_init_tex_gradient); + node_type_storage(&ntype, "NodeTexGradient", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, node_shader_exec_tex_gradient); + node_type_gpu(&ntype, node_shader_gpu_tex_gradient); nodeRegisterType(lb, &ntype); }; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c index 8d0a2d3fb85..278f141f769 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c @@ -29,56 +29,54 @@ #include "../node_shader_util.h" -static void magic(float rgb[3], float p[3], int n, float turbulence) +static void magic(float rgb[3], float p[3], int n, float distortion) { - float turb = turbulence/5.0f; - float x = sinf((p[0] + p[1] + p[2])*5.0f); float y = cosf((-p[0] + p[1] - p[2])*5.0f); float z = -cosf((-p[0] - p[1] + p[2])*5.0f); if(n > 0) { - x *= turb; - y *= turb; - z *= turb; + x *= distortion; + y *= distortion; + z *= distortion; y = -cosf(x-y+z); - y *= turb; + y *= distortion; if(n > 1) { x= cosf(x-y-z); - x *= turb; + x *= distortion; if(n > 2) { z= sinf(-x-y-z); - z *= turb; + z *= distortion; if(n > 3) { x= -cosf(-x+y-z); - x *= turb; + x *= distortion; if(n > 4) { y= -sinf(-x+y+z); - y *= turb; + y *= distortion; if(n > 5) { y= -cosf(-x+y+z); - y *= turb; + y *= distortion; if(n > 6) { x= cosf(x+y+z); - x *= turb; + x *= distortion; if(n > 7) { z= sinf(x+y-z); - z *= turb; + z *= distortion; if(n > 8) { x= -cosf(-x-y+z); - x *= turb; + x *= distortion; if(n > 9) { y= -sinf(x-y+z); - y *= turb; + y *= distortion; } } } @@ -90,11 +88,11 @@ static void magic(float rgb[3], float p[3], int n, float turbulence) } } - if(turb != 0.0f) { - turb *= 2.0f; - x /= turb; - y /= turb; - z /= turb; + if(distortion != 0.0f) { + distortion *= 2.0f; + x /= distortion; + y /= distortion; + z /= distortion; } rgb[0]= 0.5f - x; @@ -106,12 +104,14 @@ static void magic(float rgb[3], float p[3], int n, float turbulence) static bNodeSocketTemplate sh_node_tex_magic_in[]= { { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Scale", 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Distortion", 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, { -1, 0, "" } }; static bNodeSocketTemplate sh_node_tex_magic_out[]= { { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } }; @@ -130,16 +130,17 @@ static void node_shader_exec_tex_magic(void *data, bNode *node, bNodeStack **in, ShaderCallData *scd= (ShaderCallData*)data; NodeTexMagic *tex= (NodeTexMagic*)node->storage; bNodeSocket *vecsock = node->inputs.first; - float vec[3], turbulence; + float vec[3], distortion; if(vecsock->link) nodestack_get_vec(vec, SOCK_VECTOR, in[0]); else copy_v3_v3(vec, scd->co); - nodestack_get_vec(&turbulence, SOCK_FLOAT, in[1]); + nodestack_get_vec(&distortion, SOCK_FLOAT, in[1]); - magic(out[0]->vec, vec, tex->depth, turbulence); + magic(out[0]->vec, vec, tex->depth, distortion); + out[1]->vec[0] = (out[0]->vec[0] + out[0]->vec[1] + out[0]->vec[2])*(1.0f/3.0f); } static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_marble.c b/source/blender/nodes/shader/nodes/node_shader_tex_marble.c deleted file mode 100644 index 3bb999659c9..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_marble.c +++ /dev/null @@ -1,128 +0,0 @@ -/** - * $Id: node_shader_output.c 32517 2010-10-16 14:32:17Z campbellbarton $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "../node_shader_util.h" -#include "node_shader_noise.h" - -static float marble(float vec[3], float size, int type, int wave, int basis, int hard, float turb, int depth) -{ - float p[3]; - float x = vec[0]; - float y = vec[1]; - float z = vec[2]; - float n = 5.0f * (x + y + z); - float mi; - - mul_v3_v3fl(p, vec, 1.0f/size); - - mi = n + turb * noise_turbulence(p, basis, depth, hard); - - mi = noise_wave(wave, mi); - - if(type == SHD_MARBLE_SHARP) - mi = sqrt(mi); - else if(type == SHD_MARBLE_SHARPER) - mi = sqrt(sqrt(mi)); - - return mi; -} - -/* **************** MARBLE ******************** */ - -static bNodeSocketTemplate sh_node_tex_marble_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_tex_marble_out[]= { - { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_init_tex_marble(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) -{ - NodeTexMarble *tex = MEM_callocN(sizeof(NodeTexMarble), "NodeTexMarble"); - default_tex_mapping(&tex->base.tex_mapping); - default_color_mapping(&tex->base.color_mapping); - tex->type = SHD_MARBLE_SOFT; - tex->wave = SHD_WAVE_SINE; - tex->basis = SHD_NOISE_PERLIN; - tex->hard = 0; - tex->depth = 2; - - node->storage = tex; -} - -static void node_shader_exec_tex_marble(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - ShaderCallData *scd= (ShaderCallData*)data; - NodeTexMarble *tex= (NodeTexMarble*)node->storage; - bNodeSocket *vecsock = node->inputs.first; - float vec[3], size, turbulence; - - if(vecsock->link) - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - else - copy_v3_v3(vec, scd->co); - - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - nodestack_get_vec(&turbulence, SOCK_FLOAT, in[2]); - - out[0]->vec[0]= marble(vec, size, tex->type, tex->wave, tex->basis, tex->hard, turbulence, tex->depth); -} - -static int node_shader_gpu_tex_marble(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - if(!in[0].link) - in[0].link = GPU_attribute(CD_ORCO, ""); - - node_shader_gpu_tex_mapping(mat, node, in, out); - - return GPU_stack_link(mat, "node_tex_marble", in, out); -} - -/* node type definition */ -void register_node_type_sh_tex_marble(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_TEX_MARBLE, "Marble Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_tex_marble_in, sh_node_tex_marble_out); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, node_shader_init_tex_marble); - node_type_storage(&ntype, "NodeTexMarble", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_tex_marble); - node_type_gpu(&ntype, node_shader_gpu_tex_marble); - - nodeRegisterType(lb, &ntype); -}; - diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c index 7cf33445a5d..cb5a8d7da0b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c @@ -34,12 +34,12 @@ * * H: fractal increment parameter * lacunarity: gap between successive frequencies - * octaves: number of frequencies in the fBm + * detail: number of frequencies in the fBm * * from "Texturing and Modelling: A procedural approach" */ -static float noise_musgrave_fBm(float p[3], int basis, float H, float lacunarity, float octaves) +static float noise_musgrave_fBm(float p[3], int basis, float H, float lacunarity, float detail) { float rmd; float value = 0.0f; @@ -47,13 +47,13 @@ static float noise_musgrave_fBm(float p[3], int basis, float H, float lacunarity float pwHL = pow(lacunarity, -H); int i; - for(i = 0; i < (int)octaves; i++) { + for(i = 0; i < (int)detail; i++) { value += noise_basis(p, basis) * pwr; pwr *= pwHL; mul_v3_fl(p, lacunarity); } - rmd = octaves - floor(octaves); + rmd = detail - floor(detail); if(rmd != 0.0f) value += rmd * noise_basis(p, basis) * pwr; @@ -64,10 +64,10 @@ static float noise_musgrave_fBm(float p[3], int basis, float H, float lacunarity * * H: highest fractal dimension * lacunarity: gap between successive frequencies - * octaves: number of frequencies in the fBm + * detail: number of frequencies in the fBm */ -static float noise_musgrave_multi_fractal(float p[3], int basis, float H, float lacunarity, float octaves) +static float noise_musgrave_multi_fractal(float p[3], int basis, float H, float lacunarity, float detail) { float rmd; float value = 1.0f; @@ -75,13 +75,13 @@ static float noise_musgrave_multi_fractal(float p[3], int basis, float H, float float pwHL = pow(lacunarity, -H); int i; - for(i = 0; i < (int)octaves; i++) { + for(i = 0; i < (int)detail; i++) { value *= (pwr * noise_basis(p, basis) + 1.0f); pwr *= pwHL; mul_v3_fl(p, lacunarity); } - rmd = octaves - floor(octaves); + rmd = detail - floor(detail); if(rmd != 0.0f) value *= (rmd * pwr * noise_basis(p, basis) + 1.0f); /* correct? */ @@ -92,29 +92,29 @@ static float noise_musgrave_multi_fractal(float p[3], int basis, float H, float * * H: fractal dimension of the roughest area * lacunarity: gap between successive frequencies - * octaves: number of frequencies in the fBm + * detail: number of frequencies in the fBm * offset: raises the terrain from `sea level' */ -static float noise_musgrave_hetero_terrain(float p[3], int basis, float H, float lacunarity, float octaves, float offset) +static float noise_musgrave_hetero_terrain(float p[3], int basis, float H, float lacunarity, float detail, float offset) { float value, increment, rmd; float pwHL = pow(lacunarity, -H); float pwr = pwHL; int i; - /* first unscaled octave of function; later octaves are scaled */ + /* first unscaled octave of function; later detail are scaled */ value = offset + noise_basis(p, basis); mul_v3_fl(p, lacunarity); - for(i = 1; i < (int)octaves; i++) { + for(i = 1; i < (int)detail; i++) { increment = (noise_basis(p, basis) + offset) * pwr * value; value += increment; pwr *= pwHL; mul_v3_fl(p, lacunarity); } - rmd = octaves - floor(octaves); + rmd = detail - floor(detail); if(rmd != 0.0f) { increment = (noise_basis(p, basis) + offset) * pwr * value; value += rmd * increment; @@ -127,11 +127,11 @@ static float noise_musgrave_hetero_terrain(float p[3], int basis, float H, float * * H: fractal dimension of the roughest area * lacunarity: gap between successive frequencies - * octaves: number of frequencies in the fBm + * detail: number of frequencies in the fBm * offset: raises the terrain from `sea level' */ -static float noise_musgrave_hybrid_multi_fractal(float p[3], int basis, float H, float lacunarity, float octaves, float offset, float gain) +static float noise_musgrave_hybrid_multi_fractal(float p[3], int basis, float H, float lacunarity, float detail, float offset, float gain) { float result, signal, weight, rmd; float pwHL = pow(lacunarity, -H); @@ -142,7 +142,7 @@ static float noise_musgrave_hybrid_multi_fractal(float p[3], int basis, float H, weight = gain * result; mul_v3_fl(p, lacunarity); - for(i = 1; (weight > 0.001f) && (i < (int)octaves); i++) { + for(i = 1; (weight > 0.001f) && (i < (int)detail); i++) { if(weight > 1.0f) weight = 1.0f; @@ -153,7 +153,7 @@ static float noise_musgrave_hybrid_multi_fractal(float p[3], int basis, float H, mul_v3_fl(p, lacunarity); } - rmd = octaves - floor(octaves); + rmd = detail - floor(detail); if(rmd != 0.0f) result += rmd * ((noise_basis(p, basis) + offset) * pwr); @@ -164,11 +164,11 @@ static float noise_musgrave_hybrid_multi_fractal(float p[3], int basis, float H, * * H: fractal dimension of the roughest area * lacunarity: gap between successive frequencies - * octaves: number of frequencies in the fBm + * detail: number of frequencies in the fBm * offset: raises the terrain from `sea level' */ -static float noise_musgrave_ridged_multi_fractal(float p[3], int basis, float H, float lacunarity, float octaves, float offset, float gain) +static float noise_musgrave_ridged_multi_fractal(float p[3], int basis, float H, float lacunarity, float detail, float offset, float gain) { float result, signal, weight; float pwHL = pow(lacunarity, -H); @@ -180,7 +180,7 @@ static float noise_musgrave_ridged_multi_fractal(float p[3], int basis, float H, result = signal; weight = 1.0f; - for(i = 1; i < (int)octaves; i++) { + for(i = 1; i < (int)detail; i++) { mul_v3_fl(p, lacunarity); weight = CLAMPIS(signal * gain, 0.0f, 1.0f); signal = offset - fabsf(noise_basis(p, basis)); @@ -193,22 +193,23 @@ static float noise_musgrave_ridged_multi_fractal(float p[3], int basis, float H, return result; } -static float musgrave(int type, int basis, float dimension, float lacunarity, float octaves, float offset, float intensity, float gain, float size, float vec[3]) +static float musgrave(int type, float dimension, float lacunarity, float detail, float offset, float intensity, float gain, float scale, float vec[3]) { float p[3]; + int basis = SHD_NOISE_PERLIN; - mul_v3_v3fl(p, vec, 1.0f/size); + mul_v3_v3fl(p, vec, scale); if(type == SHD_MUSGRAVE_MULTIFRACTAL) - return intensity*noise_musgrave_multi_fractal(p, basis, dimension, lacunarity, octaves); + return intensity*noise_musgrave_multi_fractal(p, basis, dimension, lacunarity, detail); else if(type == SHD_MUSGRAVE_FBM) - return intensity*noise_musgrave_fBm(p, basis, dimension, lacunarity, octaves); + return intensity*noise_musgrave_fBm(p, basis, dimension, lacunarity, detail); else if(type == SHD_MUSGRAVE_HYBRID_MULTIFRACTAL) - return intensity*noise_musgrave_hybrid_multi_fractal(p, basis, dimension, lacunarity, octaves, offset, gain); + return intensity*noise_musgrave_hybrid_multi_fractal(p, basis, dimension, lacunarity, detail, offset, gain); else if(type == SHD_MUSGRAVE_RIDGED_MULTIFRACTAL) - return intensity*noise_musgrave_ridged_multi_fractal(p, basis, dimension, lacunarity, octaves, offset, gain); + return intensity*noise_musgrave_ridged_multi_fractal(p, basis, dimension, lacunarity, detail, offset, gain); else if(type == SHD_MUSGRAVE_HETERO_TERRAIN) - return intensity*noise_musgrave_hetero_terrain(p, basis, dimension, lacunarity, octaves, offset); + return intensity*noise_musgrave_hetero_terrain(p, basis, dimension, lacunarity, detail, offset); return 0.0f; } @@ -217,16 +218,17 @@ static float musgrave(int type, int basis, float dimension, float lacunarity, fl static bNodeSocketTemplate sh_node_tex_musgrave_in[]= { { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Scale", 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Detail", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, { SOCK_FLOAT, 1, "Dimension", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, { SOCK_FLOAT, 1, "Lacunarity", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Octaves", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Offset", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Offset", 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, { SOCK_FLOAT, 1, "Gain", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, { -1, 0, "" } }; static bNodeSocketTemplate sh_node_tex_musgrave_out[]= { + { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } }; @@ -236,8 +238,7 @@ static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode* node, NodeTexMusgrave *tex = MEM_callocN(sizeof(NodeTexMusgrave), "NodeTexMusgrave"); default_tex_mapping(&tex->base.tex_mapping); default_color_mapping(&tex->base.color_mapping); - tex->type = SHD_MUSGRAVE_FBM; - tex->basis = SHD_NOISE_PERLIN; + tex->musgrave_type = SHD_MUSGRAVE_FBM; node->storage = tex; } @@ -247,21 +248,25 @@ static void node_shader_exec_tex_musgrave(void *data, bNode *node, bNodeStack ** ShaderCallData *scd= (ShaderCallData*)data; NodeTexMusgrave *tex= (NodeTexMusgrave*)node->storage; bNodeSocket *vecsock = node->inputs.first; - float vec[3], size, dimension, lacunarity, octaves, offset, gain; + float vec[3], fac, scale, dimension, lacunarity, detail, offset, gain; if(vecsock->link) nodestack_get_vec(vec, SOCK_VECTOR, in[0]); else copy_v3_v3(vec, scd->co); - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - nodestack_get_vec(&dimension, SOCK_FLOAT, in[2]); - nodestack_get_vec(&lacunarity, SOCK_FLOAT, in[3]); - nodestack_get_vec(&octaves, SOCK_FLOAT, in[4]); + nodestack_get_vec(&scale, SOCK_FLOAT, in[1]); + nodestack_get_vec(&detail, SOCK_FLOAT, in[2]); + nodestack_get_vec(&dimension, SOCK_FLOAT, in[3]); + nodestack_get_vec(&lacunarity, SOCK_FLOAT, in[4]); nodestack_get_vec(&offset, SOCK_FLOAT, in[5]); nodestack_get_vec(&gain, SOCK_FLOAT, in[6]); - out[0]->vec[0]= musgrave(tex->type, tex->basis, dimension, lacunarity, octaves, offset, 1.0f, gain, size, vec); + fac= musgrave(tex->musgrave_type, dimension, lacunarity, detail, offset, 1.0f, gain, scale, vec); + out[0]->vec[0]= fac; + out[0]->vec[1]= fac; + out[0]->vec[2]= fac; + out[1]->vec[0]= fac; } static int node_shader_gpu_tex_musgrave(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c index e8fb4737305..8cde640f8b2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c @@ -30,26 +30,49 @@ #include "../node_shader_util.h" #include "node_shader_noise.h" -static float noise_texture_value(float vec[3]) +static float noise_texture(float scale, float detail, float distortion, float vec[3], float color[3]) { - float p[3]; + float p[3], pg[3], pb[3]; + int basis= SHD_NOISE_PERLIN; - mul_v3_v3fl(p, vec, 1e8f); - return cellnoise(p); -} + mul_v3_v3fl(p, vec, scale); -static void noise_texture_color(float rgb[3], float vec[3]) -{ - float p[3]; + if(distortion != 0.0f) { + float r[3], p_offset[3], p_noffset[3]; + float offset[3] = {13.5f, 13.5f, 13.5f}; + + add_v3_v3v3(p_offset, p, offset); + sub_v3_v3v3(p_noffset, p, offset); + + r[0] = noise_basis(p_offset, basis) * distortion; + r[1] = noise_basis(p, basis) * distortion; + r[2] = noise_basis(p_noffset, basis) * distortion; + + add_v3_v3(p, r); + } - mul_v3_v3fl(p, vec, 1e8f); - cellnoise_color(rgb, p); + pg[0]= p[1]; + pg[1]= p[0]; + pg[2]= p[2]; + + pb[0]= p[1]; + pb[1]= p[2]; + pb[2]= p[0]; + + color[0]= noise_turbulence(p, basis, detail, 0); + color[1]= noise_turbulence(pg, basis, detail, 0); + color[2]= noise_turbulence(pb, basis, detail, 0); + + return color[0]; } /* **************** NOISE ******************** */ static bNodeSocketTemplate sh_node_tex_noise_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_FLOAT, 1, "Scale", 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Detail", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, + { SOCK_FLOAT, 1, "Distortion", 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, { -1, 0, "" } }; @@ -72,15 +95,18 @@ static void node_shader_exec_tex_noise(void *data, bNode *node, bNodeStack **in, { ShaderCallData *scd= (ShaderCallData*)data; bNodeSocket *vecsock = node->inputs.first; - float vec[3]; + float vec[3], scale, detail, distortion; if(vecsock->link) nodestack_get_vec(vec, SOCK_VECTOR, in[0]); else copy_v3_v3(vec, scd->co); - noise_texture_color(out[0]->vec, vec); - out[1]->vec[0]= noise_texture_value(vec); + nodestack_get_vec(&scale, SOCK_FLOAT, in[1]); + nodestack_get_vec(&detail, SOCK_FLOAT, in[2]); + nodestack_get_vec(&distortion, SOCK_FLOAT, in[3]); + + out[1]->vec[0]= noise_texture(scale, detail, distortion, vec, out[0]->vec); } static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) @@ -103,7 +129,7 @@ void register_node_type_sh_tex_noise(ListBase *lb) node_type_socket_templates(&ntype, sh_node_tex_noise_in, sh_node_tex_noise_out); node_type_size(&ntype, 150, 60, 200); node_type_init(&ntype, node_shader_init_tex_noise); - node_type_storage(&ntype, "", NULL, NULL); + node_type_storage(&ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); node_type_exec(&ntype, node_shader_exec_tex_noise); node_type_gpu(&ntype, node_shader_gpu_tex_noise); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_stucci.c b/source/blender/nodes/shader/nodes/node_shader_tex_stucci.c deleted file mode 100644 index 3eb315052a9..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_stucci.c +++ /dev/null @@ -1,123 +0,0 @@ -/** - * $Id: node_shader_output.c 32517 2010-10-16 14:32:17Z campbellbarton $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "../node_shader_util.h" -#include "node_shader_noise.h" - -static float stucci(int type, int basis, int hard, float turbulence, float size, float vec[3]) -{ - float p[3], b2, ofs, r; - - mul_v3_v3fl(p, vec, 1.0f/size); - b2 = noise_basis_hard(p, basis, hard); - ofs = turbulence/200.0f; - - if(type != SHD_STUCCI_PLASTIC) - ofs *= b2*b2; - - p[2] += ofs; - r = noise_basis_hard(p, basis, hard); - - if(type == SHD_STUCCI_WALL_OUT) - r = 1.0f - r; - - return MAX2(r, 0.0f); -} - -/* **************** STUCCI ******************** */ - -static bNodeSocketTemplate sh_node_tex_stucci_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Turbulence", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_tex_stucci_out[]= { - { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_init_tex_stucci(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) -{ - NodeTexStucci *tex = MEM_callocN(sizeof(NodeTexStucci), "NodeTexStucci"); - default_tex_mapping(&tex->base.tex_mapping); - default_color_mapping(&tex->base.color_mapping); - tex->type = SHD_STUCCI_PLASTIC; - tex->basis = SHD_NOISE_PERLIN; - tex->hard = 0; - - node->storage = tex; -} - -static void node_shader_exec_tex_stucci(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - ShaderCallData *scd= (ShaderCallData*)data; - NodeTexStucci *tex= (NodeTexStucci*)node->storage; - bNodeSocket *vecsock = node->inputs.first; - float vec[3], size, turbulence; - - if(vecsock->link) - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - else - copy_v3_v3(vec, scd->co); - - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - nodestack_get_vec(&turbulence, SOCK_FLOAT, in[2]); - - out[0]->vec[0]= stucci(tex->type, tex->basis, tex->hard, turbulence, size, vec); -} - -static int node_shader_gpu_tex_stucci(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - if(!in[0].link) - in[0].link = GPU_attribute(CD_ORCO, ""); - - node_shader_gpu_tex_mapping(mat, node, in, out); - - return GPU_stack_link(mat, "node_tex_stucci", in, out); -} - -/* node type definition */ -void register_node_type_sh_tex_stucci(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_TEX_STUCCI, "Stucci Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_tex_stucci_in, sh_node_tex_stucci_out); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, node_shader_init_tex_stucci); - node_type_storage(&ntype, "NodeTexStucci", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_tex_stucci); - node_type_gpu(&ntype, node_shader_gpu_tex_stucci); - - nodeRegisterType(lb, &ntype); -}; - diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c index ee8838ca1b3..4045a25de88 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c @@ -30,58 +30,25 @@ #include "../node_shader_util.h" #include "node_shader_noise.h" -static float voronoi_tex(int distance_metric, int coloring, - float weight1, float weight2, float weight3, float weight4, - float exponent, float intensity, float size, float vec[3], float color[3]) +static float voronoi_tex(int coloring, float scale, float vec[3], float color[3]) { - float aw1 = fabsf(weight1); - float aw2 = fabsf(weight2); - float aw3 = fabsf(weight3); - float aw4 = fabsf(weight4); - float sc = (aw1 + aw2 + aw3 + aw4); float da[4]; float pa[4][3]; float fac; float p[3]; - if(sc != 0.0f) - sc = intensity/sc; - /* compute distance and point coordinate of 4 nearest neighbours */ - mul_v3_v3fl(p, vec, 1.0f/size); - voronoi_generic(p, distance_metric, exponent, da, pa); - - /* Scalar output */ - fac = sc * fabsf(weight1*da[0] + weight2*da[1] + weight3*da[2] + weight4*da[3]); + mul_v3_v3fl(p, vec, scale); + voronoi_generic(p, SHD_VORONOI_DISTANCE_SQUARED, 1.0f, da, pa); - /* colored output */ + /* output */ if(coloring == SHD_VORONOI_INTENSITY) { + fac = fabsf(da[0]); color[0]= color[1]= color[2]= fac; } else { - float rgb1[3], rgb2[3], rgb3[3], rgb4[3]; - - cellnoise_color(rgb1, pa[0]); - cellnoise_color(rgb2, pa[1]); - cellnoise_color(rgb3, pa[2]); - cellnoise_color(rgb4, pa[3]); - - mul_v3_v3fl(color, rgb1, aw1); - madd_v3_v3fl(color, rgb2, aw2); - madd_v3_v3fl(color, rgb3, aw3); - madd_v3_v3fl(color, rgb4, aw4); - - if(coloring != SHD_VORONOI_POSITION) { - float t1 = MIN2((da[1] - da[0])*10.0f, 1.0f); - - if(coloring == SHD_VORONOI_POSITION_OUTLINE_INTENSITY) - mul_v3_fl(color, t1*fac); - else if(coloring == SHD_VORONOI_POSITION_OUTLINE) - mul_v3_fl(color, t1*sc); - } - else { - mul_v3_fl(color, sc); - } + cellnoise_color(color, pa[0]); + fac= (color[0] + color[1] + color[2])*(1.0f/3.0f); } return fac; @@ -91,12 +58,7 @@ static float voronoi_tex(int distance_metric, int coloring, static bNodeSocketTemplate sh_node_tex_voronoi_in[]= { { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Weight1", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_FLOAT, 1, "Weight2", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_FLOAT, 1, "Weight3", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_FLOAT, 1, "Weight4", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_FLOAT, 1, "Exponent", 2.5f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, + { SOCK_FLOAT, 1, "Scale", 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, { -1, 0, "" } }; @@ -111,7 +73,6 @@ static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode* node, NodeTexVoronoi *tex = MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi"); default_tex_mapping(&tex->base.tex_mapping); default_color_mapping(&tex->base.color_mapping); - tex->distance_metric = SHD_VORONOI_ACTUAL_DISTANCE; tex->coloring = SHD_VORONOI_INTENSITY; node->storage = tex; @@ -122,22 +83,16 @@ static void node_shader_exec_tex_voronoi(void *data, bNode *node, bNodeStack **i ShaderCallData *scd= (ShaderCallData*)data; NodeTexVoronoi *tex= (NodeTexVoronoi*)node->storage; bNodeSocket *vecsock = node->inputs.first; - float vec[3], size, w1, w2, w3, w4, exponent; + float vec[3], scale; if(vecsock->link) nodestack_get_vec(vec, SOCK_VECTOR, in[0]); else copy_v3_v3(vec, scd->co); - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - nodestack_get_vec(&w1, SOCK_FLOAT, in[2]); - nodestack_get_vec(&w2, SOCK_FLOAT, in[3]); - nodestack_get_vec(&w3, SOCK_FLOAT, in[4]); - nodestack_get_vec(&w4, SOCK_FLOAT, in[5]); - nodestack_get_vec(&exponent, SOCK_FLOAT, in[6]); + nodestack_get_vec(&scale, SOCK_FLOAT, in[1]); - out[1]->vec[0]= voronoi_tex(tex->distance_metric, tex->coloring, w1, w2, w3, w4, - exponent, 1.0f, size, vec, out[0]->vec); + out[1]->vec[0]= voronoi_tex(tex->coloring, scale, vec, out[0]->vec); } static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c new file mode 100644 index 00000000000..a911f615b79 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c @@ -0,0 +1,129 @@ +/** + * $Id: node_shader_output.c 32517 2010-10-16 14:32:17Z campbellbarton $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" +#include "node_shader_noise.h" + +static float wave(float vec[3], float scale, int type, float distortion, float detail) +{ + float p[3], w, n; + + mul_v3_v3fl(p, vec, scale); + + if(type == SHD_WAVE_BANDS) + n= (p[0] + p[1] + p[2])*10.0f; + else /* if(type == SHD_WAVE_RINGS) */ + n= len_v3(p)*20.0f; + + w = noise_wave(SHD_WAVE_SINE, n); + + /* XXX size compare! */ + if(distortion != 0.0f) + w += distortion * noise_turbulence(p, SHD_NOISE_PERLIN, detail, 0); + + return w; +} + +/* **************** WAVE ******************** */ + +static bNodeSocketTemplate sh_node_tex_wave_in[]= { + { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_FLOAT, 1, "Scale", 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Distortion", 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { SOCK_FLOAT, 1, "Detail", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, + { SOCK_FLOAT, 1, "Detail Scale", 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate sh_node_tex_wave_out[]= { + { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void node_shader_init_tex_wave(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeTexWave *tex = MEM_callocN(sizeof(NodeTexWave), "NodeTexWave"); + default_tex_mapping(&tex->base.tex_mapping); + default_color_mapping(&tex->base.color_mapping); + tex->wave_type = SHD_WAVE_BANDS; + + node->storage = tex; +} + +static void node_shader_exec_tex_wave(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + ShaderCallData *scd= (ShaderCallData*)data; + NodeTexWave *tex= (NodeTexWave*)node->storage; + bNodeSocket *vecsock = node->inputs.first; + float vec[3], scale, detail, distortion, fac; + + if(vecsock->link) + nodestack_get_vec(vec, SOCK_VECTOR, in[0]); + else + copy_v3_v3(vec, scd->co); + + nodestack_get_vec(&scale, SOCK_FLOAT, in[1]); + nodestack_get_vec(&detail, SOCK_FLOAT, in[1]); + nodestack_get_vec(&distortion, SOCK_FLOAT, in[2]); + + fac= wave(vec, scale, tex->wave_type, distortion, detail); + out[0]->vec[0]= fac; + out[0]->vec[1]= fac; + out[0]->vec[2]= fac; + out[1]->vec[0]= fac; +} + +static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) +{ + if(!in[0].link) + in[0].link = GPU_attribute(CD_ORCO, ""); + + node_shader_gpu_tex_mapping(mat, node, in, out); + + return GPU_stack_link(mat, "node_tex_wave", in, out); +} + +/* node type definition */ +void register_node_type_sh_tex_wave(ListBase *lb) +{ + static bNodeType ntype; + + node_type_base(&ntype, SH_NODE_TEX_WAVE, "Wave Texture", NODE_CLASS_TEXTURE, 0); + node_type_compatibility(&ntype, NODE_NEW_SHADING); + node_type_socket_templates(&ntype, sh_node_tex_wave_in, sh_node_tex_wave_out); + node_type_size(&ntype, 150, 60, 200); + node_type_init(&ntype, node_shader_init_tex_wave); + node_type_storage(&ntype, "NodeTexWave", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, node_shader_exec_tex_wave); + node_type_gpu(&ntype, node_shader_gpu_tex_wave); + + nodeRegisterType(lb, &ntype); +} + diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wood.c b/source/blender/nodes/shader/nodes/node_shader_tex_wood.c deleted file mode 100644 index f1beb8e5d7d..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_wood.c +++ /dev/null @@ -1,130 +0,0 @@ -/** - * $Id: node_shader_output.c 32517 2010-10-16 14:32:17Z campbellbarton $ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "../node_shader_util.h" -#include "node_shader_noise.h" - -static float wood(float p[3], float size, int type, int wave, int basis, unsigned int hard, float turb) -{ - float x = p[0]; - float y = p[1]; - float z = p[2]; - - if(type == SHD_WOOD_BANDS) { - return noise_wave(wave, (x + y + z)*10.0f); - } - else if(type == SHD_WOOD_RINGS) { - return noise_wave(wave, sqrt(x*x + y*y + z*z)*20.0f); - } - else if (type == SHD_WOOD_BAND_NOISE) { - float psize[3] = {p[0]/size, p[1]/size, p[2]/size}; - float wi = turb*noise_basis_hard(psize, basis, hard); - return noise_wave(wave, (x + y + z)*10.0f + wi); - } - else if (type == SHD_WOOD_RING_NOISE) { - float psize[3] = {p[0]/size, p[1]/size, p[2]/size}; - float wi = turb*noise_basis_hard(psize, basis, hard); - return noise_wave(wave, sqrt(x*x + y*y + z*z)*20.0f + wi); - } - - return 0.0f; -} - -/* **************** WOOD ******************** */ - -static bNodeSocketTemplate sh_node_tex_wood_in[]= { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_tex_wood_out[]= { - { SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - -static void node_shader_init_tex_wood(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) -{ - NodeTexWood *tex = MEM_callocN(sizeof(NodeTexWood), "NodeTexWood"); - default_tex_mapping(&tex->base.tex_mapping); - default_color_mapping(&tex->base.color_mapping); - tex->type = SHD_WOOD_BANDS; - tex->wave = SHD_WAVE_SINE; - tex->basis = SHD_NOISE_PERLIN; - tex->hard = 0; - - node->storage = tex; -} - -static void node_shader_exec_tex_wood(void *data, bNode *node, bNodeStack **in, bNodeStack **out) -{ - ShaderCallData *scd= (ShaderCallData*)data; - NodeTexWood *tex= (NodeTexWood*)node->storage; - bNodeSocket *vecsock = node->inputs.first; - float vec[3], size, turbulence; - - if(vecsock->link) - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - else - copy_v3_v3(vec, scd->co); - - nodestack_get_vec(&size, SOCK_FLOAT, in[1]); - nodestack_get_vec(&turbulence, SOCK_FLOAT, in[2]); - - out[0]->vec[0]= wood(vec, size, tex->type, tex->wave, tex->basis, tex->hard, turbulence); -} - -static int node_shader_gpu_tex_wood(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) -{ - if(!in[0].link) - in[0].link = GPU_attribute(CD_ORCO, ""); - - node_shader_gpu_tex_mapping(mat, node, in, out); - - return GPU_stack_link(mat, "node_tex_wood", in, out); -} - -/* node type definition */ -void register_node_type_sh_tex_wood(ListBase *lb) -{ - static bNodeType ntype; - - node_type_base(&ntype, SH_NODE_TEX_WOOD, "Wood Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); - node_type_socket_templates(&ntype, sh_node_tex_wood_in, sh_node_tex_wood_out); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, node_shader_init_tex_wood); - node_type_storage(&ntype, "NodeTexWood", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_exec_tex_wood); - node_type_gpu(&ntype, node_shader_gpu_tex_wood); - - nodeRegisterType(lb, &ntype); -}; - |