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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Custom Pass to rerender object with a special rendering layer

Discussion in 'High Definition Render Pipeline' started by rikoo, Jun 3, 2021.

  1. rikoo

    rikoo

    Joined:
    Nov 17, 2016
    Posts:
    11
    Hey, hope you are all good :)

    I would like to render objects with a special rendering layer with another material.
    So far I have tried multiple things but nothing worked.
    I tried reproducing in simpler the HDRP draw renderer.
    I followed these ideas also: https://forum.unity.com/threads/custom-render-pass-custom-buffers.758558/

    My code:
    Code (CSharp):
    1. protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult)
    2.     {
    3.         var result = new RendererListDesc(shaderTags, cullingResult, hdCamera.camera)
    4.         {
    5.             rendererConfiguration = PerObjectData.None,
    6.             renderQueueRange = RenderQueueRange.all,
    7.             sortingCriteria = SortingCriteria.BackToFront,
    8.             excludeObjectMotionVectors = false,
    9.             overrideMaterial = m_OverrideMaterial,
    10.             overrideMaterialPassIndex = 0,
    11.             layerMask = ~0,
    12.         };
    13.  
    14.         RendererList renderList = RendererList.Create(result);
    15.         renderList.filteringSettings.renderingLayerMask = m_RenderingLayer;
    16.         HDUtils.DrawRendererList(renderContext, cmd, renderList);
    17.     }
    There m_RenderingLayer is something like "1 << index".

    But it does not do anything, even when commenting the filter line.

    Does anyone have an idea? Or a tutorial to follow to create a custom pass?

    Have a nice evening :)

    EDIT:
    I found the solution, the code is almost right.
    The only thing to change is the overrideMaterialPassIndex, 0 is invalid and on my material it was the 5(the last one available) that was working. But I will write an editor to be able to pick the pass wanted.
     
    Last edited: Jun 4, 2021
  2. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    199
  3. rikoo

    rikoo

    Joined:
    Nov 17, 2016
    Posts:
    11
    Yeah, I already saw that
    I will try to reproduce one of them, thanks for the help :)