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

HDRP and multiple render passes

Discussion in 'Shaders' started by BlakeSchreurs, Jan 8, 2019.

  1. BlakeSchreurs

    BlakeSchreurs

    Joined:
    Aug 10, 2016
    Posts:
    50
    Hey folks,

    Trying to get back into HDRP, especially now that we can use the shader graph in 2018.3. I have a tricky effect that I was able to get in the standard shader, but I don't know how to do it in the HDRP. I'm not looking for someone to implement it for me, rather a general approach to how to go about implementing it (guides/tutorials welcome)

    Here's the general idea:
    Say you have a room with various objects. They all look the same (standard camera stuff). Secretly one object is different. I've made it red here, for the purposes of this example.
    upload_2019-1-8_15-43-39.png

    The player will want to switch camera modes, so they see an occluded silhouette and nothing else, like this:

    upload_2019-1-8_15-48-39.png
    (Yes, this is just an unlit color render of those objects with a given property set)

    I tried multiple materials, with synchronized cameras using different rendering settings so that one camera would render it in one mode, and another camera would render it in another. This has two problems:
    a) It only works on the first submesh, which is a problem for objects with multiple submeshes
    b) When I assign more materials than submeshes, the editor tells me not to do that, and that I should consider using multiple shader passes.

    I've also tried mucking about with the render queue, so that the object renders in the transparent layer, and then have the two cameras render differently (one only renders opaque object, the other only renders transparent objects). The down-sides of this approach are:
    c) I can't have any actual transparent objects
    d) I can then only get my special object to render in one view or the other, instead of both

    Again, I can combine this with multiple materials, but results in issues a) and b)

    I have no clue as to how to set up multiple shader passes, and have one material provide the information needed for rendering the object two ways. Thoughts on how to go about doing this?
     
    ModLunar likes this.
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Seems like you're trying too hard:

    Special objects on their own hdrp layer.
    Regular objects on the usual (default) hdrp layer.

    When the time comes to do the second screenshot, tell camera to stop rendering regular objects and change the renderer material for the special object. That's all you need to do.

    Note: HDRP has it's own special rendering layers you can use instead of the Unity layers system. For convenience.
     
  3. BlakeSchreurs

    BlakeSchreurs

    Joined:
    Aug 10, 2016
    Posts:
    50
    Cool, I'll certainly try that!

    Also, it'd also be nice to do this with a scope on a weapon. Unfortunately this means being able to render both views. I figured it'd be plausible to have a camera on the front of the weapon rendering to a render texture on the scope, but I'm not sure this would work with the layers as you've mentioned?
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You'll have enable the HDRP layers support in the HDRP asset (unless it supports and uses Unity layers as well and you want to use those)
     
  5. BlakeSchreurs

    BlakeSchreurs

    Joined:
    Aug 10, 2016
    Posts:
    50
    I was able to selectively render using the culling mask in the camera, which will allow me to switch back/forth (though that requires a material swap, which is problematic for the scope approach).

    I found the HDRP layers in the material, but I can't see where to enable HDRP Layer Support in the HDRP asset (Unity 2018.3), nor can I find documentation on how to go about doing similar. I can see the definitions OF the layers, but I have no idea where they're defined. Are there docs/blogs/examples anywhere? I'm trying to be self-directed, but the number of guides available on this topic are few & far between since it's so new.
     
  6. Ambre_Lc

    Ambre_Lc

    Joined:
    Dec 11, 2017
    Posts:
    2
    Hi,
    I'm in a similar situation and I found where the layers are defined in the HD Render Pipeline Asset (maybe it became more obvious in my version, 2020.1.0f1)

    upload_2020-9-22_13-31-27.png

    I have enabled them, but the camera is still using the default unity layers for its culling (they are displayed in the "CullingMask" field in inspector and used when I update cullingMask via scripting). Am I missing something ? How can I use the light layers on my cameras ?