﻿using UnityEngine;
using System.Collections;



[ExecuteInEditMode]
public class ShaderBlit : MonoBehaviour {

	public bool					Dirty = true;
	public bool					AlwaysDirtyInEditor = true;
	public Texture				Input;
	public Shader				BlitShader;
	public Material				BlitMaterial;
	public RenderTexture		Output;
	public UnityEngine.Events.UnityEvent	OnClean;

	public void SetDirty()
	{ 
		Dirty = true;
	}

	void Update ()
	{
		if ( Application.isEditor && !Application.isPlaying && AlwaysDirtyInEditor )
			Dirty = true;

		if ( !Dirty )
			return;

		if ( Input == null )
			return;

		if (BlitShader != null)
		{
			if ( BlitMaterial == null )
				BlitMaterial = new Material( BlitShader );
		}

		if ( BlitMaterial == null )
			return;

		Graphics.Blit( Input, Output, BlitMaterial );

		Dirty = false;

		if ( OnClean != null )
			OnClean.Invoke();

	}
}

﻿using UnityEngine;
using System.Collections;



[ExecuteInEditMode]
public class ShaderBlit : MonoBehaviour {

	[InspectorButton("Execute")]
	public bool					Dirty = true;
	public bool					AlwaysDirtyInEditor = true;
	public Texture				Input;
	public Shader				BlitShader;
	public Material				BlitMaterial;
	public RenderTexture		Output;
	public UnityEngine.Events.UnityEvent	OnClean;

	public void SetDirty()
	{ 
		Dirty = true;
	}

	public void Execute()
	{
		if (BlitShader != null)
		{
			if ( BlitMaterial == null )
				BlitMaterial = new Material( BlitShader );
		}

		if ( BlitMaterial == null )
			return;

		Graphics.Blit( Input, Output, BlitMaterial );

	}


	void Update ()
	{
		if ( Application.isEditor && !Application.isPlaying && AlwaysDirtyInEditor )
			Dirty = true;

		if ( !Dirty )
			return;

		if ( Input == null )
			return;

		Execute();

		Dirty = false;

		if ( OnClean != null )
			OnClean.Invoke();

	}
}

Put explicit blit in its own Execute func, added inspector button
Put explicit blit in its own Execute func, added inspector button

