Advertisement
Guest User

Shader controlling script for Unity

a guest
May 31st, 2014
2,816
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditMode]
  4. [RequireComponent(typeof(Camera))]
  5.  
  6. public class TVShader : MonoBehaviour
  7. {
  8.     public Shader shader;
  9.     private Material _material;
  10.  
  11.     protected Material material
  12.     {
  13.         get
  14.         {
  15.             if (_material == null)
  16.             {
  17.                 _material = new Material(shader);
  18.                 _material.hideFlags = HideFlags.HideAndDontSave;
  19.             }
  20.             return _material;
  21.         }
  22.     }
  23.  
  24.     private void OnRenderImage(RenderTexture source, RenderTexture destination)
  25.     {
  26.         if (shader == null) return;
  27.         Material mat = material;
  28.         Graphics.Blit(source, destination, mat);
  29.     }
  30.  
  31.     void OnDisable()
  32.     {
  33.         if (_material)
  34.         {
  35.             DestroyImmediate(_material);
  36.         }
  37.     }
  38. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement