Committing patch #25675 "Make "Cast Buffer Shadows" option work in viewport and BGE...
authorMitchell Stokes <mogurijin@gmail.com>
Wed, 24 Aug 2011 20:28:54 +0000 (20:28 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Wed, 24 Aug 2011 20:28:54 +0000 (20:28 +0000)
Description from the tracker:
"It's really handy to be able to prevent an object/material from casting a shadow. So, I made use of the Cast Buffer Shadows option in the material settings, and made it work in the viewport and the BGE."

source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/makesdna/DNA_view3d_types.h
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Ketsji/BL_Material.h
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
source/gameengine/Rasterizer/RAS_MaterialBucket.cpp

index ddc10d78cac0faabaa7667cdbc6a7a9bc6355fd1..3133ad131bbf0daf0409e6ec188709890a7323a4 100644 (file)
@@ -2843,8 +2843,20 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        Object *ob= base->object;
        Object *obedit= scene->obedit;
        Mesh *me= ob->data;
+       Material *ma=NULL;
        EditMesh *em= me->edit_mesh;
-       int do_alpha_pass= 0, drawlinked= 0, retval= 0, glsl, check_alpha;
+       int do_alpha_pass= 0, drawlinked= 0, retval= 0, glsl, check_alpha, i;
+
+       /* If we are drawing shadows and any of the materials don't cast a shadow, then don't draw the object */
+       if (v3d->flag2 & V3D_RENDER_SHADOW)
+       {
+               for(i=0; i<ob->totcol; ++i)
+               {
+                       ma = give_current_material(ob, i);
+                       if (ma && !(ma->mode & MA_SHADBUF))
+                               return 1;
+               }
+       }
        
        if(obedit && ob!=obedit && ob->data==obedit->data) {
                if(ob_get_key(ob) || ob_get_key(obedit));
index f8837594ddb1aa0e11fda0e7c6302b7f340ed37a..9249d4d2bf0c08e28680c4617bd329a0b366c3a9 100644 (file)
@@ -2155,7 +2155,7 @@ static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d)
                v3d->drawtype = OB_SOLID;
                v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
                v3d->flag2 &= ~V3D_SOLID_TEX;
-               v3d->flag2 |= V3D_RENDER_OVERRIDE;
+               v3d->flag2 |= V3D_RENDER_OVERRIDE | V3D_RENDER_SHADOW;
                
                GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
 
index 89b8bad28069db22865f0ab0144ffe91147423e5..3c8d20a6f16d65902405ba32b098da05e068dfd5 100644 (file)
@@ -247,6 +247,7 @@ typedef struct View3D {
 #define V3D_SOLID_TEX                  8
 #define V3D_DISPGP                             16
 #define V3D_LOCK_CAMERA                        32
+#define V3D_RENDER_SHADOW              64 /* This is a runtime only flag that's used to tell draw_mesh_object() that we're doing a shadow pass instead of a regular draw */
 
 /* View3D->around */
 #define V3D_CENTER              0
index 7b9c5d4b4d6c93c931db8c226b4ecf03665d636e..35c319e263b4ced3b099c9b3ca96670aaf1d85a0 100644 (file)
@@ -350,6 +350,8 @@ bool ConvertMaterial(
 
                // use lighting?
                material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT;
+               // cast shadows?
+               material->ras_mode |= ( mat->mode & MA_SHADBUF )?CAST_SHADOW:0;
                MTex *mttmp = 0;
                numchan = getNumTexChannels(mat);
                int valid_index = 0;
index ef25c9218a3c7f391463f2dcbbb5bc3ec61a51ec..c0440e665018b9f445e10a9cfc063177bb6f091f 100644 (file)
@@ -157,7 +157,8 @@ enum BL_ras_mode
        ALPHA=8,
        // TRIANGLE=16,
        USE_LIGHT=32,
-       WIRE=64
+       WIRE=64,
+       CAST_SHADOW=128
 };
 
 // -------------------------------------
index 9ff32ba57c53cbb8e4f6a9cc4d3e0b5abec983cb..4226896aec00a0aad3c6130eadb7e43517c0fdb9 100644 (file)
@@ -85,6 +85,7 @@ void KX_BlenderMaterial::Initialize(
        m_flag |= (mMaterial->IdMode>=ONETEX)? RAS_MULTITEX: 0;
        m_flag |= ((mMaterial->ras_mode & USE_LIGHT)!=0)? RAS_MULTILIGHT: 0;
        m_flag |= (mMaterial->glslmat)? RAS_BLENDERGLSL: 0;
+       m_flag |= ((mMaterial->ras_mode & CAST_SHADOW)!=0)? RAS_CASTSHADOW: 0;
 
        // figure max
        int enabled = mMaterial->num_enabled;
index 47f1dcb412a5228397d04eade6abeb6ccce99f06..5a1b52489b436e7865add869fb77a51473e6ffd7 100644 (file)
@@ -246,6 +246,11 @@ bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
        return dolights;
 }
 
+bool RAS_IPolyMaterial::CastsShadows() const
+{
+       return (m_flag & RAS_CASTSHADOW) != 0;
+}
+
 bool RAS_IPolyMaterial::UsesObjectColor() const
 {
        return !(m_flag & RAS_BLENDERGLSL);
index b0e7daf81d760b72c7db1b6653c3a4aa09cb4280..2a5c6a179b61d41b02e51d2dfdff38090c93d025 100644 (file)
@@ -62,7 +62,8 @@ enum MaterialProps
        RAS_AUTOGEN             =128,
        RAS_NORMAL              =256,
        RAS_DEFMULTI    =512,
-       RAS_BLENDERGLSL =1024
+       RAS_BLENDERGLSL =1024,
+       RAS_CASTSHADOW  =2048
 };
 
 /**
@@ -169,6 +170,7 @@ public:
        virtual void            GetMaterialRGBAColor(unsigned char *rgba) const;
        virtual bool            UsesLighting(RAS_IRasterizer *rasty) const;
        virtual bool            UsesObjectColor() const;
+       virtual bool            CastsShadows() const;
 
        virtual void            Replace_IScene(SCA_IScene *val) {}; /* overridden by KX_BlenderMaterial */
 
index 7647f7d3f279fc9be3272dee902c5a1eef931b62..85284096bb9d09cf75f23e1a0ddd681ad13fd871 100644 (file)
@@ -586,6 +586,9 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I
        RAS_IRenderTools *rendertools)
 {
        bool uselights;
+       
+       if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW && !m_material->CastsShadows())
+               return false;
 
        if(!rasty->SetMaterial(*m_material))
                return false;