Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is there any way to do a single Camera.Render() with URP?

Discussion in 'Universal Render Pipeline' started by kbm, Jan 27, 2020.

  1. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Right now, a feature in our game relies on being able to disable some effects, then manually render one camera into a render texture, then re-enable the effects. all in one frame.

    Is there any way to do this with the URP or not at all? Camera.Render() hook is listed as "not supported" and without this feature we can't really upgrade to URP at all.

    Also, bonus question: Would our game theoretically be able to run on a Nintendo Switch with the built-in render pipeline?
     
  2. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    You can use UniversalRenderPipeline.RenderSingleCamera. That is the similar to Camera.Render

    Both URP and Builtin' pipelines support Nintendo Switch.
     
    CyrilGhys and avandenberg like this.
  3. osso_geo

    osso_geo

    Joined:
    Mar 4, 2019
    Posts:
    2
    Thanks for asking this question, kbm.

    What Context do you pass RenderSingleCamera? I'm using it to render one frame of a secondary camera. I can't find any examples of its use.

    Thanks in advance for any assistance!

    Geo
     
    deus0 and Mese96 like this.
  4. avandenberg

    avandenberg

    Joined:
    Nov 22, 2018
    Posts:
    23
    I case you haven't figured this out, I ran into the same problem, just paying forward the help I was offered!


    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;
    using RenderPipeline = UnityEngine.Rendering.RenderPipelineManager;
    ...

    private void OnEnable()
    {
    RenderPipeline.beginCameraRendering += UpdateCamera;
    }
    ...
    void UpdateCamera(ScriptableRenderContext SRC, Camera camera)
    {
    ...
    UniversalRenderPipeline.RenderSingleCamera(SRC, portalCamera);
    ...
    }
     
    deus0, Adunato, CyrilGhys and 4 others like this.
  5. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Is there a way to do this from an editor script?

    (Just trying to render a texture from a temporary camera and save it to a file, something that used to work with camera.Render() with the classic render pipeline)

    edit: Got it working after discovering the editor coroutines package, and using a coroutine to just wait a frame for the camera to render itself
     
    Last edited: Jan 14, 2021
    Arlorean likes this.
  6. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    79
    Last edited: Jan 16, 2021
    tsukimi, UniqueCode and bluescrn like this.
  7. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Interesting. Might have just been a Graphics.CopyTexture (from RenderTexture to saveable Texture2D) not working as expected when I tried that then, as I ended up switching to Texture2D.ReadPixels to get the coroutine version working.
     
  8. xujinm

    xujinm

    Joined:
    Dec 11, 2018
    Posts:
    13
    when I used UniversalRenderPipeline.RenderSingleCamera() with this camera.enabled is false,this camera just can't render ui canvas .Does anyone konw this???
     
  9. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    220
    The RenderRequest api should be what you need. It landed in 2022.2 https://github.com/Unity-Technologies/Graphics/commit/76150c8114170b7e2359ccd786c02b22bafdb125


     
  10. yu_yang

    yu_yang

    Joined:
    May 3, 2015
    Posts:
    85
  11. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Second that, it yet not usable

    Would be great to have some updates on this as well

    thanks
     
  12. AMoulin

    AMoulin

    Unity Technologies

    Joined:
    Mar 29, 2022
    Posts:
    5
    Hi @yu_yang, you can call SubmitRenderRequest() from your scripts as long as it is called outside of the Unity render loop.

    As you noticed, we currently prevent its usage in functions called by the render loop to avoid recursive rendering trouble, but we plan to address that restriction.

    RenderRequest API works for both URP/HDRP. Here is one example: https://docs.unity3d.com/Packages/c...es.core@17.0/manual/User-Render-Requests.html

    Let me know if it helps!
     
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Hi, thanks.

    So is better to use the RenderSingleCamera() for now as the SubmitRenderRequest() is not yet working inside the render loop and will be updated later ?

    Because removing it from the render loop changes a lot the functionality of the program.
     
  14. TomGoethals

    TomGoethals

    Joined:
    Jan 29, 2022
    Posts:
    46
    Looking forward to some updates on this. Currently stuck to have world space Canvas render in to a renderTexture. SubmitRenderRequest makes them render alright but calling that from within beginCameraRendering throws an error (even though everything looks and works allright)
    So I would really like to be able to do a SubmitRenderRequest from within a BeginCameraRendering without the error. Moving the SubmitRenderRequest outside of the rendering thread (in lateUpdate for example) works but makes my planar reflections lag by one frame.
     
    Last edited: Dec 27, 2023
  15. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    What really sucks about this is having to wait for the SRP to update the render makes tooling much more complex.

    In BiRP, I can simply render something to a texture and use it. Now if I want to do something like this, I either need to move my entire tooling into the rendering system, or come up with some way to serialize the data instead of rendering it on the fly, and defering updates until after rendering happens.

    For instance, I render depth buffers from meshes and use them to modify the terrain height when I load the scene in the editor. This works great in BiRP, but in SRPs this data won't be available until after rendering a frame, which means I can't update the scene until after the first frame.

    I realize this is designed this way to prevent stalling the renderer, which is great for gameplay, but tooling does not care about that and is being saddled with loads of extra complexity because of it. Also, if you try to render just a depth buffer with this technique, you'll get a null reference exception- so I now have to waste memory on a full color buffer for no reason, which doesn't seem to be creating a valid depth buffer anyway. Blerg..
     
    Last edited: Jan 15, 2024
  16. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Hi,

    No, it certainly does not help. Please fix the pipeline so it is usable or just tell us than will remain useless to stop working with it. URP seems like a practical joke at this point, is slow, vastly slower in custom image effects that BiRP, complex, fragmented, render graph will destroy its already problematic API completely, not a single custom effect will work, simply does not work in many cases, has not got major features in Shader Graph etc

    If something is to be ready for development in 10-15 years down the line, should not be released and declared as a ready to use system and trick users into making use of it. There is only one usable pipeline currently and for the many years to come and that is BiRP, unless want to make the most basic of visuals and effects.