Jump to content
  • Advertisement
Sign in to follow this  
Tordin

DX11 [DX11]Shader multiplications

This topic is 2526 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!

I resently "developed" a problem, no idea how or how to solve it.

The thing is, when i rotate a model in the X axis, it rotates the Y axis,and the Y rotates the X axis.
To solve the problem i started to mess around with the vertex shader to find a solution.. with out any Luck!

My question is now, is this correct? (psudo code)

1 : Set my ViewProjection to the shader as a TRANPOSED matrix.
2 : calculate World * ViewProjection
3 : calculate VertexPos * (World*Viewprojection)


That is the way i have been doing it befor and it workt perfect by then.
any helps would be nice! cheers!

Share this post


Link to post
Share on other sites
Advertisement
Give the ObjectTransformationMatrix, ViewMatrix and ProjectionMatrix to the shader.
Multiply from object space to screen space in the vertex shader and give all 4 types of vertex position to the pixel shader.
ObjectSpace -> WorldSpace -> CameraSpace -> ScreenSpace

If you try to optimize by making one matrix on the CPU, you will sooner or later have to split it to support more advanced materials.

Each object should store:
Normalized orthogonal 3x3 matrix for fast rotation.
X,Y,Z scaling vector for setting the size.
X,Y,Z translation vector for moving.

Multiply the object's normalized orthogonal 3x3 matrix with a rotation matrix, orthogonalize to remove rounding errors and let the compiler optimize the multiplications with 0 and 1.
http://en.wikipedia....Rotation_matrix

Scale object's normalized orthogonal 3x3 matrix with the scaling vector and insert it to a 4x4 matrix together with the translation vector to create the final ObjectTransformationMatrix that you can give to your shader.

Share this post


Link to post
Share on other sites
well, most of the stuff you said i do understand.

what i dont understand isent why my matrix calulation wont work :

(World * View * Projection) * localpos;

Share this post


Link to post
Share on other sites
If you are applying the multiplication in screen space, it will rotate in screen space. Only apply rotations to the matrix that convert object space to world space.

Share this post


Link to post
Share on other sites
How are you calculating your world transformation? If you think about it, the world matrix is simply a mapping from one space to another, so if it is being done incorrectly then there are really only two possible reasons why - 1. the mapping calculated is wrong or 2. the two spaces are related in the way that you think they are.

I'm pretty sure that it is either the calculation is incorrect, or possibly that the arguments on your matrix multiplication should be flipped - i.e. mul(vector, matrix) should be mul(matrix, vector) or vice versa. Are you able to post the relevant code snippets?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!