Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

LWRP and multipass effect using ScriptableRenderPass

Discussion in 'Graphics Experimental Previews' started by Kichang-Kim, Nov 8, 2018.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi, I'm trying to change my legacy render pipeline based project to LWRP based and stucked for multi-pass shader.

    My original shader using two pass, (solid color outline effect)
    Pass1 Front culling, no z-write, add vertex offset using its normal, solid color output
    Pass2 Normal lit shading

    The problem is that LWRP can render using only 1 pass, named LightweightForward. So my plan is here:
    1. Create shader which has two pass, "OutlinePass" (releated to pass 1) and "LightweightForward" (related to pass 2)
    2. Create Custom ScriptableRenderPass that registered pass name "OutlinePass" and insert this to LWRP's before opaque pass.


    I think that this is the only way to implement multipass effect using LWRP.

    My questions are here:
    1. When I create custom pass, what is happen when the other shader which does not have the specific pass is rendered.

    2. (related to question 1) If only few objects has this 2-pass shader and most of other objects has normal lit shader, it seems that inserting custom pass to entire render pipeline for few object may be overkill. Is this approach correct and safe?

    Thanks.
     
  2. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    The correct approach depends on how many objects you want to render with that outline pass.

    If you have just a couple ones it might be faster to just call CommandBuffer.DrawRenderer. https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.DrawRenderer.html

    If you have a few more then put then in a separate rendering layer (or layer) and when issueing context.DrawRenderers pass the layer as filter settings. https://docs.unity3d.com/ScriptReference/Experimental.Rendering.FilterRenderersSettings.html

    This should be fast as it early discard all others object not in this layer.
     
    kakashi8841 likes this.
  3. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Hi Phil
    Would it be possible to get a Graphics.DrawRenderer(Renderer renderer, Material material, int submeshIndex = 0, int shaderPass = -1); method to queue up the rendering of a renderer? Similar to Graphics.DrawMesh. For simple stuff, it might be easier to have a script with ExecuteAlways call this Graphics.DrawRenderer method every update instead of having to maintain a command buffer as objects turn on and off.
     
  4. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    195
    I'm struggling with this as well. Could someone pls provide a full example of how to get a multi-pass shader to
    work with LWRP?
     
    AndreiMarian and Desoxi like this.
  5. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Yea, i would like to see that as well.
     
  6. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Unity- what is the rationale behind only doing the first pass? Why not just render all the appropriate passes in LWRP? I have a lightning shader that draws a glow pass with expanded mesh geometry and then a second pass with less expanded but still expanded mesh geometry creating a thinner inner bolt. This is now impossible in LWRP...
     
    Last edited: Feb 24, 2019
  7. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Unity has said one pass is working as designed according to this issue: https://issuetracker.unity3d.com/is...s-gets-rendered-when-using-multi-pass-shaders

    This is quite limiting and cripples or makes much more difficult a number of effects. I know as an asset and game developer I don't want to have to write the same thing three different ways for standard, lwrp and hdrp.

    Can someone from Unity chime in on why only the first pass is rendered in LWRP?
     
    Last edited: Feb 26, 2019
    Desoxi likes this.
  8. naiwen_xie

    naiwen_xie

    Joined:
    Mar 11, 2017
    Posts:
    12
  9. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Thanks for sharing, does this replace the standard LWRP pipeline?
     
  10. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    Hi, we added a way in LWRP that you can render objects with some filtering/override options without having to write code. This is the proper way to render objects with multiple passes in the shader. It's achieved by adding renderer features to the renderer and choosing for instance which passes should be rendered. You can create new renderer features or use the RenderObjects one we provide with 5.10+ version of LWRP.

    Here's a video showing the power of rendering in LWRP by extending the renderer with renderer features. It mostly uses the RenderObjects one. In that feature you can choose the ShaderPassNames you want to render. You can pass a list of ShaderPassNames and all will render.
     
  11. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Thank you so much for sharing, it is helpful. May I inquire why rendering all the passes for the standard rendering passes (opaque and transparent objects) was not the default behavior? Was there an issue with re-using shaders from standard pipeline?
     
  12. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    That looks very interesting. Couple of questions though...

    Suppose I had certain renderer features that I only wanted to be enabled for certain cameras, such that I could render the main view as normal, but then render the objects to an off-screen buffer using a completely different material and/or some post-effect. Is this possible with this system? I see there is a tick-box in the UI override section marked "Camera" - would this achieve precisely that by any chance??

    Secondly, if we look at the occlusion effect in the video, where the characters are rendered with a different material if they are hidden behind other objects... What if, hypothetically, I wanted to do something similar but render the dither effect a different unique colour for each object. Extend that such that the number of unique objects/colours is too many to be done simply via layers & masking. Is there any way this could be done within this framework? As shown, while you can specify a replacement material for a pass, how might I be able to specify per-object attributes that get passed to the shader? Would MaterialPropertyBlocks work in conjunction with this system and basically allow me to do exactly that?

    Many thanks
     
    foxnne likes this.
  13. cassidycurtis

    cassidycurtis

    Joined:
    Apr 8, 2019
    Posts:
    6
    It's a great feature, and a great demo! But I'm stuck trying to follow Andre's steps, because some of the features he's using in the video don't seem to exist in the released LWRP.

    I'm using Unity 2019.2.0b1 with the latest stable version of LWRP (6.5.3). When I try to add a new Renderer Feature, it doesn't show "Render Objects" as an option in the dropdown menu. The only options I see are "Blit" and "FullScreenQuad":

    Screen Shot 2019-05-20 at 1.52.25 PM.png

    Will we get the "Render Objects" option in a later version of LWRP? And if not, is there any workaround you'd recommend for those of us who'd like to try it?
     
  14. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    After downloading it and setting up a test project, I can answer my own question I guess:

    No, that's sadly (for me) not what the "Camera" override does. It's not a "per-camera" override, instead it lets you change the FOV and a positional offset. :(
     
  15. LoganBlack13

    LoganBlack13

    Joined:
    Apr 7, 2019
    Posts:
    2
    Hi,

    Last LWRP stable release is 5.7.2, render object is only available in preview version from 5.10+. I don't see any 6.x version for LWRP, so check yours and if your under 5.10, that's why you haven't render object.
     
  16. curiouspers

    curiouspers

    Joined:
    Aug 7, 2014
    Posts:
    19
    I tried to use blit in custom renderer object in 2019.2.0f1 with LWRP 6.9.1 and 2019.1.10f1 with LWRP 5.13.0, both on windows and i only have "Render Objects" in a Renderer Features list.
    upload_2019-8-6_19-19-52.png

    I also tried to open https://github.com/Unity-Technologies/LWRP-CustomRendererExamples in 2019.1.10f1 and 2019.2.0f1, both resulting in compile errors.

    Can you please tell what versions should I use to Blit and FullScreenQuad to work?
    Or maybe point me in direction of documentation on how to implement custom Blit pass in 2019.1.10f1?
     
    Last edited: Aug 6, 2019
    foxnne likes this.
  17. curiouspers

    curiouspers

    Joined:
    Aug 7, 2014
    Posts:
    19
  18. jensVrag

    jensVrag

    Joined:
    Aug 9, 2019
    Posts:
    13
    This helped me with getting some basic stencil ops working without having to muck about in hlsl all the time, great update!
     
  19. jensVrag

    jensVrag

    Joined:
    Aug 9, 2019
    Posts:
    13
    Ah, will we have access to two-sided stencils at some point soon? Seems like a weird omission.
     
  20. Fjonan

    Fjonan

    Joined:
    Jun 16, 2013
    Posts:
    5
    I was successful in adapting a default render multi pass stencil shader to work in the Lightweight Render Pipeline. See my answer to my own question here: http://answers.unity.com/answers/1660770/view.html

    Maybe it helps some of you on the right track. This thread pointed me in the right direction so I wanted to share :)
     
    cassidycurtis likes this.
  21. curiouspers

    curiouspers

    Joined:
    Aug 7, 2014
    Posts:
    19
    If I use custom blit in 2019.1.14f1, it breaks reflection probes baking, how can I fix this?
    Reflection probes appear full or partially black after baking. @phil_lira can you help?
     
    Last edited: Sep 10, 2019
  22. aero-alex

    aero-alex

    Joined:
    May 21, 2019
    Posts:
    3
    I have been trying to get lwrp to work with steamvr's highlight shader and for the most part I got it working using render features, but now every highlight effect has to have the same color. Any thoughts on how you could recreate the original highlight effect but allowing each mesh to have its own colored material?
     
    raphaelnew, KenAtGlu and Ofx360 like this.