• Advertisement
Sign in to follow this  

Problem with D3D11_INPUT_ELEMENT_DESC

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

Hi Guys,

I am currently trying to add color to my D3D11_INPUT_ELEMENT_DESC.

So far I have been using plain vertex buffers and the shader itself has been coloring the models to a single color.

I have created an D3D11_INPUT_ELEMENT_DESC
 
D3D11_INPUT_ELEMENT_DESC vertexLayout[] =
{
	{ "POSITION", 0 ,DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
and have created the geometry as a custom Float7 array. First 3 floats are the XYZ co-ordinates and the last 4 float are the RGBA values.

Here is the code I am using for a simple quad.

	vertex_data[0] = { -0.5f, -0.5f, 0.0f,		255.0f, 0.0f, 0.0f, 255.0f };
	vertex_data[1] = { -0.5f, 0.5f, 0.0f, 		0.0f, 255.0f, 0.0f, 255.0f };
	vertex_data[2] = { 0.5f, -0.5f, 0.0f,		0.0f, 0.0f, 255.0f, 255.0f };
	vertex_data[3] = { 0.5f, -0.5f, 0.0f,		0.0f, 0.0f, 255.0f, 255.0f };
	vertex_data[4] = { -0.5f, 0.5f, 0.0f,		0.0f, 255.0f, 0.0f, 255.0f };
	vertex_data[5] = { 0.5f, 0.5f, 0.0f,		255.0f, 0.0f, 0.0f, 255.0f };


	D3D11_BUFFER_DESC vertexDesc;
	ZeroMemory(&vertexDesc, sizeof(vertexDesc));
	vertexDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexDesc.ByteWidth = sizeof(Float7) * nVerts;

	D3D11_SUBRESOURCE_DATA resourceData;
	ZeroMemory(&resourceData, sizeof(resourceData));
	resourceData.pSysMem = vertex_data;
	
	result = d3dDevice->CreateBuffer(&vertexDesc, &resourceData, &d3dVertexBuffer);

And this is how I am rendering the quad

		unsigned int stride = sizeof(Float7);
		unsigned int offset = 0;
		d3dContext->IASetInputLayout(d3dInputLayout);
		d3dContext->IASetVertexBuffers(0, 1, &d3dVertexBuffer, &stride, &offset);
		d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		d3dContext->Draw(nVerts, 0);    // nVerts = 6...
The problem is that the geometry is rendering correctly but the coloring is incorrect.

It is rendering as a white box with an aqua line running where the triangles intersect to make up the quad.

I'd expect to be seeing more of a rainbow type of effect where each corner graduates between the primary colors.

Been tearing my hear out for a few hours and can't seem to see where I am going wrong.

Any advice would be awesome smile.png Edited by DarkRonin

Share this post


Link to post
Share on other sites
Advertisement
Since you're using DXGI_FORMAT_R32G32B32A32_FLOAT, the input assembler is going to interpret your color values as-is. In other words, your vertex shader is going to get values of (255, 0, 0), (0, 255, 0), etc. You probably want to change all of those 255.0f's to 1.0f's.

If you were using DXGI_FORMAT_R8G8B8A8_UNORM, then you want want your RGBA values to be 1-byte unsigned integers from 0 to 255. In that case, it would make sense to values of 255, but for float values it probably doesn't make sense.

Share this post


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

  • Advertisement