Sneaked in new feature (request samo):
authorTon Roosendaal <ton@blender.org>
Wed, 28 Apr 2004 18:08:34 +0000 (18:08 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 28 Apr 2004 18:08:34 +0000 (18:08 +0000)
The Image texture repeat options, now allow a "Checker" repeat. With
odd and even tiles set separately, and a size button to set a
'Mortar' inbetween tiles.

http://www.blender3d.org/cms/Render_engine_features.215.0.html

Also fixed bug: using 'CalcAlpha' option for image textures didn't give
antialised edges for image.

source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/texture.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_texture_types.h
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c
source/blender/src/previewrender.c

index a87b01a1b8f8a8e273604602303b4407baca5e19..d3f0d3b72af275a7143d3dc37c1303bf044dda9c 100644 (file)
@@ -602,17 +602,15 @@ int imagewrap(Tex *tex, float *texvec)
        int ofs, x, y;
        char *rect;
 
+       Tin= Ta= Tr= Tg= Tb= 0.0;
        ima= tex->ima;
-
        if(ima==0 || ima->ok== 0) {
-               Tin= Ta= Tr= Tg= Tb= 0.0;
                return 0;
        }
        
        if(ima->ibuf==0) ima_ibuf_is_nul(tex);
 
        if (ima->ok) {
-
                ibuf = ima->ibuf;
 
                if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
@@ -628,18 +626,37 @@ int imagewrap(Tex *tex, float *texvec)
                        fy= texvec[1];
                }
                
+               if(tex->extend == TEX_CHECKER) {
+                       int xs, ys;
+                       
+                       xs= (int)floor(fx);
+                       ys= (int)floor(fy);
+                       fx-= xs;
+                       fy-= ys;
+
+                       if( (tex->flag & TEX_CHECKER_ODD)==0) {
+                               if((xs+ys) & 1);else return 0;
+                       }
+                       if( (tex->flag & TEX_CHECKER_EVEN)==0) {
+                               if((xs+ys) & 1) return 0; 
+                       }
+                       /* scale around center, (0.5, 0.5) */
+                       if(tex->checkerdist<1.0) {
+                               fx= (fx-0.5)/(1.0-tex->checkerdist) +0.5;
+                               fy= (fy-0.5)/(1.0-tex->checkerdist) +0.5;
+                       }
+               }
+
                x = (int)(fx*ibuf->x);
                y = (int)(fy*ibuf->y);
 
                if(tex->extend == TEX_CLIPCUBE) {
                        if(x<0 || y<0 || x>=ibuf->x || y>=ibuf->y || texvec[2]<-1.0 || texvec[2]>1.0) {
-                               Tin= 0;
                                return 0;
                        }
                }
-               else if(tex->extend == TEX_CLIP) {
+               else if( tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) {
                        if(x<0 || y<0 || x>=ibuf->x || y>=ibuf->y) {
-                               Tin= 0;
                                return 0;
                        }
                }
@@ -1308,16 +1325,70 @@ int imagewraposa(Tex *tex, float *texvec, float *dxt, float *dyt)
                imaprepeat= (tex->extend==TEX_REPEAT);
                imapextend= (tex->extend==TEX_EXTEND);
 
+               if(tex->extend == TEX_CHECKER) {
+                       int xs, ys, xs1, ys1, xs2, ys2, boundary;
+                       
+                       xs= (int)floor(fx);
+                       ys= (int)floor(fy);
+                       
+                       // both checkers available, no boundary exceptions, checkerdist will eat aliasing
+                       if( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) {
+                               fx-= xs;
+                               fy-= ys;
+                       }
+                       else {
+                               
+                               xs1= (int)floor(fx-minx);
+                               ys1= (int)floor(fy-miny);
+                               xs2= (int)floor(fx+minx);
+                               ys2= (int)floor(fy+miny);
+                               boundary= (xs1!=xs2) || (ys1!=ys2);
+       
+                               if(boundary==0) {
+                                       if( (tex->flag & TEX_CHECKER_ODD)==0) {
+                                               if((xs+ys) & 1); 
+                                               else return 0;
+                                       }
+                                       if( (tex->flag & TEX_CHECKER_EVEN)==0) {
+                                               if((xs+ys) & 1) return 0;
+                                       }
+                                       fx-= xs;
+                                       fy-= ys;
+                               }
+                               else {
+                                       if(tex->flag & TEX_CHECKER_ODD) {
+                                               if((xs1+ys) & 1) fx-= xs2;
+                                               else fx-= xs1;
+                                               
+                                               if((ys1+xs) & 1) fy-= ys2;
+                                               else fy-= ys1;
+                                       }
+                                       if(tex->flag & TEX_CHECKER_EVEN) {
+                                               if((xs1+ys) & 1) fx-= xs1;
+                                               else fx-= xs2;
+                                               
+                                               if((ys1+xs) & 1) fy-= ys1;
+                                               else fy-= ys2;
+                                       }
+                               }
+                       }
+
+                       /* scale around center, (0.5, 0.5) */
+                       if(tex->checkerdist<1.0) {
+                               fx= (fx-0.5)/(1.0-tex->checkerdist) +0.5;
+                               fy= (fy-0.5)/(1.0-tex->checkerdist) +0.5;
+                               minx/= (1.0-tex->checkerdist);
+                               miny/= (1.0-tex->checkerdist);
+                       }
+               }
 
                if(tex->extend == TEX_CLIPCUBE) {
                        if(fx+minx<0.0 || fy+miny<0.0 || fx-minx>1.0 || fy-miny>1.0 || texvec[2]<-1.0 || texvec[2]>1.0) {
-                               Tin= 0;
                                return 0;
                        }
                }
-               else if(tex->extend == TEX_CLIP) {
+               else if(tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) {
                        if(fx+minx<0.0 || fy+miny<0.0 || fx-minx>1.0 || fy-miny>1.0) {
-                               Tin= 0.0;
                                return 0;
                        }
                }
@@ -1471,7 +1542,7 @@ int imagewraposa(Tex *tex, float *texvec, float *dxt, float *dyt)
                BRICONRGB;
                
                if(tex->imaflag & TEX_CALCALPHA) {
-                       Ta= Tin= MAX3(Tr, Tg, Tb);
+                       Ta= Tin= Ta*MAX3(Tr, Tg, Tb);
                }
                else Tin= Ta;
                if(tex->flag & TEX_NEGALPHA) Ta= 1.0f-Ta;
index 0d472f278de268929662f7c53735a4035c55dce6..a1dc9dec3d0e509ece1309436147473d7acc0450 100644 (file)
@@ -329,6 +329,7 @@ void default_tex(Tex *tex)
        int a;
 
        tex->stype= 0;
+       tex->flag= TEX_CHECKER_ODD;
        tex->imaflag= TEX_INTERPOL+TEX_MIPMAP;
        tex->extend= TEX_REPEAT;
        tex->cropxmin= tex->cropymin= 0.0;
index 2a2ca1c7f2b1ed6cc634f9884185d2a03fd0fb87..c5ac1a7bce8b5ac20df15d4530f2a24fd5f5851c 100644 (file)
@@ -4155,6 +4155,9 @@ static void do_versions(Main *main)
                Scene *sce;
 
                while(tex) {    
+                       if((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
+                               tex->flag |= TEX_CHECKER_ODD;
+                       }
                        /* copied from kernel texture.c */
                        if(tex->ns_outscale==0.0) {
                                /* musgrave */
index a60c4f117d65d015eeccd3a6899bb67ff8adae02..88f25f9c0a5a9212d3edd411ed50535ab1a363f4 100644 (file)
@@ -149,6 +149,7 @@ typedef struct Tex {
        float cropxmin, cropymin, cropxmax, cropymax;
        short xrepeat, yrepeat;
        short extend, len;
+       float checkerdist, pad;
        short frames, offset, sfra, fie_ima;
        float norfac, *nor;
        
@@ -224,15 +225,18 @@ typedef struct Tex {
 #define TEX_MORKPATCH  16384
 
 /* flag */
-#define TEX_COLORBAND  1
-#define TEX_FLIPBLEND  2
-#define TEX_NEGALPHA   4
+#define TEX_COLORBAND          1
+#define TEX_FLIPBLEND          2
+#define TEX_NEGALPHA           4
+#define TEX_CHECKER_ODD                8
+#define TEX_CHECKER_EVEN       16
 
 /* extend (starts with 1 because of backward comp.) */
 #define TEX_EXTEND             1
 #define TEX_CLIP               2
 #define TEX_REPEAT             3
 #define TEX_CLIPCUBE   4
+#define TEX_CHECKER            5
 
 /* noisetype */
 #define TEX_NOISESOFT  0
index 47a12627bf0723cc1dd61cef5d6b0be563142d21..762e00073c2ecaecce3e4a0e8c84c204b312e481 100644 (file)
@@ -895,17 +895,18 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
                }
                
                /* repeat */
-               if(tex->xrepeat>1) {
-                       fx *= tex->xrepeat;
-                       if(fx>1.0) fx -= (int)(fx);
-                       else if(fx<0.0) fx+= 1-(int)(fx);
-               }
-               if(tex->yrepeat>1) {
-                       fy *= tex->yrepeat;
-                       if(fy>1.0) fy -= (int)(fy);
-                       else if(fy<0.0) fy+= 1-(int)(fy);
+               if(tex->extend==TEX_REPEAT) {
+                       if(tex->xrepeat>1) {
+                               fx *= tex->xrepeat;
+                               if(fx>1.0) fx -= (int)(fx);
+                               else if(fx<0.0) fx+= 1-(int)(fx);
+                       }
+                       if(tex->yrepeat>1) {
+                               fy *= tex->yrepeat;
+                               if(fy>1.0) fy -= (int)(fy);
+                               else if(fy<0.0) fy+= 1-(int)(fy);
+                       }
                }
-               
                /* crop */
                if(tex->cropxmin!=0.0 || tex->cropxmax!=1.0) {
                        fac1= tex->cropxmax - tex->cropxmin;
@@ -994,21 +995,22 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float
                }
                
                /* repeat */
-               if(tex->xrepeat>1) {
-                       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) {
-                       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(tex->extend==TEX_REPEAT) {
+                       if(tex->xrepeat>1) {
+                               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) {
+                               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);
+                       }
                }
-               
                /* crop */
                if(tex->cropxmin!=0.0 || tex->cropxmax!=1.0) {
                        fac1= tex->cropxmax - tex->cropxmin;
index 45c908d46ff7c7d8f9196cde648ca08dc46297d6..bd0f094ae692385f95f175b61e5f5a186728ca40 100644 (file)
@@ -1098,16 +1098,27 @@ static void texture_panel_image(Tex *tex)
        
        uiDefButF(block, NUM, B_TEXPRV, "Filter :",     10,92,150,19, &tex->filtersize, 0.1, 25.0, 0, 0, "Sets the filter size used by mipmap and interpol");
        uiBlockBeginAlign(block);
-       uiDefButS(block, ROW, 0, "Extend",                      10,70,75,19, &tex->extend, 4.0, 1.0, 0, 0, "Extends the colour of the edge pixels");
-       uiDefButS(block, ROW, 0, "Clip",                        85,70,75,19, &tex->extend, 4.0, 2.0, 0, 0, "Sets alpha 0.0 outside Image edges");
-       uiDefButS(block, ROW, 0, "ClipCube",            160,70,75,19, &tex->extend, 4.0, 4.0, 0, 0, "Sets alpha to 0.0 outside cubeshaped area around Image");
-       uiDefButS(block, ROW, 0, "Repeat",                      235,70,75,19, &tex->extend, 4.0, 3.0, 0, 0, "Causes Image to repeat horizontally and vertically");
-       uiBlockBeginAlign(block);
-       uiDefButS(block, NUM, B_TEXPRV, "Xrepeat:",     10,50,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,50,150,19, &tex->yrepeat, 1.0, 512.0, 0, 0, "Sets a repetition multiplier in the Y direction");
+       uiDefButS(block, ROW, B_TEXREDR_PRV, "Extend",                  10,70,63,19, &tex->extend, 4.0, 1.0, 0, 0, "Extends the colour of the edge pixels");
+       uiDefButS(block, ROW, B_TEXREDR_PRV, "Clip",                    73,70,48,19, &tex->extend, 4.0, 2.0, 0, 0, "Sets alpha 0.0 outside Image edges");
+       uiDefButS(block, ROW, B_TEXREDR_PRV, "ClipCube",                121,70,63,19, &tex->extend, 4.0, 4.0, 0, 0, "Sets alpha to 0.0 outside cubeshaped area around Image");
+       uiDefButS(block, ROW, B_TEXREDR_PRV, "Repeat",                  184,70,63,19, &tex->extend, 4.0, 3.0, 0, 0, "Causes Image to repeat horizontally and vertically");
+       uiDefButS(block, ROW, B_TEXREDR_PRV, "Checker",                 247,70,63,19, &tex->extend, 4.0, 5.0, 0, 0, "Causes Image to repeat in checker pattern");
+
+       if(tex->extend==TEX_REPEAT) {
+               uiBlockBeginAlign(block);
+               uiDefButS(block, NUM, B_TEXPRV, "Xrepeat:",     10,50,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,50,150,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);
+               uiDefButS(block, TOG|BIT|3, B_TEXPRV, "Odd",    10,50,100,19, &tex->flag, 0.0, 0.0, 0, 0, "Sets odd checker tiles");
+               uiDefButS(block, TOG|BIT|4, B_TEXPRV, "Even",   110,50,100,19, &tex->flag, 0.0, 0.0, 0, 0, "Sets even checker tiles");
+               uiDefButF(block, NUM, B_TEXPRV, "Mortar:",              210,50,100,19, &tex->checkerdist, 0.0, 0.99, 0, 0, "Set checkers distance (like mortar)");
+       }
        uiBlockBeginAlign(block);
        uiDefButF(block, NUM, B_REDR, "MinX ",          10,28,150,19, &tex->cropxmin, -10.0, 10.0, 10, 0, "Sets minimum X value to crop Image");
        uiDefButF(block, NUM, B_REDR, "MinY ",          10,8,150,19, &tex->cropymin, -10.0, 10.0, 10, 0, "Sets minimum Y value to crop Image");
+
        uiBlockBeginAlign(block);
        uiDefButF(block, NUM, B_REDR, "MaxX ",          160,28,150,19, &tex->cropxmax, -10.0, 10.0, 10, 0, "Sets maximum X value to crop Image");
        uiDefButF(block, NUM, B_REDR, "MaxY ",          160,8,150,19, &tex->cropymax, -10.0, 10.0, 10, 0, "Sets maximum Y value to crop Image");
@@ -2121,7 +2132,7 @@ static void lamp_panel_lamp(Object *ob, Lamp *la)
        uiBlockBeginAlign(block);
        if ELEM(la->type, LA_LOCAL, LA_SPOT) {
                uiDefButF(block, NUMSLI,B_MATPRV,"Quad1 ",      120,30,180,19,&la->att1, 0.0, 1.0, 0, 0, "Set the linear distance attenuatation for a quad lamp");
-               uiDefButF(block, NUMSLI,B_MATPRV,"Quad2 ",  120,10,180,19,&la->att2, 0.0, 1.0, 0, 0, "Set the qudratic distance attenuatation for a quad lamp");
+               uiDefButF(block, NUMSLI,B_MATPRV,"Quad2 ",  120,10,180,19,&la->att2, 0.0, 1.0, 0, 0, "Set the quadratic distance attenuatation for a quad lamp");
        }
        else if(la->type==LA_AREA) {
                if(la->k==0.0) la->k= 1.0;
index 214161e53fdf08e01805df8b04eb7558a3604b93..92821b11aa74d49e8777275d0875bfbc86581ae8 100644 (file)
@@ -588,15 +588,16 @@ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
                texvec[1]= 0.5+v1*y;
                
                /* no coordinate mapping, exception: repeat */
-               if(tex->xrepeat>1) {
-                       texvec[0] *= tex->xrepeat;
-                       if(texvec[0]>1.0) texvec[0] -= (int)(texvec[0]);
-               }
-               if(tex->yrepeat>1) {
-                       texvec[1] *= tex->yrepeat;
-                       if(texvec[1]>1.0) texvec[1] -= (int)(texvec[1]);
+               if(tex->extend==TEX_REPEAT) {
+                       if(tex->xrepeat>1) {
+                               texvec[0] *= tex->xrepeat;
+                               if(texvec[0]>1.0) texvec[0] -= (int)(texvec[0]);
+                       }
+                       if(tex->yrepeat>1) {
+                               texvec[1] *= tex->yrepeat;
+                               if(texvec[1]>1.0) texvec[1] -= (int)(texvec[1]);
+                       }
                }
-
        }
        else if(tex->type==TEX_ENVMAP) {
                if(tex->env) {