Unity Noise Effect

Or we can call is Tv Noise Effect. Here is a small C# code to handle a noise effect with Unity. Here is the Logic :

  • Create a very simple plane.
  • Add a Material on it.
  • Configure material as Particle > Additive.
  • Choose tint Color as middle grey tones for uncolored noise.
  • Assign this PNG image on Texture box. [I created this image photoshop blackbackground PSD, add noise(100), you can choose monochromatic if you want. ] (You can crop that image to 128x128, its too big)
  • Then create a new c# script and attach the script to plane gameobject.
  • place the plane gameobject on a camera to a desired location and watch.
  • you can tweak the manualTime float variable for more slow or fast noise update frequency.

Script logic :

  • Calculate a custom time update interval. [Noise update time]
  • Start a coroutine for it ( Stay away from Update )
  • Define an UpdateFunction
  • inside while(true) loop, define a Vector2 for offsetting that png on the material.
  • random values are multiplied by x and y coordinates everytime coroutine is called with a update interval and call call SetTextureOffset function of renderer.material to do that.

Good luck!

using UnityEngine;  
using System.Collections;

public class NoiseAnim : MonoBehaviour {

public float manualTime = 1.0f;  
public float frequency = 24.0f;  
public int offsetX = 10;  
public int offsetY = 10;

// Use this for initialization
IEnumerator Start () {  
float customtime = manualTime / frequency;  
//print(customtime + " < customtime");
yield return StartCoroutine("UpdateTexture", customtime);  
}

IEnumerator UpdateTexture ( float waitTime ){  
while(true){  
Vector2 offset = new Vector2(offsetX * Random.value,offsetY * Random.value);  
renderer.material.SetTextureOffset ("_MainTex", offset);  
yield return new WaitForSeconds(waitTime);  
}
}

// poor update function :)
void Update () {}

}
comments powered by Disqus