Understanding matrices (in shader)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Christi258
Posts: 62
Joined: Wed Feb 06, 2013 12:11 pm

Understanding matrices (in shader)

Post by Christi258 »

Hi everyone,
I have problems to understand matrices, espacially when it comes to shader.
For example what does the function mul() exaclty do? When you multiply a float4 with float4x4 how can there result a float4 ?
And what does the fourth value of a vector exactly (w).
I don't expect an description here but perhaps a link to a tutorial or something like that would be nice.
tothex
Posts: 5
Joined: Tue Sep 24, 2013 5:38 pm

Re: Understanding matrices (in shader)

Post by tothex »

Hi shaders are mostly math so its hard to get started
in hlsl:
struct_name.v_pos = mul(float4(v_pos, 1.0f), wvp_matrix)
we use mul to transform vector (v_pos) from 3D space to our 2d screen.

v_pos has x y z.
but for the shader vectors have 4 components: (x,y,z,w)

w=1 indicates that it is a vector with position only (vertex)
w=0 its a vector (which can only be rotated )

It results to a vector=[x,y,z,w] because you multiply each vector row by each matrix column
(check some linear algebra examples)
BitPuffin
Posts: 8
Joined: Mon Apr 01, 2013 8:25 pm

Re: Understanding matrices (in shader)

Post by BitPuffin »

Hey!

I recommend Khan Academy: https://www.khanacademy.org/math/linear-algebra excellent free video explanations on linear algebra (and other topics)!

While I didn't learn from that mainly, instead I read this book: http://gamemath.com/ but you are maybe not in the market for buying a book. If you are I really recommend it. It's good!

Hope that helps, good luck!
Christi258
Posts: 62
Joined: Wed Feb 06, 2013 12:11 pm

Re: Understanding matrices (in shader)

Post by Christi258 »

Thanks, that should be enough to start ;)
Christi258
Posts: 62
Joined: Wed Feb 06, 2013 12:11 pm

Re: Understanding matrices (in shader)

Post by Christi258 »

tothex wrote: we use mul to transform vector (v_pos) from 3D space to our 2d screen.
Does that mean if I use:
outPos = mul(v_pos, ViewProjectionWorldMatrix);
I have as result in outPos the 2D position on the screen of the vertex?
tothex
Posts: 5
Joined: Tue Sep 24, 2013 5:38 pm

Re: Understanding matrices (in shader)

Post by tothex »

Christi258 wrote:
tothex wrote: we use mul to transform vector (v_pos) from 3D space to our 2d screen.
Does that mean if I use:
outPos = mul(v_pos, ViewProjectionWorldMatrix);
I have as result in outPos the 2D position on the screen of the vertex?
its still a vector with 4 components with normalized values from -1 to 1
the gpu and the pixel shader do the rest.

some good shader books: (directx & opengl )
  • Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach
  • OpenGL SuperBible
Post Reply