# Distortion Effect

I am making simple distortion effect in a 2D space. The distortion is simple as I am mapping the image to a quadrilateral. When I distort the first image to the shape of the second, the result is not uniform. It seems like splitting up the image into 2 triangles to do the transformation. How can I solve this problem?

1. original image:
http://www.cs.ust.hk/~yvonne/gl/e1.jpg
2. distorted image:
http://www.cs.ust.hk/~yvonne/gl/e2.jpg

[This message has been edited by pigpig (edited 08-01-2000).]

Enabling perspective-correct texture mapping should do the trick:

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

no, it shouldn’t (and won’t) do the trick. perspective won’t work in 2D space!! (besides, it’s only a hint)
sub-divided the polygon. minimise the linear interpolation error.

cheers
John

Oops, my mistake. Sorry

“sub-divided the polygon” means I have to divide both the texture coordinates and the mapped polygon?

Yes, bilinearly interpolate the xy and uv space on that polygon.
To get the distortion solved you’ll have to issue 4D texture coordinates on the vertices with the last paramter q from (s, t, r, q) holding the informations for the algorithm to do “perspective correction” which in your case is not occuring because it’s just plain flat, only distorted.

So the \$100,000 question is now, how do you get the correct q values?
I haven’t done that before, but I would code the distortion into an 4x4 shear matrix and feed 4D vectors through it, and would feed the homogenous coordinate w into the texture as q=1/w.

Sorry, I’ve no idea if that stuff above is working or if q=w. I would have to look up the specs, but I’m too lazy right now.
But the 4D texture coordinates are a must to solve your problem.

[This message has been edited by Relic (edited 08-02-2000).]

It seems that it’s very complicated to solve like that…

How about any usual method to handle image transformation? eg. in photoshop. Is it very difficult to work around this way?

The Photoshop method is simply the bilinear interpolation on pixel level. Tesselate your geometry high enough and you get the same result.

Howdy,

what exactly do you want to do? I’ve done 2D distortions before, and the way I did it was apply a warp mesh (of arbitary high resolution to avoid the bilinear interploation problem you’ve been describing) over the frame buffer. But that might not be what you want…

cheers,
John

john: how can I do this? can u describe more?

thx…

I need to perform some free transformation on rectangular image to form any quadrilateral shape. I am seeking for some methods that involve less calculation and that can use OpenGL built-in functions as much as possible.