#GPU Instancing and Array based MaterialPropertyBlock

1 messages · Page 1 of 1 (latest)

stable summit
#

So in my game, I have about 800 3D Mesh tiles. I have implemented GPU Instancing, which significantly reduced draw calls during spawning, and now I plan to add a trailing highlight effect that triggers when hovering over the tiles.

For this mechanic to work, I need the MaterialPropertyBlock to take in a float array. As we know the shader graph wont take in any array properties. I was just wondering if there are any other alternatives like HLSL? Maybe that could take in an array.

At the end of the day I just need to input in a unique float for each of the tiles every frame and make it work with GPU Instance.

shadow pier
stable summit
#

So it is possible with HLSL. That's nice.

#

Can you give a general insight of what to look into within HLSL includes. Is it something to do with Instanced property?

shadow pier
#

I'm not sure of your question here.
An HLSL include is just a hlsl code file that is included in the shader hlsl code (think of a c# using directive).
Use the custom function node : https://docs.unity3d.com/Packages/com.unity.shadergraph@17.5/manual/Custom-Function-Node.html
Set to "file" type.

Create a .hlsl file, and assign it in the source field.

In the .hlsl, declare your array like
float myFloatArray[];
And a function that will be used from the custom function node to retrieve a value from it :

void GetFloatFromArray_float( int index, out float value )
{
  value = muFloatArray[index];
}
rancid lotus
#

notably, you don't need something in the blackboard (or in the inspector, more generally) to be able to set it with one of the Material.Set* methods