|
Blender
V2.59
|
00001 /* 00002 * $Id: SHD_mapping.c 36276 2011-04-21 15:53:30Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2005 Blender Foundation. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #include "../SHD_util.h" 00036 00037 /* **************** MAPPING ******************** */ 00038 static bNodeSocketType sh_node_mapping_in[]= { 00039 { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, 00040 { -1, 0, "" } 00041 }; 00042 00043 static bNodeSocketType sh_node_mapping_out[]= { 00044 { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, 00045 { -1, 0, "" } 00046 }; 00047 00048 /* do the regular mapping options for blender textures */ 00049 static void node_shader_exec_mapping(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00050 { 00051 TexMapping *texmap= node->storage; 00052 float *vec= out[0]->vec; 00053 00054 /* stack order input: vector */ 00055 /* stack order output: vector */ 00056 nodestack_get_vec(vec, SOCK_VECTOR, in[0]); 00057 mul_m4_v3(texmap->mat, vec); 00058 00059 if(texmap->flag & TEXMAP_CLIP_MIN) { 00060 if(vec[0]<texmap->min[0]) vec[0]= texmap->min[0]; 00061 if(vec[1]<texmap->min[1]) vec[1]= texmap->min[1]; 00062 if(vec[2]<texmap->min[2]) vec[2]= texmap->min[2]; 00063 } 00064 if(texmap->flag & TEXMAP_CLIP_MAX) { 00065 if(vec[0]>texmap->max[0]) vec[0]= texmap->max[0]; 00066 if(vec[1]>texmap->max[1]) vec[1]= texmap->max[1]; 00067 if(vec[2]>texmap->max[2]) vec[2]= texmap->max[2]; 00068 } 00069 } 00070 00071 00072 static void node_shader_init_mapping(bNode *node) 00073 { 00074 node->storage= add_mapping(); 00075 } 00076 00077 static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) 00078 { 00079 TexMapping *texmap= node->storage; 00080 float domin= (texmap->flag & TEXMAP_CLIP_MIN) != 0; 00081 float domax= (texmap->flag & TEXMAP_CLIP_MAX) != 0; 00082 GPUNodeLink *tmat = GPU_uniform((float*)texmap->mat); 00083 GPUNodeLink *tmin = GPU_uniform(texmap->min); 00084 GPUNodeLink *tmax = GPU_uniform(texmap->max); 00085 GPUNodeLink *tdomin = GPU_uniform(&domin); 00086 GPUNodeLink *tdomax = GPU_uniform(&domax); 00087 00088 return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax); 00089 } 00090 00091 void register_node_type_sh_mapping(ListBase *lb) 00092 { 00093 static bNodeType ntype; 00094 00095 node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, 00096 sh_node_mapping_in, sh_node_mapping_out); 00097 node_type_size(&ntype, 240, 160, 320); 00098 node_type_init(&ntype, node_shader_init_mapping); 00099 node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); 00100 node_type_exec(&ntype, node_shader_exec_mapping); 00101 node_type_gpu(&ntype, gpu_shader_mapping); 00102 00103 nodeRegisterType(lb, &ntype); 00104 }