Important bugfix: Image mapping "repeat" didn't support mirrored tiling

yet: http://www.blender.org/bf/rep1.jpg

Psst psst... to solve this bug I had to add the buttons for the option too!
This commit is contained in:
Ton Roosendaal
2007-01-14 11:51:52 +00:00
parent 444246d016
commit bd0f9a59f0
4 changed files with 56 additions and 13 deletions

View File

@@ -262,6 +262,8 @@ typedef struct TexMapping {
#define TEX_CHECKER_EVEN 16
#define TEX_PRV_ALPHA 32
#define TEX_PRV_NOR 64
#define TEX_REPEAT_XMIR 128
#define TEX_REPEAT_YMIR 256
/* extend (starts with 1 because of backward comp.) */
#define TEX_EXTEND 1

View File

@@ -493,7 +493,7 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max
{
/* Sample box, performs clip. minx etc are in range 0.0 - 1.0 .
* Enlarge with antialiased edges of pixels.
* If global variable 'imaprepeat' has been set, the
* If variable 'imaprepeat' has been set, the
* clipped-away parts are sampled as well.
*/
/* note: actually minx etc isnt in the proper range... this due to filter size and offset vectors for bump */
@@ -711,6 +711,13 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *dxt, f
imaprepeat= (tex->extend==TEX_REPEAT);
imapextend= (tex->extend==TEX_EXTEND);
if(tex->extend == TEX_REPEAT) {
if(tex->flag & (TEX_REPEAT_XMIR|TEX_REPEAT_YMIR)) {
imaprepeat= 0;
imapextend= 1;
}
}
if(tex->extend == TEX_CHECKER) {
int xs, ys, xs1, ys1, xs2, ys2, boundary;
@@ -779,7 +786,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *dxt, f
}
}
else {
if(tex->extend==TEX_EXTEND) {
if(imapextend) {
if(fx>1.0) fx = 1.0;
else if(fx<0.0) fx= 0.0;
}
@@ -788,7 +795,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *dxt, f
else if(fx<0.0) fx+= 1-(int)(fx);
}
if(tex->extend==TEX_EXTEND) {
if(imapextend) {
if(fy>1.0) fy = 1.0;
else if(fy<0.0) fy= 0.0;
}

View File

@@ -915,14 +915,28 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
/* repeat */
if(tex->extend==TEX_REPEAT) {
if(tex->xrepeat>1) {
fx *= tex->xrepeat;
float origf= fx *= tex->xrepeat;
if(fx>1.0) fx -= (int)(fx);
else if(fx<0.0) fx+= 1-(int)(fx);
if(tex->flag & TEX_REPEAT_XMIR) {
int orig= (int)floor(origf);
if(orig & 1)
fx= 1.0-fx;
}
}
if(tex->yrepeat>1) {
fy *= tex->yrepeat;
float origf= fy *= tex->yrepeat;
if(fy>1.0) fy -= (int)(fy);
else if(fy<0.0) fy+= 1-(int)(fy);
if(tex->flag & TEX_REPEAT_YMIR) {
int orig= (int)floor(origf);
if(orig & 1)
fy= 1.0-fy;
}
}
}
/* crop */
@@ -1024,21 +1038,39 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
if(tex->extend==TEX_REPEAT) {
float max= 1.0f;
if(tex->xrepeat>1) {
float origf= fx *= tex->xrepeat;
if(fx>1.0f) fx -= (int)(fx);
else if(fx<0.0f) fx+= 1-(int)(fx);
if(tex->flag & TEX_REPEAT_XMIR) {
int orig= (int)floor(origf);
if(orig & 1)
fx= 1.0f-fx;
}
max= tex->xrepeat;
fx *= tex->xrepeat;
dxt[0]*= tex->xrepeat;
dyt[0]*= tex->xrepeat;
if(fx>1.0) fx -= (int)(fx);
else if(fx<0.0) fx+= 1-(int)(fx);
}
if(tex->yrepeat>1) {
float origf= fy *= tex->yrepeat;
if(fy>1.0f) fy -= (int)(fy);
else if(fy<0.0f) fy+= 1-(int)(fy);
if(tex->flag & TEX_REPEAT_YMIR) {
int orig= (int)floor(origf);
if(orig & 1)
fy= 1.0f-fy;
}
if(max<tex->yrepeat)
max= tex->yrepeat;
fy *= tex->yrepeat;
dxt[1]*= tex->yrepeat;
dyt[1]*= tex->yrepeat;
if(fy>1.0) fy -= (int)(fy);
else if(fy<0.0) fy+= 1-(int)(fy);
}
if(max!=1.0f) {
dxt[2]*= max;

View File

@@ -1240,8 +1240,10 @@ static void texture_panel_image_map(Tex *tex)
if(tex->extend==TEX_REPEAT) {
uiBlockBeginAlign(block);
uiDefButS(block, NUM, B_TEXPRV, "Xrepeat:", 10,60,150,19, &tex->xrepeat, 1.0, 512.0, 0, 0, "Sets a repetition multiplier in the X direction");
uiDefButS(block, NUM, B_TEXPRV, "Yrepeat:", 160,60,150,19, &tex->yrepeat, 1.0, 512.0, 0, 0, "Sets a repetition multiplier in the Y direction");
uiDefButBitS(block, TOG, TEX_REPEAT_XMIR, B_TEXPRV, "Mirr", 10,60,30,19, &tex->flag, 0.0, 0.0, 0, 0, "Mirrors X direction repeat");
uiDefButS(block, NUM, B_TEXPRV, "Xrepeat:", 40,60,120,19, &tex->xrepeat, 1.0, 512.0, 0, 0, "Sets a repetition multiplier in the X direction");
uiDefButBitS(block, TOG, TEX_REPEAT_YMIR, B_TEXPRV, "Mirr", 160,60,30,19, &tex->flag, 0.0, 0.0, 0, 0, "Mirrors Y direction repeat");
uiDefButS(block, NUM, B_TEXPRV, "Yrepeat:", 190,60,120,19, &tex->yrepeat, 1.0, 512.0, 0, 0, "Sets a repetition multiplier in the Y direction");
}
else if(tex->extend==TEX_CHECKER) {
uiBlockBeginAlign(block);