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

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/SHD_nodes/SHD_texture.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_texture.c,v 1.4 2007/04/04 13:58:12 jesterking 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
/* **************** TEXTURE ******************** */
 
33
static bNodeSocketType sh_node_texture_in[]= {
 
34
        {       SOCK_VECTOR, 1, "Vector",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},   /* no limit */
 
35
        {       -1, 0, ""       }
 
36
};
 
37
static bNodeSocketType sh_node_texture_out[]= {
 
38
        {       SOCK_VALUE, 0, "Value",         1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
39
        {       SOCK_RGBA , 0, "Color",         1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
 
40
        {       SOCK_VECTOR, 0, "Normal",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
 
41
        {       -1, 0, ""       }
 
42
};
 
43
 
 
44
static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
45
{
 
46
        if(data && node->id) {
 
47
                ShadeInput *shi= ((ShaderCallData *)data)->shi;
 
48
                TexResult texres;
 
49
                float vec[3], nor[3]={0.0f, 0.0f, 0.0f};
 
50
                int retval;
 
51
                
 
52
                /* out: value, color, normal */
 
53
                
 
54
                /* we should find out if a normal as output is needed, for now we do all */
 
55
                texres.nor= nor;
 
56
                
 
57
                if(in[0]->hasinput) {
 
58
                        nodestack_get_vec(vec, SOCK_VECTOR, in[0]);
 
59
                        
 
60
                        if(in[0]->datatype==NS_OSA_VECTORS) {
 
61
                                float *fp= in[0]->data;
 
62
                                retval= multitex_ext((Tex *)node->id, vec, fp, fp+3, shi->osatex, &texres);
 
63
                        }
 
64
                        else if(in[0]->datatype==NS_OSA_VALUES) {
 
65
                                float *fp= in[0]->data;
 
66
                                float dxt[3], dyt[3];
 
67
                                
 
68
                                dxt[0]= fp[0]; dxt[1]= dxt[2]= 0.0f;
 
69
                                dyt[0]= fp[1]; dyt[1]= dyt[2]= 0.0f;
 
70
                                retval= multitex_ext((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres);
 
71
                        }
 
72
                        else
 
73
                                retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
 
74
                }
 
75
                else {  /* only for previewrender, so we see stuff */
 
76
                        VECCOPY(vec, shi->lo);
 
77
                        retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
 
78
                }
 
79
                
 
80
                /* stupid exception */
 
81
                if( ((Tex *)node->id)->type==TEX_STUCCI) {
 
82
                        texres.tin= 0.5f + 0.7f*texres.nor[0];
 
83
                        CLAMP(texres.tin, 0.0f, 1.0f);
 
84
                }
 
85
                
 
86
                /* intensity and color need some handling */
 
87
                if(texres.talpha)
 
88
                        out[0]->vec[0]= texres.ta;
 
89
                else
 
90
                        out[0]->vec[0]= texres.tin;
 
91
                
 
92
                if((retval & TEX_RGB)==0) {
 
93
                        out[1]->vec[0]= out[0]->vec[0];
 
94
                        out[1]->vec[1]= out[0]->vec[0];
 
95
                        out[1]->vec[2]= out[0]->vec[0];
 
96
                        out[1]->vec[3]= 1.0f;
 
97
                }
 
98
                else {
 
99
                        out[1]->vec[0]= texres.tr;
 
100
                        out[1]->vec[1]= texres.tg;
 
101
                        out[1]->vec[2]= texres.tb;
 
102
                        out[1]->vec[3]= 1.0f;
 
103
                }
 
104
                
 
105
                VECCOPY(out[2]->vec, nor);
 
106
                
 
107
                if(shi->do_preview)
 
108
                        nodeAddToPreview(node, out[1]->vec, shi->xs, shi->ys);
 
109
                
 
110
        }
 
111
}
 
112
 
 
113
bNodeType sh_node_texture= {
 
114
        /* *next,*prev */       NULL, NULL,
 
115
        /* type code   */       SH_NODE_TEXTURE,
 
116
        /* name        */       "Texture",
 
117
        /* width+range */       120, 80, 240,
 
118
        /* class+opts  */       NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW,
 
119
        /* input sock  */       sh_node_texture_in,
 
120
        /* output sock */       sh_node_texture_out,
 
121
        /* storage     */       "",
 
122
        /* execfunc    */       node_shader_exec_texture,
 
123
        /* butfunc     */       NULL,
 
124
        /* initfunc    */       NULL,
 
125
        /* freestoragefunc    */        NULL,
 
126
        /* copystoragefunc    */        NULL,
 
127
        /* id          */       NULL
 
128
        
 
129
};
 
130