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