Jump to content
  • Advertisement
Sign in to follow this  
tscott1213

OpenGL Shader Register Values

This topic is 5034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, If D3D uses row vectors and openGL uses col vectors, then when D3D transposes its WorldViewProj matrix before setting the shader registers then it is setting the same Matrix as OpenGL (which does not tranpose the matrix before setting the register). However, OpenGl is col-major and D3D is row major. Which means that if registers c0-c3 were set with the WorldViewProj matrix from D3D they would hold the rows of the matrix and if they were set with OpenGL they would hold the cols of the matrix. So, why don't you have to write two versions of the same shader? To clarify, here is my understanding, which I believe to be flawed, but don't understand why it is flawed: An OpenGL translation matrix would be as follows: 1 0 0 tx 0 1 0 ty 0 0 1 tz 0 0 0 1 A D3D translation matrix would be as follows: 1 0 0 0 0 1 0 0 0 0 1 0 tx ty tz 1 So, when you transpose the D3D matrix it becomes the same as the OpenGL matrix. But, D3D is row-major and OpenGL is col-major. So, when you set the registers using D3D each register holds a row but when you set the registers using OpenGL each register holds a column. Therefore, if we set registers c0-c3 they would hold different values for OpenGL and D3D. Thanks for the help. Todd [Edited by - tscott1213 on January 7, 2005 9:20:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
I'm being thick here, because that is still leaving me with a question.

I get that we only transpose if the shader is col-major. My confusion is that if the shader is col-major we still have a problem because D3D uses row vectors and OpenGL uses col vectors (note this is completely independent of the fact that one is row-major and the other col-major). So, when we transpose the D3D matrix we are still setting different values for the registers than when we don't transpose the OpenGL matrix and set the registers.

Thanks for your patience.
I'm sure once I understand this I am going to be embarrassed about this thread!

Todd

Share this post


Link to post
Share on other sites
I think I found where I was going wrong here...


The following comment was made by Joakim Hårsman on FlipCode:

"LHS vs RHS isn't the only difference between D3D and OpenGL that can cause differences. First of all, OpenGL treats vertices as column vectors, so transformations are concatenated by left multiplying: M'=TM, v'=Mv and this causes the typical tranformation matrix to be the transpose of the Direct3D standard. However, since OpenGL treats matrices as they were stored in column major order (vs D3D's row major), everything works out the same anyway (ignoring coord system orientation) provided you're consistent in how you construct the matrix you load into OpenGL/D3D. "

Coder, thanks again for all of your help. As expected, I am now thoroughly embarrassed by this thread!

Todd

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!