Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

c# - 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):

enter image description here

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

    enter image description here

  • ScreenSpaceCamera -> Camera:

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

    enter image description here


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

enter image description here


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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...