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 How to modify an image post render?

Discussion in 'General Graphics' started by luca-venturini98, Jul 12, 2023.

  1. luca-venturini98

    luca-venturini98

    Joined:
    Jul 12, 2023
    Posts:
    4
    Hello,
    I would like to find a way to retrieve the rendered image from unity before it is displayed. In this way I may apply some shifting/rotations and then reproject it on my screen.

    Is there a way to do it in Unity?

    Thanks
    Luca
     
  2. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,859
    Hi, sure, there is many ways, depending on which pipeline is used.

    In all cases can just render everything to a target texture on camera and use that texture in any way, e.g. as input to a shader to edit it and then display it, by using the shader in a material in a quad in the final scene camera. Or use a image effect to display it etc
     
  3. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    547
    The simplest way is probably OnRenderImage if you are using the built-in render pipeline:
    https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnRenderImage.html
    https://docs.unity3d.com/540/Documentation/Manual/WritingImageEffects.html

    But be aware that you have to write a shader to do this. Fetching the rendered image from the GPU, modifying it on the CPU and then uploading it again would be extremely slow.

    For URP and HDRP it's a bit more complicated:
     
  4. luca-venturini98

    luca-venturini98

    Joined:
    Jul 12, 2023
    Posts:
    4
    Unfortunately i need it for URP, any suggestion? I am quite new and I don't really know how to handle it.

    Thanks
     
  5. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    625
    You can create a custom URP renderer feature (with a custom ScriptableRenderPass) and use your custom shader to apply image effects to screen. (an example for URP 14+ from documentation)

    If you're on URP 14+ (Unity 2022.2+), you can also try the new full screen blit renderer feature to apply your custom full screen shader graph to screen.
     
    c0d3_m0nk3y likes this.
  6. luca-venturini98

    luca-venturini98

    Joined:
    Jul 12, 2023
    Posts:
    4
    I managed to use OnRenderImage. I get the src renderTexture, I scale it and then I use Graphics.Blit(src, dest, scale, shift)
    Is there a way to know how much time does it takes from the start of OnRenderImage till when the the image is really displayed to the user?

    Thanks
     
  7. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    547
    Not really. The latency depends on a lot of factors which differ from player to player. For example, it depends how much latency there is in the monitor and how many frames the CPU is allowed to run ahead of the GPU.

    What some people do is using special devices to measure how long it takes from pressing a mouse button to seeing a brightness change on the screen. But that's more for hardware review purposes:
    https://www.nvidia.com/en-us/geforce/news/reflex-latency-analyzer-360hz-g-sync-monitors/

    The best you can do on consoles is measure the time remaining until the next vsync (not supported on PC). Some of this information is exposed through FrameTimingManager.
    https://docs.unity3d.com/ScriptReference/FrameTimingManager.html