Results 1 to 2 of 2

Thread: GLSL: Incorrect WorldPosition

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2016
    Posts
    3

    GLSL: Incorrect WorldPosition

    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?

    http://i.imgur.com/j73W9sW.png

    Code :
    glm::mat4x4 EBaseEntity::getModelMatrix() {
        glm::mat4x4 Model = glm::mat4(1);
        Model = glm::translate(
            Model,
            position);
        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.

    Code :
    #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:

    Code :
    #version 330
     
    in vec4 WorldPos;
     
    layout(location = 0) out vec4 position;
     
    ...
     
    void main() {
        position = WorldPos;
        ...
    }

  2. #2
    Member Contributor
    Join Date
    Nov 2016
    Posts
    67
    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.

Similar Threads

  1. uint texture data has incorrect values in glsl
    By chisser98 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-21-2018, 01:21 AM
  2. Reflection Ray incorrect
    By JasonRay in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-26-2015, 10:28 AM
  3. glDrawArrays() bug or incorrect use?
    By posixoptions in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-27-2010, 06:29 AM
  4. Incorrect lighting
    By blender in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-14-2004, 10:56 AM
  5. Incorrect timing
    By dew in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-13-2001, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean