Cleanup: style
[blender.git] / source / blender / nodes / shader / nodes / node_shader_tex_coord.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19
20 #include "../node_shader_util.h"
21
22 #include "DNA_customdata_types.h"
23
24 /* **************** OUTPUT ******************** */
25
26 static bNodeSocketTemplate sh_node_tex_coord_out[] = {
27         {       SOCK_VECTOR, 0, N_("Generated"),                0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
28         {       SOCK_VECTOR, 0, N_("Normal"),                   0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
29         {       SOCK_VECTOR, 0, N_("UV"),                               0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
30         {       SOCK_VECTOR, 0, N_("Object"),                   0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
31         {       SOCK_VECTOR, 0, N_("Camera"),                   0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
32         {       SOCK_VECTOR, 0, N_("Window"),                   0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
33         {       SOCK_VECTOR, 0, N_("Reflection"),               0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
34         {       -1, 0, ""       },
35 };
36
37 static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
38 {
39         Object *ob = (Object *)node->id;
40         invert_m4_m4(ob->imat, ob->obmat);
41
42         GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) : GPU_builtin(GPU_INVERSE_OBJECT_MATRIX);
43
44         GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
45         GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, "");
46
47         GPU_link(mat, "generated_from_orco", orco, &orco);
48
49         return GPU_stack_link(mat, node, "node_tex_coord", in, out,
50                               GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
51                               GPU_builtin(GPU_INVERSE_VIEW_MATRIX), inv_obmat,
52                               GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface);
53 }
54
55 /* node type definition */
56 void register_node_type_sh_tex_coord(void)
57 {
58         static bNodeType ntype;
59
60         sh_node_type_base(&ntype, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT, 0);
61         node_type_socket_templates(&ntype, NULL, sh_node_tex_coord_out);
62         node_type_init(&ntype, NULL);
63         node_type_storage(&ntype, "", NULL, NULL);
64         node_type_gpu(&ntype, node_shader_gpu_tex_coord);
65
66         nodeRegisterType(&ntype);
67 }