• Advertisement
Sign in to follow this  

unable to manually set world,view,proj in shader

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

Why wouldn't i be able to set the worldviewproj matrix in the shader? When I do it turns out to be covering the whole screen. When I configure it inside the render loop of mesh - it looks fine.

 

I need to be able to translate the meshes bones being sent to the shader - I can't do that unless I am able to:

float4x4 bwvp = mWorld * mView * mProj * bonematrix;

output.position = mul(input.position, bwvp);

the bones matrixes have their own constant buffer in array of 100. a common cb per object was created holding the World, View, Proj. I've tried:

input.position.w = 1.0f;
output.position = mul(input.position, mWorld);
output.position = mul(output.position, mView);
output.position = mul(output.position, mProj);

That doesn't do anything just renders the mesh covering the whole screen. Where it should look more like this:

[attachment=28736:ScreenCaptured_nossao26616756.jpg]

 

not like this:

 

[attachment=28737:ScreenCaptured_nossao52295916.jpg]

 

the mWorld has scale * rotation * translation from the model's world space.
 

Any insight what may be happening? the first image posted was from the commonperobj cbuffer's mWorldViewProj matrix.

 

The commonperobj cbuffer is layout is:
 

cbuffer cbCommonPerObj : register(b0) {
	float4x4 mWorldViewProj;
	float4x4 mWorld;
	float4x4 mView;
	float4x4 mProj;
};

Anyone possibly knows why?

Share this post


Link to post
Share on other sites
Advertisement

Hi!

 

Have you transposed your input matrices?

yup all of them are transposed before going to shader.

		D3D11_MAPPED_SUBRESOURCE commonMap;
		CBCommonPerObject *cbCommonPerObject;
		canvas->getDeviceContext()->Map(commonConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &commonMap);
		cbCommonPerObject = (CBCommonPerObject*)commonMap.pData;
		cbCommonPerObject->mWorldViewProj = XMMatrixTranspose(wvp);
		cbCommonPerObject->World = XMMatrixTranspose(mWorld);
		cbCommonPerObject->View = XMMatrixTranspose(view);
		cbCommonPerObject->Proj = XMMatrixTranspose(proj);

		canvas->getDeviceContext()->Unmap(commonConstantBuffer, 0);

Share this post


Link to post
Share on other sites

I forgot to mention my mesh layout for the shader as is:

D3D11_INPUT_ELEMENT_DESC meshInputDescription[] = {

	{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "BONES", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
	{ "WEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA,0 }
};

I looked at the skinning10 from the directx samples and saw the bones id were configured as a DXGI_FORMAT_R8G8B8A8_UINT.

I'm using a 32 bit index buffer.

the bonesID and bone weights are stored in the vertex structure as is:
 

struct Vertex {
	XMFLOAT3 position;
	XMFLOAT2 uvs;
	XMFLOAT3 normals;
	XMFLOAT3 tangents;
	XMFLOAT3 biTangents;
	XMFLOAT4 boneIDS;
	XMFLOAT4 boneWeights;

};

I know before any time I ran into rendering issues - it mostly constant buffers, or how the input element lay out.

Share this post


Link to post
Share on other sites

*high five to everyone*

 

Pretty interesting actually - it works now. I transposed the mWorld, mView, mProj matrices. However, before I set the mWorld, mView, mProj I flatten them with XMMatrixIdentity.

 

Inside the shader code I did this:
 

        input.position.w = 1.0f;
	float4 vertexWorldPos = mul(float4(input.position),mWorld);
	float4x4 bViewProj = mul(mView, mProj);
	
	output.position = mul(vertexWorldPos, bViewProj);
    

So what I had to do was to transform the input positions to the world matrix, create a matrix for the view * proj matrices. Finally output the vertex position to the world transformed vertexes to the view projection matrix.

 

Now I'll be getting the animation up running possibly tonight.

Share this post


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

  • Advertisement