// 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);
ModelViewProj Matrix Problem
Hi, I'm building my modelview and projection matrices by hand and using state.matrix.mvp in my vert shader to transform the vertices. I'm calculating the projection matrix and using glLoadMatrixf to set the perspective and using glLoadMatrixf/glMultMatrixf along with my calculated ModelView. Everything fine so far. I've made many apps using my base code and I have had no problems.
However, I tried to create a ModelViewProj matrix from my ModelView and Projection matrices and send it to my shader so I can use my hand-rolled ModelViewProj rather than the state.matrix.mvp matrix. I know my matrix code works fine as i've been calculating matrices and inverses for all sorts of effects in various spaces and have had no problem. I know my projection matrix is fine because I've made ortho and perspective matrices for GUI and 3D applications and have had no problems (as i say, I'm loading my proj matrix straight in with no probs). It's just that when I send it to the shader i get nothing :S
I'm using CG and the psuedo-code is something like this:
...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?
Are your matrices column-major or row major? Does the CG function expect them in your layout of choice?
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.
Thats the best answer i can give without more info.
good luck.
-Joe
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.
Thats the best answer i can give without more info.
good luck.
-Joe
Hi, thanks for the responses. Here's my rendering/CG code I'm using:
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):
I'm pretty stumped now so any info would be much appreciated.
// 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.
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement