Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Always On Top UI in VR with HDRP like Alyx's diaglog

Discussion in 'High Definition Render Pipeline' started by TsingLoo, Nov 2, 2023.

  1. TsingLoo

    TsingLoo

    Joined:
    Dec 25, 2021
    Posts:
    2
    Hello, I am a newcomer to VR and HDRP within Unity, and am aiming to create a dialog interface like that seen in Half-Life: Alyx. I think, the dialog in Alyx operates in 'World Space' within Unity's framework.

    In Unity version 2022.3.3f1, I attempted to utilize World Space and despite switching to setting the canvas to Screen Space - Overlay, I still encountered the issue where the UI text is occluded by GameObjects within the scene.

    I then do some research and find that a Custom Pass Volume may do help to make the UI always on top. I then create a DrawRenderersCustomPass Before Transparent and set its Filters to Queue - All Opaque and Layer Mask - OnTop, where the OnTop layer is I created and assing to the canvas of dialog. I also override its Depth to Always and disable Write Depth.While this approach appears to work well for showing general GameObjects(the gameobject is painted all white but can always be seen), it unfortunately did not yield the desired effect for the UI - the dialog remains unchanged.
     
  2. TsingLoo

    TsingLoo

    Joined:
    Dec 25, 2021
    Posts:
    2
    Hello! I've discovered a potential solution. Based on the discussion from this thread (https://forum.unity.com/threads/shader-always-on-top.710888/), I altered the code in the 'TextMeshPro/Distance Field' shader. I changed the line from ZTest [unity_GUIZTestMode] to ZTest Always.

    After making this modification, I apply the updated shader to the corresponding TMP_Font Asset.
    This resulted in the exact outcome I was anticipating: