Bugfix #4212
Material Nodes: The Texture node didn't do the standard "2d mapping" yet in case an Image Texture is used. Caused wrong mapping for example for UV coordinate inputs.
This commit is contained in:
@@ -1011,7 +1011,7 @@ static void texture_procedural(CompBuf *cbuf, float *col, float xco, float yco)
|
||||
vec[1]= size[1]*(yco + sock->ns.vec[1]);
|
||||
vec[2]= size[2]*sock->ns.vec[2];
|
||||
|
||||
retval= multitex((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
||||
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
||||
|
||||
if(type==CB_VAL) {
|
||||
if(texres.talpha)
|
||||
|
||||
@@ -335,7 +335,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((Tex *)node->id, vec, fp, fp+3, shi->osatex, &texres);
|
||||
retval= multitex_ext((Tex *)node->id, vec, fp, fp+3, shi->osatex, &texres);
|
||||
}
|
||||
else if(in[0]->datatype==NS_OSA_VALUES) {
|
||||
float *fp= in[0]->data;
|
||||
@@ -343,14 +343,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((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres);
|
||||
retval= multitex_ext((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres);
|
||||
}
|
||||
else
|
||||
retval= multitex((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
||||
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
||||
}
|
||||
else { /* only for previewrender, so we see stuff */
|
||||
vec= shi->lo;
|
||||
retval= multitex((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
||||
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
|
||||
}
|
||||
|
||||
/* stupid exception */
|
||||
@@ -744,7 +744,8 @@ int ntreeShaderGetTexco(bNodeTree *ntree, int osa)
|
||||
if(node->type==SH_NODE_TEXTURE) {
|
||||
if(osa && node->id) {
|
||||
Tex *tex= (Tex *)node->id;
|
||||
if ELEM3(tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) texco |= TEXCO_OSA;
|
||||
if ELEM3(tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP)
|
||||
texco |= TEXCO_OSA|NEED_UV;
|
||||
}
|
||||
}
|
||||
else if(node->type==SH_NODE_GEOMETRY) {
|
||||
@@ -753,15 +754,15 @@ int ntreeShaderGetTexco(bNodeTree *ntree, int osa)
|
||||
if(sock->flag & SOCK_IN_USE) {
|
||||
switch(a) {
|
||||
case GEOM_OUT_GLOB:
|
||||
texco |= TEXCO_GLOB; break;
|
||||
texco |= TEXCO_GLOB|NEED_UV; break;
|
||||
case GEOM_OUT_VIEW:
|
||||
texco |= TEXCO_VIEW; break;
|
||||
texco |= TEXCO_VIEW|NEED_UV; break;
|
||||
case GEOM_OUT_ORCO:
|
||||
texco |= TEXCO_ORCO; break;
|
||||
texco |= TEXCO_ORCO|NEED_UV; break;
|
||||
case GEOM_OUT_UV:
|
||||
texco |= TEXCO_UV; break;
|
||||
texco |= TEXCO_UV|NEED_UV; break;
|
||||
case GEOM_OUT_NORMAL:
|
||||
texco |= TEXCO_NORM; break;
|
||||
texco |= TEXCO_NORM|NEED_UV; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,7 @@ typedef struct ShadeInput
|
||||
|
||||
/* node shaders... */
|
||||
struct Tex;
|
||||
int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres);
|
||||
|
||||
int multitex_ext(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres);
|
||||
|
||||
#endif /* RE_SHADER_EXT_H */
|
||||
|
||||
|
||||
@@ -830,7 +830,7 @@ static int plugintex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex
|
||||
}
|
||||
|
||||
|
||||
static int cubemap_glob(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2)
|
||||
static int cubemap_glob(VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2)
|
||||
{
|
||||
float x1, y1, z1, nor[3];
|
||||
int ret;
|
||||
@@ -867,9 +867,10 @@ static int cubemap_glob(MTex *mtex, VlakRen *vlr, float x, float y, float z, flo
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* mtex argument only for projection switches */
|
||||
static int cubemap(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2)
|
||||
{
|
||||
int proj[4], ret= 0;
|
||||
int proj[4]={0, ME_PROJXY, ME_PROJXZ, ME_PROJYZ}, ret= 0;
|
||||
|
||||
if(vlr) {
|
||||
int index;
|
||||
@@ -884,19 +885,21 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *a
|
||||
else if( fabs(nor[0])<fabs(nor[1]) && fabs(nor[2])<fabs(nor[1]) ) vlr->puno |= ME_PROJXZ;
|
||||
else vlr->puno |= ME_PROJYZ;
|
||||
}
|
||||
else return cubemap_glob(mtex, vlr, x, y, z, adr1, adr2);
|
||||
else return cubemap_glob(vlr, x, y, z, adr1, adr2);
|
||||
}
|
||||
|
||||
/* the mtex->proj{xyz} have type char. maybe this should be wider? */
|
||||
/* casting to int ensures that the index type is right. */
|
||||
index = (int) mtex->projx;
|
||||
proj[index]= ME_PROJXY;
|
||||
if(mtex) {
|
||||
/* the mtex->proj{xyz} have type char. maybe this should be wider? */
|
||||
/* casting to int ensures that the index type is right. */
|
||||
index = (int) mtex->projx;
|
||||
proj[index]= ME_PROJXY;
|
||||
|
||||
index = (int) mtex->projy;
|
||||
proj[index]= ME_PROJXZ;
|
||||
index = (int) mtex->projy;
|
||||
proj[index]= ME_PROJXZ;
|
||||
|
||||
index = (int) mtex->projz;
|
||||
proj[index]= ME_PROJYZ;
|
||||
index = (int) mtex->projz;
|
||||
proj[index]= ME_PROJYZ;
|
||||
}
|
||||
|
||||
if(vlr->puno & proj[1]) {
|
||||
*adr1 = (x + 1.0) / 2.0;
|
||||
@@ -914,7 +917,7 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *a
|
||||
}
|
||||
}
|
||||
else {
|
||||
return cubemap_glob(mtex, vlr, x, y, z, adr1, adr2);
|
||||
return cubemap_glob(vlr, x, y, z, adr1, adr2);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -922,7 +925,7 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *a
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static int cubemap_ob(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2)
|
||||
static int cubemap_ob(Object *ob, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2)
|
||||
{
|
||||
float x1, y1, z1, nor[3];
|
||||
int ret;
|
||||
@@ -930,7 +933,7 @@ static int cubemap_ob(MTex *mtex, VlakRen *vlr, float x, float y, float z, float
|
||||
if(vlr==NULL) return 0;
|
||||
|
||||
VECCOPY(nor, vlr->n);
|
||||
if(mtex->object) MTC_Mat4Mul3Vecfl(mtex->object->imat, nor);
|
||||
if(ob) MTC_Mat4Mul3Vecfl(ob->imat, nor);
|
||||
|
||||
x1= fabs(nor[0]);
|
||||
y1= fabs(nor[1]);
|
||||
@@ -959,11 +962,15 @@ static int cubemap_ob(MTex *mtex, VlakRen *vlr, float x, float y, float z, float
|
||||
static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float *dyt)
|
||||
{
|
||||
Tex *tex;
|
||||
Object *ob= NULL;
|
||||
float fx, fy, fac1, area[8];
|
||||
int ok, proj, areaflag= 0, wrap;
|
||||
int ok, proj, areaflag= 0, wrap, texco;
|
||||
|
||||
/* mtex variables localized, only cubemap doesn't cooperate yet... */
|
||||
wrap= mtex->mapping;
|
||||
tex= mtex->tex;
|
||||
ob= mtex->object;
|
||||
texco= mtex->texco;
|
||||
|
||||
if(R.osa==0) {
|
||||
|
||||
@@ -974,8 +981,8 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
|
||||
else if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy);
|
||||
else if(wrap==MTEX_SPHERE) spheremap(t[0], t[1], t[2], &fx, &fy);
|
||||
else {
|
||||
if(mtex->texco==TEXCO_OBJECT) cubemap_ob(mtex, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
else if(mtex->texco==TEXCO_GLOB) cubemap_glob(mtex, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
if(texco==TEXCO_OBJECT) cubemap_ob(ob, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
else if(texco==TEXCO_GLOB) cubemap_glob(vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
else cubemap(mtex, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
}
|
||||
|
||||
@@ -1051,8 +1058,8 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
|
||||
}
|
||||
else {
|
||||
|
||||
if(mtex->texco==TEXCO_OBJECT) proj = cubemap_ob(mtex, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
else if (mtex->texco==TEXCO_GLOB) proj = cubemap_glob(mtex, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
if(texco==TEXCO_OBJECT) proj = cubemap_ob(ob, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
else if (texco==TEXCO_GLOB) proj = cubemap_glob(vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
else proj = cubemap(mtex, vlr, t[0], t[1], t[2], &fx, &fy);
|
||||
|
||||
if(proj==1) {
|
||||
@@ -1133,10 +1140,9 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
|
||||
static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
|
||||
{
|
||||
int retval=0; /* return value, int:0, col:1, nor:2, everything:3 */
|
||||
|
||||
@@ -1230,6 +1236,33 @@ int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRes
|
||||
return retval;
|
||||
}
|
||||
|
||||
int multitex_ext(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
|
||||
{
|
||||
|
||||
if(tex==NULL) return 0;
|
||||
|
||||
/* 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);
|
||||
VECCOPY(dxt_l, dxt);
|
||||
VECCOPY(dyt_l, dyt);
|
||||
|
||||
do_2d_mapping(&mtex, texvec_l, NULL, dxt_l, dyt_l);
|
||||
|
||||
return multitex(tex, texvec_l, dxt_l, dyt_l, osatex, texres);
|
||||
}
|
||||
else
|
||||
return multitex(tex, texvec, dxt, dyt, osatex, texres);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* in = destination, tex = texture, out = previous color */
|
||||
|
||||
Reference in New Issue
Block a user