Advertisement
dimmpixeye

Untitled

Feb 22nd, 2019
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1.  
  2. [ExecuteInEditMode]
  3. [RequireComponent(typeof(Camera))]
  4. [AddComponentMenu("Image Effects/Screen Transition ImageEffec")]
  5. public class ScreenTransitionImageEffect : MonoBehaviour
  6. {
  7.     public Shader shader;
  8.  
  9.     [Range(0, 1.0f)]
  10.     public float maskValue;
  11.  
  12.     public Color maskColor = Color.black;
  13.     public Texture2D maskTexture;
  14.     public float maskInvert;
  15.     public Vector2 xy;
  16.     Material m_Material;
  17.     bool m_maskInvert;
  18.  
  19.     Material material
  20.     {
  21.         get
  22.         {
  23.             if (m_Material == null)
  24.             {
  25.                 m_Material = new Material(shader);
  26.                 m_Material.hideFlags = HideFlags.HideAndDontSave;
  27.             }
  28.  
  29.             return m_Material;
  30.         }
  31.     }
  32.  
  33.     void Start()
  34.     {
  35.         if (!SystemInfo.supportsImageEffects)
  36.         {
  37.             enabled = false;
  38.             return;
  39.         }
  40.  
  41.  
  42.         shader = Shader.Find("Hidden/ScreenTransitionImageEffect");
  43.  
  44.  
  45.         if (shader == null || !shader.isSupported)
  46.         {
  47.             enabled = false;
  48.         }
  49.  
  50.     }
  51.  
  52.     void OnDisable()
  53.         {
  54.             if (m_Material)
  55.             {
  56.                 DestroyImmediate(m_Material);
  57.             }
  58.         }
  59.  
  60.         void OnRenderImage(RenderTexture source, RenderTexture destination)
  61.         {
  62.             if (!enabled)
  63.             {
  64.                 Graphics.Blit(source, destination);
  65.                 return;
  66.             }
  67.  
  68.             material.SetColor("_MaskColor", maskColor);
  69.             material.SetFloat("_MaskValue", maskValue);
  70.             material.SetFloat("_INVERT_MASK", maskInvert);
  71.             material.SetTexture("_MainTex", source);
  72.  
  73.             material.SetTexture("_MaskTex", maskTexture);
  74.             material.SetVector("_XY", xy);
  75.  
  76.             Graphics.Blit(source, destination, material);
  77.         }
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement