YOUR ACCOUNT

Login or Register to post new topics or replies
jffe
Posts: 2869
Filters: 90
Pyramids by matrix
http://www.filterforge.com/filters/5419.html

Filter Forger
  Details E-Mail
jffe
Posts: 2869
Filters: 90
Nice work. I haven't got a clue what I'd ever use it for, but it's a very good looking technical achievement type of filter. smile:)

jffe
Filter Forger
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Hey Matt!

Ahh, finally you published this!

Guys you should take a look at the guts of this one - it shows how to achieve correct depth perspective transformations/distortions... smile8)
  Details E-Mail
uberzev
not lyftzev

Posts: 1890
Filters: 36
Fantastic smile8)

The only issue I have is the the blurriness of the presets. Otherwise great job.
  Details E-Mail
matrix
matrix
Posts: 13
Filters: 2
Hey all,

I'd like to fill in some more details about the implementation...

I'll try to describe the process in which we arrived at our final solution. smile:)

First of all, we considered the problem of finding the inverse transformation of the offset module. That is, how can we get back to the original image after it has been transformed by an offset?

Specifically we looked at the case when the image was rescaled uniformly using vertical and horizontal gradients.

We found that the offset module performed a transformation according to this formula:

y = x + 2*x*p

where x is the input coordinate, y is the output coordinate and p is the percentage parameter. We assumed that x was in the range -0.5..0.5.

If the offset module is represented as a function f and its source sampler as a function g, then it means that the returned value can be computed as

f(x) = g(x + 2*x*p).

Now let us assume that as second offset module h(x), is able to reverse the transformation of the first offset, according to the formula

h(x) = f(x - 2*x*u(p)),

where u is an unknown function.

If this module reverses the transformation of f, then clearly h(x) = g(x).

Thus we have the following recurrence equation:

