Search Unity

Rendering at different times in the queue without instancing a material.

Discussion in 'General Graphics' started by quinng, May 1, 2019.

  1. quinng

    quinng

    Joined:
    Jul 2, 2015
    Posts:
    22
    I'm working on a project that involves me rendering multiple duplicates of an object, each at a different time in the render queue. Currently this means that I need to create a separate material instance for each object and use material.renderQueue to set it to the appropriate place in the queue. Otherwise, the materials are the same and would not need to be instanced.

    This is for a nested portal effect, and my concern is that as I try to render more and more layers with more and more objects, the number of material instances I need to create will begin to take up significant space in memory.

    So my question is. Is there a way to get the pipeline to render two or more meshes using a shared material but at different times in the queue? It would be nice if I could simply pass the intended queue position in as part of a property block, but that doesn't seem to be the case.
     
  2. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    34
    Hi @quinng
    did you manage to find a solution to this? i am trying to find out how to render the same sprite a second time with a slightly different setting (with mask applied and a shader with stencil comparison) but not having to duplicate the same gameobject.
     
    Last edited: Aug 29, 2019
  3. quinng

    quinng

    Joined:
    Jul 2, 2015
    Posts:
    22
    Hi, I did not find a way that suited my purposes, but that was because I needed to render the same object in specific but dynamically changing order.

    In your case, it sounds like you can write a shader that makes two passes, each masked by a different setting in the stencil layer.

    Edit: If you are curious how I solved/mitigated my issue. I set up a material pool so that my objects could share material instances. This ensures that I always have the minimal number of material instances stored in memory.