2
* $Id: SHD_texture.c,v 1.4 2007/04/04 13:58:12 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) 2005 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 "../SHD_util.h"
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 */
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},
44
static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
46
if(data && node->id) {
47
ShadeInput *shi= ((ShaderCallData *)data)->shi;
49
float vec[3], nor[3]={0.0f, 0.0f, 0.0f};
52
/* out: value, color, normal */
54
/* we should find out if a normal as output is needed, for now we do all */
58
nodestack_get_vec(vec, SOCK_VECTOR, in[0]);
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);
64
else if(in[0]->datatype==NS_OSA_VALUES) {
65
float *fp= in[0]->data;
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);
73
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
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);
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);
86
/* intensity and color need some handling */
88
out[0]->vec[0]= texres.ta;
90
out[0]->vec[0]= texres.tin;
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];
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;
105
VECCOPY(out[2]->vec, nor);
108
nodeAddToPreview(node, out[1]->vec, shi->xs, shi->ys);
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,
122
/* execfunc */ node_shader_exec_texture,
125
/* freestoragefunc */ NULL,
126
/* copystoragefunc */ NULL,