Jump to content
  • Advertisement
Sign in to follow this  
KarimIO

GLSL: Incorrect WorldPosition

This topic is 687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

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;
...
}

 

Share this post


Link to post
Share on other sites
Advertisement

Im not sure what "matTotal" is or how youre building it, is "matTotal" the combined world * view * proj matrix? if it is you might be transforming object space verts (vertexPos) into world (WorldPos) and then transforming world space pos "WorldPos" by world again, as part of the world view proj matrix "matTotal".

"matTotal" is an odd name, might wanna name it what it is, MVP or VP.

Share this post


Link to post
Share on other sites

Im not sure what "matTotal" is or how youre building it, is "matTotal" the combined world * view * proj matrix? if it is you might be transforming object space verts (vertexPos) into world (WorldPos) and then transforming world space pos "WorldPos" by world again, as part of the world view proj matrix "matTotal".

"matTotal" is an odd name, might wanna name it what it is, MVP or VP.

Sorry for the confusion. matTotal is VP (It's called total because it used to be MVP before I started working on animation, and I never got around to changing it). 

 

Anyways, if you look at the picture, the actual vertex positions are fine. It's MVP-multiplied. The issue is with the World-Space Position. On one object, it's at an estimated 10x the scale, for an unknown reason.

Share this post


Link to post
Share on other sites

On one object, it's at an estimated 10x the scale, for an unknown reason.

 

Due to the scale maybe ?

 

Model = glm::scale(Model, getScale());

Share this post


Link to post
Share on other sites

OMG nevermind. I messed up, it actually was MVP. This is legit so embarrassing haha sorry for wasting your time, and thanks for the answers anyways.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!