Przeglądaj źródła

Calculate instance depth after shadow calculation in VisualServer

(cherry picked from commit 096417905b7fc2dcf0c18eeed9b46f61c4258749)
Cory Petkovsek 4 lat temu
rodzic
commit
4204c02fd1
1 zmienionych plików z 11 dodań i 3 usunięć
  1. 11 3
      servers/visual/visual_server_scene.cpp

+ 11 - 3
servers/visual/visual_server_scene.cpp

@@ -2189,9 +2189,6 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca
 
 				geom->gi_probes_dirty = false;
 			}
-			Vector3 aabb_center = ins->transformed_aabb.position + (ins->transformed_aabb.size * 0.5);
-			ins->depth = near_plane.distance_to(aabb_center);
-			ins->depth_layer = CLAMP(int(ins->depth * 16 / z_far), 0, 15);
 		}
 
 		if (!keep) {
@@ -2346,6 +2343,17 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca
 			}
 		}
 	}
+
+	// Calculate instance->depth from the camera, after shadow calculation has stopped overwriting instance->depth
+	for (int i = 0; i < instance_cull_count; i++) {
+		Instance *ins = instance_cull_result[i];
+
+		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);
+			ins->depth_layer = CLAMP(int(ins->depth * 16 / z_far), 0, 15);
+		}
+	}
 }
 
 void VisualServerScene::_render_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {