Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

ASM shaders (DX9)

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

Hey all. I'm trying to learn to use low level ASM shaders in Dx9. I've searched google for hours and haven't found anything except for Dx8 (which uses a different process). The DirectX documentation wasn't very helpful either because the samples (in the help file) had multiple errors in them making the learning process very confusing. Anyone else have any good links? Now I know that you're all about to say, "Why on earth do you want to use ASM shaders? Why not use HLSL instead?". The project I'm working on is best done on a low level, so ASM is the way to go (IMO). I've been trying to learn by trial and error, but so far have been unsuccessful. Here's the code I've been using. The shader:
vs_1_1              // version instruction
dcl_position v0     // define position data in register v0
m4x4 oPos, v0, c0   // transform vertices by view/projection matrix
mov oD0, c4         // load constant color
The initialization process:
//
	// Create a simple vertex shader
	//
	ID3DXBuffer* pVshBuffer = NULL;
	ID3DXBuffer* pErrorMsgBuffer = NULL;

	// Create the shader declaration.
	D3DVERTEXELEMENT9 decl[] = 
	{
		{ 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
		D3DDECL_END()
	};

	// Assemble the vertex shader
	hr = D3DXAssembleShaderFromFile( "shaders\\vs_simple.asm", NULL, NULL, 0,
									&pVshBuffer, &pErrorMsgBuffer );
	if( FAILED( hr ) )
	{
		char string[2048];
		sprintf( string, "D3DCreateDeviceFunc(): Error assembling vertex shader!\n\n%s", 
			(char*) pErrorMsgBuffer->GetBufferPointer() );

		SAFE_RELEASE( pErrorMsgBuffer );

		return DXUtil_Error( string, hr );
	}

	// Create vertex shader
	hr = pD3DDevice->CreateVertexShader( (DWORD*) pVshBuffer->GetBufferPointer(), &g_pd3dVertexShader );
	if( FAILED( hr ) )
		return DXUtil_Error( "D3DCreateDeviceFunc(): Error creating vertex shader!", hr );

	// Release buffer objects if they are valid
	SAFE_RELEASE( pVshBuffer );
	SAFE_RELEASE( pErrorMsgBuffer );

Setting constants:
// Set the vertex shader so that the changes to the constants will
	// effect it.
	pD3DDevice->SetVertexShader( g_pd3dVertexShader );

	D3DXMATRIX mtxView, mtxProj, mtxOut;
	
	// Get a copy of the view and projection matrix
	pD3DDevice->GetTransform( D3DTS_VIEW, &mtxView );
	pD3DDevice->GetTransform( D3DTS_PROJECTION, &mtxProj );

	// Multiply view and projection matrices, and transpose the result
	D3DXMatrixMultiply( &mtxOut, &mtxView, &mtxProj );
	D3DXMatrixTranspose( &mtxOut, &mtxOut );

	// Set the result as a vertex shader constant
	pD3DDevice->SetVertexShaderConstantF( 0, (float*) &mtxOut, 4 );

	// Set the constant color
	float fConstColor[] = { 0.0f, 1.0f, 0.0f, 0.0f };	// RGBA
	pD3DDevice->SetVertexShaderConstantF( 4, (float*) fConstColor, 1 );

When rendering my geometry using a fixed-function vertex format, it works just fine. When setting the program to use the vertex shader instead, it shows nothing. I've been at this for hours now and I have no idea what the problem is. This sucks. Any ideas? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Matt Aufderheide
Well, it's not possible to use a vertex shader without a pixel shader as well
Yes it is, I've been doing it for a while now.

No idea about the problem though I'm afraid.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
That's interesting, I was under the impression that it cant work this way.. how do you do it?
The fixed function gets automatically used for the pixel shader unless you specify otherwise.

Share this post


Link to post
Share on other sites
Well if you're going to use the fixed-function pipeline for the pixel shader then you're going to have to make sure the fixed-function stuff is set up correctly. I believe that the first texture stage defaults to using the texture (which you haven't set, so the color will be black). You'll want to set the first color arg as your diffuse material color.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!