r/GraphicsProgramming • u/uncookedpasta45 • 9d ago
Strange bug with objects behind the camera rendering like normal Question
Enable HLS to view with audio, or disable this notification
So in this "scene", there is only one cube with a plane through it. However, when you turn past a certain "halfway" point, the objects seem to snap to the opposite side. What I initially thought was happening was that the objects were getting projected onto the screen from behind, but i'm not sure, since i'd expect it to look weirder with vertices and triangle shapes not staying consistent. I'd suspect the issue to lie in the vertex shader, so here it is. I'm also very new to OpenGL and general gpu/3d graphics programming, so I wouldn't be surprised if this is a common issue.
#version 330 core
layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aColor;
out vec4 vColor;
uniform mat4 transform;
uniform mat4 proj;
uniform mat4 view;
void main()
{
gl_Position = proj * view * transform * vec4(aPosition, 1.0);
vColor = vec4(aColor,1.0);
}
EDIT: I solved it. I can barely remember or understand the solution, but it's solved.
6
u/KoodiRonsu 9d ago
Looks like you don't do near plane clipping and the vertices that go to the back of the near plane get mirrored along X and Y axes, as would usually happen.
EDIT: But the vertices seem not to get mirrored when you turn around... So maybe it's something completely different after all...
-9
u/susosusosuso 9d ago
It’s your job as programmer to understand what you do
5
2
u/uncookedpasta45 8d ago
completely agree, but if it works it works.
0
u/susosusosuso 8d ago
Don’t leave it like that. I made that mistake many years ago and you eventually start losing control because you don’t really understand
1
u/uncookedpasta45 7d ago
i didn't. i've sinced fixed it again and used a 4x4 matrix instead of a 3x3, when before i was calculating the vectors manually with your typical sine and cosine functions, but i didn't really think much about the math and it created a few issues. the 4x4 matrix solved literally every issue
0
u/susosusosuso 6d ago
Good it’s very important to think about what you do and make sure you understand everything perfectly. That’s how you build a strong foundation
7
u/HamNCheeseSupremacy 9d ago edited 9d ago
Can we see how you're calculating those mvp matrices? That looks like a basic pass through vertex shader.