#Graphics.RenderMeshInstanced with additional custom data

1 messages · Page 1 of 1 (latest)

placid pasture
#

Hi, I've been using Graphics.RenderMeshInstanced to draw instanced meshes, my shader is simple. Now how can I add a new custom float to each instance?

I looked into https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Graphics.RenderMeshInstanced.html but it doesn't go into details about the custom weight property.
I also saw some advise about using MaterialPropertyBlock but that system doesn't yet support NativeArray so I rather find an alternative.

Right now I'm just using my NativeList<Matrix4x4> _matrices with the Graphics.RenderMeshInstanced function and its pretty good. I wonder if I can keep it in the same quality and add custom data to the instances.

++ standard render pipeline

#

if it matters, right now my shader is also pretty simple and follows the standards

v2f vert(appdata v)
{
    v2f o;
    UNITY_SETUP_INSTANCE_ID(v);
    UNITY_TRANSFER_INSTANCE_ID(v, o);
    o.vertex = UnityObjectToClipPos(v.vertex);
    return o;
}
fixed4 frag(v2f i) : SV_Target
{
    UNITY_SETUP_INSTANCE_ID(i);
    return fixed4(1, 1, 1, _Opacity);
}
#

ideally I'd like to have a float t in the frag which is instanced. and ideally I'd like to not use managed List or Array in the C# side for that! and also, ideally not using the Indirect rendering methods!

#

Thanks in advance! 😅🙏 messages got a little long, so let me know if it needs to be summarized and shortened

drifting cargo
placid pasture
placid pasture
#

With the other approach, the good thing about it was it handled size and capacity automatically.

#

the Graphics.RenderMeshInstanced with NativeArray<Matrix4x4> as its T

#

I guess there's no running away from StructuredBuffer

#

Thanks again 🙏

drifting cargo
placid pasture
# drifting cargo Unfortunately no. But it is not that hard as it seems at first.

Hey, just wanted to say that indeed it was easier than I thought and it's implemented. Thanks again! For sake of referencing, this video helped a lot too (Unity Japan is such a treasure!) on the ordering of the API callings and that we need to use the material's SetBuffer and not the RenderParameter's matProp's

RenderMeshInstanced (いわゆる「GPU インスタンシング」)を使うと大量のオブジェクトを低負荷に描画することができますが、オブジェクト毎に異なる色やプロパティを与えようとすると工夫が必要になってきます。

この動画では、アイドルコンサートなどで見...

▶ Play video
placid pasture
#

so this is 100,000 lines drawn every frame 😅