Search Unity

Question Camera.RenderWithShader in URP

Discussion in 'Universal Render Pipeline' started by RakNet, Jun 1, 2023.

  1. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    315
    For performance, I want to be able to replace the shader on all materials in use with Default/Unlit, as a runtime toggle.

    This was previously easy using Camera.RenderWithShader.

    With URP I can't figure out any way to do something similar. ScriptableRenderPass seems to for add passes to add more things to the screen, or update what was already rendered, such as adding lens flare (https://docs.unity.cn/Packages/com....tainers/create-custom-renderer-feature-1.html).
     
  2. Allan-MacDonald

    Allan-MacDonald

    Joined:
    Sep 21, 2015
    Posts:
    112
    After reading a bit about Camera.RenderWithShader, it sounds like it was also intended to be use as more of a modification to the main camera's visuals. They mention "Heat Vision" and it being applied to another camera which you can enable. This essentially what URP's render features allow you to do, except you can apply 1 material to the final render. It doesn't sound much less efficient, shouldn't it just be one extra pass?
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,741
    Reading URP’s render feature examples it doesn’t feel like this is something you can do, care to point me in the right direction?

    Lack of easy replacement shaders is one of the main reasons I’m not considering moving to URP.
     
  4. AurochChris

    AurochChris

    Joined:
    Jan 7, 2014
    Posts:
    24
    I haven't used this myself, but was curious to see if there was a defined way of rendering a pass for a single camera only. Looks like the official method is to use the API mentioned in this thread to execute a RenderPass on your target camera:
    Is there any way to do a single Camera.Render() with URP? - Unity Forum

    In your custom RenderPass, you should then be able to use DrawRenderers with an override material defined in the DrawSettings param to replace the rendering of specific shader types / filtered objects etc.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,741
    Thanks, while it’s good that it’s maybe doable, that sounds like too much work to replace 3 lines of code and for no real benefit in my case at least.
     
  6. Allan-MacDonald

    Allan-MacDonald

    Joined:
    Sep 21, 2015
    Posts:
    112

    AFAIK you use render layers which are new to URP. Each Mesh Renderer now has a Render Layer tag for it to control if it's a part of the render feature pass. So you can apply the feature to your entire screen, then opt certain things in or out.

    https://docs.unity3d.com/Packages/c...al@16.0/manual/features/rendering-layers.html
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,741
    While that seems cool (thanks for the link), I don't see it as quite equivalent? Render feature pass seems like a post processing thing, while what I really want is to renderer everything with a custom shader.
     
  8. Allan-MacDonald

    Allan-MacDonald

    Joined:
    Sep 21, 2015
    Posts:
    112
    what's the difference in the end if all the objects you want to do the replacement on get the treatment?
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,741
    Do they? If I want to do a bunch of stuff based on world position, can I just calculate it in the vertex shader, or is it something that I need to reconstruct from depth and normals in a render pass?
     
  10. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    229
    AcidArrow likes this.