adding clip alpha (binary alpha) to the 3D view and game engine.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 9 Jun 2008 15:45:46 +0000 (15:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 9 Jun 2008 15:45:46 +0000 (15:45 +0000)
source/blender/makesdna/DNA_meshdata_types.h
source/blender/src/buttons_editing.c
source/blender/src/drawmesh.c
source/gameengine/GamePlayer/common/GPC_PolygonMaterial.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.cpp

index 79c1710a897b04e4aa63e234ee594c5b0c500e8f..a717df640f1b7ec04e296a1cca2436614690ed0b 100644 (file)
@@ -229,14 +229,16 @@ typedef struct PartialVisibility {
 #define TF_SHADOW              8192
 #define TF_BMFONT              16384
 
-/* mtface->transp */
+/* mtface->transp, values 1-4 are used as flags in the GL, WARNING, TF_SUB cant work with this */
 #define TF_SOLID       0
 #define TF_ADD         1
 #define TF_ALPHA       2
+#define TF_CLIP                4 /* clipmap alpha/binary alpha all or nothing! */
 
 /* sub is not available in the user interface anymore */
 #define TF_SUB         3
 
+
 /* mtface->unwrap */
 #define TF_DEPRECATED1 1
 #define TF_DEPRECATED2 2
index 6250b69345bc6f156e2a322dfa9aa281d05b769b..7e154d6c3416ceeef1e13e28aa042be5ac8c08c7 100644 (file)
@@ -6235,6 +6235,7 @@ static void editing_panel_mesh_texface(void)
                uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,80,60,19, &tf->transp, 2.0, (float)TF_SOLID,0, 0, "Render color of textured face as color");
                uiDefButC(block, ROW, REDRAWVIEW3D, "Add",              660,80,60,19, &tf->transp, 2.0, (float)TF_ADD,  0, 0, "Render face transparent and add color of face");
                uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha",    720,80,60,19, &tf->transp, 2.0, (float)TF_ALPHA,0, 0, "Render polygon transparent, depending on alpha channel of the texture");
+               uiDefButC(block, ROW, REDRAWVIEW3D, "Clip Alpha",       780,80,80,19, &tf->transp, 2.0, (float)TF_CLIP,0, 0, "Use the images alpha values clipped with no blending (binary alpha)");
        }
        else
                uiDefBut(block,LABEL,B_NOP, "(No Active Face)", 10,200,150,19,0,0,0,0,0,"");
index b72cd3f56f8bb7c4bcbdd00a952a5e96bd4e171b..dd512595ebc4da622cd52fa5187a4a65a4f81a52 100644 (file)
@@ -228,13 +228,14 @@ int set_tpage(MTFace *tface)
                alphamode= tface->transp;
 
                if(alphamode) {
-                       glEnable(GL_BLEND);
-                       
                        if(alphamode==TF_ADD) {
+                               glEnable(GL_BLEND);
                                glBlendFunc(GL_ONE, GL_ONE);
+                               glDisable ( GL_ALPHA_TEST );
                        /*      glBlendEquationEXT(GL_FUNC_ADD_EXT); */
                        }
                        else if(alphamode==TF_ALPHA) {
+                               glEnable(GL_BLEND);
                                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                                
                                /* added after 2.45 to clip alpha */
@@ -245,9 +246,12 @@ int set_tpage(MTFace *tface)
                                        glEnable ( GL_ALPHA_TEST );
                                        glAlphaFunc ( GL_GREATER, U.glalphaclip );
                                }
-                               
-                       /*      glBlendEquationEXT(GL_FUNC_ADD_EXT); */
+                       } else if (alphamode==TF_CLIP){         
+                               glDisable(GL_BLEND); 
+                               glEnable ( GL_ALPHA_TEST );
+                               glAlphaFunc(GL_GREATER, 0.5f);
                        }
+                       /*      glBlendEquationEXT(GL_FUNC_ADD_EXT); */
                        /* else { */
                        /*      glBlendFunc(GL_ONE, GL_ONE); */
                        /*      glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT); */
index 46fe24d8b8721574e223a0d53d75d84900f351dc..09dd14172c88109720fe7dcdac314257c92a46f6 100644 (file)
@@ -154,16 +154,23 @@ int set_tpage(MTFace *tface)
                fAlphamode= tface->transp;
 
                if(fAlphamode) {
-                       glEnable(GL_BLEND);
-                       
                        if(fAlphamode==TF_ADD) {
+                               glEnable(GL_BLEND);
                                glBlendFunc(GL_ONE, GL_ONE);
+                               glDisable ( GL_ALPHA_TEST );
                        /*      glBlendEquationEXT(GL_FUNC_ADD_EXT); */
                        }
                        else if(fAlphamode==TF_ALPHA) {
+                               glEnable(GL_BLEND);
                                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+                               glDisable ( GL_ALPHA_TEST );
                        /*      glBlendEquationEXT(GL_FUNC_ADD_EXT); */
                        }
+                       else if (alphamode==TF_CLIP){           
+                               glDisable(GL_BLEND); 
+                               glEnable ( GL_ALPHA_TEST );
+                               glAlphaFunc(GL_GREATER, 0.5f);
+                       }
                        /* else { */
                        /*      glBlendFunc(GL_ONE, GL_ONE); */
                        /*      glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT); */
index 447275881065e85d73f18b40837fbfaacd327494..5efe1ad26ca06ec523c75e99f644155e60dd5c44 100644 (file)
@@ -478,16 +478,23 @@ bool KX_BlenderMaterial::setDefaultBlending()
        if( mMaterial->transp &TF_ADD) {
                glEnable(GL_BLEND);
                glBlendFunc(GL_ONE, GL_ONE);
+               glDisable ( GL_ALPHA_TEST );
                return true;
        }
        
        if( mMaterial->transp & TF_ALPHA ) {
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               glDisable ( GL_ALPHA_TEST );
                return true;
        }
        
-       glDisable(GL_BLEND);
+       if( mMaterial->transp & TF_CLIP ) {
+               glDisable(GL_BLEND); 
+               glEnable ( GL_ALPHA_TEST );
+               glAlphaFunc(GL_GREATER, 0.5f);
+               return true;
+       }
        return false;
 }