View Full Version : GLSL: Incorrect WorldPosition

08-30-2016, 10:42 AM
Hi guys! Not a beginner here, but I'm having a beginner problem.

I'm using deferred rendering in my project. I noticed (around 2 months after finishing my basic rendering code, lol) that my outputted WorldPosition is different from how it should be; compare the Altair model with the Crytek Sponza background: Position Space-colored Image Notice how the change to green is more gradual on the character (I'm guessing 10x slower). To clarify, the projected vertices are in the correct position. It's just that the world space positions in the fragment shader seem to be messed up. What could be causing this?


glm::mat4x4 EBaseEntity::getModelMatrix() {
glm::mat4x4 Model = glm::mat4(1);
Model = glm::translate(
Model = glm::scale(Model, getScale());
float maxRot = (glm::max(glm::max(angles.x, angles.y), angles.z));
if (maxRot > 0)
Model = glm::rotate(Model, maxRot, angles / maxRot);

return Model;

Both models are treated the same on the CPU end. Here are main.vs and main.fs, the vertex and fragment shaders.

#version 330
layout(location = 0) in vec3 vertexPos;

uniform mat4 matTotal;
uniform mat4 matModel;

out vec4 WorldPos;

void main () {
WorldPos = matModel * vec4(vertexPos, 1.0);
gl_Position = matTotal * WorldPos;
Fragment Shader:

#version 330

in vec4 WorldPos;

layout(location = 0) out vec4 position;


void main() {
position = WorldPos;

08-31-2016, 06:14 AM
I had a similar problem once because the last row of the model matrix wasn't (0,0,0,1). Check your matrices, or send a 3x4 matrix instead.