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.
Understanding matrices (in shader)
Re: Understanding matrices (in shader)
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)
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)
Re: Understanding matrices (in shader)
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!
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!
-
- Posts: 62
- Joined: Wed Feb 06, 2013 12:11 pm
Re: Understanding matrices (in shader)
Thanks, that should be enough to start
-
- Posts: 62
- Joined: Wed Feb 06, 2013 12:11 pm
Re: Understanding matrices (in shader)
Does that mean if I use:tothex wrote: we use mul to transform vector (v_pos) from 3D space to our 2d screen.
outPos = mul(v_pos, ViewProjectionWorldMatrix);
I have as result in outPos the 2D position on the screen of the vertex?
Re: Understanding matrices (in shader)
its still a vector with 4 components with normalized values from -1 to 1Christi258 wrote:Does that mean if I use:tothex wrote: we use mul to transform vector (v_pos) from 3D space to our 2d screen.
outPos = mul(v_pos, ViewProjectionWorldMatrix);
I have as result in outPos the 2D position on the screen of the vertex?
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