Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vertex Shaders?

Started by SirKnight Apr 6, 2001 at 8:02 PM 3 replies 650+ views
Original Post
SirKnight
SirKnight
I have a question about vertex shaders. Here is a sample shader. vs.1.0 dp4 oPos.x , v0 , c4 dp4 oPos.y , v0 , c5 dp4 oPos.z , v0 , c6 dp4 oPos.w , v0 , c7 mov oD0 , v5 Ok in this case c4 to c7 holds WorldViewProj matrix, v5 is the diffuse color. Ok on to my few questions. 1) Now the first thing im confused about is the c4 to c7 thing. This holds the transpose of the product of the world, view and projection matricies according to MS''s code. Is the WorldViewProj matrix the "modelview" matrix in OpenGL? 2) I noticed before MS set the c4 to c7 registers w/ the WorldViewProj matrix, they did a transpose. Why did they do that? 3) Ok now they do 4, 4 component dot products between the position (v0) and c4 to c7. Why are they doing a dot product? And why is like say the x pos getting the dot prod between v0 and c4, y between v0 and c5, and so on? I think i probably need to get the book called "Mathematics for Computer Graphics Applications." Because its the math im rusy on. -SirKnight
sjelkjd
sjelkjd
Well, haven't done much with vertex shaders but i bet i can figure this out.

quote:
Original post by SirKnight

I have a question about vertex shaders. Here is a sample shader.

vs.1.0
dp4 oPos.x , v0 , c4
dp4 oPos.y , v0 , c5
dp4 oPos.z , v0 , c6
dp4 oPos.w , v0 , c7
mov oD0 , v5

Ok in this case c4 to c7 holds WorldViewProj matrix, v5 is the diffuse color. Ok on to my few questions.

1) Now the first thing im confused about is the c4 to c7 thing. This holds the transpose of the product of the world, view and projection matricies according to MS's code. Is the WorldViewProj matrix the "modelview" matrix in OpenGL?


Almost - I'm guessing WorldViewProj is the concatenation of the MODELVIEW and the PROJECTION matrices. That way you could multiply the vertex and this matrix to transform it from object space into screen space(standard transform pipeline).

quote:

2) I noticed before MS set the c4 to c7 registers w/ the WorldViewProj matrix, they did a transpose. Why did they do that?


Dx and GL store matrices in column major. THis puts it in row major form.
quote:

3) Ok now they do 4, 4 component dot products between the position (v0) and c4 to c7. Why are they doing a dot product? And why is like say the x pos getting the dot prod between v0 and c4, y between v0 and c5, and so on?


They are transforming the vertex by doing a matrix multiplication. Matrix multiplication is essentially four dot products, if the matrix is in row-major form.
Apparently this is a standard transform mapping the object into screen space
quote:

I think i probably need to get the book called "Mathematics for Computer Graphics Applications." Because its the math im rusy on.

-SirKnight


I'd recommend "Computer Graphics Principles and Practice" by Foley and van Dam.


Edited by - sjelkjd on April 7, 2001 1:03:47 AM
SirKnight
SirKnight
Thanks, i understand now. I have heard good things about that foley book you mentioned, i think ill get that. At first i didnt understand why they needed to change the matrix into row major form at first. But then when you said, that matrix multiplication is pretty much a 4 component DP if in row mojor form it clicked. Now this makes sence. Cool!

-SirKnight
SirKnight
SirKnight
Welp, i just ordered "Computer Graphics Principles and Practice" by Foley and van dam. Hope it comes in soon.

-SirKnight
sjelkjd
sjelkjd
quote:
Original post by SirKnight

Thanks, i understand now. I have heard good things about that foley book you mentioned, i think ill get that. At first i didnt understand why they needed to change the matrix into row major form at first. But then when you said, that matrix multiplication is pretty much a 4 component DP if in row mojor form it clicked. Now this makes sence. Cool!

-SirKnight

good stuff =)



Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.