Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

How to render everything with a replacement shader... with HDRP?

Discussion in 'General Graphics' started by DaveL99, May 14, 2019.

  1. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    I have a complicated scene with lots of different objects in it. Each object can consist of a hierarchy of multiple sub-objects. Each sub-object can have a mesh with multiple and varied materials on it. Each material could use one of many different shaders. etc.

    What I need to be able to do is:-

    Render my main camera as normal, but also have an additional camera through which I render all the objects again, however instead of their usual Lit/PBR shaders I simply want to render (for example) all cars blue, all buildings red, all people yellow, all badgers magenta, etc. (completely unlit - I need the final RGB values to be accurate and consistent).

    With no support for Camera.SetReplacementShader in HDRP/LWRP, I must admit I'm stumped as to how I would achieve this. Does anybody have any helpful suggestions? Bonus points if it also works with Shader Graph shaders as well...

    Thanks.
     
  2. wlad_s

    wlad_s

    Joined:
    Feb 18, 2011
    Posts:
    148
    I’d also like to know if that’s possible. Did you get any info on this in the meantime?
     
  3. straylight

    straylight

    Joined:
    Jan 7, 2013
    Posts:
    17
    I too would love an answer to this...
     
    wlad_s likes this.
  4. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    In URP/HDRP you can use scriptable render pass with one pass for each color.
    And yeah, lack of ReplacementShader this is a very big limitation of SRP.
     
    straylight likes this.
  5. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    234
    straylight likes this.
  6. Ggz91

    Ggz91

    Joined:
    Nov 7, 2019
    Posts:
    2
    Last edited: Dec 14, 2019
  7. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    @Ggz91 I downloaded the examples but am having trouble seeing where the equivalent of ShaderReplacement is used. The ScriptableRenderPipelines have been hard for me to get into overall, so perhaps I'm missing something basic?

    Or maybe an easier question: Where do I create an OverrideMaterial, is that doable in the editor, in C#, or both? And how do I use it?

    Is it possible to do this every frame, as if I was doing camera's RenderWithShader(...) method, without significant performance hit? (I just want to render a black and white mask of the scene, so the shaders would be super simple)
     
    qstrinati_expleo likes this.
  8. tkg_szaluga

    tkg_szaluga

    Joined:
    Sep 7, 2018
    Posts:
    3
    @ModLunar
    It can be done like so (tested with URP 7.3.1):
    * Create a new URP renderer asset (right-click somewhere in the Project view, then select Create -> Rendering -> Universal Render Pipeline -> Forward Renderer), name it, lets say, CameraReplacementRenderer.
    * Click on the CameraReplacementRenderer asset to edit its properties
    * Change filtering: Opaque Layer Mask: None, Transparent Layer Mask: None. This is to disable normal camera rendering (we only want the render features to do work, without this we would render everything twice)
    * Add "Render Objects (Experimental)" Render Feature
    * On "Render Objects (Experimental)"
    - Set layers you want it to render
    - Set Overrides -> Material to a material that's using your replacement shader
    * Add CameraReplacementRenderer to your URP Render Pipeline Asset
    * Set your camera to use CameraReplacementRenderer

    Hope this helps.

    ReplacementMaterial.png
     
  9. zsmays

    zsmays

    Joined:
    Sep 7, 2020
    Posts:
    2
    i could only get this to work when I set opaque layer mask and transparent layer mask to everything
     
  10. dieguete11

    dieguete11

    Joined:
    Nov 17, 2018
    Posts:
    1
    If you want to override specific object materila. How do you do it?
     
  11. xujinm

    xujinm

    Joined:
    Dec 11, 2018
    Posts:
    13
    I have this problem too, did you solve it?
     
  12. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,389
    This does not seem to grab the original object shader variables like color or emission properties though, just applies a shader but does not keep the original scene information.

    Or i miss something ?

    Thanks
     
  13. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    234
  14. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,389
    Hi, thanks for the heads up, that is great news :)

    Will this system retain the original materials variables like in the Standard Pipeline, so can do operations based on the item color - emission etc values of the normal material ?

    Also is this version available to install from the Hub ?

    Thanks
     
  15. PixelDough

    PixelDough

    Joined:
    Apr 27, 2018
    Posts:
    56
    ModLunar likes this.