Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only apply LOD when camera is outside the AABB of mesh in mobile renderer. #92232

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1879,25 +1879,27 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const
// LOD

if (p_render_data->scene_data->screen_mesh_lod_threshold > 0.0 && mesh_storage->mesh_surface_has_lod(surf->surface)) {
// Get the LOD support points on the mesh AABB.
Vector3 lod_support_min = inst->transformed_aabb.get_support(p_render_data->scene_data->cam_transform.basis.get_column(Vector3::AXIS_Z));
Vector3 lod_support_max = inst->transformed_aabb.get_support(-p_render_data->scene_data->cam_transform.basis.get_column(Vector3::AXIS_Z));

// Get the distances to those points on the AABB from the camera origin.
float distance_min = (float)p_render_data->scene_data->cam_transform.origin.distance_to(lod_support_min);
float distance_max = (float)p_render_data->scene_data->cam_transform.origin.distance_to(lod_support_max);

float distance = 0.0;

if (distance_min * distance_max < 0.0) {
//crossing plane
distance = 0.0;
} else if (distance_min >= 0.0) {
distance = distance_min;
} else if (distance_max <= 0.0) {
distance = -distance_max;
// Check if camera is NOT inside the mesh AABB.
if (!inst->transformed_aabb.has_point(p_render_data->scene_data->cam_transform.origin)) {
// Get the LOD support points on the mesh AABB.
Vector3 lod_support_min = inst->transformed_aabb.get_support(p_render_data->scene_data->cam_transform.basis.get_column(Vector3::AXIS_Z));
Vector3 lod_support_max = inst->transformed_aabb.get_support(-p_render_data->scene_data->cam_transform.basis.get_column(Vector3::AXIS_Z));

// Get the distances to those points on the AABB from the camera origin.
float distance_min = (float)p_render_data->scene_data->cam_transform.origin.distance_to(lod_support_min);
float distance_max = (float)p_render_data->scene_data->cam_transform.origin.distance_to(lod_support_max);

if (distance_min * distance_max < 0.0) {
//crossing plane
distance = 0.0;
} else if (distance_min >= 0.0) {
distance = distance_min;
} else if (distance_max <= 0.0) {
distance = -distance_max;
}
}

if (p_render_data->scene_data->cam_orthogonal) {
distance = 1.0;
}
Expand Down
Loading