From 95917c88888d8879f0928bc3312acea9e18012fb Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 23 Nov 2026 00:09:28 +0000 Subject: [PATCH] fix: VOBs, NPCs, the hands and the menu no longer vanish at some places - only the world mesh is occlusion culled The worlds' baked occlusion data culls runtime-created renderers as dynamic objects; at some places (a Khorinis alley) its cells put the camera inside a wall and every VOB, NPC, the hands and the menu panels vanished or got cut, flickering with each degree the head turned. Gothic meshes of VOBs and NPCs and VOB particle effects set allowOcclusionWhenDynamic = false (frustum and our distance culling still apply); everything under the player is checked once a second. The world chunks keep occlusion culling. --- .../Meshes/Builder/AbstractMeshBuilder.cs | 6 +++++ .../Meshes/Builder/VobPfxMeshBuilder.cs | 2 ++ .../Scripts/Adapters/Player/VRPlayer.cs | 25 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/AbstractMeshBuilder.cs b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/AbstractMeshBuilder.cs index d5ebc33d3..9be771c4c 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/AbstractMeshBuilder.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/AbstractMeshBuilder.cs @@ -342,6 +342,12 @@ protected void CheckPreconditions() protected void PrepareMeshRenderer(Renderer rend, IMultiResolutionMesh mrmData) { + // VOBs and NPCs are created at runtime, after the world's occlusion data was baked: Unity tests them as + // dynamic objects against it, and at some places (a Khorinis alley) the baked cells put the camera inside a + // wall - every VOB and NPC around vanished, flickering with each degree the head turned. Only the world + // mesh keeps occlusion culling; VOBs and NPCs are culled by the frustum and our distance culling. + rend.allowOcclusionWhenDynamic = false; + if (null == mrmData) { Logger.LogError($"No mesh data could be added to renderer: {rend.transform.parent.name}", LogCat.Mesh); diff --git a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs index 946aa346a..4af0fd45b 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Meshes/Builder/VobPfxMeshBuilder.cs @@ -344,6 +344,8 @@ public override GameObject Build() // Renderer module { var rendererModule = pfxGo.GetComponent(); + // Like VOB meshes (AbstractMeshBuilder.PrepareMeshRenderer): not culled by the baked occlusion data. + rendererModule.allowOcclusionWhenDynamic = false; // FIXME - Move to a cached constant value var standardShader = Constants.ShaderUnlitParticles; var material = new Material(standardShader); diff --git a/Assets/Gothic-VR/Scripts/Adapters/Player/VRPlayer.cs b/Assets/Gothic-VR/Scripts/Adapters/Player/VRPlayer.cs index 11451730e..5569f3f77 100644 --- a/Assets/Gothic-VR/Scripts/Adapters/Player/VRPlayer.cs +++ b/Assets/Gothic-VR/Scripts/Adapters/Player/VRPlayer.cs @@ -78,10 +78,35 @@ private void Start() { // Enabled later via button press or other events MenuHandler?.gameObject.SetActive(false); + StartCoroutine(KeepPlayerRenderersVisible()); GlobalEventDispatcher.HeroDied.AddListener(OnHeroDied); GlobalEventDispatcher.LoadGameStart.AddListener(OnLoadGameStart); } + // How often new renderers under the player (menus, held items, the hero body) are taken out of occlusion culling. + private const float _occlusionCheckSeconds = 1f; + private readonly System.Collections.Generic.List _playerRenderers = new(); + + /// + /// The world's baked occlusion data culled the player's own renderers at some places: the hands, the hero body + /// and the menu panels (their meshes and texts) vanished or got cut with each degree the head turned. Everything + /// under the player is never occlusion culled - checked once a second for new ones (menus, items in the hands). + /// + private IEnumerator KeepPlayerRenderersVisible() + { + var wait = new WaitForSeconds(_occlusionCheckSeconds); + while (true) + { + GetComponentsInChildren(true, _playerRenderers); + foreach (var playerRenderer in _playerRenderers) + { + if (playerRenderer.allowOcclusionWhenDynamic) + playerRenderer.allowOcclusionWhenDynamic = false; + } + yield return wait; + } + } + private void OnDestroy() { GlobalEventDispatcher.HeroDied.RemoveListener(OnHeroDied);