godot icon indicating copy to clipboard operation
godot copied to clipboard

Fix unintended frustum culling

Open feng716 opened this issue 1 year ago • 1 comments

When view some models in scene import settings dialog, the subviewport will have some unintended frustum culling. image

Adding a custom aabb for the preview fix this bug.

image

feng716 avatar Jul 26 '24 03:07 feng716

The frustum culling fix is queued to be reviewed in 4.4.

fire avatar Jul 29 '24 00:07 fire

This makes sense as a temporary solution, but I don't know why frustum culling would break in the first place. Is this because skinned meshes skip generating an AABB before being imported for some reason? I thought the advanced import settings dialog already imported the mesh once, with the AABB being set at import-time as an optimization (so it doesn't need to be generated by RenderingServer every frame).

PS: I think we have a dedicated RenderingServer method to disable frustum culling for a specific node entirely, or do we? This would be more reliable than using a large magic number.

Calinou avatar Jul 30 '24 06:07 Calinou

@Calinou I've seen this. The AABB on skinned meshes seems wrong until the first update skeleton (e.g. if you rotate a bone and then undo). This could be the bug.

I wonder if this is a rendering server bug since I'm not sure how the AABB can get desynced, or as a hack, if there is a way to manually force an update on all skeletons during import or upon loading a scn

lyuma avatar Jul 30 '24 09:07 lyuma

This makes sense as a temporary solution, but I don't know why frustum culling would break in the first place. Is this because skinned meshes skip generating an AABB before being imported for some reason? I thought the advanced import settings dialog already imported the mesh once, with the AABB being set at import-time as an optimization (so it doesn't need to be generated by RenderingServer every frame).

PS: I think we have a dedicated RenderingServer method to disable frustum culling for a specific node entirely, or do we? This would be more reliable than using a large magic number.

I dont think this is a problem of AABB. Initially I thought this was a problem of AABB but later I add

    auto show_aabb = [=](AABB aabb){
        MeshInstance3D* a = memnew(MeshInstance3D);
        auto box = memnew(BoxMesh);
        box->set_size(aabb.get_size());
        a->set_mesh(box);
        a->set_global_position(aabb.get_position()+aabb.get_size()/2.);
        a->set_transparency(.5);
        mesh_preview->get_parent()->add_child(a);
    };
    show_aabb(mesh_preview->get_aabb());

before scene_import_settings.cpp line 882 I got this

image

It seems the AABB generation is coreect. There's an error after adding the code node_3d.cpp:345 - Condition "!is_inside_tree()" is true. Returning: Transform3D() from get_position(). If there's better way of debugging the AABB plz let me know.

I think I've found the function for disabling the culling: RenderingServer.instance_set_ignore_culling. I'll make changes to the commit later.

feng716 avatar Jul 30 '24 14:07 feng716

@Calinou I've seen this. The AABB on skinned meshes seems wrong until the first update skeleton (e.g. if you rotate a bone and then undo). This could be the bug.

I wonder if this is a rendering server bug since I'm not sure how the AABB can get desynced, or as a hack, if there is a way to manually force an update on all skeletons during import or upon loading a scn

Can you give me a way of editing the bones in this dialog? This bug only happens in this dialog. If I place this model into the scene, it works well.

feng716 avatar Jul 30 '24 14:07 feng716

This bug still exists in this commit. any update?

feng716 avatar Sep 25 '24 10:09 feng716

I don't think this is the correct fix. We need to figure why the mesh is getting incorrectly culled and then resolve the problem at the source instead of simply disabling culling.

In general, we don't merge PRs until we are happy that they are the correct fix for a problem

clayjohn avatar Sep 25 '24 16:09 clayjohn

hmm... thanks for your reply. i will try to fix it myself.

feng716 avatar Sep 26 '24 11:09 feng716