Created
September 22, 2016 07:20
-
-
Save arunkarnann/59d978d671032c82c70936001074f0a2 to your computer and use it in GitHub Desktop.
vgseffects.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
[ExecuteInEditMode] | |
public class PostRenderer : MonoBehaviour | |
{ | |
public Material _material; | |
void Awake() | |
{ | |
_material = new Material(Shader.Find("Custom/VHSeffect")); | |
_material.SetTexture("_SecondaryTex", Resources.Load("Textures/TVnoise") as Texture); | |
_material.SetFloat("_OffsetPosY", 0f); | |
_material.SetFloat("_OffsetColor", 0.01f); | |
_material.SetFloat("_OffsetDistortion", 480f); | |
_material.SetFloat("_Intensity", 0.64f); | |
} | |
public void OnRenderImage(RenderTexture source, RenderTexture destination) | |
{ | |
// TV noise | |
_material.SetFloat("_OffsetNoiseX", Random.Range(0f, 0.6f)); | |
float offsetNoise = _material.GetFloat("_OffsetNoiseY"); | |
_material.SetFloat("_OffsetNoiseY", offsetNoise + Random.Range(-0.03f, 0.03f)); | |
// Vertical shift | |
float offsetPosY = _material.GetFloat("_OffsetPosY"); | |
if(offsetPosY > 0.0f) | |
{ | |
_material.SetFloat("_OffsetPosY", offsetPosY - Random.Range(0f, offsetPosY)); | |
} | |
else if (offsetPosY < 0.0f) | |
{ | |
_material.SetFloat("_OffsetPosY", offsetPosY + Random.Range(0f, -offsetPosY)); | |
} | |
else if (Random.Range(0, 150) == 1) | |
{ | |
_material.SetFloat("_OffsetPosY", Random.Range(-0.5f, 0.5f)); | |
} | |
// Channel color shift | |
float offsetColor = _material.GetFloat("_OffsetColor"); | |
if (offsetColor > 0.003f) | |
{ | |
_material.SetFloat("_OffsetColor", offsetColor - 0.001f); | |
} | |
else if (Random.Range(0, 400) == 1) | |
{ | |
_material.SetFloat("_OffsetColor", Random.Range(0.003f, 0.1f)); | |
} | |
// Distortion | |
if (Random.Range(0, 15) == 1) | |
{ | |
_material.SetFloat("_OffsetDistortion", Random.Range(1f, 480f)); | |
} | |
else | |
{ | |
_material.SetFloat("_OffsetDistortion", 480f); | |
} | |
Graphics.Blit(source, destination, _material); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment