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

爱⌒轻易说出口 提交于 2020-12-23 11:38:53

问题


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?


回答1:


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 e.g. 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 e.g. BackgroundCamera as child of the MainCamera (so it is automatically moved correctly) and give it

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

If you have something more complex in mind like e.g.

  • 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.



来源:https://stackoverflow.com/questions/55407632/unity-how-to-show-world-space-canvas-above-screen-overlay-canvas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!