Help getting simple vertex shader to work

Started by
1 comment, last by superpig 19 years, 7 months ago
I've been trying to learn vertex shaders. I made a simple vertex shader using hlsl and compiled it to assembly language in vp.vp and then try to use it in my code but don't get any display at all (I do when I just use the fixed pipeline). Am I missing some vital step, or have I messed something up?

	D3DXAssembleShaderFromFile("c:\\source\\vp.vp", NULL, NULL, 0, &b, &e);
	if (e != NULL)
	{
		MessageBox(NULL, (char*)e->GetBufferPointer(), "Error", MB_OK);
		exit(0);
	}
	g_pd3dDevice->CreateVertexShader((DWORD*)b->GetBufferPointer(), &pVertexShader);
	g_pd3dDevice->SetVertexShader(pVertexShader);

The code of my shader is

struct in_s
{
	float4 position : POSITION;
	float4 Col0	: COLOR0;
};

struct out_s
{
	float4 HPos	: POSITION;
	float4 Col0	: COLOR0;
};

out_s main(in_s IN, uniform float4x4 ModelViewProj)
{
	out_s OUT;	

	OUT.HPos = mul(ModelViewProj, IN.position);
	OUT.Col0 = IN.Col0;
	OUT.Col0.x = 1.0;

	return OUT;
}

Advertisement
Or if nobody is able to help me on that does anyone have a very simple example of the code needed to load a vertex shader that does as little as possible and just renders a square or something using it so I can figure out how my code is wrong?



Thanks
First: Turn on the debug runtime and watch your debug output, as detailed in the Forum FAQ.

Second: I believe you're missing a vertex declaration.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement