gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Fish eye lens?

#152944 - Dwedit - Sun Mar 23, 2008 3:16 am

What's a good way to implement a fisheye lens for a 2D game?
I'll assume the hardware 2D renderer is not the way to go, and an undistorted image would be created using software 2D rendering to a framebuffer.
To do the fisheye distortion, would you use a pixel-by-pixel renderer performing an inverse mapping, or would this be accelerated by approximating the mapping using polygons, then texturing them with the 2D framebuffer?
I was wondering about this because the 3D sonic game which was in development for the Sega Saturn would have used a fisheye style camera to allow the player to see farther to the left and right than a flat camera would allow.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#152956 - TwentySeven - Sun Mar 23, 2008 11:43 am

Well afaik the DS doesn't allow you to specify vertexes directly in screen space.. which would be ideal if you were doing a non-linear transform from world to screen..

So I'm thinking you'd have to set up a standard ortho camera and do the distortion directly in world space... which isn't the end of the world I guess.

#152969 - silent_code - Sun Mar 23, 2008 2:58 pm

i guess you can do some h-/vblank tricks to achieve the desired effect. much like "mode7", whaz means you'll still be able to use the 2d hw. ;^)

happy coding!

ps: read cearn's tonc to learn how to program those effects.

#152972 - M3d10n - Sun Mar 23, 2008 4:10 pm

That Sonic game didn't use a post-processing lens (it was on the Sega Saturn, remember?). The game simply used a custom projection algorithm for all vertices, which caused the fisheye.

If your game is 2D, you could do it by using the 3D engine for 2D. Use quads for your tiles and sprites, then manually displace the quads' vertices based on your filter.

If you want to use the 2D engine, like silent_code said, just change the scrolling and scaling values for both sprites and BGs on each scanline and you can achieve an horizontal cylinder distortion.

#152997 - silent_code - Mon Mar 24, 2008 1:42 am

... vertical distorsion is also possible. ;^)

example of the overall distorsion effect: remember yoshi's island (snes/gba)?

remember the "puffs" that would make yoshi drunk/dizzy when it touches them? everything gets swirly and shaky... that all and more (like heat distorsion effects in other games, e.g. motroid fusion [gba], iirc) can be done with this technique.

happy coding!