Modifying pixels of a texture efficiently

Hello guys,

Currenlty I am working in a project where I use a big texture (2000x1000 pixels) and I receive information of every pixel colour via TCP socket (RGB).

I want to modify the big texture with this information in a efficient way, so basically I want to paint pixels with colors on the texture as fast as possible, I have tested some alternatives:

  • Using SetPixel() → Not viable, it is really slow and I can only do it on the main thread so I block the application during the process.

  • Using GetRawTextureData, modifying all the bytes and then using Apply() → Way faster alternative, I can do most of the processing part in another thread but I still have to call the texture.Apply() which has to be done in the main thread.

Is there a more efficient way of solving this problem?

I have read about using shaders for solving this kind of problem but I am a bit lost in the topic, anyone can explain me how you will solve this issue using a shader or maybe a example of a really simple shader that changes the colour of a few pixels of a texture?

Thank you for your time and sorry for possible spelling errors, English is not my main language ;D

You can have an array of Color and use SetPixels, instead of SetPixel, it is faster than its counterpart.

1 Like