diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-04 14:30:53 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-04 14:30:53 +0200 |
| commit | 69a4ff899618cc40bcf5aed2130d4cb2e3c021d6 (patch) | |
| tree | 97c2eab59e52b251c83263a98322b1fa25285ab0 /core/math | |
| parent | a1ab28701079652cfd5acdb2fcb26294eac349ea (diff) | |
| parent | d950f5f83819240771aebb602bfdd4875363edce (diff) | |
| download | redot-engine-69a4ff899618cc40bcf5aed2130d4cb2e3c021d6.tar.gz | |
Merge pull request #88328 from Khasehemwy/reversed-z
Use Reverse Z for the depth buffer
Diffstat (limited to 'core/math')
| -rw-r--r-- | core/math/projection.cpp | 7 | ||||
| -rw-r--r-- | core/math/projection.h | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/core/math/projection.cpp b/core/math/projection.cpp index 9d5dc8b4d6..d3cf11f91a 100644 --- a/core/math/projection.cpp +++ b/core/math/projection.cpp @@ -719,7 +719,8 @@ Projection Projection::operator*(const Projection &p_matrix) const { return new_matrix; } -void Projection::set_depth_correction(bool p_flip_y) { +void Projection::set_depth_correction(bool p_flip_y, bool p_reverse_z, bool p_remap_z) { + // p_remap_z is used to convert from OpenGL-style clip space (-1 - 1) to Vulkan style (0 - 1). real_t *m = &columns[0][0]; m[0] = 1; @@ -732,11 +733,11 @@ void Projection::set_depth_correction(bool p_flip_y) { m[7] = 0.0; m[8] = 0.0; m[9] = 0.0; - m[10] = 0.5; + m[10] = p_remap_z ? (p_reverse_z ? -0.5 : 0.5) : (p_reverse_z ? -1.0 : 1.0); m[11] = 0.0; m[12] = 0.0; m[13] = 0.0; - m[14] = 0.5; + m[14] = p_remap_z ? 0.5 : 0.0; m[15] = 1.0; } diff --git a/core/math/projection.h b/core/math/projection.h index b98f636344..7bba9b337e 100644 --- a/core/math/projection.h +++ b/core/math/projection.h @@ -69,7 +69,7 @@ struct _NO_DISCARD_ Projection { void set_identity(); void set_zero(); void set_light_bias(); - void set_depth_correction(bool p_flip_y = true); + void set_depth_correction(bool p_flip_y = true, bool p_reverse_z = true, bool p_remap_z = true); void set_light_atlas_rect(const Rect2 &p_rect); void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false); |
