I want to make like a noise/static effect on screen simulating like you would be watching through a video camera. How would one be able to achieve these kind of effects with Unity Free?
The most efficient method would be with a custom shader. The second most efficient method is likely to be a set of images animated on plane or a GUITexture in front of the camera. You will find code here to animate a set of images.
[http://wiki.unity3d.com/index.php?title=Texture_swap_animator][1]
A less efficient method is to dynamically calculate changes in a texture:
- Create a Quad (Game Object > Create Other > Quad).
- Move the Quad directly in front of the camera just in front of the camera and just in front of the near clip plane of the camera
- Make the Quad a child of the camera
- Create a material using the Unlit/Transparent shader and apply it to the Quad (no need for a texture)
- Add the script below to the Quad.
#pragma strict
var lineFrequency = 5;
var updateFrequency = 5.0;
private var tex : Texture2D;
private var pixels : Color32[];
private var mat : Material;
function Start () {
mat = renderer.material;
tex = new Texture2D(255, 255);
var c32 = Color32(0, 0, 0, 0);
pixels = tex.GetPixels32();
for (var i = 0; i < pixels.Length; i++) {
pixels *= c32;*
-
}*
-
tex.SetPixels32(pixels);*
-
tex.Apply();*
-
mat.mainTexture = tex;*
-
InvokeRepeating(“UpdateStatic”, 0.0, 1.0/updateFrequency);*
}
function UpdateStatic() {
- for (var i = 0; i < pixels.Length; i++) {*
-
if ((((i / tex.width ) % lineFrequency) == 0 ))*
_ pixels*.a = Random.Range(85, 101.0);_
_ else*_
_ pixels*.a = Random.Range(0, 25);
}*_
* tex.SetPixels32(pixels);*
* tex.Apply();*
* mat.mainTexture = tex;*
}
There are a number of things here to play with to get the effect the way you want:
- The size of the texture and the line frequency will effect the softness/hardness of the lines…and will also have an impact on efficiency.
- The Random.Range() calls determines the look of the static for both lines and non-line areas.
- 'updateFrequency determines the rate at which the static refreshes.
[1]: http://wiki.unity3d.com/index.php?title=Texture_swap_animator