Search Unity

Render on both Screen AND RenderTexture

Discussion in 'UI Toolkit' started by Oneiros90, Mar 3, 2021.

  1. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    I'm trying to have my application render on game screen AND, at the same time, on a
    RenderTexture
    (I have to implement a screen share-like feature). The application is purely UI-based, I have no cameras in my scene, just an
    UIDocument
    .
    I see that I can put a
    RenderTexture
    as target texture in the
    PanelSettings
    but this turns off the main screen rendering. Is there an efficient and smart way to show the rendered texture on screen? Or to get the main screen as a texture?
    Thanks
     
  2. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    A couple of months ago I discussed this feature with @benoitd_unity. Maybe he has some updates on it. For now, just use a Raw Image on a default canvas and set the Render Texture to render to that. Bonus: Anti Aliasiing also works now, just set the amount in the render texture and it should work.

    Only problem is that you now have to update the Raw Image size and the Render Texture size when screen size/aspect ratio changes.
     
  3. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    698
    If I understand correctly what you're trying to do, you'll need 2 different PanelSettings, one for rendering to texture and one without a render texture so it renders to the main screen. Would that solve your problem?
     
  4. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    Thank you for the suggestion. It might actually work but I'm afraid that the actual interface on my window would look blurry and not pixel perfect. Also it feels like a dirty solution, I'd like to not introduce cameras and canvases if possible!

    I actually tried this solution but it doesn't work: using two PanelSettings means to have two instances of the same UI. And it is not ok in my case since I want the user to interact with the UI (e.g. click on a button to switch view) and those actions won't reflect on the render texture (because each UI element is duplicated and independent).