How to transmit lots of data to a Material efficiently?

Thanks for the link :slight_smile:. Here is how I solved it in my case, where I needed to store and read Vector3s.

Render target settings

  • I had to set the Texture Group to 2D pixels to be able to properly read the data in the material graph
  • Set Size X and Size Y to the size of your “array”. In my case it’s a 2D array of 256x2

How to store the data

How to read data from the render target within the material graph

Add a custom node to the graph, with the following code and inputs:

  • Tex: your render target texture
  • PixelCoordinates: the coordinates of the pixel that holds the data you need
  • TexSize: the size of your render target (In my case 256x2). There is maybe a more dynamic way to get the texture size, but this is good enough for me.

HLSL Code:

float2 UV = PixelCoordinates/TexSize;
float3 data = Texture2DSample(Tex, TexSampler, UV);

return data;

The output will be the data that you stored earlier :slight_smile:

1 Like