Search Unity

How to set texture pixel ?

Discussion in 'General Graphics' started by acropole, Dec 26, 2020.

  1. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    Hi,

    How to set texture pixel ?
    This code don't work :

    Code (CSharp):
    1. tex2D(_MainTex, float2(i.uv.x, i.uv.y)) = result;
    Thanks
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Nope, it won't.

    You can either ender to a render texture using a shader and a Blit() and copy the results using ReadPixels back to a Texture2D, or you can modify the Texture2D directly from C# using GetPixels()/SetPixels(). You cannot directly modify a Texture2D from a shader, only read from them.

    What exactly are you trying to do?
     
  3. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171