Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question When using a render texture to render game, how can I get more control of what to render?

Discussion in 'Scripting' started by mrCharli3, Sep 20, 2023.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    I use a render texture to render my entire game, I lower the size to get a "pixelation" effect. I've run into the issue now where I need to render some things in world space that should not be pixelated, like HP bars, can this be done?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    URP also has this built-in as an upscaling slider, I think that's on the camera. Pretty rad because you can also specify the filtering method, including one of the the 2x pixel art upscaler algorithms.
     
  4. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    You lost me a upscaler algorithms but upscaling slider is rly interesting.

    it does apply to everything tho, so how would I avoid running into same issue I’m running into atm? Can I control which layers are upscaled? Or is there some other way?
     
  6. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    I assume ur talking about this one called render scale? As far as I know there is no way to use seperate URP assets per camera or any other way to control which layers to pixelate.

    upload_2023-9-21_10-47-10.png
     
  7. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    Can't you just use Overlay Canvas to show UI elements and use RenderTexture for everything else? You can convert the positions from world space to canvas space/screen space.

    Or you could use 2 RenderTextures: One for the UI and second for the rest. UI could be at higher resolution and you can update it manually at lower framerate to save resources. (This might not work if you use URP and PostProcessing).

    Or you can add Canvases to the world space for the UI and use separate camera to show just UI.
     
  8. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    This might be possible if I continously update the position of the UI, since if I just use an overlay canvas the UI will follow the camera like all other UI. However I'm not sure it would be possible to get it to behave the same a canvas in world space would.

    I tried this, you cannot use 2 render textures camera stacked, at least not without some hack im unaware of. If you render only the UI layer on the top render texture, the rest will be gray backgorund that covers the other render texture.

    Cannot use a seperate camera on top of a render texture, the render texture will always be rendered on top.
     
    Last edited: Sep 21, 2023
  9. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    I take this back, I got this to work actually, just doesnt render any shadows, which is fine in my use case. I guess my perfect solution would be a render feature that pixelates everything except the layers I specify, but I can deal with that headache later.

    Unfortunately it creates this annoying box around the text, probably because I have to use
    Background type: Uninitialized
    :

    upload_2023-9-21_13-22-55.png
     
    Last edited: Sep 21, 2023
  10. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    Use 2 Cameras, each Camera renders separate layer to separate Render texture - attach each texture to the RawImages inside Canvas.

    All of the things I mentioned before will solve only the pixelation issue. There might be sorting issue if you want UI to hide behind 3D models and there can be transparency issue if you use Postprocessing with URP.

    And here is example: 3D cubes with the World Canvas. You can render UI in the world space to separate RT or just leave it as is but you have to put the another Canvas (I used Canvas - Screen Space - Camera) with the World RT attached to RawImage behind everything. World rendered at 128x64, UI native. With the shadows from 3D objects. If you want to recreate shadows from the UI then they would be pixelated like the game world.

    Or just use the OverlayCanvas for UI and use URP render scaling like people suggested. But if you use other type of canvases, they will be scaled with the URP render scaling factor also.

    upload_2023-9-21_13-46-57.png
     
  11. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    Thanks, yeah like I mentioned above I did get it working :)

    Like you said, the stuff on this second render texture will be rendered on top of EVERYTHING, so its maybe not a perfect solution, but its good enough for my prototype!
     
    tduriga likes this.