dimforge / dimforge/nalgebra

Perspective matrix for Vulkan

Open
#1,222 1 comment 1 reaction 0 assignees View on GitHub
enhancement nalgebra-glm
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

I'm using nalgebra-glm to do some work with the Vulkan API through Vulkano. The perspective matrix generated by `perspective_rh_zo` flips the Z axis in the wrong direction. I chose this function since Vulkan operates with a right handed coordinate system and the Z axis goes from 0 to 1 rather than -1 to 1.

According to these two posts:
[Why projection matrices typically used with OpenGL fail with Vulkan](https://johannesugb.github.io/gpu-programming/why-do-opengl-proj-matrices-fail-in-vulkan/)
[Setting Up a Proper Projection Matrix for Vulkan](https://johannesugb.github.io/gpu-programming/setting-up-a-proper-vulkan-projection-matrix/)

Following the math from the second post shows all that needs to change to create a 'proper' Vulkan perspective matrix is change:
```rust
//matrix_clip_space.rs
//pub fn perspective_rh_zo
mat[(0, 0)] = one / (aspect * tan_half_fovy);
```
to
```rust
mat[(0, 0)] = aspect / tan_half_fovy;
```

I'm not sure if a new function should be added or if the existing one should be changed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.