I've just begun to work with vertex shaders and I can't figure out why my shader results in nothing rendering. My vertex declaration like:
D3DVERTEXELEMENT9 dec[3] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0},
D3DDECL_END()
};
DXUTGetD3DDevice()->CreateVertexDeclaration(dec,&vertexDec);
D3DXCreateEffectFromFile(DXUTGetD3DDevice(),L"terrain.fx",NULL,NULL,
D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION,NULL,&effect,NULL);
effect->FindNextValidTechnique(NULL, &technique);
And I render it like this:
pd3dDevice->SetStreamSource( 0, vertexBuffer, 0, sizeof(VERTEX) );
pd3dDevice->SetVertexDeclaration(vertexDec);
pd3dDevice->SetIndices(indexBuffer);
pd3dDevice->SetMaterial( &material );
if (SUCCEEDED(effect->SetTechnique(technique)))
{
UINT numPasses;
effect->Begin(&numPasses,0);
for (UINT i=0;i<numPasses;i++)
{
effect->BeginPass(i); // Set the pass
pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, numVertices,0, numPolygons );
effect->EndPass();
}
effect->End();
}
When I run the code as above, I get absolutely nothing shown at all. However, if I comment out all the effect and technique stuff and just do
pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, numVertices,0, numPolygons );
then everything renders like normal.
This is my shader fx file:
float4x4 wvp : WORLDVIEWPROJECTION;
// the format of our vertex data
struct VS_OUTPUT
{
float4 Pos : POSITION;
};
// Simple Vertex Shader - carry out transformation
VS_OUTPUT VS(float4 Pos : POSITION)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul(Pos, wvp);
return Out;
}
technique terrainTechnique
{
pass p0
{
Lighting = TRUE;
VertexShader = compile vs_1_1 VS();
}
}
Everything renders fine when I view it in EffectEdit. Could anyone help me out? I don't know what I'm doing wrong.
[Edited by - Kaezin on May 10, 2007 10:47:30 PM]