- Home /
Blur (Optimized) Effect Has Very Slow Performance on Mobile Devices
I want to blur effect like Alto's Adventure (3:13). https://youtu.be/TLCFGXprM94?t=3m13s
Blur (optimized) works very well on PC but it has very bad performance on mobile devices. How can i boost blur effect's performance? https://docs.unity3d.com/500/Documentation/Manual/script-BlurOptimized.html
Answer by Nighfox · Feb 01, 2018 at 04:31 AM
Use OnPreRender()
and OnPostRender(
) instead of OnRenderImage()
in BlurOptimized.cs
as described here:
Thank you very much. But what should i select as targetTexture? I changed in BlurOptimized.cs. Is everything right in my script ? Also, Hidden/Fastblur is choosen as Blur Shader. Is this right ?
public class BlurOptimized : PostEffectsBase
{
RenderTexture myRenderTexture;
public RenderTexture targetTexture;
Camera camera;
private int width, height, postProcess$$anonymous$$aterialPassNum;
private $$anonymous$$aterial postProcess$$anonymous$$aterial;
[Range(0, 2)]
public int downsample = 1;
public enum BlurType {
StandardGauss = 0,
SgxGauss = 1,
}
[Range(0.0f, 10.0f)]
public float blurSize;
[Range(1, 4)]
public int blurIterations = 2;
public BlurType blurType= BlurType.StandardGauss;
public Shader blurShader = null;
private $$anonymous$$aterial blur$$anonymous$$aterial = null;
public override bool CheckResources () {
CheckSupport (false);
blur$$anonymous$$aterial = CheckShaderAndCreate$$anonymous$$aterial (blurShader, blur$$anonymous$$aterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
public void OnDisable () {
if (blur$$anonymous$$aterial)
DestroyImmediate (blur$$anonymous$$aterial);
}
void OnPreRender()
{
myRenderTexture = RenderTexture.GetTemporary(width,height,16);
camera.targetTexture = myRenderTexture;
}
void OnPostRender()
{
camera.targetTexture = null; //null means framebuffer
Graphics.Blit(myRenderTexture,null as RenderTexture, postProcess$$anonymous$$aterial, postProcess$$anonymous$$aterialPassNum);
RenderTexture.ReleaseTemporary(myRenderTexture);
}
}
Yes, it's Hidden/Fastblur
. Just create a Render Texture
in your Project View and drag that to reference in your BlurOptimized
script.
Firstly, Thank you very much and i am sorry for spending your time. When i use above codes, i have "material is null" error. If i delete postProcess$$anonymous$$aterial, postProcess$$anonymous$$aterialPassNum in my codes, it is working without any error but blurring working only width and height. It is not using fastblur shader. So, it looks so bad like pixels. Would you help me about BlurOptimized script. Where should i fix it in my script?
[Range(0, 2)]
public int downsample = 1;
public enum BlurType {
StandardGauss = 0,
SgxGauss = 1,
}
[Range(0.0f, 10.0f)]
public float blurSize;
[Range(1, 4)]
public int blurIterations = 2;
public BlurType blurType= BlurType.StandardGauss;
public Shader blurShader = null;
private $$anonymous$$aterial blur$$anonymous$$aterial = null;
public override bool CheckResources () {
CheckSupport (false);
blur$$anonymous$$aterial = CheckShaderAndCreate$$anonymous$$aterial (blurShader, blur$$anonymous$$aterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
public void OnDisable () {
if (blur$$anonymous$$aterial)
DestroyImmediate (blur$$anonymous$$aterial);
}
RenderTexture myRenderTexture;
public RenderTexture targetTexture;
public Camera camera;
public int width, height, postProcess$$anonymous$$aterialPassNum;
public $$anonymous$$aterial postProcess$$anonymous$$aterial;
void OnPreRender()
{
myRenderTexture = RenderTexture.GetTemporary(width,height,16);
camera.targetTexture = myRenderTexture;
}
void OnPostRender()
{
camera.targetTexture = null; //null means framebuffer
Graphics.Blit(myRenderTexture,null as RenderTexture);
RenderTexture.ReleaseTemporary(myRenderTexture, postProcess$$anonymous$$aterial, postProcess$$anonymous$$aterialPassNum);
}
Answer by Bale_txy · Feb 01, 2018 at 02:17 AM
You should use profiler to check your memory usage when running in Unity, it could be your game's optimization issue
https://i.hizliresim.com/D7265v.jpg Game always runs 60 fps but when blur effect active, fps drops to 15-20. It is related to the blur effect.I want to be smooth when blur effect activate.
Answer by Kronnect · Feb 01, 2018 at 10:52 PM
Try Beautify’s blur. It has two performances modes and a transition option that goes from crisp image to extremely blurred effect.
Answer by 1ht1baron · Feb 09, 2018 at 02:08 AM
It is still very slow on mobile devices. Are there any fix ?
Your answer
Follow this Question
Related Questions
How to blur my background 2 Answers
motion blur without unity pro 1 Answer
Creating a Blur Effect on GUITexture 0 Answers
need help with javascript for underwater blur effect 1 Answer