简体   繁体   中英

Unity - how to show world space canvas above screen overlay canvas?

Ok, basically I have a world space canvas (that currently uses a different camera) and a screen space canvas. In the screen space canvas I have a blur material from the asset store on a plane, which only works in screen space.

I need to do a switch where I still have that blurred background and the button to get back, but on top I have my world space canvas (the "text" objects below):

在此处输入图片说明

Setting clear flags to none on the second camera allows me to see what the first camera sees, but not its canvas. Is the best option here to screen capture the first camera's canvas?

Or is there a way to not make the screen space canvas block the world space?

So if I understand you correctly you have 2 Cameras let's say:

  • MainCamera : for displaying 3D content
  • ScreenSpaceCamera : for only displaying that Screenspace "plane".

and what you want is: Allways didplay the 3D content on top of the ScreenSpace content, right?


So what you can do is creating a special Layer eg ScreenSpace and than

  • MainCamera -> Camera :

    • Depth = 0 (higher value means drawn on top)
    • ClearFlags = DepthOnly
    • CullingMask = Everything except ScreenSpace

    在此处输入图片说明

  • ScreenSpaceCamera -> Camera :

    • Depth = -1 (so it is drawn behind depth level 0)
    • ClearFlags = Nothing (or whatever you want)
    • CullingMask = only ScreenSpace

    在此处输入图片说明


As you can see now the 3D content (RedImage) is always drawn on top of the ScreenSpace (white).

在此处输入图片说明


Note: In case you want to be able to switch that Screenspace on and off you need an additional Camera that actually clears the image! As you can see in the Camera Preview that camera's buffer is not "cleared" (because we told it so).

So if you would disable the Screenspace you would get what you see in the preview box! -> not good ^^

I would simply add a 3th camera eg BackgroundCamera as child of the MainCamera (so it is automatically moved correctly) and give it

  • Depth = -2 (so behind the ScreenSpace)
  • ClearFlags = eg SkyBox
  • CullingMask = Nothing (so you really only render the background here)

If you have something more complex in mind like eg

  • ontop UI (depth 0)
  • ScreenSpace (depth -1)
  • other 3D content
    let those be rendered by the ScreenSpaceCamera instead. So if you diactivate the Blurr Canvas they are displayed normal, otherwise blurred.
  • Background (depth -2)

simply extend the example with 4 Cameras, Depths and different Layers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM