Jump to content
  • Advertisement
Sign in to follow this  

[solved] My Vertex Shader makes my geometry disappear

This topic is 4030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!