Search Unity

Is it possible to exclude an object from camera far clipping in HDRP?

Discussion in 'High Definition Render Pipeline' started by Zaine7673, Oct 4, 2020.

  1. Zaine7673

    Zaine7673

    Joined:
    Feb 15, 2018
    Posts:
    238
    I have a an object that needs to render on top of other objects and not on top of other objects and also be excluded from the Camera far clipping.

    Camera stacking could have resolved both but it seems it is no longer supported and nothing has replaced it in HDRP Unity 2019.

    I've read up on the Compositor tool but I don't think its available to use yet officially.

    Can anyone guide me in the right direction?
     
    Last edited: Oct 4, 2020
  2. Zaine7673

    Zaine7673

    Joined:
    Feb 15, 2018
    Posts:
    238
    So somehow I've managed to make it work :)

    Main camera culling mask is set to exclude the layer I want and the other camera which is a duplicate but with all other components switched eff (cinemchine brain, flare layer etc.) with occlusing culling to only include the layer I want. I've also had to switch off background and volume layer for the second camera. If I didn't it just came out a solid colour or just dark. Also set the far clipping to high for the second cam and low for the first to make sure it isn't being clipped out due to distance.

    Then (importantly) there is a part called output which has a field for depth. I set this to one higher than the depth set for the main camera.

    This does work but it isn't perfect. It makes the scene look washed out and brighter for some reason. Also I am losing almost 30 fps by just doing this.

    Anyone have any better methods to make an object appear on top of some but not other objects?
     
  3. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    168
    Isn't just override one camera by second camera? How do you determine where should you draw override object and where you should not?
     
  4. Zaine7673

    Zaine7673

    Joined:
    Feb 15, 2018
    Posts:
    238
    in my case i was trying to make a way point marker in the world appear on top of everything but not the player. So i put both the player and the waypoint on the same layer. However, as I mentioned although this works, it also causes issues. I haven't found a way to get exactly what I want yet. I'm thinking I might just have to change the way the waypoint works altogether but i would rather not.
     
  5. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    168
    I think you can use Custom Passes for this kinda stuff. Look at outline effect. You can make something similar.
    Not sure what will be exactly the best way to do it. Maybe using stencil buffer to specify what will occlude and what not? "See through effect" is showing how to work with stencil.
     
  6. Zaine7673

    Zaine7673

    Joined:
    Feb 15, 2018
    Posts:
    238
    Thank you but id decided to go down another route to keep things simlpe.

    I've added a sphere around the camera and another sphere (with the texture/shader that i want to use as the waypoint) and the used transfrom.lookAt(); to point the marker in the direction the location is at. Then i used some c# to calculate the distance between the location and the camera and change some values in the shader accordingly to notify the player if he is getting closer or further. works nicely.
     
    Camarent likes this.
  7. ristetutureski

    ristetutureski

    Joined:
    Jan 29, 2019
    Posts:
    23
    We wanted to achieve something similar. We wanted to have Examine mode for the objects, and also Inventory mode where we will have 3D objects and we can rotate them. But also we wanted to prevent clipping with other objects when the object is in Examine or Inventory mode. We fixed it with Custom Passes. We wrote a blog here: https://www.intetic.com/blogs/unity-hdrp-render-object-on-top-of-everything/. If still you need some kind of solution, you can check how we made it.
     
    valarnur likes this.