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

(wip) feat: Instancer LOD #604

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

laurentsenta
Copy link

@laurentsenta laurentsenta commented Jan 25, 2025

Introduce four levels of LODs for multimesh instance

See thread in Discord

Task list:

  • Decide on using an array or hardcoded floats for the distances
  • Actually use the LOD'd mesh in the instancer
  • Shadow LOD
  • figure out the visibility margin thingy
  • Fix the "everything resets on loading" issue
  • Remove visibility range, and figure out upgrade path
  • Field validation
  • Update
  • Cleanup
  • Shadow min / max config
  • Field validation (bis)
  • Update the doc
  • Also update the notes on "in the future we'll chunk MMIs" this is already implemented

CleanShot 2025-01-25 at 19 36 50

Regarding validation:

This PR introduces a bunch of fields that are related to each other:

  • maximum lod value is valid if the scene is loaded and must be less than mesh count
  • maximum shadow lod is valid if <= maximum lod and >= minimum shadow lod (and vice versa for minimum shadow lod)
  • Cast Shadows validity depends on the shadow lods:
    • if cast shadow is double-sided or shadows only, it will interact weirdly with min/max shadow lods

Checking values in the setters will be super annoying to use, as in "I'm trying to lower the maximum lod, but nothing happens" > "yes, you need to lower the minimum shadow lod first".

This is a perfect use case for configuration warning, which is a work in progress:

@laurentsenta laurentsenta marked this pull request as draft January 25, 2025 16:44
@laurentsenta laurentsenta force-pushed the feat/instancer-lod branch 3 times, most recently from 4f7b76b to 43ff44e Compare January 25, 2025 18:31
// Saved data
real_t _height_offset = 0.f;
real_t _visibility_range = 100.f;
real_t _visibility_range = 100.f; // TODO: drop and discuss storage migration
Copy link
Author

@laurentsenta laurentsenta Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need maintainer input: should we deal with the upgrade from visibility_range to _lod_visibility_ranges[0]? how?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

  • Leave the old variable.

  • Change the setter to call the new setter.

  • Move both to the bottom of the file headed with a comment: //DEPRECATED 1.0 - Remove 1.1

  • Remove the getter.

  • _bind_methods(): Move the bound variables/functions to the bottom and add the comment.

  • _bind_methods(): change the property usage to no_editor so it doesn't show in the inspector, eg.
    ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "region_offsets", PROPERTY_HINT_ARRAY_TYPE, vformat("%tex_size/%tex_size:%tex_size", Variant::VECTOR2, PROPERTY_HINT_NONE), PROPERTY_USAGE_NO_EDITOR), "set_region_offsets", "get_region_offsets");

  • In the XML docs note it is deprecated and to see the new function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 33a46e3

_shadow_lod = CLAMP(p_lod, 0, get_maximum_lod());
LOG(INFO, "Setting shadow LOD: ", _shadow_lod);
emit_signal("instancer_setting_changed");
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need maintainer input: every time I reopen the project, the maximum lod and shadow lod values are reset to -1,
I think this is because the mesh is not loaded when the editor tries to set the instance's value.

If you change the values and then close and reopen the scene, that'll work.

Is there an idiomatic way to avoid this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Godot loads the scene file it loads all settings from the scene file. You don't really know which one it will load first. If this is loaded before the scene, get_mesh_count() will be zero, which sets your _maximum_lod = -1.

If packed_scene.is_null() then you shouldn't check get_mesh_count() and accept the value as it is. It won't be used while the scene is null.

When packed_scene is loaded, you can verify that maximum_lod is valid. Same w/ shadow lod.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fcaccb9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants