[solved] My Vertex Shader makes my geometry disappear

Started by
1 comment, last by Kaezin 16 years, 11 months ago
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]
Half the people you know are below average.Trogdor the Burninator
Advertisement
Do you ever set the shaders wvp matrix? You have to do that yourself. Setting the device material and enabling lighting won't do anything either, as a vertex shader replaces the part of the fixed pipeline that does lighting. You need to create variables for your material settings and light settings, and actually perform the lighting yourself.

You're using the fixed pipe pixel processing, which may be expecting D3DTA_DIFFUSE to be set. It's up to your vertex shader to output that. It's probably outputting black by default and all your geometry is drawn black.
Thanks for the help. I knew the Lighting code was useless, it was just leftover from before and I didn't bother removing it :P

The problem was that I was never setting wvp, like you said. I was used to working with shaders using EffectEdit, and WORLDVIEWPROJECTION is what EffectEdit uses as a default. Thanks for the help, working fine now :P
Half the people you know are below average.Trogdor the Burninator

This topic is closed to new replies.

Advertisement