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

Implement Instancer LODs #604

Merged
merged 5 commits into from
Feb 17, 2025

Conversation

laurentsenta
Copy link
Contributor

@laurentsenta laurentsenta commented Jan 25, 2025

Admin edit
Fixes #617

  • Adds support for up to 10 LODs to the instancer
  • Adds the ability to hide all instances rendering/show_instances
  • Adds the ability disable MMI generation for individual meshes

Contributes to #43
Introduce four levels of LODs for multimesh instances and min / max shadow lods.

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 4 times, most recently from 43ff44e to 0cc19cf Compare January 25, 2025 18:38
@laurentsenta laurentsenta force-pushed the feat/instancer-lod branch 3 times, most recently from ccdc7ab to 1f2af27 Compare January 26, 2025 09:06
@laurentsenta laurentsenta changed the title (wip) feat: Instancer LOD feat: Instancer LOD Jan 26, 2025
@laurentsenta laurentsenta marked this pull request as ready for review January 26, 2025 22:25
Copy link
Contributor

@Xtarsia Xtarsia left a comment

Choose a reason for hiding this comment

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

Very nice work overall.

Cory will be along asking for a good squash no doubt..

The demo changes can likley be dropped unless you want to spend time tidying them up.

Docs effort is stellar!

@TokisanGames
Copy link
Owner

Cory will be along asking for a good squash no doubt..

It can be squashed down to 3 commits: code, docs, demo changes.

I'll review in a couple of days after Xtarsia is satisfied and I get more progress on my collision commit.

@Saul2022
Copy link

Looking great, just one curiosity, so to add lods, we do it like we usually do with visibility ranges and hlod.

@TokisanGames
Copy link
Owner

@Saul2022 Should be able to setup lods in your mesh scene like this, and that's it. Or adjust defaults if desired.

image

Copy link
Owner

@TokisanGames TokisanGames left a comment

Choose a reason for hiding this comment

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

Alright, very good work on this. Thank you for the effort. Please rebase it as you address the notes.

  • Playing with the options and thinking about the names, I think they can use some adjustments to be clearer. I'd prefer to move away from "higher, lower, minimum, maximum" because lods numbers are a reverse scale, where higher/better is a lower number. The docs say "lods above this...", does "above" mean "larger number / lower detail"? Or "higher detail / lower number"? Does "maximum lod" mean "maximum distance / lowest detail" or "maximum detail / lowest distance"? I think "last" is not only shorter, but more universal in meaning lowest detail, farthest away.

    • maximum_lod means "don't show lods lower than this lod". I think last_lod is a little better. It's also lod_count-1.
    • maximum_shadow_lod means "show shadows for this lod and higher(0) - ie don't show shadows for lods lower than this value". This would be better named last_shadow_lod.
    • minimum_shadow_lod means "use this shadow impostor lod or lower(3) - ie when showing a lod higher(0) than this lod, use this one as its shadow impostor". This would be better named max_shadow_imposter_lod, or max_shadow_lod.
  • If minimum_shadow_lod is > maximum_shadow_lod, the latter doesn't work. Or more clearly, if max_shadow_imposter_lod > last_shadow_lod, then it shows shadows beyond the last_shadow_lod. Given the above descriptions it should not. It should only show shadows for lods up to last_shadow_lod.

  • I actually don't think we need a maximum_shadow_lod. Lights already have a shadow distance. We don't need to cull it ourselves. Having it prevents us from needing to create and store the MMI, but that generation is quick and only on start, and the memory should be shared with my related note elsewhere.

In my specifications here on discord I expressed the need for maximum_lod(last_lod) and shadow_lod. The lods should show shadows at all distances that the user has configured their Lights for, it just may be at a lower level LOD.

  • MeshAsset/Cast Shadows / shadows only doesn't work. Shadows Off does work.

  • MeshAsset set_scene_file doesn't do any filtering or sorting on meshes named LOD0-LOD3. It happens that sometimes the LODS might be out of order for an artist or an engine reason. I would look for all of the mesh instances that end in LOD#, then sort them and use the first 4. If I couldn't find any LODs, then just take the first original 4. Maybe print some messages saying, "found 8 lods, using the first 4." or "Meshes don't end with LOD#, assuming first 4 are LOD0-LOD3".

  • MeshAsset set_scene_file - You could also fix a bug where if they provide a scene with a MeshInstance3D as the root node, it won't use it. Probably because the find_child starts looking at the children and ignores the scene root.

@laurentsenta laurentsenta force-pushed the feat/instancer-lod branch 5 times, most recently from 1a0b6d9 to e6bee91 Compare February 6, 2025 16:35
@TokisanGames
Copy link
Owner

I'll take this over from here. Thanks for all of your efforts.

@TokisanGames
Copy link
Owner

This PR is ready for final testing and code review. After that I'm going to reorder the code and merge it in.

@TokisanGames TokisanGames changed the title feat: Instancer LOD Instancer LODs Feb 13, 2025
@TokisanGames TokisanGames changed the title Instancer LODs Implement Instancer LODs Feb 14, 2025
@TokisanGames
Copy link
Owner

Alright this is finished.

@laurentsenta Thank you very much for the first implementation and excellent effort on the docs. Both gave us a solid base to improve on.

@Xtarsia thanks for the reviews and testing.

@TokisanGames TokisanGames merged commit 227a5c7 into TokisanGames:main Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants