• 12
• 12
• 9
• 10
• 13

# ModelViewProj Matrix Problem

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

## Recommended Posts


// This is calulated elswhere and then sent to the shader:
mtxModelView = mtxView * mtxModel
mtxModelViewProj = mtxProjection * mtxModelView

// I then send said matrix to the vert shader:
paramModelViewProj = cgGetNamedParameter(vertProgram, "ModelViewProj");
cgSetMatrixParameterfr(paramModelViewProj, mtxModelViewProj.matrix);

// Then, in my shader I'm using it like this:
uniform float4x4 ModelViewProj
...
oPosition =  mul(ModelViewProj, iPosition);


...yet I get nothing. As I say, if I load the modelview and projection matrices into OGl and use the state.matrix.mvp in the shader it works fine. Any ideas?

##### Share on other sites
Are your matrices column-major or row major? Does the CG function expect them in your layout of choice?

##### Share on other sites
I've had issues with this before. Ensure that your calls to cg are in order. "updating program parameters" at the right time. I also agree with the guy above make sure the matrices are of the correct order but i assume they are.

i use multmatrix as well, but not load matrix, i start with the identity and mult the view followed by my objects matrices. Then i use the state parameters like you said, they seem to make the most sense to me.

good luck.

-Joe

##### Share on other sites
Hi, thanks for the responses. Here's my rendering/CG code I'm using:

// Vert shadercgGLEnableProfile(CG_PROFILE_ARBVP1);cgGLBindProgram(vertProgram);// Frag shadercgGLEnableProfile(CG_PROFILE_ARBFP1);cgGLBindProgram(fragProgram);// Diffuse textureglActiveTextureARB(GL_TEXTURE0);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, texBase);		SMatrix4x4 mtxView = *sceneCam.ModelView();		SMatrix4x4 mtxModel = pMesh->mtxInvModelView;		SMatrix4x4 mtxModelView = mtxView * mtxModel;		SMatrix4x4 mtxProjection = *sceneCam.Projection();		SMatrix4x4 mtxMVP = mtxProjection * mtxModelView;                // Vert MVP matrix		paramModelViewProj = cgGetNamedParameter(vertProgram, "ModelViewProj"); 		cgSetMatrixParameterfr(paramModelViewProj, mtxMVP.matrix);		// Frag eye position (object space)		paramObjEyePos = cgGetNamedParameter(fragProgram, "objEyePos");		cgSetParameter3f(paramObjEyePos, v3dObjEyePos.x, v3dObjEyePos.y, v3dObjEyePos.z);				// I don't normally call this but I am doing so as I see it in the CG example code. I've tried commenting it out to no avail		cgUpdateProgramParameters(vertProgram);		cgUpdateProgramParameters(fragProgram);		pMesh->Draw();// Disable texture stagesglActiveTextureARB(GL_TEXTURE0);glDisable(GL_TEXTURE_2D);// Disable shaderscgGLDisableProfile(CG_PROFILE_ARBFP1);cgGLDisableProfile(CG_PROFILE_ARBVP1);

I've also tried getting the ModelView and Proj matrices using glGetFloatv but the result is the same. I also tried transposing the MVP matrix but again, no luck. Here's my simple shader code (vert):

void main(in float4  iPosition				: ATTR0,		  in float4  iTangent				: ATTR1,		  in float4  iBiNormal				: ATTR2,		  in float4  iNormal				: ATTR3,		  in float4  iColour				: ATTR4,		  in float2  iTexCoord0				: ATTR5,		  in float2  iTexCoord1				: ATTR6,		  in float4  iCustomData			: ATTR7,		  out float4 oPosition				: POSITION,			// Translated and projected vertex position			  out float3 oVertex				: TEXCOORD0,		// Vertex (object space)		  out float3 oNormal				: TEXCOORD1,		// Normal (object space)		  uniform float4x4 ModelViewProj)// : state.matrix.mvp)	// ModelViewProjection matrix		{	// Transform and project the vertex	oPosition =  mul(ModelViewProj, iPosition);	oVertex = iPosition.xyz;	oNormal = iNormal.xyz;}

I'm pretty stumped now so any info would be much appreciated.

##### Share on other sites
this is going to sound weird, but maybe try a different and more advanced profile, i know that when i tried different profiles i got different results.

Also, what happens with your code?

does it just show a black screen? or do you get triangle soup?
also, i dont have my code with me to post but if you look in the sdk there is a getCGError function that is called after a lot of the api calls, maybe that could give you some more clues.

EDIT::: It has been a while so you'll have to forgive me, but i use the state parameters as well. I used to use hand rolled and ended up moving. Just curious, if your matrix stack is correct you should be getting the exact same thing. maybe do a getfloatv and get the contents of the pipe and output them.

[Edited by - AverageJoeSSU on April 2, 2010 12:51:45 PM]