- Home /
How to get Fisheye from Field Of View
I'm needing to get the 'Fisheye' effect based on the camera's Field of View. In other words, if I set it to like 180 degrees (extreme fisheye), I need the on-screen effect to match what a real 180 degree lens would see (I'm matching real cameras to 3d scenes).
Is that possible with the Fisheye Image Effect, if so, what math would map FoV to those distortion params? Or would it be better to just code my own? Or does anyone know of something like this already?
Answer by leith · Sep 09, 2011 at 11:34 PM
The fisheye effect is one of extreme lens distortion. Usually its a radial function. Radial lens distortion is not part of the standard camera model used by OpenGL and Unity3d. To get a good quality effect, where lines that are straight in the real world, are bent on screen, you'll likely need to use a "render to texture" to take a very wide angle image and render it onto a piece of geometry that has been distorted radially to distort the image.
Answer by sean · Sep 09, 2011 at 09:39 PM
The hack I once used for a true fisheye effect (that is, one screen pixel represents x angular-degrees-around-the-camera rather than x linear-units-at-distance-from-the-camera) was a custom pro-only rig that took a real-time script-generated cubemap and a full-screen normal-map-esque coordinate-to-vector mapping image (basically, the direction I wanted to see into the scene at each pixel). I knocked out a quick shader to apply to a fullscreen quad which simply returned the cubemap contents in the map-texture-indicated direction at a given pixel. I haven't used the Fisheye Image Effect, so that may be simpler/faster if it's already packed in.
I don't suppose you'd be willing to share that code? (I do have pro)
I'd love to if it were my own project, but it was for work in an industry which is paranoid enough on regulation and IP that I'm not comfortable sending anything written in-house out the door, even if it's not fundamentally groundbreaking. I will say that the sum total of the shader was basically just a cubemap lookup, so if you don't want to research and write your own from scratch, you could probably strip all the extraneous camera-object-world calculations off a simple reflection-map shader and leave just the lookup. The old Island Demo reflective water shader/script rig will generate the cubemap in real time (although you can probably read up on how to roll your own simpler script). The screen texture I ended up literally measuring out the angles by hand and creating a gradient grid in Illustrator. $$anonymous$$y "lens" geometry was a bit custom, though, so you may even be able to go without a specific map image if you're ai$$anonymous$$g for straight-up spherical curvature. Protip: smaller normal-map resolutions work better for this- try to match the screen resolution and it comes out grainy, but let the GPU do the texture UV interpolation and the result is much smoother.
Your answer
Follow this Question
Related Questions
Image Effect on single camera only 1 Answer
Enable Camera Image Effect on Button Down 1 Answer
crop or offset the camera display? 0 Answers
Anti-Aliasing causes post processing effects to flip. 3 Answers
Documentation on the bloom filter 0 Answers