armory3d / armory

3D Engine with Blender Integration
https://armory3d.org
zlib License
3.05k stars 316 forks source link

LOD by object distance to camera #2630

Open onelsonic opened 1 year ago

onelsonic commented 1 year ago

Hi there, Is there any advantage in using screenSize for LODs over object distance to camera? __ A working implementation of LOD by distance.

Armory3D already have a working and fast LOD solution which works by using size on screen of objects, but for various size prefabs or large scale objects it starts to show it's limitations, An implementation which uses distance to camera of objects for the LOD levels will be great to have.

Files affected with current LOD : https://github.com/armory3d/armory/blob/main/blender/arm/props_lod.py

https://github.com/armory3d/iron/blob/main/Sources/iron/object/MeshObject.hx

https://github.com/armory3d/iron/blob/main/Sources/iron/Sources/iron/data/MeshBatch.hx

https://github.com/armory3d/iron/blob/main/Sources/iron/Sources/iron/Scene.hx

https://github.com/armory3d/iron/blob/main/Sources/iron/Sources/iron/data/SceneFormat.hx

Implementation material (Inspiration):

https://gist.github.com/JBStepan/33c3224c40e8a2921adf4f6f11447099 https://github.com/godot-extended-libraries/godot-lod https://www-unity3d--france-com.translate.goog/unity/phpBB3/viewtopic.php?f=24&t=14928&p=107999&_x_tr_sch=http&_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=fr&_x_tr_pto=wapp#p107999

MoritzBrueckner commented 1 year ago

Is there any advantage in using screenSize for LODs over object distance to camera?

Yes, let's assume that you have a huge object in front of you that fills almost the entire screen. However, due to it's size, the object can be far away and still fill your screen. If you would use a distance-based LOD, the object would be replaced by a lower-res version although it is very prominent. Opposite to that, you could have a very small object very close to the camera that is so small that it only fills a small portion of the screen. In that case, it would still use the full-res variant although you may not see any details.

So using the screen size is more accurate in theory, but unfortunately it needs to be approximated to be fast and Armory's approximation is not really great and in fact even completely wrong in some cases due to the way object dimensions work (at least it was wrong a while ago). So I guess that adding a distance based mode would be helpful, but we shouldn't remove the screen size mode and instead try to improve it. Maybe it makes more sense to use a bounding sphere like here for example, but I'm not sure...