|

楼主 |
发表于 2012-3-28 15:39:00
|
显示全部楼层
Re:请教一下,我的地形和水都用了shader,分别渲染没问题
Kevin_Qing: Re:请教一下,我的地形和水都用了shader,分别渲染没问题,放在一起就出现问题了……
把各自渲染部分的调用贴出来看看?你是做了什么其他事情
setVS(pVSWater)
setVSConst(xxx);
draw(wat...
void CMyGame::Render()
{
……
……
……
//渲染地形
pD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );
m_pLODTerrain->RenderTerrain(pD3DDevice, TRUE);
//水
m_water->Render();
……
……
……
}
void CZFXLODTerrain::RenderTerrain( LPDIRECT3DDEVICE9 pd3dDevice, BOOL bFog )
{
//// pre rendering
//D3DXVECTOR4 lightDirVec(3.0f, 1.0f, 0, 0);
// set vertex shader constant table
D3DXMATRIXA16 mWorld, mView, mProj;
pd3dDevice->GetTransform(D3DTS_WORLD, &mWorld);
pd3dDevice->GetTransform(D3DTS_VIEW, &mView);
pd3dDevice->GetTransform(D3DTS_PROJECTION, &mProj);
D3DXMATRIXA16 mWorldViewProj = mWorld * mView * mProj;
D3DXMATRIXA16 mWorldView = mWorld * mView;
m_pVConstTable->SetMatrix(pd3dDevice,mhWVP, &mWorldViewProj);
pd3dDevice->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex));
pd3dDevice->SetVertexDeclaration(TerrainVertex: ECL);
pd3dDevice->SetIndices(m_pIB);
UINT count;
D3DXCONSTANT_DESC mDescMap0,mDescMap1,mDescMap2,mDescMap;
m_pPConstTable->GetConstantDesc(mhLayerMap0, &mDescMap0, &count);
m_pPConstTable->GetConstantDesc(mhLayerMap1, &mDescMap1, &count);
m_pPConstTable->GetConstantDesc(mhLayerMap2, &mDescMap2, &count);
m_pPConstTable->GetConstantDesc(mhBlendMap, &mDescMap, &count);
pd3dDevice->SetTexture(mDescMap0.RegisterIndex, mLayerMap0);
pd3dDevice->SetTexture(mDescMap1.RegisterIndex, mLayerMap1);
pd3dDevice->SetTexture(mDescMap2.RegisterIndex, mLayerMap2);
pd3dDevice->SetTexture(mDescMap.RegisterIndex, mBlendMap);
// rendering
pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(TerrainVertex) );
//pd3dDevice->SetVertexDeclaration(TerrainVertex::DECL);
pd3dDevice->SetVertexShader(m_pVShader);
pd3dDevice->SetPixelShader(m_pPShader);
pd3dDevice->SetIndices( m_pIB );
pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0/*base index index*/, 0,/*MinVertexIndex*/
(m_numNodeRendered << 3 ) + m_numNodeRendered/*NumVertices*/,
0/*StartIndex*/,
(m_numNodeRendered << 3 )/*PrimitiveCount*/);
// post rendering
pd3dDevice->SetVertexShader(NULL);
pd3dDevice->SetPixelShader(NULL);
}
void CWater::Render()
{
CGameObject::Render();
D3DXMATRIXA16 mWorld, mView, mProj;
m_pD3DDevice->GetTransform(D3DTS_WORLD, &mWorld);
m_pD3DDevice->GetTransform(D3DTS_VIEW, &mView);
m_pD3DDevice->GetTransform(D3DTS_PROJECTION, &mProj);
D3DXMATRIXA16 mWorldViewProj = mWorld * mView * mProj;
D3DXMATRIXA16 mViewProj = mView * mProj;
if(FAILED(m_pVConstTable->SetMatrix(m_pD3DDevice,mhWorldViewProj, &mWorldViewProj))) //为什么注释这条就正常??
MessageBoxA(NULL,"a","a",0);
m_pVConstTable->SetMatrix(m_pD3DDevice,mhViewProj, &mViewProj);
UINT count;
D3DXCONSTANT_DESC mDescReflectMap,mDescWaveTexture;
m_pPConstTable->GetConstantDesc(mhReflectMap, &mDescReflectMap, &count);
m_pPConstTable->GetConstantDesc(mhWaveTexture, &mDescWaveTexture, &count);
//m_pD3DDevice->SetTexture(mDescReflectMap.RegisterIndex, mReflectMap);
m_pD3DDevice->SetTexture(mDescWaveTexture.RegisterIndex, mWaveTexture);
m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
m_pD3DDevice->SetTexture(0,m_pTexture);
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR );
m_pD3DDevice->SetStreamSource( 0, m_pVB, 0, sizeof(WaterVertex));
m_pD3DDevice->SetFVF(WaterVertex::FVF);
//m_pD3DDevice->SetVertexDeclaration(VertexPT::DECL);
m_pD3DDevice->SetIndices(m_pIB);
m_pD3DDevice->SetVertexShader(m_pVShader);
m_pD3DDevice->SetPixelShader(m_pPShader);
m_pD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP,0,2);
m_pD3DDevice->SetVertexShader(NULL);
m_pD3DDevice->SetPixelShader(NULL);
m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
void CGameObject::Render()
{
if (!m_pD3DDevice)
{
return;
}
D3DXMATRIX matTrans,matScale,matRotX,matRotY,matRotZ;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixTranslation(&matTrans,m_pos.x ,m_pos.y ,m_pos.z);
D3DXMatrixRotationX(&matRotX,m_angle.x);
D3DXMatrixRotationY(&matRotY,m_angle.y);
D3DXMatrixRotationZ(&matRotZ,m_angle.z);
D3DXMatrixScaling(&matScale,m_size.x,m_size.y,m_size.z);
D3DXMatrixMultiply(&matWorld,&matWorld,&matScale);
D3DXMatrixMultiply(&matWorld,&matWorld,&matRotX);
D3DXMatrixMultiply(&matWorld,&matWorld,&matRotY);
D3DXMatrixMultiply(&matWorld,&matWorld,&matRotZ);
D3DXMatrixMultiply(&matWorld,&matWorld,&matTrans);
m_pD3DDevice->SetTransform(D3DTS_WORLD,&matWorld);
} |
|