summaryrefslogtreecommitdiffstats
path: root/core/math
diff options
context:
space:
mode:
authorKhasehemwy <BuluyuAzir@foxmail.com>2024-02-14 21:39:39 +0800
committerRémi Verschelde <rverschelde@gmail.com>2024-04-04 13:54:15 +0200
commitd950f5f83819240771aebb602bfdd4875363edce (patch)
treefa56b4e343184fd0bed91fa86242d624b2fbab66 /core/math
parentf47f4a02c87bb701452a621d254ad30c7be84faa (diff)
downloadredot-engine-d950f5f83819240771aebb602bfdd4875363edce.tar.gz
Use Reverse Z for the depth buffer
Diffstat (limited to 'core/math')
-rw-r--r--core/math/projection.cpp7
-rw-r--r--core/math/projection.h2
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);