-
Notifications
You must be signed in to change notification settings - Fork 194
Description
Hello! I got very confused choosing the proper Mat4::perspective_* function. I think they could be documented a lot better. In particular, listing from what coordinate system they are mapping from, and into what coordinate system they are mapping into.
I've now done the research, and the transformations are:
perspective_rh_gl: X+ right, Y+ up, Z+ out of screen -> X+ right [-1, 1], Y+ up [-1, 1], Z+ into screen [-1, 1]
perspective_rh: X+ right, Y+ up, Z+ out of screen -> X+ right [-1, 1], Y+ up [-1, 1], Z+ into screen [0, 1]
perspective_lh: X+ right, Y+ up, Z+ into screen -> X+ right [-1, 1], Y+ up [-1, 1], Z+ into screen [0, 1]
Where OpenGL uses Z+ into screen [-1, 1], Metal/DirectX/WebGPU use Z+ into screen [0, 1] and Vulkan uses Y+ down, Z+ into screen [0, 1].
The same issue applies to orthographic projections.
I propose the following to avoid breaking changes:
- Add
perspective_rh_vkandorthographic_rh_vkfunctions, that map fromX+ right, Y+ up, Z+ out of screentoY+ down, Z+ into screen [0, 1](what Vulkan expects). - Document all of the projection functions with their corresponding modelview-coordinate-system -> graphics-api pairs.
perspective_rh_gl:Z+ out of screen-> GLperspective_rh_vk:Z+ out of screen-> VKperspective_rh:Z+ out of screen-> Metal/DX/WGPUperspective_lh:Z+ into screen-> Metal/DX/WGPU- Corresponding
orthographicfunctions.
- Further document the
perspective_infiniteandperspective_infinite_reverse.
There would be no Z+ into screen -> VK, just like currently there is no Z+ into screen -> GL. Maybe those two could be added? (perspective_lh_gl, perspective_lh_vk).
Actually, I collected my thoughts while writing this issue and I think I'll write up a PR.