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

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/CMP_nodes/CMP_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: CMP_texture.c,v 1.4 2007/04/04 13:58:10 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) 2006 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 "../CMP_util.h"
 
31
 
 
32
/* **************** TEXTURE ******************** */
 
33
static bNodeSocketType cmp_node_texture_in[]= {
 
34
        {       SOCK_VECTOR, 1, "Offset",               0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f},
 
35
        {       SOCK_VECTOR, 1, "Scale",                1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f},
 
36
        {       -1, 0, ""       }
 
37
};
 
38
static bNodeSocketType cmp_node_texture_out[]= {
 
39
        {       SOCK_VALUE, 0, "Value",         1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
40
        {       SOCK_RGBA , 0, "Color",         1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
 
41
        {       -1, 0, ""       }
 
42
};
 
43
 
 
44
/* called without rect allocated */
 
45
static void texture_procedural(CompBuf *cbuf, float *col, float xco, float yco)
 
46
{
 
47
        bNode *node= cbuf->node;
 
48
        bNodeSocket *sock= node->inputs.first;
 
49
        TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
 
50
        float vec[3], *size, nor[3]={0.0f, 0.0f, 0.0f};
 
51
        int retval, type= cbuf->type;
 
52
        
 
53
        size= sock->next->ns.vec;
 
54
        
 
55
        vec[0]= size[0]*(xco + sock->ns.vec[0]);
 
56
        vec[1]= size[1]*(yco + sock->ns.vec[1]);
 
57
        vec[2]= size[2]*sock->ns.vec[2];
 
58
        
 
59
        retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
 
60
        
 
61
        if(type==CB_VAL) {
 
62
                if(texres.talpha)
 
63
                        col[0]= texres.ta;
 
64
                else
 
65
                        col[0]= texres.tin;
 
66
        }
 
67
        else if(type==CB_RGBA) {
 
68
                if(texres.talpha)
 
69
                        col[3]= texres.ta;
 
70
                else
 
71
                        col[3]= texres.tin;
 
72
                
 
73
                if((retval & TEX_RGB)) {
 
74
                        col[0]= texres.tr;
 
75
                        col[1]= texres.tg;
 
76
                        col[2]= texres.tb;
 
77
                }
 
78
                else col[0]= col[1]= col[2]= col[3];
 
79
        }
 
80
        else { 
 
81
                VECCOPY(col, nor);
 
82
        }
 
83
}
 
84
 
 
85
/* texture node outputs get a small rect, to make sure all other nodes accept it */
 
86
/* only the pixel-processor nodes do something with it though */
 
87
static void node_composit_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 
88
{
 
89
        /* outputs: value, color, normal */
 
90
        
 
91
        if(node->id) {
 
92
                /* first make the preview image */
 
93
                CompBuf *prevbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
 
94
                
 
95
                prevbuf->rect_procedural= texture_procedural;
 
96
                prevbuf->node= node;
 
97
                composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
 
98
                generate_preview(node, prevbuf);
 
99
                free_compbuf(prevbuf);
 
100
                
 
101
                if(out[0]->hasoutput) {
 
102
                        CompBuf *stackbuf= alloc_compbuf(140, 140, CB_VAL, 1); /* alloc */
 
103
                        
 
104
                        stackbuf->rect_procedural= texture_procedural;
 
105
                        stackbuf->node= node;
 
106
                        
 
107
                        out[0]->data= stackbuf;
 
108
                }
 
109
                if(out[1]->hasoutput) {
 
110
                        CompBuf *stackbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
 
111
                        
 
112
                        stackbuf->rect_procedural= texture_procedural;
 
113
                        stackbuf->node= node;
 
114
                        
 
115
                        out[1]->data= stackbuf;
 
116
                }
 
117
        }
 
118
}
 
119
 
 
120
bNodeType cmp_node_texture= {
 
121
        /* *next,*prev */       NULL, NULL,
 
122
        /* type code   */       CMP_NODE_TEXTURE,
 
123
        /* name        */       "Texture",
 
124
        /* width+range */       120, 80, 240,
 
125
        /* class+opts  */       NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW,
 
126
        /* input sock  */       cmp_node_texture_in,
 
127
        /* output sock */       cmp_node_texture_out,
 
128
        /* storage     */       "",
 
129
        /* execfunc    */       node_composit_exec_texture,
 
130
        /* butfunc     */       NULL,
 
131
        /* initfunc    */       NULL,
 
132
        /* freestoragefunc    */        NULL,
 
133
        /* copystoragefunc    */        NULL,
 
134
        /* id          */       NULL
 
135
        
 
136
};
 
137
 
 
138