Search Unity

Replacement for Camera.Render/Camera.RenderWithShader

Discussion in 'Universal Render Pipeline' started by Fewes, Mar 13, 2020.

  1. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    While attempting to make my in-editor AO baker compatible with URP, I've found this page stating that Camera.Render and Camera.RenderWithShader are not supported. Is there a current or planned replacement for this? Without them, it seems impossible to render custom depth maps, a very powerful feature.
     
    rrtt_2323 and hippocoder like this.
  2. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    There's a replacement:

    Renderer Features, especially the built-in RenderObjects renderer feature.

    upload_2020-3-13_13-58-16.png

    Your actual camera that you want to render depth with needs the right Renderer assigned, and also can have Culling set to none so that you're not rendering double:
    upload_2020-3-13_13-59-15.png

    Result of the above:
    upload_2020-3-13_14-0-9.png
     
  3. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Yeah... lack of RenderWithShader is most annoying thing in SRP. Lucky you can switch to standard on the fly, bake what you want, and switch back.
     
  4. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    Using Renderer Features seems like using a sledgehammer to crack a nut-kind of solution. Previously I could just call a single function. Any input from Unity on if this is the intended way to replace Camera.Render? I'm a little confused as to why URP makes it incompatible, anyway.
     
    PutridEx and hippocoder like this.
  5. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    This in not URP specific issue. SRP just don`t have RenderWithShader functionality.
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    @phil_lira any idea how this can be achieved? seems useful for a lot of quick tooling and bouncing back and forth between URP and built-in seems taxing...
     
  7. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    I can only repeat that RendererFeatures have been previously said to be the replacement for URP. I'd also hope this to be easier and more consistent between pipelines... Looking forward to official Unity feedback.
     
  8. nhdu73

    nhdu73

    Joined:
    Feb 8, 2020
    Posts:
    2
    Run into the same problem. Any updates?
     
  9. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,348
    Hi, any updates on this ?

    Is it at all possible to render a camera with a custom replacement shader in any URP version ?

    Thanks
     
  10. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Nope, it seems to be a design limitation.
     
    nasos_333 likes this.
  11. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,348
    I see, thanks

    I am trying to port SEGI global illumination to URP and seems wont be so easy, if possible without this feature
     
  12. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    229
  13. robinDMUnity

    robinDMUnity

    Unity Technologies

    Joined:
    Oct 13, 2020
    Posts:
    8
    With the new feature linked by AljoshaD this problem should be solvable. In fHerbst's screenshot there is only a material override. In newer versions there is also a Shader override property that allows you to maintain properties from the current materials on your objects. This is similar to how replacement shader/RenderWithShader in the built-in renderer works.

    What I found to work well is to create an extra UniversalRenderData asset (Create > Rendering > URP Universal Renderer) where I set the Filtering to "Nothing". Then add the Render Objects Renderer Feature and specify which layers you want to draw. Set the override mode to Shader and you should be good to go.

    By using an extra Universal Render Data asset it's easy to have a camera use it from code without having to toggle a bunch of settings every time you want to render. Especially with the updates to the Render Request API. Which makes it easier to trigger SRP renders from code.


    Code (CSharp):
    1. var request = new RenderPipeline.StandardRequest();
    2. request.destination = aoRT;
    3. camera.GetUniversalAdditionalCameraData().SetRenderer(k_AOBakeRendererID);
    4. RenderPipeline.SubmitRenderRequest(camera, request);
    Looking forward to any other questions and/or feedback!
     
  14. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    229
  15. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    I am literally hitting a wall today because I wanted to create a custom debug view similar to what the Rendering Debugger window does and not being able to reproduce the functionality or attach my own stuff to the existing URP classes BUT we are updating our project to 2022.2 next week. So this feature might just come at the right time for me.
    Replacement shaders has always been incredibly useful thanks for finally adding this :)


    edit:
    because someone liked this post today, a quick update.
    The render objects feature includes a shader overwrite by now, which is great because it brings one a long way, but unfortunately it can't use SRP batching it seems (at least not for me) which again makes it .. questionable.
    The rendering debugger addition mentioned above works though, although it was not easy and it suffers from that no batching issue and regular rendering has be disabled using the layermask (which is a bit tricky to get access to).
    https://forum.unity.com/threads/how-to-extend-the-srp-rendering-debugger.1321179
     
    Last edited: Jul 27, 2023
    rrtt_2323, LooperVFX and AljoshaD like this.
  16. rrtt_2323

    rrtt_2323

    Joined:
    Mar 21, 2013
    Posts:
    32
    I'm crying in unity2021.:confused::(