Search Unity

Tutorial - Read Texture Data from C# Scripts

Discussion in 'Community Learning & Teaching' started by ChrisKurhan, Oct 25, 2022.

  1. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    266


    Hey all! Happy #TutorialTuesday!

    I used to be irrationally afraid of reading texture data. For some reason I thought it was going to be this super complicated thing. If you have a similar fear (or you know, if you're just looking to learn about reading textures), this video will help you understand the basics!

    I cover how to read a specific block of pixels from a texture using the
    Texture2D.GetPixels
    method, the math behind choosing a block around the middle of the texture, and because
    Texture2D.GetPixels
    returns a 1D array of colors, how to map back from that 1D array to the 2D coordinates for the selected pixel.

    As always, the full project for this video is available on GitHub!
     
    mgear likes this.