Added new operators for "MapTo" panel as suggested & partially coded by

Kent Mein. So next to the mix, mult, add, sub we have now:

- Div: divides by texture color
- Screen: is like Mult, but works opposite (makes lighter)
- Diff: the difference between texture color and material
- Light: if texture is lighter it shows (per component)
- Dark: if texture is darker it shows (per component)

Next step: add this for specular and mirror, and the other channels...
I commit it now because it also fixes error in previous commit.
This commit is contained in:
2004-07-02 22:29:06 +00:00
parent 326f3c3d6a
commit 90d4f7a3c1
3 changed files with 80 additions and 10 deletions

View File

@@ -272,6 +272,11 @@ typedef struct Tex {
#define MTEX_MUL 1
#define MTEX_ADD 2
#define MTEX_SUB 3
#define MTEX_DIV 4
#define MTEX_DARK 5
#define MTEX_DIFF 6
#define MTEX_LIGHT 7
#define MTEX_SCREEN 8
/* **************** EnvMap ********************* */

View File

@@ -1118,7 +1118,7 @@ int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex)
/* fact = texture strength, facg = button strength value */
static void texture_rgb_blend(float *in, float *tex, float *out, float fact, float facg, int blendtype, int alphatype)
{
float facm;
float facm, col;
switch(blendtype) {
case MTEX_BLEND:
@@ -1139,6 +1139,7 @@ static void texture_rgb_blend(float *in, float *tex, float *out, float fact, flo
in[1]= (fact*tex[1] + facm*out[1]);
in[2]= (fact*tex[2] + facm*out[2]);
break;
case MTEX_MUL:
fact*= facg;
facm= 1.0-facg;
@@ -1146,6 +1147,15 @@ static void texture_rgb_blend(float *in, float *tex, float *out, float fact, flo
in[1]= (facm+fact*tex[1])*out[1];
in[2]= (facm+fact*tex[2])*out[2];
break;
case MTEX_SCREEN:
fact*= facg;
facm= 1.0-facg;
in[0]= 1.0-(facm+fact*(1.0-tex[0]))*(1.0-out[0]);
in[1]= 1.0-(facm+fact*(1.0-tex[1]))*(1.0-out[1]);
in[2]= 1.0-(facm+fact*(1.0-tex[2]))*(1.0-out[2]);
break;
case MTEX_SUB:
fact= -fact;
case MTEX_ADD:
@@ -1153,6 +1163,52 @@ static void texture_rgb_blend(float *in, float *tex, float *out, float fact, flo
in[0]= (fact*tex[0] + out[0]);
in[1]= (fact*tex[1] + out[1]);
in[2]= (fact*tex[2] + out[2]);
break;
case MTEX_DIV:
fact*= facg;
facm= 1.0-fact;
if(tex[0]!=0.0)
in[0]= facm*out[0] + fact*out[0]/tex[0];
if(tex[1]!=0.0)
in[1]= facm*out[1] + fact*out[1]/tex[1];
if(tex[2]!=0.0)
in[2]= facm*out[2] + fact*out[2]/tex[2];
break;
case MTEX_DIFF:
fact*= facg;
facm= 1.0-fact;
in[0]= facm*out[0] + fact*fabs(tex[0]-out[0]);
in[1]= facm*out[1] + fact*fabs(tex[1]-out[1]);
in[2]= facm*out[2] + fact*fabs(tex[2]-out[2]);
break;
case MTEX_DARK:
fact*= facg;
facm= 1.0-fact;
col= fact*tex[0];
if(col < out[0]) in[0]= col; else in[0]= out[0];
col= fact*tex[1];
if(col < out[1]) in[1]= col; else in[1]= out[1];
col= fact*tex[2];
if(col < out[2]) in[2]= col; else in[2]= out[2];
break;
case MTEX_LIGHT:
fact*= facg;
facm= 1.0-fact;
col= fact*tex[0];
if(col > out[0]) in[0]= col; else in[0]= out[0];
col= fact*tex[1];
if(col > out[1]) in[1]= col; else in[1]= out[1];
col= fact*tex[2];
if(col > out[2]) in[2]= col; else in[2]= out[2];
break;
}
@@ -1165,8 +1221,8 @@ void do_material_tex(ShadeInput *shi)
Material *mat_spec, *mat_har, *mat_emit, *mat_alpha, *mat_ray_mirr, *mat_translu;
MTex *mtex;
Tex *tex;
float *co = NULL, *dx = NULL, *dy = NULL, fact,
facm, factt, facmm, facmul = 0.0, stencilTin=1.0;
float *co = NULL, *dx = NULL, *dy = NULL;
float fact, facm, factt, facmm, facmul = 0.0, stencilTin=1.0;
float texvec[3], dxt[3], dyt[3], tempvec[3], norvec[3], Tnor=1.0;
int tex_nr, rgbnor= 0;
@@ -1383,10 +1439,11 @@ void do_material_tex(ShadeInput *shi)
else if(mtex->mapto & MAP_ALPHA) {
alphatype= T_ALPHA_TRANSP;
}
if(Talpha) alphatype |= T_ALPHA_PREMUL;
else Tin= Ta;
Tin= Ta;
if(Talpha) {
alphatype |= T_ALPHA_PREMUL;
}
if(mtex->mapto & MAP_COL) {
texture_rgb_blend(&shi->matren->r, tcol, &mat_col->r, Tin, mtex->colfac, mtex->blendtype, alphatype);
mat_col= shi->matren;

View File

@@ -2403,10 +2403,18 @@ static void material_panel_map_to(Material *ma)
uiDefButS(block, TOG3|BIT|12, B_MATPRV, "Disp", 1205,160,55,19, &(mtex->mapto), 0, 0, 0, 0, "Let the texture displace the surface");
uiBlockBeginAlign(block);
uiDefButS(block, ROW, B_MATPRV, "Mix", 1087,120,48,18, &(mtex->blendtype), 9.0, (float)MTEX_BLEND, 0, 0, "Sets texture to blend the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Mul", 1136,120,44,18, &(mtex->blendtype), 9.0, (float)MTEX_MUL, 0, 0, "Sets texture to multiply the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Add", 1182,120,41,18, &(mtex->blendtype), 9.0, (float)MTEX_ADD, 0, 0, "Sets texture to add the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Sub", 1226,120,40,18, &(mtex->blendtype), 9.0, (float)MTEX_SUB, 0, 0, "Sets texture to subtract the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Mix", 1087,133,48,18, &(mtex->blendtype), 9.0, (float)MTEX_BLEND, 0, 0, "Sets texture to blend the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Mul", 1136,133,44,18, &(mtex->blendtype), 9.0, (float)MTEX_MUL, 0, 0, "Sets texture to multiply the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Add", 1182,133,41,18, &(mtex->blendtype), 9.0, (float)MTEX_ADD, 0, 0, "Sets texture to add the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Sub", 1226,133,40,18, &(mtex->blendtype), 9.0, (float)MTEX_SUB, 0, 0, "Sets texture to subtract the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Div", 1087,115,60,18, &(mtex->blendtype), 9.0, (float)MTEX_DIV, 0, 0, "Sets texture to divide the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Screen", 1147,115,60,18, &(mtex->blendtype), 9.0, (float)MTEX_SCREEN, 0, 0, "Sets texture to screen the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Diff", 1207,115,59,18, &(mtex->blendtype), 9.0, (float)MTEX_DIFF, 0, 0, "Sets texture to difference the values or colour");
uiDefButS(block, ROW, B_MATPRV, "Light", 1087,98,90,18, &(mtex->blendtype), 9.0, (float)MTEX_LIGHT, 0, 0, "Sets texture to choose the lighter value");
uiDefButS(block, ROW, B_MATPRV, "Dark", 1177,98,89,18, &(mtex->blendtype), 9.0, (float)MTEX_DARK, 0, 0, "Sets texture to choose the darker");
uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI, B_MATPRV, "Col ", 1087,70,179,18, &(mtex->colfac), 0.0, 1.0, 0, 0, "Sets the amount the texture affects colour values");
/* newnoise: increased range to 25, the constant offset for bumpmapping quite often needs a higher nor setting */