ofGetCurrentMatrix unexpected behaviour


#1

Hello, I want to interpolate 2 matrices to create a camera effect.

As first thing, I have created a geometry and a vertex and fragment shader. If i use this vertex shader, everything works as expected.

#version 150

//uniforms from OF
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 modelViewProjectionMatrix;

// my custom camera uniform:
uniform mat4 projMatrix;

in vec4 position;
in vec4 normal;
in vec2 texcoord;

out vec2 vTexCoord;
out vec3 vNormal;
out vec3 vPos;

void main() {
    vTexCoord = texcoord;
    vNormal = normal;

    //vPos = modelViewProjectionMatrix * position;
    vPos = projectionMatrix * viewMatrix * modelMatrix * position;
    gl_Position = position;
}

But if I set a uniform called projMatrix, and i use it instead projectionMatrix,

vPos = projMatrix * viewMatrix * modelMatrix * position;

I do not see my colors anymore.

I am setting the uniform projMatrix like this:

shader.setUniformMatrix4f("projMatrix", ofGetCurrentMatrix(OF_MATRIX_PROJECTION));

Is it not ofGetCurrentMatrix supposed to give me back the current projection matrix from the camera?


#2

It looks like the problem is in the texcoord uniform, that from the vertex shader I pass to the fragment shader.

If I use the uniforms that comes by default from openFrameworks, meaning:

vPos = projectionMatrix * viewMatrix * modelMatrix * position;

And in the fragment shader i output the color like this:

vec3 texColor = texture(tex0, vTexCoord).xyz;

It works, I can see the geometry with my colors.

But if I change the gl_Position value as explained in the first post:

vPos = projMatrix * viewMatrix * modelMatrix * position;

I can not see the color from the texture anymore.


#3

This should be only true if you are making this call within the camera’s begin() and end().
Also, as I see you are using the programable renderer and you should get in the shader’s projectionMatrix the current cameras projection matrix.
Can you post the whole test code you are using, including the shaders and c++ code?


#4

Thanks for your reply Roy. Yes as I have said I am getting the projectionMatrix and it is working, what I want to do is to pass as a uniform another matrix, that is the interpolation between the easyCam and an orthographic cam using some easing function. I am using ofGetCurrentMatrix to see if what I am getting from this function is the same as what I receive from the projectionMatrix uniform.

The application it is huge, I will make a small example first and then I will post it here.


#5

Hi, I see.
I think I’ve done what you mention but I cant recall how.
I can take a look later.
cheers.


#6

Hello Roy, it is working when loading a texture from the image. Problems arises when I try to use a texture that is generated in a FBO that is in another windows. At the moment I do not have an easy way to make a simple debugging application for this special case, but writing the “simple-case” scenario helped me to narrow down what is going wrong. thanks :wink: