20 January 2019

Blur with Unity's Post FX v2

I recently needed to blur the scene when it's in the background of a 2D UI. This being a post process effect I expected it to be available in the PostFX v2 stack. But as you can guess, it was not.

There is this legacy blur effect, which still works but is not integrated in the stack. I took the liberty to convert it to a PostFX v2 effect.

I only converted the Standard Gauss blur type, the other one called "Sgx Gauss" is left as an exercise to the reader ;)

You can find it integrated in my unitytoolset repo on BitBucket in the post-processing profile of the Stylized Fog scene.

If there are better alternatives, I'm very interested!

5 comments:

Brechtos said...

Cool stuff!

How easy did you find it migrating an legacy pp effect to the stack and have you experimented with controlling it via script?

I still have a rather big pp effect that I would like to bring over at some point but I have been holding it off as it still seems to work quite well using the old system and it would be a rather time consuming port.

Do you think it's worth updating legacy pp effects to the new stack?

Btw, as a small performance tip. Try caching your shader find so it won't happen each render update as well as using material id's instead of string based shader property sets( again cached). They can really help avoiding unwanted gc overhead and it's something unity never did with their original legacy effects. I once updated their old fog and almost got 3xthe speed by just caching and gc optimization.

Alex Vanden Abeele said...

I found controlling the blur effect via script really easy, it's a well designed system. For example via so-called Quick Volumes:
https://docs.unity3d.com/Packages/com.unity.postprocessing@2.0/manual/Manipulating-the-Stack.html

I tried your suggestion concerning the caching, but there were no heap allocations before nor after (I don't really see why there would be any?). Avoiding the find is a good thing in any case, so I changed that. Thanks!

Is it worth converting? If you want to use your effect with the volume system, I wouldn't even think twice. If you're using both legacy and PostFXv2 effects I would convert them too because it's just messy to have two systems, otherwise it might be not worth the trouble. You're making your code future proof, though.

Converting is not hard, since it's all open source you can easily check how things are expected to be done in this system. Check my previous posts on post fx as well, definitely this one:
https://grrava.blogspot.com/2018/08/more-foggy-adventures.html

Brechtos said...

Cool. The heap thing was pre 2017 branch though so thing have changed quite a bit since then :)

I guess if I ever have a spare moment' I'll look into converting at least my primary custom pp effect. We also use some asset store effects sadly so we will always have a hybrid going on, unless they uodate as well but that doesn't seem very likely.

That quickvolume is really awesome and sounds like a great way to get more control over the pp than just using their pp volume system based on the phyisics layers and volumes.

nindim said...

Hi,

Thanks for this.

Any idea how it compares to the performance of the implementation here?

https://forum.unity.com/threads/legacy-blur-for-post-processing-stack-v2.488222/

Also, I noticed you haven't unrolled the loops, they seemed to cause problems on some devices in the past as described here: https://stackoverflow.com/questions/54926438/why-does-the-hidden-fastblur-shader-no-longer-work-on-ios-for-unity-2018/54926471#54926471

All the best,

Niall

Alex Vanden Abeele said...

Hi,

Compared to that other forum post: I think it's the same, that person did the same thing as I did, and he was less lazy, he also did the SGX option :)

I haven't unrolled the loops indeed, since I just re-used that shader, so unrolling will indeed be necessary, thanks for that!