rendering a texture over time

I am creating a game with old fashioned aesthetics and I am trying to figure out the best approach to recreating this effect in unity 5 for my loading screen. Any advice would be appreciated.

http://www.robeesworld.com/spectrum_loading_screen_simulator

Okay, this is actually fun.

Here’s a small example, but you have to set up a few things (scroll down).
I also tried random pixels which was nice, too. I can recommend that. You could also try to set them block-wise or a bit more complex: build the texture from the top and buttom at the same time :wink:

Anyway, you can tweak 2 parameters. One determines how many rows will be skipped, the other one how many pixels will be set per frame.

using UnityEngine;
using System.Collections;
public class TextureBlendExample : MonoBehaviour
{
    // source texture, dont modify this, instantiate it (see Start)
    public Texture2D tex2D;
    private Color[] pixels;
    private Material mat;

    // how many pixels until we'll yield (in other words: how many per frame)
    public int pixelsPerUpdate = 50;
    // how many rows to skip
    public int skipRows = 2;

    void Start()
    {
        mat = GetComponent<Renderer>().material;
        // make a copy
        Texture2D copy = Instantiate<Texture2D>(tex2D);
        pixels = copy.GetPixels();
        // set alpha to zero
        for (int i = 0; i < pixels.Length; i++)
        {
            pixels*.a = 0;*

}
// set pixels and apply
copy.SetPixels(pixels);
copy.Apply();
mat.mainTexture = copy;
// let the fun begin
StartCoroutine(BlendTexture_SkipRowsTopDown(copy));
}

IEnumerator BlendTexture_SkipRowsTopDown(Texture2D texture)
{
// restart to fill the ones left out
for (int i = 0; i < skipRows; i++)
{
// next row (current + skiprows)
for (int j = i; j < texture.height; j += skipRows)
{
// full width
for (int k = 0; k < texture.width; k++)
{
int index = j * texture.width + k;
pixels[index].a = 1;
if (index % pixelsPerUpdate == 0)
{
texture.SetPixels(pixels);
texture.Apply();
mat.mainTexture = texture;
yield return null;
}
}
}
}

Debug.Log(“done”);
}
}

- drop a new gameobject into the scene
- add a material to it (don’t take the default) and change to transparent rendering mode
- assign this script to the object
- put the source texture (it’s the best to have one with alpha channel) into the slot (the script will make a copy to not alter the original)
- go to the source texture’s import settings and set texture type to advanced, check read/write enabled
Now do the first check. It may throw an error because of the format, if so, set ‘none power of 2’ to ‘none’ in the texture import settings. Try again.
If it still doesn’t work, you can also check alpha from grayscale. Now it should actually work if it hasn’t already unless I forgot something.