Fisheye position warp

Monkey Forums/Monkey Programming/Fisheye position warp

Raz(Posted 2015) [#1]
Hi all, sorry I've not quite sure of the precise term, but I'd like to "fisheye" a 2d array of coordinates.

Consider each intersection of this image as a fisheyed version of a flat uniform checkered grid.



I've seen it plenty of times in demoscene demos but don't actually know what it's called. Can anyone help?


nullterm(Posted 2015) [#2]
Are you trying to do that with individual point (x,y)'s or with a whole image/screen (which might need a shader)?


Raz(Posted 2015) [#3]
Just points thanks nullterm

0,0 1,0 2,0 3,0, 4,0
0,1 1,1 2,1 3,1, 4,1
0,2 1,2 2,2 3,2, 4,2
0,3 1,3 2,3 3,3, 4,3
0,4 1,4 2,4 3,4, 4,4



Nobuyuki(Posted 2015) [#4]
You can perform a transformation in two dimensions by applying an easing curve to each dimension individually. I don't know which particular curve a fisheye lens calculation utilizes, however, a cubic interpolation curve that eases both on the in and out should be able to do it. Here is a piece of example code pulled from my framework:

	Method Ease:Float(p:Float, in:Bool, out:Bool)
		If in And out		
			If p < 0.5 Then Return 4 * Pow(p, 3)
			Return 4 * Pow(p - 1, 3) + 1

		ElseIf in
			Return (p * p * p)
		ElseIf out
			Return Pow(p - 1, 3.0) + 1
		Else
			Return p 'linear
		End If
	End Method


It maps a linear value from 0-1 to a cubic easing value. You can Lerp this value between the linear and cubic value to produce a softer effect, or increase the exponent to make the effect more pronounced, iirc.

alternate easing calcs for arcs: http://www.flong.com/texts/code/shapers_circ/


Nobuyuki(Posted 2015) [#5]


Source code for this example:



ImmutableOctet(SKNG)(Posted 2015) [#6]
@Raz: Not what you're looking for, but this got me messing around with shaders in Mojo 2:
EDIT 01: Fixed the mapping issue (At least partially).
EDIT 02: Well, it's kind of working:


I take it this page is what you were looking at? That tutorial calls the effect you want "Barrel Distortion". Shouldn't be too hard to add.

EDIT 03: See below for a Mojo 2 implementation; use at your own risk.


ImmutableOctet(SKNG)(Posted 2015) [#7]
After messing around for a bit, I was able to write a basic shader to do what you're looking for. Obviously, this is Mojo2-only, or at least, it requires Mojo 2 to be the backend. I pretty much just followed this.

Preview image:



Raz(Posted 2015) [#8]
Oh wow, thanks for your effects all :)

I'm sorry though I think I should have made myself a bit more clear though, I don't want a shader, I'd like to distort a 2d array of points. I did give your shader code a look but ... well... I'm simple :D

Here's a base app (that's currently not working at all, but you might see what I'm getting at), move the mouse to move the center of the distortion




Raz(Posted 2015) [#9]
Ahh just seen your post too Nobu, will give it a go to see if I can adapt it for what I'm after


muddy_shoes(Posted 2015) [#10]
@Raz Here's your code altered to apply the fragment shader's implied method.




Raz(Posted 2015) [#11]
Oh wow, thank you so much, that's exactly what I am after :)


Thanks all who took time to give me some help!