Public Group

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.

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 on other sites
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 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.

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• Forum Statistics

• Total Topics
633003
• Total Posts
3009842
• Who's Online (See full list)

There are no registered users currently online

×