Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem passing matrices to shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Joakitex   Members   -  Reputation: 138

Like
0Likes
Like

Posted 27 February 2012 - 01:03 AM

Hello there. I recently decided to port my engine from D3D10 to D3D11 and I am having serious problems when trying to pass the world, view and projection matrices to the GPU. I had been using the ID3D10Effect until now, which allowed me to easily set variables in the shader. Now I am using constant buffers and I am not able to pass the matrices to the video card. I've read a lot of tutorials but I don't seem to find what's wrong with my code.

This is the function where I set the buffer:
Spoiler



This two functions do the rendering (the last one is the problem):
Spoiler


This is my matrix struct:
Spoiler


And this is my shader:
Spoiler



Here's some PIX info
Spoiler


Thanks in advance.

Sponsor:

#2 relaxok   Members   -  Reputation: 133

Like
2Likes
Like

Posted 27 February 2012 - 02:10 AM

I do something similar, in D3D11 - differences are:

-- using XMFLOAT4X4 for the matrix variable format
-- loading to XMMATRIX and transposing with XMMatrixTranspose before storing back to XMFLOAT4X4 and mapping to cbuffer
-- not using packoffset in the cbuffer declaration
-- register(cb0) instead of register(b0) for the cbuffer

I'll look closer at what you did later, but those are differences I've found and mine works fine..

Also, your PIX doesn't exactly show the problem, for me - are those cbuffer variables in the debugger not reasonable? they're definitely not zeroed out or something.. in what way are they wrong?

#3 Joakitex   Members   -  Reputation: 138

Like
0Likes
Like

Posted 27 February 2012 - 02:32 AM

I do something similar, in D3D11 - differences are:

-- using XMFLOAT4X4 for the matrix variable format
-- loading to XMMATRIX and transposing with XMMatrixTranspose before storing back to XMFLOAT4X4 and mapping to cbuffer
-- not using packoffset in the cbuffer declaration
-- register(cb0) instead of register(b0) for the cbuffer

I'll look closer at what you did later, but those are differences I've found and mine works fine..

Also, your PIX doesn't exactly show the problem, for me - are those cbuffer variables in the debugger not reasonable? they're definitely not zeroed out or something.. in what way are they wrong?


Thanks, I'll try that out.

About the PIX thing, I am concerned about the pre and post Vertex shader thing, shouldn't the post Vertex shader output be equal or at least similar to the pre Vertex shader output?

#4 kauna   Crossbones+   -  Reputation: 2510

Like
1Likes
Like

Posted 27 February 2012 - 02:37 AM

Hi,

In my opinion the PIX screenshot tells exactly the problem. Your matrices aren't transposed. You should transpose the matrices you pass to the constant buffer.
The PIX shows that the vertex shaders input geometry is correct. Otherwise, relaxok has made good points about the code.

Cheers!

#5 kauna   Crossbones+   -  Reputation: 2510

Like
1Likes
Like

Posted 27 February 2012 - 02:42 AM

About the PIX thing, I am concerned about the pre and post Vertex shader thing, shouldn't the post Vertex shader output be equal or at least similar to the pre Vertex shader output?


The post vertex shader output is the position which has gone through world-view-projection transforms but not yet divided by w. If the post-vs box is empty it means that nothing will get drawn to the screen. The view port box contains the position divided by w which puts the mesh in perspective.

Best regards!

#6 Joakitex   Members   -  Reputation: 138

Like
0Likes
Like

Posted 27 February 2012 - 02:55 AM

Yay! thanks everyone. Transposing the matrices before passing them to the video card did the trick!

#7 MJP   Moderators   -  Reputation: 11352

Like
3Likes
Like

Posted 27 February 2012 - 04:17 PM

Just so you know, you need to transpose because by default HLSL shaders will expect column-major matrices while most math libraries will use row-major matrices. You can change this behavior by declaring your matrices with the "row_major" modifier in your constant buffer, or by passing D3D10_SHADER_PACK_MATRIX_ROW_MAJOR when compiling your shader.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS