Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequence of transformations: Projective Texturing (HLSL)

When I was reading this article on Projective Texturing (9.3.2) on nvidia, I came across this graph:


(source: nvidia.com)

The order in which the transformations are written confused me. This is because I learned to read matrix multiplication from left to right and also because I thought the sequence of transformations should go in this order:


(source: nvidia.com)

Now my questions are the following:

Because Matrix multiplication is not commutative, what is the order I should do the multiplications in?

And if it is indeed in the same order as the sequence of transformations of normal objects, why is it written like this?

By the same order of sequence I mean something like this hlsl code:

float4 worldPosition        = mul(input.Position, World);
float4 viewPosition         = mul(worldPosition, View);
output.Position             = mul(viewPosition, Projection);

Finally (and this is optional but might be usefull for others wondering the same), how would you write the HLSL code to do this projective texturing multiplication or how would you do the transformations if you passed the complete Matrix via XNA.

like image 623
Alexander van der Zalm Avatar asked Jul 02 '11 19:07

Alexander van der Zalm


1 Answers

Your transformation can be written symbolically as

y = T P V W x

where:

x = (x0, y0, z0, w0)T: object coordinates (column vector 4x1)
y = (s, t, r, q)T: window space coordinates (column vector 4x1)
W: world modelling matrix (4x4)
V: view modelling matrix (4x4)
P: projection matrix (4x4)
T: viewport transformation matrix (4x4)

The calculation is performed as:

y = T (P (V (W x)))

i.e. from right to left. The HLSL code would be:

float4 worldPosition  = mul(World, input.Position);     // W x
float4 viewPosition   = mul(View, worldPosition);       // V (W x)
float4 projPosition   = mul(Projection, viewPosition);  // P (V (W x))
float4 vportPosition  = mul(Viewport, projPosition);    // T (P (V (W x)))
like image 146
Jiri Kriz Avatar answered Oct 21 '22 03:10

Jiri Kriz