How to create texture in shader

Hello!

I have searched a lot and I have found no answer. If I make a shader, and make a texture2d variable in it, it is supposed that I then drag-n-drop some png/psd/whatever file there.

But how can I make this texture inside shader proceduraly? For example, I want it to be 256x256 and I want every pixel just to be random color. And the random color of each pixel should be calculated only once when the object is instantiated. So it’s like a pregeneration of a texture on program start or object instantiation.

Thank you!

don’t do this in a shader (not even possible as far as I know), do this in a script at startup. Use the Texture2D class: Unity - Scripting API: Texture2D

Use SetPixels()

It’s all fairly straightforward