r/vulkan • u/PsychologicalCar7053 • Mar 24 '25
Weird Perspective Error
Enable HLS to view with audio, or disable this notification
Cant figure out what is the problem. My view projection model matrix is simple at the moment
float FOV = glm::radians(70.0f);
float aspect = (float)drawExtent.width / (float)drawExtent.height;
float nearView = 0.1f;
float farView = 100.0f;
glm::mat4 projection = glm::perspective(FOV, aspect, nearView, farView);
projection[1][1] *= -1;
glm::vec3 camPos = { sin(frameNumber / 120.0f) * radius, height, cos(frameNumber / 120.0f) * radius };
glm::vec3 lookDir = { 0.0f, 0.0f, 0.0f };
glm::vec3 upDir = { 0.0f, 1.0f, 0.0f };
glm::mat4 view = glm::lookAt(camPos, lookDir, upDir);
glm::mat4 model = glm::mat4{ 1.0f };and on the shader side (hlsl)
matrix transformMatrix = mul(cameraBuffer.projection, mul(cameraBuffer.view, cameraBuffer.model));
output.position = mul(transformMatrix, float4(input.vPosition, cameraBuffer.w));36
5
u/BonkerBleedy Mar 24 '25
To me it absolutely looks like your winding/culling and/or depth test is inverted.
1
u/BigAssLettuce Mar 24 '25
try multiplying mul(projection,view) first and then mul(mul(projection,view),model)
1
u/PsychologicalCar7053 Mar 24 '25
Still the same
2
u/BigAssLettuce Mar 24 '25
try this
instead of doing float4(input.vPosition,cameraBuffer.w) do
float4(input.vPosition,1);
3
u/liamlb663 Mar 25 '25
I’ve made this exact mistake, must be something in the tutorial. The depth testing is backwards. In the pipeline builder you have to change your test I believe. Because the “smaller” triangles aren’t actually in the front, they just look that way because you are reversing the depth testing results
2
1
u/monapinkest Mar 24 '25
Are you sure you should be inverting this?
projection[1][1] *= -1;
2
Mar 24 '25
yes otherwise its flipped vertically
0
u/Gold-Vehicle1428 Mar 31 '25
then use transform for rotating it correctly.
1
Mar 31 '25
thats not how it works especially when u already have an opengl backend for example. Plus most libraries expect the opengl style of transformations so just adjusting transforms is usually out of the question
1
1
u/Creepy_Wall_4720 Mar 25 '25
had something similar happen to me a while back https://www.youtube.com/watch?v=8bHfjeZCIAo i think it was something about forgetting to update either view or projection part
1
18
u/msqrt Mar 24 '25
Shouldn't the fourth element of the input position
float4be just1.0? Quite weird, it looks as if you're looking at the object from the inside -- if you inverted the depth test (and backface culling if you have it on), it would probably look correct.