Important bugfix: Image mapping "repeat" didn't support mirrored tiling
authorTon Roosendaal <ton@blender.org>
Sun, 14 Jan 2007 11:51:52 +0000 (11:51 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 14 Jan 2007 11:51:52 +0000 (11:51 +0000)
yet: http://www.blender.org/bf/rep1.jpg

Psst psst... to solve this bug I had to add the buttons for the option too!

source/blender/makesdna/DNA_texture_types.h
source/blender/render/intern/source/imagetexture.c
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c

index 3fbe85818c211a8635d743749a6a640fb6086c6d..a5a2e36125f709967eab319010a3586d5aeb5d00 100644 (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
index f05162a90dccf0be6cddf97887f9dbb3dc371516..af99516b650d4c91025c1f647bfc6de45fa3ca8d 100644 (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;
                }
index e02a1e2ae8365ccead6c5abc64b0e2bffcc17fd2..7355737233d5345000f6582ef86a12f3e4b5f805 100644 (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;
index aa8ce448c522a48a005bf6cee6b270c6cc41398f..59b0cbbb2f25a7b3ab2dbcf4ec12197a02c12871 100644 (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);