Committing patch #25675 "Make "Cast Buffer Shadows" option work in viewport and BGE" by me.

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."
This commit is contained in:
2011-08-24 20:28:54 +00:00
parent 81a8f3e885
commit 7fc26e0123
9 changed files with 31 additions and 4 deletions

View 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));

View 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);

View 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

View 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;

View File

@@ -157,7 +157,8 @@ enum BL_ras_mode
ALPHA=8,
// TRIANGLE=16,
USE_LIGHT=32,
WIRE=64
WIRE=64,
CAST_SHADOW=128
};
// -------------------------------------

View 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;

View 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);

View 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 */

View 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;