From cfd686999e91ddb9039a1ce60b4e47790e5fc89d Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 3 Apr 2023 22:53:19 +0200 Subject: [PATCH] Addition of Near and Far Z-Axis Camera Planes --- .../Utility/utility.gdshaderinc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/ShaderFunction-Extras/Utility/utility.gdshaderinc b/addons/ShaderFunction-Extras/Utility/utility.gdshaderinc index 82ecc81..92f9301 100644 --- a/addons/ShaderFunction-Extras/Utility/utility.gdshaderinc +++ b/addons/ShaderFunction-Extras/Utility/utility.gdshaderinc @@ -137,3 +137,19 @@ vec3 vertex_billboard(vec2 uv, mat4 view_mat, vec3 vertex, float scale) { uv *= scale; return vert + ((vec4(uv, 0.0, 0.0) * view_mat)).xyz; } + +float camera_z_near_plane_vulkan(mat4 proj_mat) { + return abs(proj_mat[3][2] / proj_mat[2][2]); +} + +float camera_z_near_plane_gles(mat4 proj_mat) { + return proj_mat[3][2] / (proj_mat[2][2] - 1.0); +} + +float camera_z_far_plane_vulkan(mat4 proj_mat) { + return abs((proj_mat[3][2] * camera_z_near_plane(mat4 proj_mat)) / (proj_mat[3][2] + camera_z_near_plane(mat4 proj_mat))); +} + +float camera_z_far_plane_gles(mat4 proj_mat) { + return proj_mat[3][2] / (proj_mat[2][2] + 1.0); +} \ No newline at end of file