Sign in to follow this  
whathappened

Pass a matrix to a vertex shader (Cg)

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this