Thursday 20 April 2017

Shader for Mobius transformations in Unity

Last year eleVR and Henry Segerman did some amazing work, using Mobius transformations to do some weird and wonderful stuff to 360° videos. While zooming in 360 seems like an odd concept, and the visual result is incredibly strange, it allows for some really interesting effects.

I wanted to use some of these techniques in Unity. Thankfully Robert Woodley had already built a shader for WebGL (GLSL), so all I had to do was port it to ShaderLab/Cg.

The shader can be downloaded here, in case anyone fancies making some crazy visual effects with panoramic media in Unity. A zoom controller script is here, that zooms in when you press "i", out when you press "o", and sets the zoom point to where the camera is looking when you press "p".

Here's an example, showing a creative commons equirectangular image by Alexandre Duret-Lutz.

This is the original view, without any zoom applied 

Zooming out in the equirectangular.

The mapping is conformal, meaning that local angles are preserved, but straight lines don't remain straight. So things look right locally, but the global effect is quite strange.