Blender V2.61 - r43446

node_composite_texture.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2006 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "node_composite_util.h"
00034 
00035 /* **************** TEXTURE ******************** */
00036 static bNodeSocketTemplate cmp_node_texture_in[]= {
00037     {   SOCK_VECTOR, 1, "Offset",       0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_TRANSLATION},
00038     {   SOCK_VECTOR, 1, "Scale",        1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f, PROP_XYZ},
00039     {   -1, 0, ""   }
00040 };
00041 static bNodeSocketTemplate cmp_node_texture_out[]= {
00042     {   SOCK_FLOAT, 0, "Value"},
00043     {   SOCK_RGBA , 0, "Color"},
00044     {   -1, 0, ""   }
00045 };
00046 
00047 /* called without rect allocated */
00048 static void texture_procedural(CompBuf *cbuf, float *out, float xco, float yco)
00049 {
00050     bNode *node= cbuf->node;
00051     TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
00052     float vec[3], *size, nor[3]={0.0f, 0.0f, 0.0f}, col[4];
00053     int retval, type= cbuf->procedural_type;
00054     
00055     size= cbuf->procedural_size;
00056     
00057     vec[0]= size[0]*(xco + cbuf->procedural_offset[0]);
00058     vec[1]= size[1]*(yco + cbuf->procedural_offset[1]);
00059     vec[2]= size[2]*cbuf->procedural_offset[2];
00060     
00061     retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
00062     
00063     if(type==CB_VAL) {
00064         if(texres.talpha)
00065             col[0]= texres.ta;
00066         else
00067             col[0]= texres.tin;
00068     }
00069     else if(type==CB_RGBA) {
00070         if(texres.talpha)
00071             col[3]= texres.ta;
00072         else
00073             col[3]= texres.tin;
00074         
00075         if((retval & TEX_RGB)) {
00076             col[0]= texres.tr;
00077             col[1]= texres.tg;
00078             col[2]= texres.tb;
00079         }
00080         else col[0]= col[1]= col[2]= col[3];
00081     }
00082     else { 
00083         copy_v3_v3(col, nor);
00084     }
00085     
00086     typecheck_compbuf_color(out, col, cbuf->type, cbuf->procedural_type);
00087 }
00088 
00089 /* texture node outputs get a small rect, to make sure all other nodes accept it */
00090 /* only the pixel-processor nodes do something with it though */
00091 static void node_composit_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
00092 {
00093     /* outputs: value, color, normal */
00094     
00095     if(node->id) {
00096         RenderData *rd= data;
00097         short sizex, sizey;
00098         
00099         /* first make the preview image */
00100         CompBuf *prevbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
00101 
00102         prevbuf->rect_procedural= texture_procedural;
00103         prevbuf->node= node;
00104         copy_v3_v3(prevbuf->procedural_offset, in[0]->vec);
00105         copy_v3_v3(prevbuf->procedural_size, in[1]->vec);
00106         prevbuf->procedural_type= CB_RGBA;
00107         composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
00108         
00109         generate_preview(data, node, prevbuf);
00110         free_compbuf(prevbuf);
00111         
00112         /* texture procedural buffer type doesnt work well, we now render a buffer in scene size */
00113         sizex = (rd->size*rd->xsch)/100;
00114         sizey = (rd->size*rd->ysch)/100;
00115         
00116         if(out[0]->hasoutput) {
00117             CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_VAL, 1); /* alloc */
00118             
00119             stackbuf->rect_procedural= texture_procedural;
00120             stackbuf->node= node;
00121             copy_v3_v3(stackbuf->procedural_offset, in[0]->vec);
00122             copy_v3_v3(stackbuf->procedural_size, in[1]->vec);
00123             stackbuf->procedural_type= CB_VAL;
00124             composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_value, CB_VAL);
00125             stackbuf->rect_procedural= NULL;
00126             
00127             out[0]->data= stackbuf; 
00128         }
00129         if(out[1]->hasoutput) {
00130             CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_RGBA, 1); /* alloc */
00131             
00132             stackbuf->rect_procedural= texture_procedural;
00133             stackbuf->node= node;
00134             copy_v3_v3(stackbuf->procedural_offset, in[0]->vec);
00135             copy_v3_v3(stackbuf->procedural_size, in[1]->vec);
00136             stackbuf->procedural_type= CB_RGBA;
00137             composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
00138             stackbuf->rect_procedural= NULL;
00139             
00140             out[1]->data= stackbuf;
00141         }
00142     }
00143 }
00144 
00145 void register_node_type_cmp_texture(bNodeTreeType *ttype)
00146 {
00147     static bNodeType ntype;
00148 
00149     node_type_base(ttype, &ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW);
00150     node_type_socket_templates(&ntype, cmp_node_texture_in, cmp_node_texture_out);
00151     node_type_size(&ntype, 120, 80, 240);
00152     node_type_exec(&ntype, node_composit_exec_texture);
00153 
00154     nodeRegisterType(ttype, &ntype);
00155 }