Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 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 * The Original Code is Copyright (C) 2005 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "node_shader_util.h" 00034 00035 /* **************** MAPPING ******************** */ 00036 static bNodeSocketTemplate sh_node_mapping_in[]= { 00037 { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, 00038 { -1, 0, "" } 00039 }; 00040 00041 static bNodeSocketTemplate sh_node_mapping_out[]= { 00042 { SOCK_VECTOR, 0, "Vector"}, 00043 { -1, 0, "" } 00044 }; 00045 00046 /* do the regular mapping options for blender textures */ 00047 static void node_shader_exec_mapping(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00048 { 00049 TexMapping *texmap= node->storage; 00050 float *vec= out[0]->vec; 00051 00052 /* stack order input: vector */ 00053 /* stack order output: vector */ 00054 nodestack_get_vec(vec, SOCK_VECTOR, in[0]); 00055 mul_m4_v3(texmap->mat, vec); 00056 00057 if(texmap->flag & TEXMAP_CLIP_MIN) { 00058 if(vec[0]<texmap->min[0]) vec[0]= texmap->min[0]; 00059 if(vec[1]<texmap->min[1]) vec[1]= texmap->min[1]; 00060 if(vec[2]<texmap->min[2]) vec[2]= texmap->min[2]; 00061 } 00062 if(texmap->flag & TEXMAP_CLIP_MAX) { 00063 if(vec[0]>texmap->max[0]) vec[0]= texmap->max[0]; 00064 if(vec[1]>texmap->max[1]) vec[1]= texmap->max[1]; 00065 if(vec[2]>texmap->max[2]) vec[2]= texmap->max[2]; 00066 } 00067 } 00068 00069 00070 static void node_shader_init_mapping(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) 00071 { 00072 node->storage= add_tex_mapping(); 00073 } 00074 00075 static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) 00076 { 00077 TexMapping *texmap= node->storage; 00078 float domin= (texmap->flag & TEXMAP_CLIP_MIN) != 0; 00079 float domax= (texmap->flag & TEXMAP_CLIP_MAX) != 0; 00080 GPUNodeLink *tmat = GPU_uniform((float*)texmap->mat); 00081 GPUNodeLink *tmin = GPU_uniform(texmap->min); 00082 GPUNodeLink *tmax = GPU_uniform(texmap->max); 00083 GPUNodeLink *tdomin = GPU_uniform(&domin); 00084 GPUNodeLink *tdomax = GPU_uniform(&domax); 00085 00086 return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax); 00087 } 00088 00089 void register_node_type_sh_mapping(bNodeTreeType *ttype) 00090 { 00091 static bNodeType ntype; 00092 00093 node_type_base(ttype, &ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, NODE_OPTIONS); 00094 node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING); 00095 node_type_socket_templates(&ntype, sh_node_mapping_in, sh_node_mapping_out); 00096 node_type_size(&ntype, 240, 160, 320); 00097 node_type_init(&ntype, node_shader_init_mapping); 00098 node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); 00099 node_type_exec(&ntype, node_shader_exec_mapping); 00100 node_type_gpu(&ntype, gpu_shader_mapping); 00101 00102 nodeRegisterType(ttype, &ntype); 00103 }