Understanding => gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex

Hello everyone!!
This is my first post, concerning shaders…!!

After studying linear algebra, I am trying to understand how the matrix operations are implemented in the shaders’ “gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex” line of code, so that I know where I’m standing in terms of vertex values/positions, and what freedoms do I have if I start playing with each one of them separately

My understanding, so far:

Absolute position of vertex in 3d Space??
If there’s an ofBox, for example, will gl_Vertex for the 6 vertices be relative to the box, or still to the world.

The name throws me off a little bit.
Is this the vertex in cameraSpace?

So that if:
gl_Vertex.x = 100
cam.x = -100
then the vertex final position.x = 200 (aprox).

Camera-wise vanishing-point (or orthogonal) deformation.
In the shader, When I try: gl_ProjectionMatrix + vec4(0, 0, zValue, 0), it quickly goes off screen or off clipping. Maybe playing around at these stage of operations is just weird!! jaja!

I appreciate your help…!!
Please, let me know if I should clarify or rePhrase something.


1 Like
  • gl_Vertex or just position if you are using gl 3+ is the position of the vertex relative to it’s model, not in world coordinates yet

  • gl_ModelViewMatrix combines two things which if you use gl 3+ can be used separately, modelMatrix and viewMatrix but also modelViewMatrix.

  • modelMatrix transforms the vertex to world space so modelMatrix * position applies any transformation to the model, like ofTranslate, ofScale but also if you use an ofNode for example

  • viewMatrix is the inverse of the model matrix of the camera and as you well guessed transforms from world space into camera space.

  • finally gl_ProjectionMatrix or projectionMatrix if you are using gl 3+ is the matrix equivalent to the camera lens, it defines how the point is projected from camera space to 2d


This is really helpful, Arturo…!!
I will work with this!


1 Like