doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / nodes / intern / SHD_nodes / SHD_geom.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2005 Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include "../SHD_util.h"
31
32 #include "DNA_customdata_types.h"
33
34 /* **************** GEOMETRY  ******************** */
35
36 /* output socket type definition */
37 static bNodeSocketType sh_node_geom_out[]= {
38         {       SOCK_VECTOR, 0, "Global",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},   /* btw; uses no limit */
39         {       SOCK_VECTOR, 0, "Local",        0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
40         {       SOCK_VECTOR, 0, "View", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
41         {       SOCK_VECTOR, 0, "Orco", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
42         {       SOCK_VECTOR, 0, "UV",   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
43         {       SOCK_VECTOR, 0, "Normal",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
44         {       SOCK_RGBA,   0, "Vertex Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
45         {       SOCK_VALUE,   0, "Front/Back", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
46         {       -1, 0, ""       }
47 };
48
49 /* node execute callback */
50 static void node_shader_exec_geom(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
51 {
52         if(data) {
53                 ShadeInput *shi= ((ShaderCallData *)data)->shi;
54                 NodeGeometry *ngeo= (NodeGeometry*)node->storage;
55                 ShadeInputUV *suv= &shi->uv[shi->actuv];
56                 static float defaultvcol[4] = {1.0f, 1.0f, 1.0f, 1.0f};
57                 int i;
58
59                 if(ngeo->uvname[0]) {
60                         /* find uv layer by name */
61                         for(i = 0; i < shi->totuv; i++) {
62                                 if(strcmp(shi->uv[i].name, ngeo->uvname)==0) {
63                                         suv= &shi->uv[i];
64                                         break;
65                                 }
66                         }
67                 }
68
69                 /* out: global, local, view, orco, uv, normal, vertex color */
70                 VECCOPY(out[GEOM_OUT_GLOB]->vec, shi->gl);
71                 VECCOPY(out[GEOM_OUT_LOCAL]->vec, shi->co);
72                 VECCOPY(out[GEOM_OUT_VIEW]->vec, shi->view);
73                 VECCOPY(out[GEOM_OUT_ORCO]->vec, shi->lo);
74                 VECCOPY(out[GEOM_OUT_UV]->vec, suv->uv);
75                 VECCOPY(out[GEOM_OUT_NORMAL]->vec, shi->vno);
76
77                 if (shi->totcol) {
78                         /* find vertex color layer by name */
79                         ShadeInputCol *scol= &shi->col[0];
80
81                         if(ngeo->colname[0]) {
82                                 for(i = 0; i < shi->totcol; i++) {
83                                         if(strcmp(shi->col[i].name, ngeo->colname)==0) {
84                                                 scol= &shi->col[i];
85                                                 break;
86                                         }
87                                 }
88                         }
89
90                         VECCOPY(out[GEOM_OUT_VCOL]->vec, scol->col);
91                         out[GEOM_OUT_VCOL]->vec[3]= 1.0f;
92                 }
93                 else
94                         memcpy(out[GEOM_OUT_VCOL]->vec, defaultvcol, sizeof(defaultvcol));
95                 
96                 if(shi->osatex) {
97                         out[GEOM_OUT_GLOB]->data= shi->dxgl;
98                         out[GEOM_OUT_GLOB]->datatype= NS_OSA_VECTORS;
99                         out[GEOM_OUT_LOCAL]->data= shi->dxco;
100                         out[GEOM_OUT_LOCAL]->datatype= NS_OSA_VECTORS;
101                         out[GEOM_OUT_VIEW]->data= &shi->dxview;
102                         out[GEOM_OUT_VIEW]->datatype= NS_OSA_VALUES;
103                         out[GEOM_OUT_ORCO]->data= shi->dxlo;
104                         out[GEOM_OUT_ORCO]->datatype= NS_OSA_VECTORS;
105                         out[GEOM_OUT_UV]->data= suv->dxuv;
106                         out[GEOM_OUT_UV]->datatype= NS_OSA_VECTORS;
107                         out[GEOM_OUT_NORMAL]->data= shi->dxno;
108                         out[GEOM_OUT_NORMAL]->datatype= NS_OSA_VECTORS;
109                 }
110                 
111                 /* front/back, normal flipping was stored */
112                 out[GEOM_OUT_FRONTBACK]->vec[0]= (shi->flippednor)? 0.0f: 1.0f;
113         }
114 }
115
116 static void node_shader_init_geometry(bNode *node)
117 {
118    node->storage= MEM_callocN(sizeof(NodeGeometry), "NodeGeometry");
119 }
120
121 static int gpu_shader_geom(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
122 {
123         NodeGeometry *ngeo= (NodeGeometry*)node->storage;
124         GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
125         GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname);
126         GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname);
127
128         return GPU_stack_link(mat, "geom", in, out,
129                 GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
130                 GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol);
131 }
132
133 /* node type definition */
134 void register_node_type_sh_geom(ListBase *lb)
135 {
136         static bNodeType ntype;
137
138         node_type_base(&ntype, SH_NODE_GEOMETRY, "Geometry", NODE_CLASS_INPUT, NODE_OPTIONS,
139                 NULL, sh_node_geom_out);
140         node_type_size(&ntype, 120, 80, 160);
141         node_type_init(&ntype, node_shader_init_geometry);
142         node_type_storage(&ntype, "NodeGeometry", node_free_standard_storage, node_copy_standard_storage);
143         node_type_exec(&ntype, node_shader_exec_geom);
144         node_type_gpu(&ntype, gpu_shader_geom);
145
146         nodeRegisterType(lb, &ntype);
147 }
148