Link to home
Start Free TrialLog in
Avatar of jochemspek
jochemspekFlag for Netherlands

asked on

not getting the modelviewprojectionmatrix in glsl vertex shader right

Hi there,

I'm having a bit of an issue with uploading my "own" modelviewprojectionmatrix
(mvpm) to a geometryshader. As you can see in attached screendump, my own
code generates the same mvpm as OpenGL, and uploading it to the shader also
works correctly, as I can tell by uploading the matrix with a specific color in the
translation component to the fragment shader and rendering a colored quad.

However, I can't for the life of me seem to get the geometryshader to output
the correct gl_Position. all seems to go to infinity (or somewhere else i can't see)
but only if i use my handrolled mvpm. using gl_ModelViewProjectionMatrix works fine.

this is the shader code:

uniform mat4 modelViewProjectionMatrix;

void main(void){
//      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; // this works
      gl_Position = modelViewProjectionMatrix * gl_Vertex; // this doesn't.
}

I'd much appreciate any insights.

Jochem User generated image
*update1* doing a binary search by hand for where the components of the
matrices diverge, i found that elements[1][2] differ by approx. |2.0|, but i really don't
understand why that would be, let alone what causes it.

if( abs( gl_ModelViewProjectionMatrix[1][2] - modelViewProjectionMatrix[1][2] ) > 2.03125 ){
      gl_Position = vec4( 0.0 );
}

*update2*

it's getting weird, I've now handcoded the mvpm into the shader (ie setting each value
of a mat4) and I get the erroneous result. BUT ALSO, i get the erroneous result with:

      gl_Position = gl_ModelViewMatrix * gl_ProjectionMatrix * gl_Vertex;

but, as stated,

      gl_Position = modelViewProjectionMatrix * gl_Vertex;

works fine. Am I looking at a driver/card bug here ??

J



Avatar of jochemspek
jochemspek
Flag of Netherlands image

ASKER

the problem disappears when I do my modelview transform in the projectionmatrix.

...
  set( PROJECTION, Mat4::fromOrtho( l, r, b, t, m_nearc, m_farc ) );
 }
 else{
  set( PROJECTION, Mat4::fromPerspective( m_fovy * m_zoom, m_aspect, m_nearc, m_farc ) );
 }

 Mat4 m = get( PROJECTION );
 m.lookAt( m_eye, m_center, z );
 set( PROJECTION, m );

or, in OpenGL equivalents:


...
  glMatrixMode( GL_PROJECTION );
  glOrtho( l, r, b, t, m_nearc, m_farc );
 }
 else{
  glMatrixMode( GL_PROJECTION );
  gluPerspective( m_fovy * m_zoom, m_aspect, m_nearc, m_farc );
 }

 glMatrixMode( GL_PROJECTION );
 gluLookAt( m_eye[0], m_eye[1], m_eye[2], m_center[0], m_center[1], m_center[2], z[0], z[1], z[2] );

rather than doing the LookAt in MODELVIEW space, as it should be (shouldn't it ?)

I still don't understand what's going on here, so I keep the question open.

J
ASKER CERTIFIED SOLUTION
Avatar of jochemspek
jochemspek
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial