db1c9081471c6f994fa9efcb813b5231f918ed46
[blender.git] / source / blender / nodes / shader / nodes / node_shader_tex_image.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include "../node_shader_util.h"
29
30 /* **************** OUTPUT ******************** */
31
32 static bNodeSocketTemplate sh_node_tex_image_in[]= {
33         {       SOCK_VECTOR, 1, N_("Vector"),           0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
34         {       -1, 0, ""       }
35 };
36
37 static bNodeSocketTemplate sh_node_tex_image_out[]= {
38         {       SOCK_RGBA, 0, N_("Color"),              0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
39         {       SOCK_FLOAT, 0, N_("Alpha"),             0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
40         {       -1, 0, ""       }
41 };
42
43 static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
44 {
45         NodeTexImage *tex = MEM_callocN(sizeof(NodeTexImage), "NodeTexImage");
46         default_tex_mapping(&tex->base.tex_mapping);
47         default_color_mapping(&tex->base.color_mapping);
48         tex->color_space = SHD_COLORSPACE_COLOR;
49
50         node->storage = tex;
51 }
52
53 static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
54 {
55         Image *ima= (Image*)node->id;
56         ImageUser *iuser= NULL;
57
58         if (!ima)
59                 return GPU_stack_link(mat, "node_tex_image_empty", in, out);
60         
61         if (!in[0].link)
62                 in[0].link = GPU_attribute(CD_MTFACE, "");
63
64         node_shader_gpu_tex_mapping(mat, node, in, out);
65
66         return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser));
67 }
68
69 /* node type definition */
70 void register_node_type_sh_tex_image(bNodeTreeType *ttype)
71 {
72         static bNodeType ntype;
73
74         node_type_base(ttype, &ntype, SH_NODE_TEX_IMAGE, "Image Texture", NODE_CLASS_TEXTURE, NODE_OPTIONS);
75         node_type_compatibility(&ntype, NODE_NEW_SHADING);
76         node_type_socket_templates(&ntype, sh_node_tex_image_in, sh_node_tex_image_out);
77         node_type_size(&ntype, 150, 60, 200);
78         node_type_init(&ntype, node_shader_init_tex_image);
79         node_type_storage(&ntype, "NodeTexImage", node_free_standard_storage, node_copy_standard_storage);
80         node_type_exec(&ntype, NULL);
81         node_type_gpu(&ntype, node_shader_gpu_tex_image);
82
83         nodeRegisterType(ttype, &ntype);
84 }