Is it possible to handle mouse input for UI elements in a custom way?

I need a custom way to handle mouse position input in a UI. I’m using a post-processing effect on the UI, which uses spherical distortion, so it makes UI elements appear slightly distorted near the edges. They also appear slightly further than they are without the distortion effect on. The default input system doesn’t account for this displacement, obviously. Is it possible to create a custom script or something which would correct the mouse position and make UI elements react only to the corrected position?

I’m using Unity’s new input system, if that matters.


(I have to click in the red area to use the scrollbar, I’d like to drag it where it actually appears on the screen)

I did some digging and it turns out I can do exactly what I wanted with a custom input processor. Instead of using DefaultInputActions in the Input System UI Input Module component on the event system I use a custom input actions asset, which is a copy of the default one, except with a custom distortion correction processor added to the Point input, which does the reverse of what the post-processing shader did.

If anyone stumbles upon this issue, this should help: Processors | Input System | 1.0.2

Kinda cool just how flexible the new input system is.

Tricky… if you just had a lot of squares, each being a different button, you could do this quite easily. Use Camera.ScreenToWorldPoint and reverse the distortion that using the same method that you used for the screen. Use a look-up table or algorithm to determine which button was pressed and invoke its method.
However, a scroll bar needs a different solution.

Were I doing this, I would probably replace the scroll bar with an independent, non-distorted UI Slider. You’d then use that to scroll the contents of the distorted UI. Needs a bit of thinking about to get the code right but it should work quite nicely.