Search Unity

World space UI on top of scene?

Discussion in 'High Definition Render Pipeline' started by Gametyme, Jul 5, 2020.

  1. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    Is it possible to have a world space UI always render on top of the scene without writing a shader? In the old built in render you could just use 2 cameras.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    You can definitely child a world-space canvas to your camera, so it's always visible. You'll probably want to set the material to Depth Test Always to get the UI to show up on top of everything, otherwise it might go behind an object if you stand close to it.

    You might not need to write a separate shader for this, but I'm not sure any of the HDRP-provided shaders work too well for rendering UI stuff. However, it's pretty easy to create your own shader for this in Shader Graph, by accepting a texture you internally name "_MainTex" to get the sprite image, and add the "Vertex Color" node to get the tint.
     
    Gametyme likes this.
  3. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    Thanks, I tried that already but it renders over the ship too. That's the only thing I don't want it to render over. Might have to learn shader graph.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    You said you wanted it to render on top of the scene, though. I have no idea what you mean that it render over the ship. Maybe show a screenshot of what you're doing.
     
  5. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    Sorry, I making a 3rd person rail shooter like star fox . I would like my crosshair to render on top of everything but the player ship.
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    That seems a little weird to me. I think it's fine if UI is on top of everything. But if you create a situation where things aren't transitive, that can break immersion and depth perception. It would be weird if, for example, some object was between the ship and the crosshairs, such that the ship conceals the crosshairs, but the object does not.

    Anyway, what you're trying to do is probably a bit complex, and it could make your rendering a lot more complicated. You essentially want to render your scene, render something on top of the scene (the crosshairs), and only then render your ship on top of all of that. But you probably don't want your ship to always be on top of everything? Presumably something could fly between the camera and the ship?

    Anyway, I think it's fine if the crosshairs are always on top. I think that's what Star Wars Battlefront, and other space ship games do, and I think it works fine. I don't actually know how to produce the effect you're trying to achieve, even with shaders.
     
    Gametyme likes this.
  7. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    Looking at Star Wars I think that would work. I just need to adjust my camera so the crosshairs aren’t always in it.