2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2007-03-24 06:57:29 +00:00
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-03-24 06:57:29 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2006 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:13:22 +00:00
|
|
|
/** \file blender/nodes/intern/CMP_nodes/CMP_texture.c
|
|
|
|
|
* \ingroup cmpnodes
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2007-03-24 06:57:29 +00:00
|
|
|
#include "../CMP_util.h"
|
|
|
|
|
|
|
|
|
|
/* **************** TEXTURE ******************** */
|
|
|
|
|
static bNodeSocketType cmp_node_texture_in[]= {
|
|
|
|
|
{ SOCK_VECTOR, 1, "Offset", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f},
|
|
|
|
|
{ SOCK_VECTOR, 1, "Scale", 1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f},
|
|
|
|
|
{ -1, 0, "" }
|
|
|
|
|
};
|
|
|
|
|
static bNodeSocketType cmp_node_texture_out[]= {
|
|
|
|
|
{ SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
|
|
|
|
|
{ SOCK_RGBA , 0, "Color", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
|
|
|
|
|
{ -1, 0, "" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* called without rect allocated */
|
2008-04-07 15:21:25 +00:00
|
|
|
static void texture_procedural(CompBuf *cbuf, float *out, float xco, float yco)
|
2007-03-24 06:57:29 +00:00
|
|
|
{
|
|
|
|
|
bNode *node= cbuf->node;
|
|
|
|
|
TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
|
2008-04-07 15:21:25 +00:00
|
|
|
float vec[3], *size, nor[3]={0.0f, 0.0f, 0.0f}, col[4];
|
|
|
|
|
int retval, type= cbuf->procedural_type;
|
2007-03-24 06:57:29 +00:00
|
|
|
|
2008-03-13 11:26:18 +00:00
|
|
|
size= cbuf->procedural_size;
|
2007-03-24 06:57:29 +00:00
|
|
|
|
2008-03-13 11:26:18 +00:00
|
|
|
vec[0]= size[0]*(xco + cbuf->procedural_offset[0]);
|
|
|
|
|
vec[1]= size[1]*(yco + cbuf->procedural_offset[1]);
|
|
|
|
|
vec[2]= size[2]*cbuf->procedural_offset[2];
|
2007-03-24 06:57:29 +00:00
|
|
|
|
|
|
|
|
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
|
|
|
|
|
|
|
|
|
if(type==CB_VAL) {
|
|
|
|
|
if(texres.talpha)
|
|
|
|
|
col[0]= texres.ta;
|
|
|
|
|
else
|
|
|
|
|
col[0]= texres.tin;
|
|
|
|
|
}
|
|
|
|
|
else if(type==CB_RGBA) {
|
|
|
|
|
if(texres.talpha)
|
|
|
|
|
col[3]= texres.ta;
|
|
|
|
|
else
|
|
|
|
|
col[3]= texres.tin;
|
|
|
|
|
|
|
|
|
|
if((retval & TEX_RGB)) {
|
|
|
|
|
col[0]= texres.tr;
|
|
|
|
|
col[1]= texres.tg;
|
|
|
|
|
col[2]= texres.tb;
|
|
|
|
|
}
|
|
|
|
|
else col[0]= col[1]= col[2]= col[3];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
VECCOPY(col, nor);
|
|
|
|
|
}
|
2010-11-28 18:34:16 +00:00
|
|
|
|
2008-04-07 15:21:25 +00:00
|
|
|
typecheck_compbuf_color(out, col, cbuf->type, cbuf->procedural_type);
|
2007-03-24 06:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* texture node outputs get a small rect, to make sure all other nodes accept it */
|
|
|
|
|
/* only the pixel-processor nodes do something with it though */
|
|
|
|
|
static void node_composit_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
|
|
|
|
|
{
|
|
|
|
|
/* outputs: value, color, normal */
|
|
|
|
|
|
|
|
|
|
if(node->id) {
|
2011-01-06 14:58:58 +00:00
|
|
|
RenderData *rd= data;
|
|
|
|
|
short sizex, sizey;
|
2007-09-24 02:18:00 +00:00
|
|
|
|
2007-03-24 06:57:29 +00:00
|
|
|
/* first make the preview image */
|
|
|
|
|
CompBuf *prevbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
|
2010-07-08 19:29:41 +00:00
|
|
|
|
2007-03-24 06:57:29 +00:00
|
|
|
prevbuf->rect_procedural= texture_procedural;
|
|
|
|
|
prevbuf->node= node;
|
2008-03-13 11:26:18 +00:00
|
|
|
VECCOPY(prevbuf->procedural_offset, in[0]->vec);
|
|
|
|
|
VECCOPY(prevbuf->procedural_size, in[1]->vec);
|
2008-04-07 15:21:25 +00:00
|
|
|
prevbuf->procedural_type= CB_RGBA;
|
2007-03-24 06:57:29 +00:00
|
|
|
composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
|
|
|
|
|
|
2011-01-06 14:58:58 +00:00
|
|
|
generate_preview(data, node, prevbuf);
|
|
|
|
|
free_compbuf(prevbuf);
|
|
|
|
|
|
|
|
|
|
/* texture procedural buffer type doesnt work well, we now render a buffer in scene size */
|
|
|
|
|
sizex = (rd->size*rd->xsch)/100;
|
|
|
|
|
sizey = (rd->size*rd->ysch)/100;
|
|
|
|
|
|
2007-03-24 06:57:29 +00:00
|
|
|
if(out[0]->hasoutput) {
|
2011-01-06 14:58:58 +00:00
|
|
|
CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_VAL, 1); /* alloc */
|
2007-03-24 06:57:29 +00:00
|
|
|
|
|
|
|
|
stackbuf->rect_procedural= texture_procedural;
|
|
|
|
|
stackbuf->node= node;
|
2008-03-13 11:26:18 +00:00
|
|
|
VECCOPY(stackbuf->procedural_offset, in[0]->vec);
|
|
|
|
|
VECCOPY(stackbuf->procedural_size, in[1]->vec);
|
2008-04-07 15:21:25 +00:00
|
|
|
stackbuf->procedural_type= CB_VAL;
|
2011-01-16 16:00:06 +00:00
|
|
|
composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_value, CB_VAL);
|
2011-01-06 14:58:58 +00:00
|
|
|
stackbuf->rect_procedural= NULL;
|
2007-03-24 06:57:29 +00:00
|
|
|
|
2007-09-24 02:18:00 +00:00
|
|
|
out[0]->data= stackbuf;
|
2007-03-24 06:57:29 +00:00
|
|
|
}
|
|
|
|
|
if(out[1]->hasoutput) {
|
2011-01-06 14:58:58 +00:00
|
|
|
CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_RGBA, 1); /* alloc */
|
2007-03-24 06:57:29 +00:00
|
|
|
|
|
|
|
|
stackbuf->rect_procedural= texture_procedural;
|
|
|
|
|
stackbuf->node= node;
|
2008-03-13 11:26:18 +00:00
|
|
|
VECCOPY(stackbuf->procedural_offset, in[0]->vec);
|
|
|
|
|
VECCOPY(stackbuf->procedural_size, in[1]->vec);
|
2008-04-07 15:21:25 +00:00
|
|
|
stackbuf->procedural_type= CB_RGBA;
|
2011-01-16 16:00:06 +00:00
|
|
|
composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
|
2011-01-06 14:58:58 +00:00
|
|
|
stackbuf->rect_procedural= NULL;
|
2007-03-24 06:57:29 +00:00
|
|
|
|
|
|
|
|
out[1]->data= stackbuf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 09:02:16 +00:00
|
|
|
void register_node_type_cmp_texture(ListBase *lb)
|
|
|
|
|
{
|
|
|
|
|
static bNodeType ntype;
|
|
|
|
|
|
|
|
|
|
node_type_base(&ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW,
|
|
|
|
|
cmp_node_texture_in, cmp_node_texture_out);
|
|
|
|
|
node_type_size(&ntype, 120, 80, 240);
|
|
|
|
|
node_type_exec(&ntype, node_composit_exec_texture);
|
|
|
|
|
|
|
|
|
|
nodeRegisterType(lb, &ntype);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-24 06:57:29 +00:00
|
|
|
|
|
|
|
|
|