Jump to content
  • Advertisement
Sign in to follow this  

problems with shaderdeclarations

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

Arrghh.. the pain... There seems to be some problems with my shaderdeclarations.
// 4 verts - xyz (w padding)
vertexdata->add_element(-0.5f, -0.5f, 0, 1);
vertexdata->add_element(-0.5f,  0.5f, 0, 1);
vertexdata->add_element( 0.5f,  0.5f, 0, 1);
vertexdata->add_element( 0.5f, -0.5f, 0, 1);

// then comes 4 colorvalues (rgba)	
vertexdata->add_element(1, 1, 1, 1);
vertexdata->add_element(1, 1, 1, 1);
vertexdata->add_element(1, 1, 1, 1);
vertexdata->add_element(1, 1, 1, 1);

// my declaration - just a simple wrapper for the D3DVERTEX9ELEMENT
declaration->add_element(0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION);
declaration->add_element(0, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR);

// set the current stream
renderer->set_streamsource(0, vertexdata);
unless I've fried all my braincells this weekend this SHOULD work with the programmable pipeline and these vertexshaders:
// vertex shader - matProj is a float4x4 with the world-view-projection matrix
void VS
(
	in float4 ifPosition	: POSITION0,
	in float4 ifColor	: COLOR0,
	out float4 ofPosition	: POSITION,
	out float4 ofColor	: COLOR
) // end function header
{
	ofPosition	= mul(matProj, ifPosition);
 	ofColor		= ifColor;
}

// the pixelshader - just pass on the vertex difuse color
void PS
(
	in float4 ifColor		: COLOR0,
	out float4 ofColor		: COLOR
) // end function header
{
	ofColor = ifColor;
}
Can you find something that looks awfully weird in this code - because I can't and there really IS something weird going on with some distorted polygons...

Share this post


Link to post
Share on other sites
Advertisement
1) Does the DEBUG Direct3D runtime have anything to report in the debug output stream with maximum validation enabled?

2) Also, if you're using D3DX to compile your shaders or effects, try linking with the DEBUG version of the D3DX library (d3dx9d.lib rather than d3dx9.lib). This is useful for detecting shader bugs and vertex shader to pixel shader linkage problems.

3) If the above doesn't yield any clues, try specifying the D3DCREATE_SOFTWARE_VERTEXPROCESSING flag when creating your device, and D3DUSAGE_SOFTWAREPROCESSING when creating your vertex/index buffers. Then run with the debug D3D runtime. Because the D3D runtime is doing the transformation and shader work with software vertex processing, it can perform extra validation in this case. This is very useful for detecting things like out of range indices.


In my experience, the above steps are enough to find 99% of problems with vertex declarations and bad primitive data (such as bad indices, bad offsets etc).

Share this post


Link to post
Share on other sites
No, d3d does not report anything suspicious with maximum validation and with shader debugging enabled... BUT



// create a Renderbuffer containing 32 elements with a stride of 32 bytes
Ethereal::pRenderbuffer vertexdata = Ethereal::pRenderbuffer(new Ethereal::Renderbuffer(renderer, 32, 32));

// add the vertex components xyz (and w for padding)
vertexdata->add_element(-0.5f, -0.5f, 0, 1);
vertexdata->add_element(-0.5f, 0.5f, 0, 1);
vertexdata->add_element( 0.5f, 0.5f, 0, 1);
vertexdata->add_element( 0.5f, -0.5f, 0, 1);

// IF I REMOVE THE COLOR DATA and adjusts the stride, everything works
vertexdata->add_element(1, 1, 1, 1);
vertexdata->add_element(1, 1, 1, 1);
vertexdata->add_element(1, 1, 1, 1);
vertexdata->add_element(1, 1, 1, 1);

// compile (build) the vertexbuffer
vertexdata->compile();

// create the indexbuffer with 6 elements
Ethereal::pIndexbuffer indices = Ethereal::pIndexbuffer(new Ethereal::Indexbuffer(renderer, 6));
indices->add_element(0, 1, 2);
indices->add_element(2, 3, 0);

// compile (build) the index buffer
indices->compile();

// create a shaderdeclaration
Ethereal::pShaderdeclaration declaration = Ethereal::pShaderdeclaration(new Ethereal::Shaderdeclaration(renderer));

// stream 0 and 0 bytes offset - vertex data
declaration->add_element(0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION);

// stream 0 and 16 bytes offset - color data
declaration->add_element(0, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR);

// compile (create) the vertex declaration
declaration->compile();

// set the streamsource, the indexbuffer and the vertex declaration
renderer->set_streamsource(0, vertexdata);
renderer->set_indices(indices);
renderer->set_declaration(declaration);

// ... inside the render function ... //
// 4 vertices and 2 primitives - the (in)famous rotating quad
m_device3d_ptr->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);

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!