Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

HLSL and D3DFVF_XYZRHW

This topic is 3337 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

In my 2D game, I'm using the D3DFVF_XYZRHW flag for my vertices and geometry. When I use vertex shaders, nothing renders but it works fine using fixed pipeline. I've used two different vertex shaders and neither seems to work. Here are both of my shaders:
float4 fConstantAlpha : register(c4);	// Constant alpha input

// Input vertex structure
struct VPIn
{
	float4 ObjectPosition	: POSITION;
	float4 Colour			: COLOR;	
};

// Output vertex structure
struct VPOut
{
	float4 ProjectedPosition : POSITION;
	float4 Colour			 : COLOR;
};


// Vertex shader program entry point
VPOut main( VPIn In )
{
	VPOut Out;
	Out.ProjectedPosition = In.ObjectPosition;	// Passthrough the vertex into
																// projected space
	Out.Colour = float4( In.Colour.xyz, fConstantAlpha.x );			// Passthrough vertex colour
	
	return Out;						// Return transformed vertex
}

This one works okay for 3D, but not for 2D
float4x4 mtxWVP : register (c0);	// Put the WVP matrix into constant register c0-3
									// This constant is set with the Direct3D API
									// IDirect3DDevice9::SetVertexShaderConstantF

// Input vertex structure
struct VPIn
{
	float4 ObjectPosition	: POSITION;
	float4 Colour			: COLOR;	
};

// Output vertex structure
struct VPOut
{
	float4 ProjectedPosition : POSITION;
	float4 Colour			 : COLOR;
};


// Vertex shader program entry point
VPOut main( VPIn In )
{
	VPOut Out;
	Out.ProjectedPosition = mul( mtxWVP, In.ObjectPosition );	// Transform the vertex into
																// projected space
	Out.Colour = In.Colour;			// Passthrough vertex colour
	
	return Out;						// Return transformed vertex
}

And if necessary, I'll show you how I create my World*View*Projection matrix:
D3DXVECTOR3 vecLookAt, vecPosition, vecUp;
	D3DXMATRIX mtxWorld, mtxView, mtxProjection;
	D3DXMATRIX mtxWVP;

	// Set the identity to the world matrix to leave it in the center oc
	// 3D space.
	D3DXMatrixIdentity( &mtxWorld );

	// Create the view matrix
	vecPosition = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
	vecLookAt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
	vecUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	D3DXMatrixLookAtLH( &mtxView, &vecPosition, &vecLookAt, &vecUp );

	// Create the projection matrix
	D3DXMatrixPerspectiveFovLH( &mtxProjection, D3DX_PI / 4.0f, float( 640 / 480 ), 0.0f, 100.0f );
//	D3DXMatrixOrthoLH( &mtxProjection, 640, 480, -1.0f, 1.0f );

	// Multiply the three matrices together to form the WVP matrix
	mtxWVP = mtxWorld * mtxView * mtxProjection;

	// Set the FVF
//	lpD3DDevice->SetFVF( VERTEX::FVF );

	// Set the vertex shader and vertex declaration
	lpD3DDevice->SetVertexDeclaration( lpVertexDeclaration );
	lpD3DDevice->SetVertexShader( lpVshPassthrough );

	// Set the WVP matrix in vertex shader constant c0-3
	lpD3DDevice->SetVertexShaderConstantF( 0, (float*) &mtxWVP, 4 );

Does it matter what FVF I use for my vertex buffers/arrays? Is there another way to do my vertex shaders? Or is it my WVP? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
D3DFVF_XYZRHW means the vertices are pre-transformed and don't go through the vertex pipeline. Use D3DFVF_XYZW if you want to pass a 4 float value to the shader.

Share this post


Link to post
Share on other sites
Yes, D3DFVF_XYZRHW will skip the vertexshader.

You can write your vertex shader to simulate the XYZRHW. All you wanted is use screen coordinate as the veretx coordination. That is easy to implement in Vertex Shader. But make sure your clip matrix is right.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!