-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Mesh flickering [Octo-tree] #42895
Comments
I tried this sample scene(i had to add "3D" to Camera and MeshInstance, addding light) in 4.0 nightly build and sticks slowly disappeared. |
cc @lawnjelly @gdesecrate Can you reproduce this in 3.2.3 without the octree fix? |
Ah sorry my mistake, didn't see there were 2 reprod projects. Trying to do too many things at a time! 😁 |
@Calinou In 3.2.3 without fix (the stable godot) no flickering, just memory leak that leads to terrible performance degradation. In samozbor id:heaven flickering affects the weapon in player hands (very noticeable) In Kotel Ne Gori the finall boss sometimes missing face model if you corner him in particular place of map. In previous experimental lawnjelly's fix the boss was missing not the face but lower torso. I haven't experienced any flickering on weapon when was testing naithar's fix. |
Well it's not the cached_lists, and it seems dependent on the In fact set at 0.0, apart from the cached lists, the behaviour I think is identical to the old behaviour, because the minimum per octant before splitting is zero. It could actually be another pre-existing problem with the tree, but at least it is not to do with the pairing. 😀 I'm seeing if I can pin it down to an even simpler scenario for debugging in detail. |
@lawnjelly by "old behavior" you mean memory leak? Or can I fix it by fine-tuning the value in project settings? Also, does your octo-tree fix affects 3d sounds by any chance? |
You can effectively 'fix' it by settings the The bug is highly likely to be pre-existing in the octree, but certain conditions more likely in the modified version may be more likely to bring it on. The changes to the octree are actually quite limited:
This bug seems to have been brought on by (3), which is a small change to make the tree balance more sensible, and shouldn't (in theory) affect the functionality. However there is always the possibility of an unforeseen consequence, something that relied on the previous behaviour, or also very likely a pre-existing bug that occurs only under certain conditions. Debugging such problems is quite painstaking, it is a case of reproducing the behaviour in as simple a situation as possible, and debug outputting the tree and trying to debug what is going on. The problem with octree is that the current design is not a very elegant solution to the problem, and is probably over complex. Elements are kept in multiple octants, which is incredibly error prone as far as management is concerned in an octree. Depending on time I can always simply revert the behaviour to remove the minimum elements per octant, however, that re-exposes another bug, #38142 I think is the one, the overly deep recursion in the octree problem. An alternative is to simply replace the current octree template with a better (simpler) spatial partitioning scheme. That is what is intended for 4.0 .. we were intending to keep what 'worked' for 3.2, however there are a lot of problems with the current octree. Replacements could include loose octrees (where elements are not kept in multiple octants) or bounding volume hierarchies which have tended to become a more preferred solution these days. Grids also work, but we need a scalable solution because of the general purpose nature of Godot, we don't know the scene size in advance, for example. There is also the pairing to deal with, which is a major pain with the current octree. It may be possible to outright replace the innards of this with a simpler more traditional system that still meets the contract of the existing interface. I'll only know after some further debugging. Although it sounds quite involved, simply writing a more rigorous fresh structure could be less time consuming than working out all the bugs in the old. There are also off the shelf open source trees that could potentially be an option, or used for reference. SoundOn the sound, from a look I don't think the 3d sound uses the octree (90% sure?), but I can't say for absolute definite. All I can do is FindInFiles for the functions, and looking through AudioStreamPlayer3D. If you want to look through the source code for audio_stream_player_3d.cpp you are as likely as me to see a reference to an octree, even if you don't know c++. The sound may however be using the physics, which could be related to your sound bug. If you are using godot physics (rather than bullet) it does use the octree indirectly, but the previous version, not the modified. |
Another bug in the octree has been discovered which can cause flickering in rare circumstances : godotengine#42895 For safety until this is fixed properly this PR reverts the default state of the octree to match the old behaviour, which doesn't appear exhibit the bug (or at least not as readily).
I think I've tracked this down. There is another pre-existing bug in the old octree. It involves an optimized path for moving objects without changing their octants. As I suspected this is a consequence of trying to keep track of elements in multiple octants, which is very error prone. In OCTREE_FUNC(void)::move:
If this entire path is removed (by e.g. commenting out) forcing it to erase the element from the octree and reinsert for each move, the bug no longer exhibits. So the bug is not introduced by the octree PR, but having larger octants makes it more likely to exhibit. I think it is occurring because although the element is moving within the container_aabb (highest parent octant), the actual octants that the element is in are changing, so when it does the cull tests it is not hitting the octants that the elements should now be in. I'll see if I can work out a fix. It may slow down the octree a bit doing it properly .. or maybe not. Maybe I can do a quick check for the most common path where octants do not change. I'm still of the opinion that replacing the octree may be the best move, but will wait and have a look at that once this is fixed in 3.2. Maybe I can make an experimental simple BVH and see how it works. |
But why in 4.0 the object don't flicker - they just disappear? |
I don't know much about 4.0 yet, as I'm primarily working on 3.2. I'm assuming it is still using the old unfixed octree (or a slight variation of). As such there will be loads of bugs in 4.0 octree, but it is due to be replaced. In the unlikely event that we don't replace it for 4.0, I'll forward port the 3.2 changes. For future reference this is the slightly modified version of the min reproduction project I'm using: This is quite a major bug actually, it is a good thing few people were using Godot physics in 3D, this could have caused all kinds of buggy behaviour. Well done for spotting it! 👍 |
I am slightly concerned that there may not be a way of fixing this that runs fast. It is quite easy to detect when an element has moved outside its immediate owner octants, just do an AABB check with the new AABB. The problem comes that the element may enter any new child (or grandchild etc) octant of the common parent. All these AABBs need to be checked (which isn't a problem) however we need to detect whether the element is ALREADY held by octants that pass the AABB check. There is, at the moment, no fast way of checking whether an element is in an octant. You can do the reverse, lookup the octant from the element, but not the check the other way around. The elements stored in the octant are linked lists, which are very slow to iterate, and this would be need to done on every octant concerned for every element moving on boundaries between octants. Even if these were changed to flat arrays it would be slow. The problem is possibly less when we have a There may be some data structure that can deal with this, but if not, this may require the octree being replaced. |
So to fix flickering I just need to adjust project setting? Is it doable by gdscript line of code? |
For now you can just change the project setting I mentioned above, When I say fix it, you can't see visual problems in your test project. However the problem is not properly fixed, there is a fundamental flaw in the octree, as detailed above, which will need to be fixed. I've already got a proper fix, but it will drastically affect performance. If a proper fix cannot be made without being detrimental to performance, the tree structure may need rewriting. This may not be a massive deal, and the same rewrite could be used in 4.x. I will have to consult with reduz later. We may come up with a way to solve the above problem in a more performant manner, perhaps using bitfields or somesuch. |
Thanks! You were right - 1.0 setting works for me. It not just my test project. The "test project" is modeled after actual game situation. Would be a pain to record video for new trailer while the weapon and hands are blinking... |
Fixed by #44901. |
Godot version:
3.2.3 custom build (with official octotree fix)
OS/device including version:
5.8.11-1-MANJARO, GLES2
Issue description:
Mesh flickering. Really noticeable on player hands/weapon in fps games.
I was asked to make dedicated issue by #40059 (comment)
Steps to reproduce:
Move around a few hundreds of small objects.
Minimal reproduction project:
For Godot 3.2.x : octobreak.zip
~500 meshes, sticks to the right flicker
The text was updated successfully, but these errors were encountered: