mob-sakai / UIEffect

UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
https://github.com/mob-sakai/UIEffect
MIT License
5.57k stars 770 forks source link

UIEffect blur support for non-standard geometry (ie. line renderers) #231

Open BlackxSnow opened 3 years ago

BlackxSnow commented 3 years ago

I've been attempting to resolve issues between a UI line renderer and UIEffect's blur functionality for a while, but I can't seem to grasp enough of the vector math to get it to do what I want. The line is rendered as many separate quads, and due to the curving/rotation of the line, the blur effect has some significantly broken results.

With some trial and error (mostly trying random things and seeing what works) I was able to get it to a state where it actually displays somewhat like a line with the blur effect on, but still is entirely unusable. If you have time Sakai / another vector wizard, it'd be great to get something like this working.

Ideally, I'd like to be able to outline the line (the outline works fine!) and then blur it, to create a dynamic outer glow.

Normal: https://puu.sh/GFXXS/7501c58b52.png The best I got: https://puu.sh/GFXXG/354cbf9957.png

The very butchered code I was playing with: https://hatebin.com/cltjlukkdw

The line renderer in question can be found here: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls/UILineRenderer

That said, all the line renderer does that is important is make smaller quads using OnPopulateMesh that do not 'align' with the bounding box's rotation.

BlackxSnow commented 3 years ago

I smacked my head against the wall enough that I got it working. The code isn't particularly pretty, and it is very much a jerry rigged solution, but here it is: https://hatebin.com/ijdqtqzwgc

You'll need to expose m_AllQuads and m_BlurSize, as well as set up the material switching in the editor via an editor script. UVs are still a little fucky because I don't quite understand what mob-sakai does with them, but what I've done seems to work well enough for what I need.

If anyone wants to use it or otherwise modify/neaten it and combine it into the repo's UIEffect feel free. I've spent way too long on this issue already.