2
* $Id: SHD_util.c,v 1.2 2007/03/24 18:41:54 scourage Exp $
4
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* The Original Code is Copyright (C) 2005 Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
38
void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
42
if(type_in==SOCK_VALUE) {
43
if(ns->sockettype==SOCK_VALUE)
46
*in= 0.333333f*(from[0]+from[1]+from[2]);
48
else if(type_in==SOCK_VECTOR) {
49
if(ns->sockettype==SOCK_VALUE) {
58
else { /* type_in==SOCK_RGBA */
59
if(ns->sockettype==SOCK_RGBA) {
62
else if(ns->sockettype==SOCK_VALUE) {
76
/* ******************* execute and parse ************ */
78
void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr)
82
/* convert caller data to struct */
85
/* each material node has own local shaderesult, with optional copying */
86
memset(shr, 0, sizeof(ShadeResult));
88
ntreeExecTree(ntree, &scd, shi->thread); /* threads */
90
/* better not allow negative for now */
91
if(shr->combined[0]<0.0f) shr->combined[0]= 0.0f;
92
if(shr->combined[1]<0.0f) shr->combined[1]= 0.0f;
93
if(shr->combined[2]<0.0f) shr->combined[2]= 0.0f;
97
/* go over all used Geometry and Texture nodes, and return a texco flag */
98
/* no group inside needed, this function is called for groups too */
99
void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mode)
105
ntreeSocketUseFlags(ntree);
107
for(node= ntree->nodes.first; node; node= node->next) {
108
if(node->type==SH_NODE_TEXTURE) {
109
if((r_mode & R_OSA) && node->id) {
110
Tex *tex= (Tex *)node->id;
111
if ELEM3(tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP)
112
*texco |= TEXCO_OSA|NEED_UV;
114
/* usability exception... without input we still give the node orcos */
115
sock= node->inputs.first;
116
if(sock==NULL || sock->link==NULL)
117
*texco |= TEXCO_ORCO|NEED_UV;
119
else if(node->type==SH_NODE_GEOMETRY) {
120
/* note; sockets always exist for the given type! */
121
for(a=0, sock= node->outputs.first; sock; sock= sock->next, a++) {
122
if(sock->flag & SOCK_IN_USE) {
125
*texco |= TEXCO_GLOB|NEED_UV; break;
127
*texco |= TEXCO_VIEW|NEED_UV; break;
129
*texco |= TEXCO_ORCO|NEED_UV; break;
131
*texco |= TEXCO_UV|NEED_UV; break;
132
case GEOM_OUT_NORMAL:
133
*texco |= TEXCO_NORM|NEED_UV; break;
135
*texco |= NEED_UV; *mode |= MA_VERTEXCOL; break;
143
/* nodes that use ID data get synced with local data */
144
void nodeShaderSynchronizeID(bNode *node, int copyto)
146
if(node->id==NULL) return;
148
if(node->type==SH_NODE_MATERIAL) {
150
Material *ma= (Material *)node->id;
153
/* hrmf, case in loop isnt super fast, but we dont edit 100s of material at same time either! */
154
for(a=0, sock= node->inputs.first; sock; sock= sock->next, a++) {
155
if(!(sock->flag & SOCK_HIDDEN)) {
159
VECCOPY(&ma->r, sock->ns.vec); break;
161
VECCOPY(&ma->specr, sock->ns.vec); break;
163
ma->ref= sock->ns.vec[0]; break;
169
VECCOPY(sock->ns.vec, &ma->r); break;
171
VECCOPY(sock->ns.vec, &ma->specr); break;
173
sock->ns.vec[0]= ma->ref; break;