Jump to content
  • Advertisement
Sign in to follow this  
billconan

OpenGL problem with passing matrix to glsl

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

hello guys,

i'm trying to debug a problem i met while implementing the shadow map method.

i first render the scene from the light source. and save the depth map onto a texture.
and then, i write a second pass, use the modelview matrix and the projection matrix from the first pass to find the texture coordinate of a vertex on the shadow map.

the problem is that i cannot pass the matrices from the first pass to the glsl shader of the second pass properly.

i striped down my program and did some simple tests:

here is the vertex shader:


void main()

{
gl_Position=ftransform();
}




now if i set the modelview and projection matrix with gluPerspective and gluLookAt, everything renders fine.
i can also change the ftransform to gl_ProjectionMatrix*gl_ModelViewMatrix*gl_Vertex; , everything is still working.

however, if i pass the modelview matrix and projection matrix to two uniform mat4 variables i defined in the shader, then the rendering becomes wrong, i can't see anything.



uniform mat4 modelview;
uniform mat4 projection;

void main()
{
gl_Position=projection*modelview*gl_Vertex;
}




i'm sure that the uniform location ids are all valid. they are 1 and 0 in my program.

and this is how i get the two matrices inside my c++ program and pass them to the shader:


glUseProgram(secondpass);



glGetFloatv(GL_MODELVIEW_MATRIX,tmodelview);
glGetFloatv(GL_PROJECTION_MATRIX,tprojection);

glUniformMatrix4fv(modelviewUniform,1,GL_FALSE,tmodelview);
glUniformMatrix4fv(projectionUniform,1,GL_FALSE,tprojection);




mellow.gif

my self-defined matrices should have the same values as those in the gl_ProjectionMatrix and the gl_ModelViewMatrix, because i just acquired them from the opengl context before passing them to the shader.

I am working under ubuntu 10.10 with nvidia 8800GTX. I have stuck on this for two days, can't figure out why.

thank you for your help.

Share this post


Link to post
Share on other sites
Advertisement
I cannot see anything incorrect that you are doing, so you're either doing something wrong that you're not showing, you've got some kind of driver bug, or I'm somehow missing something obvious.

I'd suggest trying to do some kind of debugging inside the shader to see what kind of values are contained in your matrix. Maybe you can draw 16 screen aligned quads in a 4x4 grid, and let the color of each quad be the value of the matrix at modelview[x][y]. Or you can try coming up with other kinds of ways to output debug information from the shader.

You can also post a larger code sample if you want containing everything, though I'm not sure what else is there to see that's relevant.

Share this post


Link to post
Share on other sites
are you calling a glLoadIdentity after the first pass because that would reset the modelview matrix?

check the the data for the modelview data.
make sure the object shows up correctly with a simple fragment shader (If you are using a fragment shader to determine the shadows)

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!