Jump to content

  • Log In with Google      Sign In   
  • Create Account

Beginner Shader Problems or Misunderstandings..


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 PandaDragonThing   Members   -  Reputation: 311

Like
0Likes
Like

Posted 14 September 2013 - 10:55 AM

I am trying to be compliant with more the more up to date OpenGL profile such as not using glRotate, glTranslate, or glScale and instead doing all of that through shaders and managing my own matrixes.

 

I'm getting weird behavior like rotation is happening at weird angles or my test triangle just completely dissappears. Also with transformation anything higher than 1 will make it dissappear and on the z pos the triangles doesn't even move in depth unless to dissappear.

I'm both new to the math and shader language so I think I made some mistakes.
 

//Handled in my Mesh struct
glm::mat4 mat4T = glm::translate( glm::mat4( 1 ), glm::vec3( m_dPosX, m_dPosY, m_dPosZ ) );
glm::mat4 mat4Rx = glm::rotate( mat4T, (GLfloat)m_dRotX, glm::vec3( 1, 0, 0 ) );
glm::mat4 mat4Ry = glm::rotate( mat4Rx, (GLfloat)m_dRotY, glm::vec3( 0, 1, 0 ) );
glm::mat4 mat4V = glm::rotate( mat4Ry, (GLfloat)m_dRotZ, glm::vec3( 0, 0, 1 ) );
glm::mat4 mat4M = glm::scale( glm::mat4( 1 ), glm::vec3( m_dScale ) );
m_mat4ModelViewMatrix = mat4V * mat4M;

//Handled by my main game class
m_mat4PerspectiveMatrix = glm::perspective( (double)45, (double)iResolutionWidth / (double)iResolutionWidth, (double)1, (double)1000 );

//Done in my drawing loop after using the shader program
glUniformMatrix4fv( glGetUniformLocation( m_uiTestShader, "MVP"), 1, GL_FALSE, glm::value_ptr( m_pTestMesh->m_mat4ModelViewMatrix * m_mat4PerspectiveMatrix ) );

Here's my shader program too:

//Vertex Shader
#version 400
layout( location = 0 ) in vec3 vertex_position;
layout( location = 1 ) in vec3 vertex_color;

out vec3 color;

uniform mat4 MVP;

void main()
{
  color = vertex_color;
  gl_Position = MVP * vec4( vertex_position, 1.0 );
}

//Fragment Shader
#version 400
in vec3 color;
out vec4 frag_color;
void main()
{
  frag_color = vec4( color, 1.0 );
}


Sponsor:

#2 3TATUK2   Members   -  Reputation: 730

Like
1Likes
Like

Posted 14 September 2013 - 02:56 PM

See if it makes any difference multiplying by Perspective first, so Perspective * ModelView



#3 PandaDragonThing   Members   -  Reputation: 311

Like
0Likes
Like

Posted 14 September 2013 - 03:57 PM

Sorry.

Yea that's what I figured out too. It does the trick, but the rotation on the z axis seems to be still messed up. It should be rotating flat to the perspective( like a 2D image ) I believe, but it doesn't maintain it's shape( the points move and scale so the triangle has a constantly changing shape ).



#4 Sponji   Members   -  Reputation: 1355

Like
0Likes
Like

Posted 15 September 2013 - 03:00 AM

Your aspect ratio is wrong, it should be width/height instead of width/width.


Derp

#5 PandaDragonThing   Members   -  Reputation: 311

Like
0Likes
Like

Posted 15 September 2013 - 08:34 PM

Thanks. Stupid messs up on my part and I totally missed it. Fixed it.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS