Search Unity

What's the proper way to draw renderers to the custom RT in CustomPass?

Discussion in 'High Definition Render Pipeline' started by xVergilx, Apr 4, 2020.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Previously, I've been using CommandBuffer.DrawRenderer to render specific objects to the post fx render texture.

    There's RenderListDesc, but it makes SRP render all objects of the specific layer.
    E.g. HDUtils.DrawRendererList(renderContext, cmd, RendererList.Create(result));

    Is it possible to only render specific objects with different material?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Doing this is the problem, something is completely stalling pipeline to a crawl (at 50 renderers) (fps drops from 35 -> 4):
    Code (CSharp):
    1.          CoreUtils.SetRenderTarget(cmd, _outlineBuffer, ClearFlag.All);
    2.  
    3.          foreach (KeyValuePair<int, OutlineInstanceData> pair in _objectRenderers) {
    4.             OutlineInstanceData data = pair.Value;
    5.          
    6.             cmd.SetGlobalColor(ShaderConst.Color, data.Color);
    7.             List<Renderer> renderers = data.Renderers;
    8.  
    9.             foreach (Renderer rend in renderers) {
    10.                cmd.DrawRenderer(rend, _highlightMaterial, 0, 0);
    11.             }
    12.          }
     
  3. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,
    I tried to generate a custom mask for an effect a while ago, but couldn't figure it out myself how to get it done...
     
    xVergilx likes this.
  4. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    264
    Hello,

    There is one example of a masked effect for a blur here: https://github.com/alelievr/HDRP-Custom-Passes#slight-blur-effect but it indeed uses a Layer to generate the mask.

    Alternatively you could use the rendering layer masks to select which renderer you'll draw, it will be faster than iterating through renderers yourself. You can set it here: https://docs.unity3d.com/2018.3/Doc...lterRenderersSettings-renderingLayerMask.html but note that you'll have to write the whole ScriptableRenderContext.DrawRenderers() call yourself.
    Then you can set the rendering layer mask per renderer: upload_2020-4-6_11-25-37.png
    Note that rendering layer masks are what we use for the light layers so you probably don't want to use the 8 first values since they are reserved for this usage.
     
    xVergilx likes this.
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Yeah, that does sound like a lot of work.

    I think I'll just swap layers around when needed. Hopefully we won't run out of layers in the future.
     
  6. Dark_Seth

    Dark_Seth

    Joined:
    May 28, 2014
    Posts:
    140
    How would one do this in 2D. Need to add a layermask. Of LightMask but can't seem to get it to work. LayerMask should be a feature in this