Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ public override GameObject Build()
// Renderer module
{
var rendererModule = pfxGo.GetComponent<ParticleSystemRenderer>();
// 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);
Expand Down
25 changes: 25 additions & 0 deletions Assets/Gothic-VR/Scripts/Adapters/Player/VRPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Renderer> _playerRenderers = new();

/// <summary>
/// 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).
/// </summary>
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);
Expand Down