Black screen

Started by
2 comments, last by Juliean 12 years, 2 months ago
Hi,

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:

9233k2o9.png

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:

oaud7d2k.png

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?
Advertisement
Check your zbuffer settings. I dont see any clear depth or ztest direction specified here. It appears that all your fragments are being zrejected. Vertex shader and draw call code obviously works correctly.
In your call to IDirect3DDevice9::Clear(), for the third parameter, you only tell it to clear the color (D3DCLEAR_TARGET), you need to pass in D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER

and also D3DCLEAR_STENCIL if you are going to use the stencil buffer.

By the way, in Pix you can also right click on a pixel in the render window and click "debug pixel" or something similar, and it will show you all of the times the pixel was processed, including the output color / opacity, if it passed or failed the depth and stencil tests, and from there you can also debug the pixel shaders the same way that you can debug vertex shaders.
Thanks,

Clearing the z-buffer solved the issue. I don't know why I forgot to do so in the first place..

Thanks for the tip with PIX too. I'm just starting
with it, as my old game always kept crashing when using it.

This topic is closed to new replies.

Advertisement