Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

what is the equiverlant of matrixrotaion in HLSL

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

what is the equiverlant of matrixrotaion in HLSL.


as i can figure out , its best to use HLSL to multply the matrix's together to get the final matrix needed , so i was wondering if there is a way to use HLSL to rotate a matrix as well

Share this post


Link to post
Share on other sites
Advertisement
Why can't you define the transform yourself as a function?

messed up, semi-pseudo code:
float4x4 matrix_rotate_x(float4x4 m, float a)
{
m = identity;

float c = cos(a);
float s = sin(a);

// zero based indexing
m[1, 1] = c;
m[1, 2] = -s;
m[2, 1] = s;
m[2, 2] = c;

return m;
}


Im not really someone you should pay close attention to when it comes to shaders since I barely know about them myself, this is just simply how I might have done it (after some research churning no luck).

In the vertex shader you would then create the rotation transform, multiply it by the existing world matrix (actually its probably world * view * projection matrix at this point normally so you would also have to do the latter 2 in the vertex shader aswell, after the "local transform") and then multiply the vertices with the new world transform.

Meh I dont know, just throwing out suggestions..

Share this post


Link to post
Share on other sites
Do note that if you don't need to change the rotation per-primitive (vertex or pixel), it is much more efficient from arithmetic perspective to calculate the transformation in the host program instead of on the GPU.

Consider the total amount of relevant calculations in the following options:

  • calculate matrix once on host; apply "for free" for any amount of primitives
  • calculate matrix once per vertex on vertex shader; total calculation cost m * n where m is the single primitive calculation cost and n is the number of vertices processed
  • calculate matrix once per pixel on pixel shader; total calculation cost m * n2 where m is the single primitive calculation cost and n2 is the screen area which your primitives cover



This advice does not apply if constant register pressure is your bottleneck. However, it is difficult to isolate it as a bottleneck in simple shaders.

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!