-
Notifications
You must be signed in to change notification settings - Fork 42
Prepare compatible material
To make render possible we also need to create instancing compatible Material. There is two requirements:
- Material supports instancing
- Shader supports instancing
Which means shader can work with StructuredBuffer<T>
and obtain instanceID
.
Note: Under the hood system uses
MaterialPropertyBlock.SetBuffer(int propID, ComputeBuffer buffer)
, so you can use any shader which will recieve buffer setted like this. It can be achieved using ShaderGraph, but I couldn't figure out how to do it, so here I show basics of writing HLSL instancing code part to obtain instance (entity sprite) data.
- Before any example you can look at this gist which is HLSL shader code I was using during developing NSprites. This is complete example of instance compatible URP HLSL shader.
- To write instancing HLSL shader look at this unity doc page.
- If you want to read about writing HLSL code compatible with URP, I recommend you this brilliant documentation.
One another requirement is to complete your shader with additional StructuredBuffer<int> _propertyPointers;
which described here.
After writing instancing compatible shader you need create material from it. Then to make this you simply need to select your material in project and check Enable GPU Instancing