g(x) = f(x - 2*x*u(p)) <=>
g(x/(1 - 2*u(p)) = f(x) <=>
g(x/(1 - 2*u(p)) = g(x + 2*x*p) =>

x/(1 - 2*u(p)) = x + 2*x*p =>
u(p) = p/(1 + 2*p)

Hence, by adjusting the percentage of the second offset according to u(p), we can reverse the first offset operation.

By further experiments we figured out how to reverse a an offset that used repeated gradients for zooming out.

In this case, if we have n repetitions (and percentage = 100%), then the reverse transformation could be done using the following formula:

u(p, n) = p*n/(1 + 2*p*n)

Now, the tricky part was to find a formula that allowed us to linearly interpolate between the zoomed out and the zoomed in version of the image and thus create a perspective effect. This part wasn't done completely analytically, but rather by noticing that by adjusting the bias and the maximum parameters of a bias curve, this would create a correct perspective for a certain value of n.

The bias curve would have a maximum determined by u(p, n) and a bias value determined by a formula that we derived through curve fitting.

Finally, working out how to actually compute these formulas in FF also required some thinking.

Basically we had to figure out a way to compute the value of

u(n) = n / (1 + 2*n).

We found that a bias curve could be used to perform exact divisions, assuming that it was adjusted as follows:

Bias = 98.02
Start = 1.00
End = 1.00
Minimum = 1.00
Maximum = 100

This proved to be very useful, but still we had some problems with overflow and so we were forced to rewrite the formula using partial fraction decomposition:

u(n) = 0.5 - 0.5/(1 + 2*n)

This however successfully solved our problem and we managed to finally get the correct perspective transformation that we were looking for! smile:D
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Jesus that sounds complicated! Wouldn't you just need to get the inverse of the percentage, 1/p, to get the reverse transformation?

Nevertheless, the bias curve is certainly the answer to that one. Did you discover the Bias value of 98.02 by calculation or by trial? I'd be interested in finding the value by calculation, since I probably have some use for this.
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Well, indeed, there is some fascinating stuff in the guts of this one.

For instance, I had no idea you could shrink something down to a dot and blow it back up (internally) without loss of detail. So, I guess that, apart from a few effects, all internal calculation in FF is purely mathematical with floating point precision?
  Details E-Mail
ronviers
lighter/generalist

Posts: 4456
Filters: 35
Nice work matrix. With a simple mod it does gems. smile:)

@ronviers
  Details E-Mail
ronviers
lighter/generalist

Posts: 4456
Filters: 35
Sorry matrix. I just realized that adding reflection to uberzev's snippet has nothing to do with your excellent perspective filter.
@ronviers
  Details E-Mail
matrix
matrix
Posts: 13
Filters: 2
Quote
ThreeDee wrote:
Jesus that sounds complicated! Wouldn't you just need to get the inverse of the percentage, 1/p, to get the reverse transformation?

Well, let's just consider the following equation (this is basically what the offset does):

f(x) = g(x + 2*x*p)

Now, if we use 1/p for the "inverse" offset, then we have:

h(x) = f(x - 2*x/p)

We know that h(x) should be equal to g(x) in order to perform a correct inverse transformation, ergo:

g(x) = f(x - 2*x/p) <=> [set z = x * (1 - 2/p)]

g(z/(1 - 2/p)) = f(z) <=>
g(z/(1 - 2/p)) = g(z + 2*z*p) =>
z/(1 - 2/p) = z*(1 + 2*p) =>
1 = (1 - 2/p) * (1 + 2*p) <=>
1 = 1 - 2/p + 2*p - 2*2*p/p <=>
4*p = -2 + 2*p^2

This shows that h(x) != g(x), since otherwise the left and righthandside of this equality would have been the same.

Quote
Nevertheless, the bias curve is certainly the answer to that one. Did you discover the Bias value of 98.02 by calculation or by trial? I'd be interested in finding the value by calculation, since I probably have some use for this.


It was discovered through trial and error, but even a slight variation of this value would cause the filter to not work as predicted, so I'm fairly confident that it's correct.
  Details E-Mail
matrix
matrix
Posts: 13
Filters: 2
Quote
uberzev wrote:
The only issue I have is the the blurriness of the presets. Otherwise great job.

Yep, I was a bit unsure whether to include it or not. I think I wasn't very satisfied with the antialiasing of the previews. Will the previews be updated if I upload it again with different AA settings?
  Details E-Mail
DownTheShore

Posts: 68
Very high CPU, though. Triggered a running 100% on both cores & had to shut FF down. smile:(
  Details E-Mail
jffe
Posts: 2869
Filters: 90
Quote
matrix wrote:
Will the previews be updated if I upload it again with different AA settings?


----Yes. smile:) You can update filters any time with changes, it just takes another day or two until the *new* version is posted in the online library is all.

jffe
Filter Forger
  Details E-Mail
Kraellin
Kraellin

Posts: 12749
Filters: 99
gah! i'm boycotting this thread... MATH!!! **runs away**
If wishes were horses... there'd be a whole lot of horse crap to clean up!

Craig
  Details E-Mail
matrix
matrix
Posts: 13
Filters: 2
I think it's good to try to find a balance between your creative and analytical skills. Sort of not to make one of the brain halves feel left out. smile;)

Anyway, I've managed to simplify the perspective part of the filter quite a bit (partly thanks to ThreeDees fraction snippet), so if you downloaded the previous version you probably want to update it.
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Hey, Matrix (since we've now scared Kraellin away from here) do you know the basic math for 3D perspective imaging? I've been wracking (one half of) my brain trying to make a 3D rotateable box that is in proper perspective. I managed to work it out graphically (using the other half of my brain, hehe), but my math coprocessor seems to have an "overflow" problem on how to implement it in FF. Programmatically it is not a very big issue, but trying to do it with FF components has proven rather challenging.
  Details E-Mail
matrix
matrix
Posts: 13
Filters: 2
Sounds like an interesting challenge. If you were to do this programmatically, then there are two methods that are frequently used: scanline rendering and ray tracing. In both cases you need to be able to represent the vertices of the box and the position of the light source in 3D (assuming that you want it to be shaded).

Now, suppose that we can somehow represent 3D coordinates in FF and that we can perform the correct 3D -> 2D projection. What is left is basically to compute the depth values of each plane of the box and to clip these planes to the projected polygons (this would be similar to the scanline rendering approach). I think that could be quite feasible.

If we were to go for the ray-tracing solution instead, then we would rather need some way of representing the ray and to test whether or not it intersects the 3D object. That is, depending on which side of the box we hit, we will return the appropriate depth value.

Moreover, if we have the depth values, we could use the built-in shader of FF and the current perspective tranformation to add light and texture.

Well, I could start by trying to figure out if there is a good way to represent 3D coordinates and how one should go about projective transformations...
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Here's what I thought (I always start with the simplest approach I can take and work it up from there): If I can rotate the plane that is the original image (the monitor surface plane, so to speak) in 3D around X and Y axis in correct perspective I pretty much have it made, for a box essentially consists of six such planes rotated to 90 degree angles in relation to each other. So I would be happy to be able to accurately create the 2 (or it may be 4) horizontal and vertical offset gradients needed to rotate the image plane 360 degrees around those two axis. It could be with a fixed FOV (field of view) to begin with, such as 60 degrees.

One thing to note here is that the axis cannot lay on the image plane, but at a given depth behind it, otherwise we're not going to end up with a volume(box or cube), but with 3 planes representing x=0, y=0 and z=0.

(And, in case it wasn't obvious, the current image would be distorted in perspective on the plane.)
  Details E-Mail
CFandM
ForgeSmith

Posts: 4761
Filters: 266
Maybe you can use this for something TD...Spinning Wall..
http://www.filterforge.com/forum/read...ssage46025
basically the same as the perspective frame but a gradient...
Also a cube here
http://www.filterforge.com/forum/read...10&TID=747
Stupid things happen to computers for stupid reasons at stupid times!
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Here's an earlier attempt I made at this, rotating around the Y axis. I doubt it is accurate despite the apparency, but you get the idea. Needs to go full 360 degrees and add X axis rotation. AND be mathematically perfect...

3D rotate.ffxml
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Hi CFandM,

That's the basic idea, but with mathematically correct perspective. I'm doing this sort of step-by-step, but the real objective is a box of adjustable x, y and z dimensions that is fully rotatable around x and y axis, in proper perspective. (Going for that technical achievement award, whatever the prize was, a Yugo or something...) No, seriously speaking, I want to end up with a "packaging" filter where you could map an image to a box and rotate the thing. May be too much to ask for, but hey, if you don't aim high...
  Details E-Mail
CFandM
ForgeSmith

Posts: 4761
Filters: 266
That was my goal eventually..A photo cube of sorts that can be different primitives..Aiming high is where I am still trying to reach .. smile:D
Stupid things happen to computers for stupid reasons at stupid times!
  Details E-Mail
uberzev
not lyftzev

Posts: 1890
Filters: 36
Very nice job on the v1.1 update Matrix.

One (very minor) suggestion I have is to remove the 'Set Alpha' and just plug everything into the 'Threshold'. (Make the 'High' input the image and the 'Low' input a transparent color ['A' slider in the color picker])

Oh and this is too cool...
  Details E-Mail
matrix
matrix
Posts: 13
Filters: 2
Quote
uberzev wrote:
One (very minor) suggestion I have is to remove the 'Set Alpha' and just plug everything into the 'Threshold'. (Make the 'High' input the image and the 'Low' input a transparent color ['A' slider in the color picker])

Yep, Sphinx suggested that this would speed up the rendering too. However, when I resubmitted it, I got the following error:

"Another update for this filter is already in the queue"

I'll make another submission today though...
  Details E-Mail
StevieJ
Designer/Artist

Posts: 11264
Filters: 163
Excellent work!!! smile8) smile8) smile8)

Wow!!! Talk about a detailed mathmatical approach!!! smile:eek:

I just plug the line thingy into the node thingy..... smile:| ..... smile:dgrin: LMAO.....
Steve

"Buzzards gotta eat...same as worms..." - Clint :)
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,712 Registered Users
+19 new in 30 days!

153,534 Posts
+31 new in 30 days!

15,348 Topics
+72 new in year!

Create an Account

Online Users Last minute:

28 unregistered users.