// flat blur
void Blur(RenderTexture from ,RenderTexture to , int iterations , int blurPass, float spread )
{
RenderTexture tmp = RenderTexture.GetTemporary (to.width, to.height, 0);
if (iterations < 2) {
dofBlurMaterial.SetVector ("offsets", new Vector4 (0.0f, spread * oneOverBaseSize, 0.0f, 0.0f));
tmp.DiscardContents ();
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
to.DiscardContents ();
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
}
else {
dofBlurMaterial.SetVector ("offsets", new Vector4 (0.0f, spread * oneOverBaseSize, 0.0f, 0.0f));
tmp.DiscardContents ();
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
to.DiscardContents ();
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, spread * oneOverBaseSize, 0.0f, 0.0f));
tmp.DiscardContents ();
Graphics.Blit (to, tmp, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, -spread * oneOverBaseSize, 0.0f, 0.0f));
to.DiscardContents ();
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
}
RenderTexture.ReleaseTemporary (tmp);
}