Hello guys, me again
i am trying to implement shadow-mapping properly for a directional-light (with fitting).
So i first implemented ortho-graphic projection for my camera-class, but here is the weird-thing:
In the LunarG Vulkan-Examples there is this line of code:
// Vulkan clip space has inverted Y and half Z.
clip = Mat4f(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
I did the same thing for my perspective projection and i recognized after a few hours that this is the reason why my orthographic projection doesnt work properly.
I removed this when calculating the orthographic-projection and it works almost as intended.
When i manipulating the zNear/zFar value the clipping is not correct, but the projection matrix is correct.
By the way “depthClampEnable” in the Rasterization-State is set to false.
My question is how vulkan does the clipping and why we need that matrix above? I did not find anything about this in the spec.
That matrix is not strictly speaking necessary. The author probably used it just to make his old (OpenGL) code work. It just converts from [-1,1] to [0,1] space (by z=0.5oldZ + 1) and inverts the y (-1oldY).
Okay, but that doesnt explain why the culling is not correct. I tripple checked the matrices, they should be correct. When i modify zFar it affects somehow the zNear Plane (but does not modify the zNear value), look at the video: - YouTube
But which would be the proper projection matrix for Vulkan?
Instead of picking up a OpenGL projection matrix and transform it afterwards, which would be the proper projection matrix that would do the whole work in a single step?