From 76ff41cad154964d3aa7c59d5325e7ba0c63b5cf Mon Sep 17 00:00:00 2001 From: clayjohn Date: Tue, 19 Apr 2022 14:54:51 -0700 Subject: [PATCH] Sort based on camera position when using perspective camera --- servers/visual/visual_server_scene.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index fd1bdc87d82..64443d18ba4 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -3171,7 +3171,11 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca if (((1 << ins->base_type) & VS::INSTANCE_GEOMETRY_MASK) && ins->visible && ins->cast_shadows != VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY) { Vector3 aabb_center = ins->transformed_aabb.position + (ins->transformed_aabb.size * 0.5); - ins->depth = near_plane.distance_to(aabb_center); + if (p_cam_orthogonal) { + ins->depth = near_plane.distance_to(aabb_center); + } else { + ins->depth = p_cam_transform.origin.distance_to(aabb_center); + } ins->depth_layer = CLAMP(int(ins->depth * 16 / z_far), 0, 15); } }