Recommended Posts

Hi,
I'm trying to write a 2D pixel shader that has the effect of placing a round lens above the image: the centre should magnify, and the edges should shrink.
The lens is placed above the source image centred at the point (xOrigin, yOrigin).
I've got this so far as my shader:

t is the source texture.
This isn't quite right, it works but the upper left of the image magnifies less and the bottom right more, due to the increasing Tex.xy values, so it's an uneven zoom. Does anyone have the correct formula?
Thanks

Share this post

Link to post

Share on other sites

i think the zoomfactor should be something like:zoomfactor=strength-sqrt( (Tx-0.5)^2 + (Ty-0.5)^2 );

the squareroot is the distance from the sampled point to the center. Strength is some value that defines how strong your zoomeffect will be. When you put in 0 your lens will only shrink at the edges and in the middle everthing will look like before.

btw haven't looked at the rest of the code but you said the code shrinks some parts so everything should be fine.