Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2010-02-16 18:45:19 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2010-02-16 18:45:19 +0300
commitbd638da9a0bbd057b72164eed6583888380490ed (patch)
tree90c535062d48f73329b4597920877964e3c3b97a /source/blender
parent768f20d537967ada2c5e71c05b027533959bdc91 (diff)
Texture Nodes:
* Remove the manual OSA method but rather pass on derivatives to the textures. This means that at the moment e.g. the bricks node is not antialiased, but that image textures are now using mipmaps. Doing oversampling on the whole nodetree is convenient but it is really the individual textures that can do filtering best and quickest. * Image textures in a texture node tree were not color corrected and did not support 2d mapping, now it's passing along shadeinput to make this possible. Would like to avoid this but not sure how. * Fix preview not filling in all pixels when scaling or rotating in the texture nodes.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_node.h2
-rw-r--r--source/blender/nodes/intern/SHD_nodes/SHD_texture.c8
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_at.c6
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_bricks.c6
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_checker.c6
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_coord.c6
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_distance.c8
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_image.c6
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_output.c49
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_proc.c3
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_rotate.c56
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_scale.c15
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_texture.c7
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_translate.c10
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c20
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_viewer.c2
-rw-r--r--source/blender/nodes/intern/TEX_util.c38
-rw-r--r--source/blender/nodes/intern/TEX_util.h15
-rw-r--r--source/blender/render/extern/include/RE_shader_ext.h4
-rw-r--r--source/blender/render/intern/source/texture.c121
20 files changed, 196 insertions, 192 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 0fda9d62077..a6ebb72320c 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -433,7 +433,7 @@ extern struct ListBase node_all_textures;
/* API */
int ntreeTexTagAnimated(struct bNodeTree *ntree);
void ntreeTexSetPreviewFlag(int);
-void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, short thread, struct Tex *tex, short which_output, int cfra, int preview);
+int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, int osatex, short thread, struct Tex *tex, short which_output, int cfra, int preview, struct ShadeInput *shi, struct MTex *mtex);
void ntreeTexCheckCyclics(struct bNodeTree *ntree);
char* ntreeTexOutputMenu(struct bNodeTree *ntree);
diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_texture.c b/source/blender/nodes/intern/SHD_nodes/SHD_texture.c
index 1169307da17..b2fb3b2261c 100644
--- a/source/blender/nodes/intern/SHD_nodes/SHD_texture.c
+++ b/source/blender/nodes/intern/SHD_nodes/SHD_texture.c
@@ -64,7 +64,7 @@ static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, b
if(in[0]->datatype==NS_OSA_VECTORS) {
float *fp= in[0]->data;
- retval= multitex_thread((Tex *)node->id, vec, fp, fp+3, shi->osatex, &texres, thread, which_output);
+ retval= multitex_nodes((Tex *)node->id, vec, fp, fp+3, shi->osatex, &texres, thread, which_output, NULL, NULL);
}
else if(in[0]->datatype==NS_OSA_VALUES) {
float *fp= in[0]->data;
@@ -72,14 +72,14 @@ static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, b
dxt[0]= fp[0]; dxt[1]= dxt[2]= 0.0f;
dyt[0]= fp[1]; dyt[1]= dyt[2]= 0.0f;
- retval= multitex_thread((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output);
+ retval= multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL);
}
else
- retval= multitex_thread((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output);
+ retval= multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL);
}
else {
VECCOPY(vec, shi->lo);
- retval= multitex_thread((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output);
+ retval= multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL);
}
/* stupid exception */
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_at.c b/source/blender/nodes/intern/TEX_nodes/TEX_at.c
index ed435e9c42b..08c1c65792d 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_at.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_at.c
@@ -41,10 +41,10 @@ static bNodeSocketType outputs[]= {
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
TexParams np = *p;
- float new_coord[3];
- np.coord = new_coord;
+ float new_co[3];
+ np.co = new_co;
- tex_input_vec(new_coord, in[1], p, thread);
+ tex_input_vec(new_co, in[1], p, thread);
tex_input_rgba(out, in[0], &np, thread);
}
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c b/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c
index 8351a53f819..9d26621e08c 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c
@@ -59,10 +59,10 @@ static float noise(int n) /* fast integer noise */
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float *coord = p->coord;
+ float *co = p->co;
- float x = coord[0];
- float y = coord[1];
+ float x = co[0];
+ float y = co[1];
int bricknum, rownum;
float offset = 0;
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_checker.c b/source/blender/nodes/intern/TEX_nodes/TEX_checker.c
index 2b6e993d712..4155cec4d7f 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_checker.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_checker.c
@@ -42,9 +42,9 @@ static bNodeSocketType outputs[]= {
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float x = p->coord[0];
- float y = p->coord[1];
- float z = p->coord[2];
+ float x = p->co[0];
+ float y = p->co[1];
+ float z = p->co[2];
float sz = tex_input_value(in[2], p, thread);
/* 0.00001 because of unit sized stuff */
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_coord.c b/source/blender/nodes/intern/TEX_nodes/TEX_coord.c
index 43fa4dd7185..68e892ce77c 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_coord.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_coord.c
@@ -35,9 +35,9 @@ static bNodeSocketType outputs[]= {
static void vectorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- out[0] = p->coord[0];
- out[1] = p->coord[1];
- out[2] = p->coord[2];
+ out[0] = p->co[0];
+ out[1] = p->co[1];
+ out[2] = p->co[2];
}
static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c
index f17cf861c88..e0fee3e3153 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c
@@ -43,12 +43,12 @@ static bNodeSocketType outputs[]= {
static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float coord1[3], coord2[3];
+ float co1[3], co2[3];
- tex_input_vec(coord1, in[0], p, thread);
- tex_input_vec(coord2, in[1], p, thread);
+ tex_input_vec(co1, in[0], p, thread);
+ tex_input_vec(co2, in[1], p, thread);
- *out = len_v3v3(coord2, coord1);
+ *out = len_v3v3(co2, co1);
}
static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_image.c b/source/blender/nodes/intern/TEX_nodes/TEX_image.c
index 211a4a1ab8d..628d9026db1 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_image.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_image.c
@@ -36,8 +36,8 @@ static bNodeSocketType outputs[]= {
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float x = p->coord[0];
- float y = p->coord[1];
+ float x = p->co[0];
+ float y = p->co[1];
Image *ima= (Image *)node->id;
ImageUser *iuser= (ImageUser *)node->storage;
@@ -69,7 +69,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
QUATCOPY( out, result );
}
}
-};
+}
static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_output.c b/source/blender/nodes/intern/TEX_nodes/TEX_output.c
index 63f51073fed..09bc893cc1f 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_output.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_output.c
@@ -35,48 +35,6 @@ static bNodeSocketType inputs[]= {
{ -1, 0, "" }
};
-static void osa(
- void (*input_fn)(float *, bNodeStack *, TexParams *, short),
- float *out,
- bNodeStack *in,
- TexParams *p,
- short thread
-){
- if(!p->dxt) {
- input_fn(out, in, p, thread);
- } else {
- float sample[4] = {0};
- float coord[3];
- TexParams sp = *p;
- int i;
-
- sp.coord = coord;
- sp.dxt = sp.dyt = 0;
-
- QUATCOPY(out, sample);
-
- for(i=0; i<5; i++) {
- VECCOPY(coord, p->coord);
-
- if(i < 4)
- {
- if(i % 2) VECADD(coord, coord, p->dxt);
- if(i > 1) VECADD(coord, coord, p->dyt);
- }
- else
- {
- VECADDFAC(coord, coord, p->dxt, 0.5);
- VECADDFAC(coord, coord, p->dyt, 0.5);
- }
-
- input_fn(sample, in, &sp, thread);
-
- QUATADDFAC(out, out, sample, 0.2);
- }
- }
-}
-
-
/* applies to render pipeline */
static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
@@ -91,7 +49,7 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
tex_input_rgba(&target->tr, in[1], &params, cdata->thread);
else
tex_input_rgba(&target->tr, in[0], &params, cdata->thread);
- tex_do_preview(node, params.coord, &target->tr);
+ tex_do_preview(node, params.co, &target->tr);
}
else {
/* 0 means don't care, so just use first */
@@ -99,14 +57,14 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
TexParams params;
params_from_cdata(&params, cdata);
- osa(tex_input_rgba, &target->tr, in[0], &params, cdata->thread);
+ tex_input_rgba(&target->tr, in[0], &params, cdata->thread);
target->tin = (target->tr + target->tg + target->tb) / 3.0f;
target->talpha = 1.0f;
if(target->nor) {
if(in[1]->hasinput)
- osa(tex_input_vec, target->nor, in[1], &params, cdata->thread);
+ tex_input_vec(target->nor, in[1], &params, cdata->thread);
else
target->nor = 0;
}
@@ -210,3 +168,4 @@ bNodeType tex_node_output= {
/* copystoragefunc */ copy,
/* id */ NULL
};
+
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_proc.c b/source/blender/nodes/intern/TEX_nodes/TEX_proc.c
index ef8325465b4..16b65a4b0be 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_proc.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_proc.c
@@ -62,7 +62,8 @@ static void do_proc(float *result, TexParams *p, float *col1, float *col2, char
else
texres.nor = NULL;
- textype = multitex_thread(tex, p->coord, p->dxt, p->dyt, 0, &texres, thread, 0);
+ textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex,
+ &texres, thread, 0, p->shi, p->mtex);
if(is_normal)
return;
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c
index 7812cefa267..31b669991ad 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c
@@ -42,54 +42,44 @@ static bNodeSocketType outputs[]= {
{ -1, 0, "" }
};
-static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+static void rotate(float new_co[3], float a, float ax[3], float co[3])
{
- float new_coord[3];
- float *coord = p->coord;
-
- float ax[4];
float para[3];
float perp[3];
float cp[3];
- float magsq, ndx;
-
- float a = tex_input_value(in[1], p, thread);
float cos_a = cos(a * 2 * M_PI);
float sin_a = sin(a * 2 * M_PI);
- // x' = xcosa + n(n.x)(1-cosa)+(x*n)sina
-
- tex_input_vec(ax, in[2], p, thread);
- magsq = ax[0]*ax[0] + ax[1]*ax[1] + ax[2]*ax[2];
-
- if(magsq == 0) magsq = 1;
-
- ndx = dot_v3v3(coord, ax);
-
- para[0] = ax[0] * ndx * (1 - cos_a);
- para[1] = ax[1] * ndx * (1 - cos_a);
- para[2] = ax[2] * ndx * (1 - cos_a);
+ // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina
- sub_v3_v3v3(perp, coord, para);
+ mul_v3_v3fl(perp, co, cos_a);
+ mul_v3_v3fl(para, ax, dot_v3v3(co, ax)*(1 - cos_a));
- perp[0] = coord[0] * cos_a;
- perp[1] = coord[1] * cos_a;
- perp[2] = coord[2] * cos_a;
+ cross_v3_v3v3(cp, ax, co);
+ mul_v3_fl(cp, sin_a);
- cross_v3_v3v3(cp, ax, coord);
-
- cp[0] = cp[0] * sin_a;
- cp[1] = cp[1] * sin_a;
- cp[2] = cp[2] * sin_a;
+ new_co[0] = para[0] + perp[0] + cp[0];
+ new_co[1] = para[1] + perp[1] + cp[1];
+ new_co[2] = para[2] + perp[2] + cp[2];
+}
+
+static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ float new_co[3], new_dxt[3], new_dyt[3], a, ax[3];
- new_coord[0] = para[0] + perp[0] + cp[0];
- new_coord[1] = para[1] + perp[1] + cp[1];
- new_coord[2] = para[2] + perp[2] + cp[2];
+ a= tex_input_value(in[1], p, thread);
+ tex_input_vec(ax, in[2], p, thread);
+
+ rotate(new_co, a, ax, p->co);
+ rotate(new_dxt, a, ax, p->dxt);
+ rotate(new_dyt, a, ax, p->dyt);
{
TexParams np = *p;
- np.coord = new_coord;
+ np.co = new_co;
+ np.dxt = new_dxt;
+ np.dyt = new_dyt;
tex_input_rgba(out, in[0], &np, thread);
}
}
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_scale.c b/source/blender/nodes/intern/TEX_nodes/TEX_scale.c
index ae0c3653109..609b117e5be 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_scale.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_scale.c
@@ -42,15 +42,18 @@ static bNodeSocketType outputs[]= {
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float scale[3], new_coord[3];
+ float scale[3], new_co[3], new_dxt[3], new_dyt[3];
TexParams np = *p;
- np.coord = new_coord;
+
+ np.co = new_co;
+ np.dxt = new_dxt;
+ np.dyt = new_dyt;
tex_input_vec(scale, in[1], p, thread);
-
- new_coord[0] = p->coord[0] * scale[0];
- new_coord[1] = p->coord[1] * scale[1];
- new_coord[2] = p->coord[2] * scale[2];
+
+ mul_v3_v3v3(new_co, p->co, scale);
+ mul_v3_v3v3(new_dxt, p->dxt, scale);
+ mul_v3_v3v3(new_dyt, p->dyt, scale);
tex_input_rgba(out, in[0], &np, thread);
}
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_texture.c b/source/blender/nodes/intern/TEX_nodes/TEX_texture.c
index aa687920e46..c01caa022e5 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_texture.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_texture.c
@@ -44,7 +44,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
{
static float red[] = {1,0,0,1};
static float white[] = {1,1,1,1};
- float *coord = p->coord;
+ float *co = p->co;
Tex *nodetex = (Tex *)node->id;
@@ -52,7 +52,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
/* this node refers to its own texture tree! */
QUATCOPY(
out,
- (fabs(coord[0] - coord[1]) < .01) ? white : red
+ (fabs(co[0] - co[1]) < .01) ? white : red
);
}
else if(nodetex) {
@@ -65,7 +65,8 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
tex_input_rgba(col2, in[1], p, thread);
texres.nor = nor;
- textype = multitex_ext(nodetex, coord, 0, 0, 0, &texres);
+ textype = multitex_nodes(nodetex, co, p->dxt, p->dyt, p->osatex,
+ &texres, thread, 0, p->shi, p->mtex);
if(textype & TEX_RGB) {
QUATCOPY(out, &texres.tr);
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_translate.c b/source/blender/nodes/intern/TEX_nodes/TEX_translate.c
index df555f794f4..a823338faf9 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_translate.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_translate.c
@@ -42,15 +42,15 @@ static bNodeSocketType outputs[]= {
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float offset[3], new_coord[3];
+ float offset[3], new_co[3];
TexParams np = *p;
- np.coord = new_coord;
+ np.co = new_co;
tex_input_vec(offset, in[1], p, thread);
- new_coord[0] = p->coord[0] + offset[0];
- new_coord[1] = p->coord[1] + offset[1];
- new_coord[2] = p->coord[2] + offset[2];
+ new_co[0] = p->co[0] + offset[0];
+ new_co[1] = p->co[1] + offset[1];
+ new_co[2] = p->co[2] + offset[2];
tex_input_rgba(out, in[0], &np, thread);
}
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c b/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c
index a0d7b96a600..46aefe5ad47 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c
@@ -41,29 +41,29 @@ static bNodeSocketType outputs[]= {
static void normalfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
- float new_coord[3];
- float *coord = p->coord;
+ float new_co[3];
+ float *co = p->co;
float nabla = tex_input_value(in[1], p, thread);
float val;
float nor[3];
TexParams np = *p;
- np.coord = new_coord;
+ np.co = new_co;
val = tex_input_value(in[0], p, thread);
- new_coord[0] = coord[0] + nabla;
- new_coord[1] = coord[1];
- new_coord[2] = coord[2];
+ new_co[0] = co[0] + nabla;
+ new_co[1] = co[1];
+ new_co[2] = co[2];
nor[0] = tex_input_value(in[0], &np, thread);
- new_coord[0] = coord[0];
- new_coord[1] = coord[1] + nabla;
+ new_co[0] = co[0];
+ new_co[1] = co[1] + nabla;
nor[1] = tex_input_value(in[0], &np, thread);
- new_coord[1] = coord[1];
- new_coord[2] = coord[2] + nabla;
+ new_co[1] = co[1];
+ new_co[2] = co[2] + nabla;
nor[2] = tex_input_value(in[0], &np, thread);
out[0] = val-nor[0];
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c b/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c
index f5f0ebe8397..698c894a8d8 100644
--- a/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c
+++ b/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c
@@ -47,7 +47,7 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
params_from_cdata(&params, cdata);
tex_input_rgba(col, in[0], &params, cdata->thread);
- tex_do_preview(node, params.coord, col);
+ tex_do_preview(node, params.previewco, col);
}
}
diff --git a/source/blender/nodes/intern/TEX_util.c b/source/blender/nodes/intern/TEX_util.c
index 829a93c089c..f471198d8ee 100644
--- a/source/blender/nodes/intern/TEX_util.c
+++ b/source/blender/nodes/intern/TEX_util.c
@@ -53,7 +53,7 @@ void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thr
dg->fn(out, params, dg->node, dg->in, thread);
if(dg->cdata->do_preview)
- tex_do_preview(dg->node, params->coord, out);
+ tex_do_preview(dg->node, params->previewco, out);
}
}
@@ -101,19 +101,23 @@ float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void params_from_cdata(TexParams *out, TexCallData *in)
{
- out->coord = in->coord;
+ out->co = in->co;
out->dxt = in->dxt;
out->dyt = in->dyt;
+ out->previewco = in->co;
+ out->osatex = in->osatex;
out->cfra = in->cfra;
+ out->shi = in->shi;
+ out->mtex = in->mtex;
}
-void tex_do_preview(bNode *node, float *coord, float *col)
+void tex_do_preview(bNode *node, float *co, float *col)
{
bNodePreview *preview= node->preview;
if(preview) {
- int xs= ((coord[0] + 1.0f)*0.5f)*preview->xsize;
- int ys= ((coord[1] + 1.0f)*0.5f)*preview->ysize;
+ int xs= ((co[0] + 1.0f)*0.5f)*preview->xsize;
+ int ys= ((co[1] + 1.0f)*0.5f)*preview->ysize;
nodeAddToPreview(node, col, xs, ys);
}
@@ -162,30 +166,40 @@ void ntreeTexCheckCyclics(struct bNodeTree *ntree)
}
}
-void ntreeTexExecTree(
+int ntreeTexExecTree(
bNodeTree *nodes,
TexResult *texres,
- float *coord,
+ float *co,
float *dxt, float *dyt,
+ int osatex,
short thread,
Tex *tex,
short which_output,
int cfra,
- int preview
+ int preview,
+ ShadeInput *shi,
+ MTex *mtex
){
- TexResult dummy_texres;
TexCallData data;
-
- if(!texres) texres = &dummy_texres;
- data.coord = coord;
+ int retval = TEX_INT;
+
+ data.co = co;
data.dxt = dxt;
data.dyt = dyt;
+ data.osatex = osatex;
data.target = texres;
data.do_preview = preview;
data.thread = thread;
data.which_output = which_output;
data.cfra= cfra;
+ data.mtex= mtex;
+ data.shi= shi;
ntreeExecTree(nodes, &data, thread);
+
+ if(texres->nor) retval |= TEX_NOR;
+ retval |= TEX_RGB;
+
+ return retval;
}
diff --git a/source/blender/nodes/intern/TEX_util.h b/source/blender/nodes/intern/TEX_util.h
index 04d29051ea7..a9465e17623 100644
--- a/source/blender/nodes/intern/TEX_util.h
+++ b/source/blender/nodes/intern/TEX_util.h
@@ -70,18 +70,29 @@
typedef struct TexCallData {
TexResult *target;
- float *coord;
+ float *co;
float *dxt, *dyt;
+ int osatex;
char do_preview;
short thread;
short which_output;
int cfra;
+
+ ShadeInput *shi;
+ MTex *mtex;
} TexCallData;
typedef struct TexParams {
- float *coord;
+ float *co;
float *dxt, *dyt;
+ float *previewco;
int cfra;
+ int osatex;
+
+ /* optional. we don't really want these here, but image
+ textures need to do mapping & color correction */
+ ShadeInput *shi;
+ MTex *mtex;
} TexParams;
typedef void(*TexFn) (float *out, TexParams *params, bNode *node, bNodeStack **in, short thread);
diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h
index 5969497b424..f7dfb4d889e 100644
--- a/source/blender/render/extern/include/RE_shader_ext.h
+++ b/source/blender/render/extern/include/RE_shader_ext.h
@@ -191,8 +191,10 @@ typedef struct ShadeInput
/* node shaders... */
struct Tex;
+struct MTex;
int multitex_ext(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres);
-int multitex_thread(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres, short thread, short which_output);
+int multitex_nodes(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres,
+ short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex);
/* shaded view and bake */
struct Render;
diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c
index 67b4b4cf9b4..0fe6a2d921a 100644
--- a/source/blender/render/intern/source/texture.c
+++ b/source/blender/render/intern/source/texture.c
@@ -716,20 +716,6 @@ static float voronoiTex(Tex *tex, float *texvec, TexResult *texres)
/* ------------------------------------------------------------------------- */
-static int evalnodes(Tex *tex, float *texvec, float *dxt, float *dyt, TexResult *texres, short thread, short which_output)
-{
- short rv = TEX_INT;
- bNodeTree *nodes = tex->nodetree;
-
- ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, thread, tex, which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0);
-
- if(texres->nor) rv |= TEX_NOR;
- rv |= TEX_RGB;
- return rv;
-}
-
-/* ------------------------------------------------------------------------- */
-
static int texnoise(Tex *tex, TexResult *texres)
{
float div=3.0;
@@ -1182,8 +1168,8 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex,
texres->talpha= 0; /* is set when image texture returns alpha (considered premul) */
if(tex->use_nodes && tex->nodetree) {
- if(osatex) retval = evalnodes(tex, texvec, dxt, dyt, texres, thread, which_output);
- else retval = evalnodes(tex, texvec, NULL, NULL, texres, thread, which_output);
+ retval = ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, osatex, thread,
+ tex, which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0, NULL, NULL);
}
else
switch(tex->type) {
@@ -1288,48 +1274,85 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex,
return retval;
}
-/* Warning, if the texres's values are not declared zero, check the return value to be sure
- * the color values are set before using the r/g/b values, otherwise you may use uninitialized values - Campbell */
-int multitex_ext(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
-{
- return multitex_thread(tex, texvec, dxt, dyt, osatex, texres, 0, 0);
-}
-
-int multitex_thread(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres, short thread, short which_output)
+/* this is called from the shader and texture nodes */
+int multitex_nodes(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres, short thread, short which_output, ShadeInput *shi, MTex *mtex)
{
if(tex==NULL) {
memset(texres, 0, sizeof(TexResult));
return 0;
}
+
+ if(mtex)
+ which_output= mtex->which_output;
- /* Image requires 2d mapping conversion */
if(tex->type==TEX_IMAGE) {
- MTex mtex;
- float texvec_l[3], dxt_l[3], dyt_l[3];
-
- mtex.mapping= MTEX_FLAT;
- mtex.tex= tex;
- mtex.object= NULL;
- mtex.texco= TEXCO_ORCO;
-
- VECCOPY(texvec_l, texvec);
- if(dxt && dyt) {
- VECCOPY(dxt_l, dxt);
- VECCOPY(dyt_l, dyt);
+ int rgbnor;
+
+ if(mtex) {
+ /* we have mtex, use it for 2d mapping images only */
+ do_2d_mapping(mtex, texvec, shi->vlr, shi->facenor, dxt, dyt);
+ rgbnor= multitex(tex, texvec, dxt, dyt, osatex, texres, thread, which_output);
+
+ if(mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) {
+ ImBuf *ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser);
+
+ /* don't linearize float buffers, assumed to be linear */
+ if(ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT)
+ srgb_to_linearrgb_v3_v3(&texres->tr, &texres->tr);
+ }
}
else {
- dxt_l[0]= dxt_l[1]= dxt_l[2]= 0.0f;
- dyt_l[0]= dyt_l[1]= dyt_l[2]= 0.0f;
+ /* we don't have mtex, do default flat 2d projection */
+ MTex localmtex;
+ float texvec_l[3], dxt_l[3], dyt_l[3];
+
+ localmtex.mapping= MTEX_FLAT;
+ localmtex.tex= tex;
+ localmtex.object= NULL;
+ localmtex.texco= TEXCO_ORCO;
+
+ VECCOPY(texvec_l, texvec);
+ if(dxt && dyt) {
+ VECCOPY(dxt_l, dxt);
+ VECCOPY(dyt_l, dyt);
+ }
+ else {
+ dxt_l[0]= dxt_l[1]= dxt_l[2]= 0.0f;
+ dyt_l[0]= dyt_l[1]= dyt_l[2]= 0.0f;
+ }
+
+ do_2d_mapping(&localmtex, texvec_l, NULL, NULL, dxt_l, dyt_l);
+ rgbnor= multitex(tex, texvec, dxt, dyt, osatex, texres, thread, which_output);
}
-
- do_2d_mapping(&mtex, texvec_l, NULL, NULL, dxt_l, dyt_l);
- return multitex(tex, texvec_l, dxt_l, dyt_l, osatex, texres, thread, which_output);
+ return rgbnor;
}
else
return multitex(tex, texvec, dxt, dyt, osatex, texres, thread, which_output);
}
+/* this is called for surface shading */
+int multitex_mtex(ShadeInput *shi, MTex *mtex, float *texvec, float *dxt, float *dyt, TexResult *texres)
+{
+ Tex *tex= mtex->tex;
+
+ if(tex->use_nodes && tex->nodetree) {
+ /* stupid exception here .. but we have to pass shi and mtex to
+ textures nodes for 2d mapping and color management for images */
+ return ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, shi->osatex, shi->thread,
+ tex, mtex->which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0, shi, mtex);
+ }
+ else
+ return multitex(mtex->tex, texvec, dxt, dyt, shi->osatex, texres, shi->thread, mtex->which_output);
+}
+
+/* Warning, if the texres's values are not declared zero, check the return value to be sure
+ * the color values are set before using the r/g/b values, otherwise you may use uninitialized values - Campbell */
+int multitex_ext(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
+{
+ return multitex_nodes(tex, texvec, dxt, dyt, osatex, texres, 0, 0, NULL, NULL);
+}
+
/* ------------------------------------------------------------------------- */
/* in = destination, tex = texture, out = previous color */
@@ -1874,7 +1897,7 @@ void do_material_tex(ShadeInput *shi)
// center, main return value
texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex(tex, texvec, dxt, dyt, shi->osatex, &texres, shi->thread, mtex->which_output);
+ rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, &texres);
cd = fromrgb ? (texres.tr + texres.tg + texres.tb)*0.33333333f : texres.tin;
if (mtex->texco == TEXCO_UV) {
@@ -1888,7 +1911,7 @@ void do_material_tex(ShadeInput *shi)
tco[1] = co[1] + dvdnu*du;
tco[2] = 0.f;
texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex(tex, texv, dxt, dyt, shi->osatex, &ttexr, shi->thread, mtex->which_output);
+ multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr);
ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
// +v val
@@ -1896,7 +1919,7 @@ void do_material_tex(ShadeInput *shi)
tco[1] = co[1] + dvdnv*du;
tco[2] = 0.f;
texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex(tex, texv, dxt, dyt, shi->osatex, &ttexr, shi->thread, mtex->which_output);
+ multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr);
vd = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
}
else {
@@ -1927,7 +1950,7 @@ void do_material_tex(ShadeInput *shi)
tco[1] = co[1] + tu[1]*du;
tco[2] = co[2] + tu[2]*du;
texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex(tex, texv, dxt, dyt, shi->osatex, &ttexr, shi->thread, mtex->which_output);
+ multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr);
ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
// +v val
@@ -1935,7 +1958,7 @@ void do_material_tex(ShadeInput *shi)
tco[1] = co[1] + tv[1]*dv;
tco[2] = co[2] + tv[2]*dv;
texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex(tex, texv, dxt, dyt, shi->osatex, &ttexr, shi->thread, mtex->which_output);
+ multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr);
vd = idv*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin));
}
@@ -1956,12 +1979,12 @@ void do_material_tex(ShadeInput *shi)
}
else {
texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex(tex, texvec, dxt, dyt, shi->osatex, &texres, shi->thread, mtex->which_output);
+ rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, &texres);
}
}
else {
texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex(tex, texvec, dxt, dyt, shi->osatex, &texres, shi->thread, mtex->which_output);
+ rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, &texres);
}
/* texture output */