* New material option: TexFace Alpha
authorMatt Ebb <matt@mke3.net>
Thu, 15 Nov 2007 00:11:00 +0000 (00:11 +0000)
committerMatt Ebb <matt@mke3.net>
Thu, 15 Nov 2007 00:11:00 +0000 (00:11 +0000)
This is an additional option for 'TexFace', which uses the alpha of
the UV assigned faces as well as the colour. It appears in material
buttons as a little 'A' button next to 'TexFace', when 'TexFace is
switched on. It's a bit horrible, but no point tweaking that layout in
isolation at this stage.

This image is using texface alpha, with different assigned images, all
sharing the one material:
http://mke3.net/blender/devel/rendering/texface_alpha.jpg

Usually I consider texface (and teaching people to use it for UV
mapping) to be pretty evil, but in some cases, when you have lots of
separate images that you want to control in the one material, it can
be quite handy.

source/blender/makesdna/DNA_material_types.h
source/blender/render/extern/include/RE_shader_ext.h
source/blender/render/intern/source/shadeinput.c
source/blender/render/intern/source/shadeoutput.c
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c

index 252af0ebdb1691d02f49c6b53b65f26d1b66d6e8..3e2197f2d83590c9f1f6af5916537866f1e67e07 100644 (file)
@@ -188,6 +188,7 @@ typedef struct Material {
 /* qdn: a bit clumsy this, tangents needed for normal maps separated from shading */
 #define MA_NORMAP_TANG 0x8000000
 #define MA_GROUP_NOLAY 0x10000000
+#define MA_FACETEXTURE_ALPHA   0x20000000
 
 #define        MA_MODE_MASK    0x1fffffff      /* all valid mode bits */
 
index 364535736ae03face3adb66bcbae9076c32c8158..052e104ee62ac16fc55d1d5beedaf34cdb576323 100644 (file)
@@ -124,7 +124,7 @@ typedef struct ShadeInput
        float layerfac;
        
        /* texture coordinates */
-       float lo[3], gl[3], ref[3], orn[3], winco[3], sticky[3], vcol[3], rad[3];
+       float lo[3], gl[3], ref[3], orn[3], winco[3], sticky[3], vcol[4], rad[3];
        float refcol[4], displace[3];
        float strand, tang[3], stress, winspeed[4];
 
index ca661469b36a99121b78ff6d294fcf2654484039..71b59f7b8bebe9e3920ca93341faa84488cbf9e7 100644 (file)
@@ -675,11 +675,13 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                                        shi->vcol[0]= shi->col[0].col[0];
                                        shi->vcol[1]= shi->col[0].col[1];
                                        shi->vcol[2]= shi->col[0].col[2];
+                                       shi->vcol[3]= 1.0f;
                                }
                                else {
                                        shi->vcol[0]= 0.0f;
                                        shi->vcol[1]= 0.0f;
                                        shi->vcol[2]= 0.0f;
+                                       shi->vcol[3]= 1.0f;
                                }
                        }
 
@@ -721,6 +723,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                                                shi->vcol[0]= 1.0f;
                                                shi->vcol[1]= 1.0f;
                                                shi->vcol[2]= 1.0f;
+                                               shi->vcol[3]= 1.0f;
                                        }
                                        if(tface && tface->tpage)
                                                render_realtime_texture(shi, tface->tpage);
@@ -739,6 +742,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                                        shi->vcol[0]= 1.0f;
                                        shi->vcol[1]= 1.0f;
                                        shi->vcol[2]= 1.0f;
+                                       shi->vcol[3]= 1.0f;
                                }
                        }
                }
index 24eabffdf6ff3b7250531554b79ff62051f65643..56cb226560a224c8970c5e399c1606d4f520be43 100644 (file)
@@ -829,6 +829,8 @@ void shade_color(ShadeInput *shi, ShadeResult *shr)
                shi->r= shi->vcol[0];
                shi->g= shi->vcol[1];
                shi->b= shi->vcol[2];
+               if(ma->mode & (MA_FACETEXTURE_ALPHA))
+                       shi->alpha= shi->vcol[3];
        }
        
        if(ma->texco)
@@ -1149,6 +1151,10 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
        
        if (lar->energy == 0.0) return;
        
+       /* optimisation, don't render fully black lamps */
+       if (!(lar->mode & LA_TEXTURE) && (lar->r + lar->g + lar->b == 0.0f))
+               return;
+       
        /* lampdist, spot angle, area side, ... */
        visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist);
        if(visifac==0.0f)
