2
* $Id: CMP_texture.c,v 1.4 2007/04/04 13:58:10 jesterking 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) 2006 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 *****
30
#include "../CMP_util.h"
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},
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},
44
/* called without rect allocated */
45
static void texture_procedural(CompBuf *cbuf, float *col, float xco, float yco)
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;
53
size= sock->next->ns.vec;
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];
59
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
67
else if(type==CB_RGBA) {
73
if((retval & TEX_RGB)) {
78
else col[0]= col[1]= col[2]= col[3];
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)
89
/* outputs: value, color, normal */
92
/* first make the preview image */
93
CompBuf *prevbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
95
prevbuf->rect_procedural= texture_procedural;
97
composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
98
generate_preview(node, prevbuf);
99
free_compbuf(prevbuf);
101
if(out[0]->hasoutput) {
102
CompBuf *stackbuf= alloc_compbuf(140, 140, CB_VAL, 1); /* alloc */
104
stackbuf->rect_procedural= texture_procedural;
105
stackbuf->node= node;
107
out[0]->data= stackbuf;
109
if(out[1]->hasoutput) {
110
CompBuf *stackbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
112
stackbuf->rect_procedural= texture_procedural;
113
stackbuf->node= node;
115
out[1]->data= stackbuf;
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,
129
/* execfunc */ node_composit_exec_texture,
132
/* freestoragefunc */ NULL,
133
/* copystoragefunc */ NULL,