#RenderMeshIndirect - injecting struct data into ShaderGraph

1 messages · Page 1 of 1 (latest)

clever horizon
#

Hi guys,

currently trying to implement RenderMeshIndirect, rendering instances of a mesh.
Pretty new in this kind of field, programming C#/HLSL in general, but with some help I got it to work.

As of right no I am using a HLSL/Shader code to get it to work, but I would like to intend to use Shader Graph for this kind of stuff.

This is my current shader code: https://pastebin.com/KTYbCg6d
This is part of the C# code: https://pastebin.com/1hep4fnV (I hope I did not missed anything important here)

As far as I am aware of, injecting a GraphicsBuffer is not possible within ShaderGraph, but I found a video on Youtube, in which shich someone was bypassing this kind of stuff by using a custom function.
https://github.com/KDSBest/Render1MillionObjectsWithUnityAndShaderGraph/blob/main/Assets/Shaders/BeltInstancing.hlsl

And there I thought, well, this looks pretty similar to my problem actually.

So my quuestion is ... is this similiar to my case and if yes, could you give me a hin on how to solve this?
Unfortunately I can't find anything to this topic, also not on this discord. When searching for 'RenderMeshIndirect' in this and the coding channel, I can't find any related post ~

Thanks for the help and have a nice day 🙂

Render 1 Million Objects with Shader Graph and Unity.
We leverage Graphics.DrawMeshInstancedIndirect and make it work in Shader Graph, which is not supported by default.

Links for Community:
Patreon: https://www.patreon.com/kdsmmorpg
Discord: https://discord.gg/GjcuUfUny7

Github: https://github.com/KDSBest/Render1MillionObjectsWithUnityAndShad...

▶ Play video
GitHub

Render 1 Million Objects with Unity and ShaderGraph. Make Graphics.DrawMeshInstancedIndirect work with ShaderGraph - KDSBest/Render1MillionObjectsWithUnityAndShaderGraph

frigid blaze
#

I have a recent tutorial that covers functions like RenderMeshIndirect + ShaderGraph (to render grass quads in my case) which should help
https://www.cyanilux.com/tutorials/gpu-instanced-grass-breakdown/

The setup varies a bit between versions, so the post has tabs to switch the page content. The main difference being :

  • Unity 6 allows you to use the Instance ID node to inject/obtain SV_InstanceID which you'd pass into a Custom Function to index a StructuredBuffer.
  • Versions prior had to use a somewhat hacky workaround with two Custom Function nodes, to force the "procedural instancing path" to be defined.