@@ -1471,6 +1477,8 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
                        shi->r= shi->vcol[0];
                        shi->g= shi->vcol[1];
                        shi->b= shi->vcol[2];
+                       if(ma->mode & (MA_FACETEXTURE_ALPHA))
+                               shi->alpha= shi->vcol[3];
                }
                if(ma->texco)
                        do_material_tex(shi);
index 8c366593034e879c3bb02bbec434794f87a7f28e..f541b161e0adf7fcf9ac4ebc664e9649e08cf440 100644 (file)
@@ -2450,6 +2450,7 @@ void render_realtime_texture(ShadeInput *shi, Image *ima)
        shi->vcol[0]*= texr.tr;
        shi->vcol[1]*= texr.tg;
        shi->vcol[2]*= texr.tb;
+       shi->vcol[3]*= texr.ta;
 }
 
 /* eof */
index 67ccf78c5f6d3054a1eb161c72fbe30cbac613f5..f422a39266a00a4960b24deda8d1cf784e35f424 100644 (file)
@@ -3785,8 +3785,9 @@ static void material_panel_material(Material *ma)
                        uiBlockSetCol(block, TH_BUT_SETTING1);
                        uiDefButBitI(block, TOG, MA_VERTEXCOL, B_MAT_VCOL_LIGHT,        "VCol Light",   8,166,74,20, &(ma->mode), 0, 0, 0, 0, "Adds vertex colors as extra light");
                        uiDefButBitI(block, TOG, MA_VERTEXCOLP, B_MAT_VCOL_PAINT, "VCol Paint", 82,166,74,20, &(ma->mode), 0, 0, 0, 0, "Replaces material's colors with vertex colors");
-                       uiDefButBitI(block, TOG, MA_FACETEXTURE, B_REDR, "TexFace",             156,166,74,20, &(ma->mode), 0, 0, 0, 0, "Sets UV-Editor assigned texture as color and texture info for faces");
-                       uiDefButBitI(block, TOG, MA_SHLESS, B_MATPRV, "Shadeless",      230,166,73,20, &(ma->mode), 0, 0, 0, 0, "Makes material insensitive to light or shadow");
+                       uiDefButBitI(block, TOG, MA_FACETEXTURE, B_REDR, "TexFace",             156,166,64,20, &(ma->mode), 0, 0, 0, 0, "Sets UV-Editor assigned texture as color and texture info for faces");
+                       if (ma->mode & MA_FACETEXTURE) uiDefButBitI(block, TOG, MA_FACETEXTURE_ALPHA, B_REDR, "A",              220,166,20,20, &(ma->mode), 0, 0, 0, 0, "Use alpha channel in 'TexFace' assigned images");
+                       uiDefButBitI(block, TOG, MA_SHLESS, B_MATPRV, "Shadeless",      240,166,63,20, &(ma->mode), 0, 0, 0, 0, "Makes material insensitive to light or shadow");
                        
                        uiDefButBitI(block, TOG, MA_NOMIST, B_NOP,      "No Mist",              8,146,74,20, &(ma->mode), 0, 0, 0, 0, "Sets the material to ignore mist values");
                        uiDefButBitI(block, TOG, MA_ENV, B_MATPRV,      "Env",                  82,146,74,20, &(ma->mode), 0, 0, 0, 0, "Causes faces to render with alpha zero: allows sky/backdrop to show through (only for solid faces)");
@@ -3830,7 +3831,8 @@ static void material_panel_material(Material *ma)
                        uiDefButF(block, NUMSLI, B_MATPRV, "B ",                128,57,175,19, colpoin+2, 0.0, 1.0, rgbsel, 0, "");
                }
                uiBlockEndAlign(block);
-               uiDefButF(block, NUMSLI, B_MATPRV, "A ",                        128,30,175,19, &ma->alpha, 0.0, 1.0, 0, 0, "Alpha");
+               if (ma->mode & (MA_FACETEXTURE) && ma->mode & (MA_FACETEXTURE_ALPHA)) ;
+               else uiDefButF(block, NUMSLI, B_MATPRV, "A ",                   128,30,175,19, &ma->alpha, 0.0, 1.0, 0, 0, "Alpha");
                
        }
        uiBlockBeginAlign(block);