Search Unity

How to pass custom per-draw data to shader in Scriptable Render Pipeline ?

Discussion in 'Universal Render Pipeline' started by HeqiLu, Aug 10, 2020.

  1. HeqiLu

    HeqiLu

    Joined:
    Sep 19, 2017
    Posts:
    1
    Hi,

    Is that possible to inject custom per-draw data to shader, in scriptable render pipeline?

    I am asking this, because we have a rendering technique requires rendering some objects many times with different data per draw.

    CommandBuffer.DrawMeshInstanced is a workaround. I can collect the objects that will be drawn many times, then use this function to draw. I can inject an ID into Matrix4x4, then use that ID to access external buffers to get the all the data I need. However, as the objects are not all instances, and we have many materials of same shader, it may result in many DrawMeshInstanced calls. This workaround seems more expensive than SRP batcher.

    Please correct me if I am wrong. To use SRP batcher, I have to use ScriptableRenderContext.DrawRenderers. But this function is a black box in terms of creating the batch. If there were a way to let users arrange the objects for the batch, that would be nice. It could be just two layers for each shader, the first layer is for instances, the second layer is for meshes. Then a mesh could be drawn many times by specifying many instances in the first layer. A UnityPerDraw could be provided for each instance and result in a buffer. This UnityPerDraw buffer might be similar to Built-in UnityPerDraw buffer, but has an instance ID for each UnityPerDraw . Users could use this instance ID to access external buffers to get their custom per-draw data. Because, the two layer arrangement is specified by users, users know how to create instanceID to buffer index mapping. This approach also supports per-object data of course.

    Please note that. Even if our rendering technique might be very specific. The capability of supporting per-draw and per-object data in Scriptable Render Pipline would make this framework more useful.

    Thanks a lot,
     
  2. msue

    msue

    Joined:
    Jun 10, 2015
    Posts:
    6
    bump
     
    Pavlov_Oleg likes this.