What is what in the Matrix

Posted By: Beorn

What is what in the Matrix - 12/20/03 01:45

I got the texture sizing working with some tirekicking, but i dont know how the transformation matrix works in detail. I know that 41 and 42 controlls UV position. and i also found out that 21, 22 controlls scaling in some way, but its hard to try and guess those things.

So could anyone tell me/point me to some info on this?



Posted By: Beorn

Re: What is what in the Matrix - 12/20/03 12:51

Bumping this since i really would like some input here.
I found out i was quite wrong in my earlier post about what does what.

I have found out how to scale stuff. Can i scale and move a texture using the same matrix or do i havce to use separate?

Is it correct to assume that if i change 11,22,33 i will scale the texture?

What i am trying to achieve is using different parts of a large bitmaps for different entities in the fixed Function pipeline. I have some success but no control;)

Any nuggets of information would be appreciated.
Posted By: Marco_Grubert

Re: What is what in the Matrix - 12/24/03 06:54

I am not sure which Matrix you are referring to, but at the same time it sounds like general matrix operations that confuse you, so here's a quick intro to linear algebra:
a matrix is an ordered collection of numbers and in computer graphics it's mostly a 2 dimensional grid with 3x3 or 4x4 entries. Matrices can be multiplied in order to yield a new matrix. This is of particular interest since a coordinate/vector can be regarded as a one-dimensional matrix. Here's how the two get multiplied, assuming a 4x4 matrix and a 4x1 vector (4 rows, 1column):
Code:

Matrix * in-vector = output-vector

(e11 e12 e13 e14) (x) (x*e11 + y*e12 + z*e13 + w*e14)
(e21 e22 e23 e24) (y) (x*e21 + y*e22 + z*e23 + w*e24)
(e31 e32 e33 e34) * (z) = (x*e31 + y*e32 + z*e33 + w*e34)
(e41 e42 e43 e44) (w) (x*e41 + y*e42 + z*e43 + w*e44)



If e11,e22,e33 and e44 are all 1 and the rest of the matrix is 0, you have an Identity Matrix and the resulting vector would simply be (x,y,z,w).
Usually you have an x,y,z coordinate (or U,V,0 for texture coordinates) and w is set to 1. With w==1 looking at the last column of the equation you can see that this basically adds the vector (e14,e24,e34,e44) to the original (x,y,z,1). Therefore (e14,e24,e34,e44) is said to be a translation vector which moves the input point around (or shifts the texture around).
If you have an identity matrix (everything zero accepts for the center diagonal from top left to bottom right) and then change the diagonal to something other then 1, e.g. to all 4s, your output vector changes to (4x, 4y, 4z, 4w).

To summarize: the 4th column (or the 4th row- I don't know which standard the shader uses) determines offset/translation. The diagonal (e11,e22,e33,e44) determines scaling.

What about the rest of the elements ? They rotate your input vectors. e12, e13, etc. are sines and cosines of a rotation. If you want to figure out how to set those- do a google search for "rotation matrix".
Posted By: Anonymous

Re: What is what in the Matrix - 12/24/03 10:11

I know this thread is about shaders (and matrix) and don't want to turn this shader/matrix thread into a math/matrix thread but I think I've probably seen the matrix before (probably in 11th grade in high-school) and I do have a question.

In the matrix, is it something like you add or subtract like for example:

(By the way, it seems like you have added a plus sign in between the two of the numbers/letters...)

Code:

{10 15 25} {20 10 15} {30 + 25 + 40}
{ 5 20 10} + (15 5 40} = {20 + 25 + 50}
{30 0 5} {10 20 25} {40 + 20 + 30}



...and...

Code:

{50 25 15} {30 10 10} {20 + 15 + 5}
{45 30 55} - {15 20 45} = {30 + 10 + 10}
{60 20 35} {15 5 20} {45 + 15 + 15}



And is it the same thing as if you multiply or divide?

If no, please correct me if I'm wrong.

The reason I ask is this is pretty fascinating... Gonna have to get my memory refreshed...
Posted By: Beorn

Re: What is what in the Matrix - 12/31/03 12:57

Thanks Marco,
Very good explanation.
I have some knowledge of the concept behind matrices but i havent used it before so theres a stack of books beside my computer all the time;)
Applying this splinter of knowledge is tricky though.

If i understand this correctly the matrices that are listed in the docs are pre-set by the engine (world, view etc) plus the mtlMat that i can set myself.


Posted By: indiGLOW

Re: What is what in the Matrix - 02/12/04 20:23

all i see is ...blonde......brunette.......redhead.....

In all seriousness this is exactly what I am looking for! A starting point to understanding the syntex of shaders...
Posted By: Marco_Grubert

Re: What is what in the Matrix - 02/13/04 05:57

Quote:

Code:

{10 15 25} {20 10 15} {30 + 25 + 40}
{ 5 20 10} + (15 5 40} = {20 + 25 + 50}
{30 0 5} {10 20 25} {40 + 20 + 30}


And is it the same thing as if you multiply or divide?




The above is wrong. Matrix addition is done element-wise.
Code:

(a11 a12) (b11 b12) (a11+b11 a12+b12)
(a21 a22) + (b21 b22) = (a21+b21 a22+b22)

Same thing for subtraction- just replace the plus with a minus. Matrix multiplication is done by multiplying rows of matrix A with each column of matrix B. The matrix-vector multiplication I wrote about above is only a special case where the second matrix is a vector, i.e. a single-column-matrix.
Matrix division does not exist. But you can (sometimes) do a matrix multiplication with an inverse matrix which is similar to a division.

There is an excellent website covering all fields of mathematics:
http://mathworld.wolfram.com/

I also highly recommend the math program "Derive" which is a bit expensive for hobby users, but there is a 30-day-trial allowing you to play around with matrix and vector equations.
© 2024 lite-C Forums