Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Access to RenderObjects pass info from script?

Discussion in 'Universal Render Pipeline' started by joeld42, Nov 21, 2019.

  1. joeld42

    joeld42

    Joined:
    Oct 3, 2016
    Posts:
    31
    Hello,

    I have a UWP project that is using the "RenderObjects" render pass to draw an overlay grid on the scene with some feedback data. That works great so far.

    However, I need to access this RenderObjects pass through code, in this case to set the override material from code. I can't seem to figure out how to get to this through the api. Here's the closest I've come:

    Code (CSharp):
    1.             UniversalRenderPipelineAsset urpAsset = (UniversalRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
    2.             ScriptableRenderer render = urpAsset.scriptableRenderer;
    3.  
    4.             ScriptableRendererData rendererData = render.???;
    5.  
    6.  
    7.             List<ScriptableRendererFeature> rendererFeatures = rendererData.rendererFeatures;
    8.             foreach (ScriptableRendererFeature feature in rendererFeatures)
    9.             {
    10.                 RenderObjects objectPass = feature as RenderObjects;
    11.                 if (objectPass != null)
    12.                 {
    13.                     // do something with objectPass
    14.                     Debug.LogFormat("Override material is {0}", objectPass.settings.overrideMaterial.name );
    15.                 }
    16.             }

    Right now I'm working around this by just keeping a reference to the material somewhere else, but this is not idea for a few reasons -- I would like to be able to enable/disable the overrideMaterial at runtime (right now I'm just setting and unsetting the layer for things so it's always running the renderObjects pass even when it doesn't need it, and also this modifies the .mat file in the scene which is just annoying.

    Am I missing something to get access to the objectPass asset at runtime?

    We're using 2019.1.7f1 with LWRP 5.16.1, but I've also tried this with 2019.3.0b11 and UWP 7.1.5 since we're considering upgrading and didn't see any difference.

    Thanks!
    Joel
     
    oleg_v likes this.
  2. Solovykh

    Solovykh

    Joined:
    Aug 28, 2017
    Posts:
    59
    Yep, you're on the right track with that code snippet. Just use reflection to get the
    m_RendererData field of the pipeline asset. Also keep in mind that you'll need to change the override material on the pass itself not the feature. However, the feature has a reference to the pass called "renderObjectsPass", which has a public setter for the override material. renderObjectsPass is marked internal so you'll need to use reflection to get access to it as well.
     
    oleg_v likes this.
  3. Robber33

    Robber33

    Joined:
    Feb 22, 2015
    Posts:
    52
    Hi, I took a different appoach to communicate with a renderpass.
    you will need to create your own version of the renderobjects feature tho

    I use a scriptable object, that holds the data i need.
    in the renderfeature setting i have a slot to put this type of scriptableobject, and i pass this to the
    ScriptableRenderPass.

    in another script (monobehaviour) i reference the same asset, i can change any data i want.

    hope this helps
     
    oleg_v and Pronotron like this.
  4. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,106
    For me it works for LWRP but in URP not working anymore :(
    Editor Works but Android Player dont
     
  5. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,106
    Hack with access to GraphicsSettings.renderPipelineAsset... through reflection works on URP :)
     
  6. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Damn encapsulation:mad: