I've recently been re-writing my first 3d game, because it was slow and a pain to develop with. However I've ran into a problem where I can't get a cube with a basic shader to show on the screen. The shader simply outputs a white color for the whole cube.. in theory. Practically, what I get is a total black screen. When clearing to any other color like red, I get a red screen. However, using the Nvidia PerfHUD to debug, I get this output:
So, the cube is actually there - adjusting the parameters of my view/world-matrices moves the cube around like it should. But why is the cube only showing up here and not in the actual game? Here is some code:
The shader:
float4x4 World : World;
shared float4x4 ViewProj : ViewProjection;
struct VS_INPUT
{
float3 vPos : POSITION0;
float2 vTex0 : TEXCOORD0;
float3 vNrm : NORMAL0;
float3 vTan : TANGENT0;
float3 vBin : BINORMAL0;
};
float4 mainVS(VS_INPUT i) : POSITION
{
float4x4 WorldViewProj = mul(World, ViewProj);
return mul(float4(i.vPos.xyz, 1.0), WorldViewProj);
}
float4 mainPS() : COLOR {
return float4(1.0, 1.0, 1.0, 1.0);
}
technique technique0 {
pass p0 {
VertexShader = compile vs_3_0 mainVS();
PixelShader = compile ps_3_0 mainPS();
CullMode = ccw;
ColorWriteEnable = red | green | blue | alpha;
}
}
//mesh render method
void Mesh::Render(void)
{
m_lpDevice->SetStreamSource(0, m_lpVertexBuffer, 0, sizeof(D3DVERTEX));
m_lpDevice->SetIndices(m_lpIndexBuffer);
m_lpDevice->SetVertexDeclaration(m_lpVertexDeclaration);
m_lpDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_nNumVertices,0,m_nNumVertices/3);
}
//render model with mesh,material and effect
void Model::Render(void)
{
D3DXMATRIX Identity;
D3DXMatrixTranslation(&Identity,1.0f, 1.0f, 1.0f);
m_pEffect->SetMatrix("World", Identity);
m_pEffect->Begin();
m_pMaterial->Use(m_pEffect);
m_pEffect->BeginPass();
m_pMesh->Render();
m_pEffect->EndPass();
m_pEffect->End();
}
void Graphics3D::Render(Camera* pCamera)
{
D3DXMATRIX Matrix = pCamera->GetViewProjectionMatrix();
m_EffectSpace.GetPoolEffect(L"Models")->SetMatrix("ViewProj",Matrix);
for(vector<Model*>::iterator ii=m_vModels.begin();ii!=m_vModels.end();++ii)
{
(*ii)->Render();
}
}
//camera class
Camera::Camera(void) : m_vPosition(10.0f, 0.0, 0.0), m_vLookAt(0.0f,0.0f,0.0f),m_vUp(0.0f,1.0f,0.0f)
{
D3DXMatrixLookAtLH(&m_mView, &m_vPosition, &m_vLookAt, &m_vUp);
D3DXMatrixPerspectiveFovLH(&m_mProjection, D3DX_PI/4, 2560.0f / 1600.0f, 0.5f, 5000.0f );
D3DXMatrixMultiply(&m_mViewProjection,&m_mView,&m_mProjection);
}
Camera::~Camera(void)
{
}
D3DXMATRIX Camera::GetViewProjectionMatrix(void)
{
return m_mViewProjection;
}
This is most of the code involved into rendering the mesh. Using the directx debug runtime, I get no errors or warning, and DrawIndexedPrimitve succeedes.
Only hint I have is that PIX shows me something like this for the call to set the ViewProjection-Matrix:
Other than the mesh obviously rendered correctly on the right side, why is there a NULL in the SetMatrix-Call? The matrix I pass is valid, but Nvidia PerfHUD also shows that the constants for the ViewProjection-Matrix are all 0. On the other hand, why does but PIX and PerfHUD show the mesh drawn correctly, at least as wireframe?
I am really at the end of my knowledge, does somebody else see any obvious mistake here?