Jump to content
  • Advertisement
Sign in to follow this  
whathappened

Pass a matrix to a vertex shader (Cg)

This topic is 4057 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

Im playing around with Cg, and I need to separate the "world-transform" from the camera-transform. I thougt I could do this by only applying the world-transform to the vertices in my C++-code, and then send the camera-transform as a separate parameter to the vertex shader and do the multiplying there. Is this a good way to do it? And if I want to send a transform (or a arbitrary matrix) to the shader, how can I do this? I got something like this struct appdata { float4 position : POSITION; float4 color : COLOR0; float4x4 matr : COLOR1; }; And in my C++ code, I have a float matrix. But how do I pass it? (I mean I cant use the cgGLSetParameter3f or cgGLSetParameter4f).

Share this post


Link to post
Share on other sites
Advertisement
I think you would use:


void cgGLSetStateMatrixParameter(CGparameter param,
GLenum matrix,
GLenum transform);



/Edit: Theres a Nehe tutorial that sets the modelview matrix here

Share this post


Link to post
Share on other sites
Thanks!

Since OpenGL doesn't separate the model transformations and the camera transformation, should I do something like this?

glLoadIdentity();
// Make camera transformations
// ...
cgGLSetStateMatrixParameter(viewMatrix, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);

// For every object, make model(world) transformations and run
cgGLSetStateMatrixParameter(modelMatrix, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);


[Edited by - whathappened on August 11, 2007 7:06:34 PM]

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!