Hello,
I’ve been experimenting with the function DrawMeshInstancedIndirect along with Compute Buffers (to update the instanced positions with a flocking algorithm). I can display all the mesh instances with a basic colour but when I want to be able to use the built in URP Lit Shader on the generated Instances it is becoming complicated to say the least.
I’ve been trying to create a custom Lit Shader by duplicating and modifying the LitForwardPass.hlsl but I’m not sure if I will be able to actually access the unity_InstanceID necessary to get the proper mesh instance from the buffer:
Varyings LitPassVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
#if SHADER_TARGET >= 45
Boid data = boidsBuffer[???];
#else
Boid data = 0;
#endif
…
Not sure how to actually access the id at ???.
The Boid data is made like this :
struct Boid
{
float4 position;
float3 direction;
float noise_offset;
};
StructuredBuffer boidsBuffer;
Any idea / suggestion?
I’m happy to share more of the code if need be.
Thanks
Romain