MeanBlurHandler.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. [ExecuteInEditMode]
  3. public class MeanBlurHandler : MonoBehaviour
  4. {
  5. public Material meanBlurMaterial; //create material from shader and attatch here
  6. [Range(0, 40)]
  7. public int intensity;
  8. void OnRenderImage(RenderTexture src, RenderTexture dst)
  9. {
  10. RenderTexture renderTexture = RenderTexture.GetTemporary(src.width, src.height);
  11. Graphics.Blit(src, renderTexture); //copies source texture to destination texture
  12. //apply the render texture as many iterations as specified
  13. for (int i = 0; i < intensity; i++)
  14. {
  15. RenderTexture tempTexture = RenderTexture.GetTemporary(src.width, src.height); //creates a quick temporary texture for calculations
  16. Graphics.Blit(renderTexture, tempTexture, meanBlurMaterial);
  17. RenderTexture.ReleaseTemporary(renderTexture); //releases the temporary texture we got from GetTemporary
  18. renderTexture = tempTexture;
  19. }
  20. Graphics.Blit(renderTexture, dst);
  21. RenderTexture.ReleaseTemporary(renderTexture);
  22. }
  23. }