Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ExecuteInEditMode]
- [RequireComponent(typeof(Camera))]
- [AddComponentMenu("Image Effects/Screen Transition ImageEffec")]
- public class ScreenTransitionImageEffect : MonoBehaviour
- {
- public Shader shader;
- [Range(0, 1.0f)]
- public float maskValue;
- public Color maskColor = Color.black;
- public Texture2D maskTexture;
- public float maskInvert;
- public Vector2 xy;
- Material m_Material;
- bool m_maskInvert;
- Material material
- {
- get
- {
- if (m_Material == null)
- {
- m_Material = new Material(shader);
- m_Material.hideFlags = HideFlags.HideAndDontSave;
- }
- return m_Material;
- }
- }
- void Start()
- {
- if (!SystemInfo.supportsImageEffects)
- {
- enabled = false;
- return;
- }
- shader = Shader.Find("Hidden/ScreenTransitionImageEffect");
- if (shader == null || !shader.isSupported)
- {
- enabled = false;
- }
- }
- void OnDisable()
- {
- if (m_Material)
- {
- DestroyImmediate(m_Material);
- }
- }
- void OnRenderImage(RenderTexture source, RenderTexture destination)
- {
- if (!enabled)
- {
- Graphics.Blit(source, destination);
- return;
- }
- material.SetColor("_MaskColor", maskColor);
- material.SetFloat("_MaskValue", maskValue);
- material.SetFloat("_INVERT_MASK", maskInvert);
- material.SetTexture("_MainTex", source);
- material.SetTexture("_MaskTex", maskTexture);
- material.SetVector("_XY", xy);
- Graphics.Blit(source, destination, material);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement