mcat
mcat

Reputation: 67

Projection matrix OpenGL/GLSL issue

I have a problem while trying to apply a projection matrix to an object in GLSL.

Here is the GLSL code:

#version 330

layout (location = 0) in vec3 pos;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;

out vec4 originalPos;
out vec4 transformedPos;
out vec4 col;

void main(){

    col = vec4(pos, 1);
    originalPos = (projectionMatrix / transformationMatrix) * vec4(pos, 1);

    vec4 newPos = projectionMatrix * vec4(pos, 1);

    transformedPos = newPos;
    gl_Position = newPos;
}   

It works perfectly fine on Windows: Rendering on Windows

But it's not working on Linux: Rendering on Linux

I know for sure is some kind of problem related to the projection matrix because if I omit the matrix application, it works just fine.

It is the exact same code and shaders.

Using lwjgl and Java.

Upvotes: 0

Views: 262

Answers (2)

mcat
mcat

Reputation: 67

Solution:

It sounds weird, but removing:

originalPos = (projectionMatrix / transformationMatrix) * vec4(pos,1);

and the transformationMatrix, it works completely fine. That code was a test of lightning.

Upvotes: 0

datenwolf
datenwolf

Reputation: 162164

This

originalPos = (projectionMatrix / transformationMatrix) * vec4(pos,1);

Makes no sense, for a vector transformation. The '/' operator, when applied in GLSL to matrices does a component-wide division. What you probably want through is inversion, which is an entirely different operation.

Upvotes: 4

Related Questions