游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2200|回复: 0

平面阴影(planar shadow)D3DXMatrixShadow的问题。

[复制链接]

12

主题

46

帖子

46

积分

注册会员

Rank: 2

积分
46
发表于 2011-7-27 11:43:00 | 显示全部楼层 |阅读模式
D3DLIGHT9 light = *GetGameSun();
Device->SetRenderState(D3DRS_STENCILENABLE, true);
Device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
Device->SetRenderState(D3DRS_STENCILREF, 0x0);
Device->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
Device->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
Device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR); // increment to 1


// position shadow
//D3DXVECTOR4 lightDirection(0.707f, -0.707f, 0.707f, 0.0f);
// 光线方向的值是0.4,-0.4,-0.8
D3DXVECTOR4 lightDirection(light.Direction.x,light.Direction.y,light.Direction.z, 0.0f);
D3DXPLANE groundPlane(0.0f, 0.0f, -1.0f, 0.0f );//(0.0f, 0.0f, 1.0f, 0.0f);


D3DXMATRIX shadow;
D3DXMatrixShadow(
&shadow,
&lightDirection,
&groundPlane);

D3DXMATRIX T;
D3DXVECTOR3 myPos = GetPos();
D3DXMatrixTranslation(
&T,
myPos.x,
myPos.y,
myPos.z);

D3DXMATRIX W = T * shadow;
Device->SetTransform(D3DTS_WORLD, &W);

// alpha blend the shadow
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


const D3DXCOLOR BLACK( D3DCOLOR_XRGB( 255, 255, 255) );
D3DMATERIAL9 mtrl;
mtrl.Ambient = BLACK;
mtrl.Diffuse = BLACK;
mtrl.Specular = BLACK;
mtrl.Emissive = BLACK;
mtrl.Power = 0.0f;

mtrl.Diffuse.a = 0.5f; // 50% transparency.a


// Disable depth buffer so that z-fighting doesn't occur when we
// render the shadow on top of the floor.
Device->SetRenderState(D3DRS_ZENABLE, false);

Device->SetMaterial(&mtrl);
Device->SetTexture(0, 0);

//Teapot->DrawSubset(0);

if(g_World.GetFootupLevel())
{
light = g_World.m_lgtRoleSun;
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, (D3DXVECTOR3*)&light.Direction );
}

if( theApp->GetPlayerMgr()->GetMouseTargetPlayerSeverID() == m_stID )
{
float fFactor = 0.2f;
light.Ambient.a = 1.0f;
light.Ambient.r = 0.2f;
light.Ambient.g = 0.2f;
light.Ambient.b = 0.2f;
}


if( m_pCharEffectContainer && m_pCharEffectContainer->HasEffectLight() )
{
m_pCharEffectContainer->UpdateLight( g_dwLastFrameBeginTime , &light );
}

GetHREngine()->GetRenderer()->SetLight( 0, &light );

if( gCfg.m_bUseSkinMeshShader )
SkinMeshParam( pDevice, &light, HR3D_Config::GetCamera(), m_fCurRenderAlpha );



if( m_fCurRenderAlpha > 0 )
{
if( m_bMounting )
{
m_pMountAnim->Render( m_fCurRenderAlpha );
m_pAnim->Render( m_fCurRenderAlpha );
}
else
{
if( m_bMorphing )
{
m_pMorphAnim->Render( m_fCurRenderAlpha );
}
else
{
m_pAnim->Render( m_fCurRenderAlpha);
}
}
}
GetHREngine()->GetRenderer()->SetLight( 0, &g_World.m_lgtRoleSun );

Device->SetRenderState(D3DRS_ALPHATESTENABLE, false);

Device->SetRenderState(D3DRS_ZENABLE, true);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
Device->SetRenderState(D3DRS_STENCILENABLE, false);


D3DXMatrixTranslation(
&T,
myPos.x,
myPos.y,
myPos.z);
Device->SetTransform( D3DTS_WORLD, &T );


if(g_World.GetFootupLevel())
{
light = g_World.m_lgtRoleSun;
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, (D3DXVECTOR3*)&light.Direction );
}

if( theApp->GetPlayerMgr()->GetMouseTargetPlayerSeverID() == m_stID )
{
float fFactor = 0.2f;
light.Ambient.a = 1.0f;
light.Ambient.r = 0.2f;
light.Ambient.g = 0.2f;
light.Ambient.b = 0.2f;
}

if( m_pCharEffectContainer && m_pCharEffectContainer->HasEffectLight() )
{
m_pCharEffectContainer->UpdateLight( g_dwLastFrameBeginTime , &light );
}

GetHREngine()->GetRenderer()->SetLight( 0, &light );

if( gCfg.m_bUseSkinMeshShader )
SkinMeshParam( pDevice, &light, HR3D_Config::GetCamera(), m_fCurRenderAlpha );

if( m_fCurRenderAlpha > 0 )
{
if( m_bMounting )
{
m_pMountAnim->Render( m_fCurRenderAlpha );
m_pAnim->Render( m_fCurRenderAlpha );
}
else
{
if( m_bMorphing )
{
m_pMorphAnim->Render( m_fCurRenderAlpha );
}
else
{
m_pAnim->Render( m_fCurRenderAlpha );
}
}
}

GetHREngine()->GetRenderer()->SetLight( 0, &g_World.m_lgtRoleSun );

我这样写有什么问题呢?现在只能画出人物模型,而画不出人物模型下面的阴影。我也按照要求设置了shadow matrix.并且在绘制人物模型的时候,重新设置了世界矩阵,请大家帮帮忙。另外,我不绘制人物阴影,而绘制一个茶壶,却能够绘制出了,不知道咋回事呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-8 11:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表