How to invert uvmap?

Hello,
after reading this interesting thread and seeing @snaut solutions there, I started thinking about how can one properly invert uvmap (or stmap if this naming makes more sense in this context).

Lets say we have some distortion applied on uvmap (this could be anything - some noise, lens distortion, linear transformation, etc.) and we want to get uvmap with inverse of this distortion.

Having such inverted uvmap would be a huge help in getting inverted lens distortion. I feel like the math involved in getting inverted distortion coefficients is quite complicated. This was also discussed in another thread with @robmc.

But once I imagined I could just invert the uvmap containing such distortion, it seemed like a very simple and nice solution! …I mean until I have realized that inverting such uvmap isn’t also super straight forward :smiley: Here is a simple example from nuke, where they do this exactly the same way - by inverting their stmap.

The concept of inverted uvmap sounds quite simple, but I got stuck at the fact that I don’t sample a pixel. I need to “move the pixel” (while doing cubic interpolation)…
I have created a simple project which hopefully explains what I mean.
inverted_uvmap.4.toe (8.3 KB)

I was originally going for something very fast with minimum overhead, but I am not sure if this alone is even possible in GLSL. I was looking at imageStore, but that doesn’t seem to do the trick due to integer pixel values. Please do you have any idea how to approach this in GLSL? Or do you think it needs to be done in custom cpp operator (or should I look into something like compute shaders)? Thanks :slight_smile:

2 Likes