How to render a data buffer in game? (e.g. how to display a changing height or influence map)

I have an actor which holds an array of floats that I want to render out on a plane somehow (values close to 1.0f are green, values close to 0.0f are black, values in the middle are pink etc). Effectively it is a height map but the data changes every frame.

I originally tried to use DrawMaterialToRenderTarget. This works for changing a few pixels but of course grinds to a halt if you try and update an entire texture (which I should have seen coming!).

Is there a method to achieve what I am trying to do?

Thanks!

It’s been a while since I’ve done dynamic data, but I remember that there are several ways to do this. Two paths that you could consider:

  1. Make a texture of type float32 of size 1xN where N is the number of data points. Bind this texture into your material. Create an array of data points in your program, and update the texture data with the contents of this array once per frame, after updating all the array values.

  2. Use ProceduralMesh with a custom vertex data channel, and a shader that knows how to read and interpret this channel data.

Given what you say about your use case, I think option 1 would be more efficient, but you’d have to try it and see. The main tool to apply is “apply all the change for a frame in a single operation,” and generally, a ProceduralMesh will likely be more overhead than just updating a dynamic texture.

One point to start threading this out is likely UpdateTextureRegion():

Thank you for your suggestions! Very helpful :smiley:

When I did some googling earlier I found that this person tried UpdateTextureRegions Updating a texture by code at every tick? - #2 by Pino_of_DFT_Games but since he had poor performance with quite a small texture I didn’t investigate any further. I will give it a try :slight_smile:

I will give option 1 a try as well :slight_smile: When I was googling I came across examples of updating texture data in one batch at runtime e.g. https://www.orfeasel.com/generating-procedural-textures/ but I discounted it since it requires UpdateResources which the above forum post also mentions kills performance completely. That is why I thought that I was totally on the wrong path.