~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/SHD_util.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: SHD_util.c,v 1.2 2007/03/24 18:41:54 scourage Exp $
 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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
 
 
33
 
 
34
 
 
35
 
 
36
/* ****** */
 
37
 
 
38
void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
 
39
{
 
40
        float *from= ns->vec;
 
41
                
 
42
        if(type_in==SOCK_VALUE) {
 
43
                if(ns->sockettype==SOCK_VALUE)
 
44
                        *in= *from;
 
45
                else 
 
46
                        *in= 0.333333f*(from[0]+from[1]+from[2]);
 
47
        }
 
48
        else if(type_in==SOCK_VECTOR) {
 
49
                if(ns->sockettype==SOCK_VALUE) {
 
50
                        in[0]= from[0];
 
51
                        in[1]= from[0];
 
52
                        in[2]= from[0];
 
53
                }
 
54
                else {
 
55
                        VECCOPY(in, from);
 
56
                }
 
57
        }
 
58
        else { /* type_in==SOCK_RGBA */
 
59
                if(ns->sockettype==SOCK_RGBA) {
 
60
                        QUATCOPY(in, from);
 
61
                }
 
62
                else if(ns->sockettype==SOCK_VALUE) {
 
63
                        in[0]= from[0];
 
64
                        in[1]= from[0];
 
65
                        in[2]= from[0];
 
66
                        in[3]= 1.0f;
 
67
                }
 
68
                else {
 
69
                        VECCOPY(in, from);
 
70
                        in[3]= 1.0f;
 
71
                }
 
72
        }
 
73
}
 
74
 
 
75
 
 
76
/* ******************* execute and parse ************ */
 
77
 
 
78
void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr)
 
79
{
 
80
        ShaderCallData scd;
 
81
        
 
82
        /* convert caller data to struct */
 
83
        scd.shi= shi;
 
84
        scd.shr= shr;
 
85
        /* each material node has own local shaderesult, with optional copying */
 
86
        memset(shr, 0, sizeof(ShadeResult));
 
87
                   
 
88
        ntreeExecTree(ntree, &scd, shi->thread);        /* threads */
 
89
        
 
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;
 
94
        
 
95
}
 
96
 
 
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)
 
100
{
 
101
        bNode *node;
 
102
        bNodeSocket *sock;
 
103
        int a;
 
104
        
 
105
        ntreeSocketUseFlags(ntree);
 
106
 
 
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;
 
113
                        }
 
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;
 
118
                }
 
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) {
 
123
                                        switch(a) {
 
124
                                                case GEOM_OUT_GLOB: 
 
125
                                                        *texco |= TEXCO_GLOB|NEED_UV; break;
 
126
                                                case GEOM_OUT_VIEW: 
 
127
                                                        *texco |= TEXCO_VIEW|NEED_UV; break;
 
128
                                                case GEOM_OUT_ORCO: 
 
129
                                                        *texco |= TEXCO_ORCO|NEED_UV; break;
 
130
                                                case GEOM_OUT_UV: 
 
131
                                                        *texco |= TEXCO_UV|NEED_UV; break;
 
132
                                                case GEOM_OUT_NORMAL: 
 
133
                                                        *texco |= TEXCO_NORM|NEED_UV; break;
 
134
                                                case GEOM_OUT_VCOL:
 
135
                                                        *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break;
 
136
                                        }
 
137
                                }
 
138
                        }
 
139
                }
 
140
        }
 
141
}
 
142
 
 
143
/* nodes that use ID data get synced with local data */
 
144
void nodeShaderSynchronizeID(bNode *node, int copyto)
 
145
{
 
146
        if(node->id==NULL) return;
 
147
        
 
148
        if(node->type==SH_NODE_MATERIAL) {
 
149
                bNodeSocket *sock;
 
150
                Material *ma= (Material *)node->id;
 
151
                int a;
 
152
                
 
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)) {
 
156
                                if(copyto) {
 
157
                                        switch(a) {
 
158
                                                case MAT_IN_COLOR:
 
159
                                                        VECCOPY(&ma->r, sock->ns.vec); break;
 
160
                                                case MAT_IN_SPEC:
 
161
                                                        VECCOPY(&ma->specr, sock->ns.vec); break;
 
162
                                                case MAT_IN_REFL:
 
163
                                                        ma->ref= sock->ns.vec[0]; break;
 
164
                                        }
 
165
                                }
 
166
                                else {
 
167
                                        switch(a) {
 
168
                                                case MAT_IN_COLOR:
 
169
                                                        VECCOPY(sock->ns.vec, &ma->r); break;
 
170
                                                case MAT_IN_SPEC:
 
171
                                                        VECCOPY(sock->ns.vec, &ma->specr); break;
 
172
                                                case MAT_IN_REFL:
 
173
                                                        sock->ns.vec[0]= ma->ref; break;
 
174
                                        }
 
175
                                }
 
176
                        }
 
177
                }
 
178
        }
 
179
        
 
180
}