Jump to content
  • Advertisement
Sign in to follow this  

Getting invalid instance matrices in vertex shader

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

Hello all


Im using instancing to draw the opaque parts of of heavily repeated objects. I am running into some problems reading the instance data however.


My input structure for the vertex shader is like that:

struct VertexInput
	float3 position : POSITION0;
	float4 boneWeights : BLENDWEIGHT0;
	int4 bones : BLENDINDEX0;
	float3 normal : NORMAL0;
	float2 texCoord : TEXCOORD0;
	float2 texCoord2 : TEXCOORD1;

	float4 mat0 : TEXCOORD2;
	float4 mat1 : TEXCOORD3;
	float4 mat2 : TEXCOORD4;
	float4 mat3 : TEXCOORD5;

In order to get the position (before view and projection) i do the following:

VertexOutput main(VertexInput input) {
	float4x4 matInstance = float4x4(input.mat0, input.mat1, input.mat2, input.mat3);

	// bone & animation stuff

	position = mul(position, matInstance);
	// ...

the animation stuff and the per vertex input data is correct, I modified the last line to be: position = position.xyz + eyePosition + float3(100, 0, 0); and the elements appear correctly in front of my camera.


I have checked with the graphics debugger, in my opinion the input data looks correct (im not showing the per vertex stuff, since thats working):

Instance buffer (i checked, its bound):




Input Layout:



Im using the DrawIndexedInstanced function.


The result is completely wrong however: 



Where should i begin to look at? What could be the reason of this strange behavior?


Thanks in advance,


Share this post

Link to post
Share on other sites

Hello again


Because i didnt know what else to try i just did a transpose on the instance matrix and what do you know, it works. In retrospect it makes sense, float4x4 is column-major, the float4x4 contstructor takes row-major. Thus i had to pass the matrix entries untransposed compared to view/proj and the rest.




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!