/* Calls multitex and copies the result to the outputs. Called by xxx_exec, which handles inputs. */ static void do_proc(float *result, TexParams *p, const float col1[4], const float col2[4], char is_normal, Tex *tex, const short thread) { TexResult texres; int textype; if (is_normal) { texres.nor = result; } else texres.nor = NULL; textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex, &texres, thread, 0, p->shi, p->mtex); if (is_normal) return; if (textype & TEX_RGB) { copy_v4_v4(result, &texres.tr); } else { copy_v4_v4(result, col1); ramp_blend(MA_RAMP_BLEND, result, texres.tin, col2); } }
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { Tex *nodetex = (Tex *)node->id; static float red[] = {1,0,0,1}; static float white[] = {1,1,1,1}; float co[3], dxt[3], dyt[3]; copy_v3_v3(co, p->co); copy_v3_v3(dxt, p->dxt); copy_v3_v3(dyt, p->dyt); if(node->custom2 || node->need_exec==0) { /* this node refers to its own texture tree! */ QUATCOPY(out, (fabs(co[0] - co[1]) < .01) ? white : red ); } else if(nodetex) { TexResult texres; int textype; float nor[] = {0,0,0}; float col1[4], col2[4]; tex_input_rgba(col1, in[0], p, thread); tex_input_rgba(col2, in[1], p, thread); texres.nor = nor; textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->shi, p->mtex); if(textype & TEX_RGB) { QUATCOPY(out, &texres.tr); } else { QUATCOPY(out, col1); ramp_blend(MA_RAMP_BLEND, out, out+1, out+2, texres.tin, col2); } } }
static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { if(data && node->id) { ShadeInput *shi= ((ShaderCallData *)data)->shi; TexResult texres; float vec[3], nor[3]={0.0f, 0.0f, 0.0f}; int retval; short which_output = node->custom1; short thread = shi->thread; /* out: value, color, normal */ /* we should find out if a normal as output is needed, for now we do all */ texres.nor= nor; texres.tr= texres.tg= texres.tb= 0.0f; if(in[0]->hasinput) { nodestack_get_vec(vec, SOCK_VECTOR, in[0]); if(in[0]->datatype==NS_OSA_VECTORS) { float *fp= in[0]->data; 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; float dxt[3], dyt[3]; dxt[0]= fp[0]; dxt[1]= dxt[2]= 0.0f; dyt[0]= fp[1]; dyt[1]= dyt[2]= 0.0f; retval= multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL); } else retval= multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL); } else { VECCOPY(vec, shi->lo); retval= multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL); } /* stupid exception */ if( ((Tex *)node->id)->type==TEX_STUCCI) { texres.tin= 0.5f + 0.7f*texres.nor[0]; CLAMP(texres.tin, 0.0f, 1.0f); } /* intensity and color need some handling */ if(texres.talpha) out[0]->vec[0]= texres.ta; else out[0]->vec[0]= texres.tin; if((retval & TEX_RGB)==0) { out[1]->vec[0]= out[0]->vec[0]; out[1]->vec[1]= out[0]->vec[0]; out[1]->vec[2]= out[0]->vec[0]; out[1]->vec[3]= 1.0f; } else { out[1]->vec[0]= texres.tr; out[1]->vec[1]= texres.tg; out[1]->vec[2]= texres.tb; out[1]->vec[3]= 1.0f; } VECCOPY(out[2]->vec, nor); if(shi->do_preview) nodeAddToPreview(node, out[1]->vec, shi->xs, shi->ys, shi->do_manage); } }
static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { if (data && node->id) { ShadeInput *shi = ((ShaderCallData *)data)->shi; TexResult texres; bNodeSocket *sock_vector = node->inputs.first; float vec[3], nor[3] = {0.0f, 0.0f, 0.0f}; int retval; short which_output = node->custom1; short thread = shi->thread; /* out: value, color, normal */ /* we should find out if a normal as output is needed, for now we do all */ texres.nor = nor; texres.tr = texres.tg = texres.tb = 0.0f; /* don't use in[0]->hasinput, see material node for explanation */ if (sock_vector->link) { nodestack_get_vec(vec, SOCK_VECTOR, in[0]); if (in[0]->datatype == NS_OSA_VECTORS) { float *fp = in[0]->data; retval = multitex_nodes((Tex *)node->id, vec, fp, fp + 3, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); } else if (in[0]->datatype == NS_OSA_VALUES) { const float *fp = in[0]->data; float dxt[3], dyt[3]; dxt[0] = fp[0]; dxt[1] = dxt[2] = 0.0f; dyt[0] = fp[1]; dyt[1] = dyt[2] = 0.0f; retval = multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); } else retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); } else { copy_v3_v3(vec, shi->lo); retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); } /* stupid exception */ if ( ((Tex *)node->id)->type == TEX_STUCCI) { texres.tin = 0.5f + 0.7f * texres.nor[0]; CLAMP(texres.tin, 0.0f, 1.0f); } /* intensity and color need some handling */ if (texres.talpha) out[0]->vec[0] = texres.ta; else out[0]->vec[0] = texres.tin; if ((retval & TEX_RGB) == 0) { copy_v3_fl(out[1]->vec, out[0]->vec[0]); out[1]->vec[3] = 1.0f; } else { copy_v3_v3(out[1]->vec, &texres.tr); out[1]->vec[3] = 1.0f; } copy_v3_v3(out[2]->vec, nor); if (shi->do_preview) { BKE_node_preview_set_pixel(execdata->preview, out[1]->vec, shi->xs, shi->ys, shi->do_manage); } } }