Calculate optimum FOV based on resolution
Calculate optimum FOV based on resolution
In a conversation with someone yesterday about a game he said that he wished he could figure out what the optimal FOV was, based on his screen resolution (the resolution the game was being played at).
Is there an easy way to programatically figure that out?
Is there an easy way to programatically figure that out?
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
So its not the FOV but the aspect ratio? I don't really know, I don't play games really. But will not the FOV look different between aspect ratios? I mean its still going to be for example a 90 degree FOV, but the aspect ration then has no effect on that or does it?
How about for wide screen monitors? I was searching around and came across this > http://www.widescreengamingforum.com/fovcalc.php - is it affected for widescreen monitors?
How about for wide screen monitors? I was searching around and came across this > http://www.widescreengamingforum.com/fovcalc.php - is it affected for widescreen monitors?
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
As far as the gameengine which is used calculates the projectionmatrix with the right aspect ratio you shouldn't ever have to change the field of view.SFSxOI wrote:So its not the FOV but the aspect ratio? I don't really know, I don't play games really. But will not the FOV look different between aspect ratios? I mean its still going to be for example a 90 degree FOV, but the aspect ration then has no effect on that or does it?
Here you can see "Original Aspect Ratio" and "New Aspect Ratio". The game has no option to change the aspect ratio then. Newer games either automatically determine which aspect ratio your monitor has, or they have options to change it. On old games it is only possible to change the fov and then you may approximate it until it looks similar to your old aspect ratio if you buy a new screen. But I'm sure the fisheye effect which comes then is more annoying than getting used to the new size of the display.SFSxOI wrote:How about for wide screen monitors? I was searching around and came across this > http://www.widescreengamingforum.com/fovcalc.php - is it affected for widescreen monitors?
bye,
Daniel
Daniel
Not sure I understand everything you said, I don't have any experience with this and i'm not sure what is meant by the fish eye thing you mentioned as I don't have anything to relate to in this matter. To me, it would seem as you said, that a game should detect what the display parameters are and adjust accordingly (basically thats what you said isn't it? I think), at least thats what i would have thought. But after looking around the internet some more it seems as if games don't actually do that all the time, there are thousands of posts and links from people discussing aspect ratio in relation to FOV and devoting, it seems, a lot of time to solving what they think is a problem for widescreen with various calculators and software "fixes" and adjustments etc...
Thanks for your reply, its sparked a curiosity point for me I might explore a little more but i'm not going to spend a lot of time on it. I might just go out and buy one of these games these people are talking about and experiment some.
Thanks for your reply, its sparked a curiosity point for me I might explore a little more but i'm not going to spend a lot of time on it. I might just go out and buy one of these games these people are talking about and experiment some.
I don't know if this is the optimal solution but I give an example of how to adjust the FOV based on the aspect ratio in this PureGDK example:
http://www.purebasic.fr/english/viewtop ... 398#278398
http://www.purebasic.fr/english/viewtop ... 398#278398
Here is the compiled example and source:
http://puregdk.com/files/upload/aspect-ratio.zip
And another, simpler example with source:
http://puregdk.com/files/upload/aspect-ratio_2.zip
http://puregdk.com/files/upload/aspect-ratio.zip
And another, simpler example with source:
http://puregdk.com/files/upload/aspect-ratio_2.zip
OK, after taking a look at Mistrel's code and several things around the net, and living thru a massive sinus headache
I decided there had to be a simpler, more straight forward, way just to figure out what the FOV would be for a given aspect ratio at a given resolution for wide screen monitors. I've come up with this simple (and probably dumb) formula that seems to work and gives results pretty close to the same results as the on line calculators do for a simple 90 degree FOV to an aspect ratio based FOV conversion.
Yes, I know its stupid, just wanted to satisfy my curious nature.
Code: Select all
;based on a change from a 4:3 ratio (normal commercial base game design aspect ratio for FOV = 90
conv_radtodeg.f = 3.141593 / 180
;Resolutions: 1280x800 - 1680x1050 - 1920x1200
;for FOV for a wide screen 16:10 aspect ratio at resolutions shown
;16:10 = 19.2:12 = ( 19.2 = 16/10 * 12 )
;4:3 = 16.0:12 = ( 19.2 = 4/3 * 12 )
FOV_A.f = 2 * ATan(19.20/16.00) / conv_radtodeg
;Resolutions: 1280x768 - 1600x960 - 1920x1152
;for FOV for a wide screen 16:9 aspect ratio at resolutions shown
;16:9.6 = 16.00:9.6
;4:3 = 12.80:9.6
FOV_B.f = 2 * ATan(16.00/12.80) / conv_radtodeg
;Resolutions: 1280x720 - 1600x900 - 1920x1080
;for FOV for a wide screen 16:9 aspect ratio at resolutions shown
;16:9 = 16:9
;4:3 = 12:9
FOV_C.f = 2 * ATan(16.00/12.00) / conv_radtodeg
Debug FOV_A
Debug FOV_B
Debug FOV_C
One of the best Field Of View Calculators (Not just bragging, it really is!):
http://emsai.net/projects/widescreen/fovcalc/
Use that to calibrate your code as I use the "proper" way to calculate, based on math articles on FOV etc. at Wikipedia.
There is also a vertical FOV but that is usually untouched and static.
The FOV people talk about is the horizontal (width) FOV.
Do not assume 90 degrees though as many games use other values, like Valve which seems to use 70 or 75 or something like that I think?
Other games use 80 or 85, or 90, 95, some even use 100.
The smaller the value, the flatter the view looks, and you loose left and right view area.
The higher the value, the more bent the view looks, you gain left and right view area but they edges look bent or stretched, how much depends on the game engine and developers design choice.
Which brings us to the main issue and reason why people mess with the FOV. Normally you would never need to mess with the FOV.
The developers designed the game to look the way it looks.
The game engine they use is supposed to calculate the FOV based on the screen aspect ratio.
As screen aspect ratio has a static height which is the industry standard in TV, Movies, and Games (well, Games tend to mess this up a lot).
So it's the width in the relation to the height that define the aspect ratio,
and thus the FOV should also dynamically adapt.
Some games have different FOV presets for 4:3, 16:9 and 16:10.
Some games only have a FOV set for the design aspect ratio,
so if the game was designed for 16:9 then the game engine should automatically adjust so things look right (less width or more width in the image seen).
Sadly not all games/developers/game engines get this right, so you get a combination of odd behaviors like: Image stretched in width, or the view is zoomed in or out.
Personally I hate the "fisheye" effect as I usually play on a single 16:10 screen, if I had multiple screens where the side screens are partly angled to the side of my head I wouldn't need the fisheye effect at all.
The "fisheye" effect is there to simulate side vision, a few games/game engines tend to overdo that value.
It "is" possible to extend/shrink the width of the view by adjusting the viewport of the camera in the game engine, but most games seem to just change the FOV instead, and in the worst cases they adjusting the vertical FOV as well making the view zoomed in our out, messing the viewpoint up. (Bioshock fans got upset with that)
Another issue is that not all games let you change or see the FOV setting, in which case a FOV calculator is useless as you got no clue what the FOV of the game actually is at all.
In some games, even if you use the correct FOV setting it may still look like crap due to other design decisions made by the developers.
If you look at the OGRE API I think you'll see both horizontal and vertical FOV settings as well as viewport area and camera position settings, all these have a impact on how a game looks in 4:3 or 16:9 or 16:10 for example, most games/gameengines have the same settings inside them.
http://www.widescreengamingforum.com/
Is "the" facto place for all things widescreen (some of the nutters there have up to 3x16:10 screens for super super wide screen)
The left and right sides of the video captures on those setups makes me seasick due to the "fish eye" effect of the FOV.
The ideal FOV would be close to flat 180 degrees (90 left + 90 degrees right = 180, in games you choose 90 to get the 180 degree effect, as it's 90 per eye I think?)
Why flat? Because then you could angle or physically "wrap" the screen around your face, but I haven't seen any curved screens yet (for consumers that is, I have seen some weird stuff on some tech sites though).
To wrap up this long rant *cough*, as has been said, you can't calculate FOV based on resolution (pixels/width/height),
but you can calcuate based on aspect ratio, that is the only way to do it,
and the way most game engines do it, unless they use preset but in that case they are limited to "common" aspect ratios only so dual or tripple screens will get the image stretched etc.
Oh and there is also the 5:4 aspect ratio that some folks have, which is more narrow than 4:3
Imagine trying to have presets for: 5:4, 4:3, 16:10, 16:9, or 2x16:10 or 3x16:9,
or (ugh...) 1x4:3 + 1x:16:10 + 1x4:3 (no kidding, it's possible)
There's also a 2.35:1 screen on the market which is like cinema width.
The "magic" in my FOV calculator on my site is (PHP code):
$newfov=(ATan(Tan(($oldfov*pi())/360.0)*($newaspect/$oldaspect))*360.0)/pi();
Well, there's a bit more to it than that like calculating the aspect ratio from the resolution the user input etc. into a value that can be used with the FOV calculation line, but it's not that hard to do.
The line above took me quite some time to figure out as I suck at reading scientific math notation and stuff like that.
Getting the aspect ratio from the resolution is pretty simple, the good old "width/height" does the job quite nicely.
If anyone is really interested in the full code lemme know and I'll write up a PureBasic example/port of my PHP code and post it in Tips'n'Tricks so you can use it in your own programs/games/engines.
http://emsai.net/projects/widescreen/fovcalc/
Use that to calibrate your code as I use the "proper" way to calculate, based on math articles on FOV etc. at Wikipedia.
There is also a vertical FOV but that is usually untouched and static.
The FOV people talk about is the horizontal (width) FOV.
Do not assume 90 degrees though as many games use other values, like Valve which seems to use 70 or 75 or something like that I think?
Other games use 80 or 85, or 90, 95, some even use 100.
The smaller the value, the flatter the view looks, and you loose left and right view area.
The higher the value, the more bent the view looks, you gain left and right view area but they edges look bent or stretched, how much depends on the game engine and developers design choice.
Which brings us to the main issue and reason why people mess with the FOV. Normally you would never need to mess with the FOV.
The developers designed the game to look the way it looks.
The game engine they use is supposed to calculate the FOV based on the screen aspect ratio.
As screen aspect ratio has a static height which is the industry standard in TV, Movies, and Games (well, Games tend to mess this up a lot).
So it's the width in the relation to the height that define the aspect ratio,
and thus the FOV should also dynamically adapt.
Some games have different FOV presets for 4:3, 16:9 and 16:10.
Some games only have a FOV set for the design aspect ratio,
so if the game was designed for 16:9 then the game engine should automatically adjust so things look right (less width or more width in the image seen).
Sadly not all games/developers/game engines get this right, so you get a combination of odd behaviors like: Image stretched in width, or the view is zoomed in or out.
Personally I hate the "fisheye" effect as I usually play on a single 16:10 screen, if I had multiple screens where the side screens are partly angled to the side of my head I wouldn't need the fisheye effect at all.
The "fisheye" effect is there to simulate side vision, a few games/game engines tend to overdo that value.
It "is" possible to extend/shrink the width of the view by adjusting the viewport of the camera in the game engine, but most games seem to just change the FOV instead, and in the worst cases they adjusting the vertical FOV as well making the view zoomed in our out, messing the viewpoint up. (Bioshock fans got upset with that)
Another issue is that not all games let you change or see the FOV setting, in which case a FOV calculator is useless as you got no clue what the FOV of the game actually is at all.
In some games, even if you use the correct FOV setting it may still look like crap due to other design decisions made by the developers.
If you look at the OGRE API I think you'll see both horizontal and vertical FOV settings as well as viewport area and camera position settings, all these have a impact on how a game looks in 4:3 or 16:9 or 16:10 for example, most games/gameengines have the same settings inside them.
http://www.widescreengamingforum.com/
Is "the" facto place for all things widescreen (some of the nutters there have up to 3x16:10 screens for super super wide screen)
The left and right sides of the video captures on those setups makes me seasick due to the "fish eye" effect of the FOV.
The ideal FOV would be close to flat 180 degrees (90 left + 90 degrees right = 180, in games you choose 90 to get the 180 degree effect, as it's 90 per eye I think?)
Why flat? Because then you could angle or physically "wrap" the screen around your face, but I haven't seen any curved screens yet (for consumers that is, I have seen some weird stuff on some tech sites though).
To wrap up this long rant *cough*, as has been said, you can't calculate FOV based on resolution (pixels/width/height),
but you can calcuate based on aspect ratio, that is the only way to do it,
and the way most game engines do it, unless they use preset but in that case they are limited to "common" aspect ratios only so dual or tripple screens will get the image stretched etc.
Oh and there is also the 5:4 aspect ratio that some folks have, which is more narrow than 4:3
Imagine trying to have presets for: 5:4, 4:3, 16:10, 16:9, or 2x16:10 or 3x16:9,
or (ugh...) 1x4:3 + 1x:16:10 + 1x4:3 (no kidding, it's possible)
There's also a 2.35:1 screen on the market which is like cinema width.
The "magic" in my FOV calculator on my site is (PHP code):
$newfov=(ATan(Tan(($oldfov*pi())/360.0)*($newaspect/$oldaspect))*360.0)/pi();
Well, there's a bit more to it than that like calculating the aspect ratio from the resolution the user input etc. into a value that can be used with the FOV calculation line, but it's not that hard to do.
The line above took me quite some time to figure out as I suck at reading scientific math notation and stuff like that.
Getting the aspect ratio from the resolution is pretty simple, the good old "width/height" does the job quite nicely.
If anyone is really interested in the full code lemme know and I'll write up a PureBasic example/port of my PHP code and post it in Tips'n'Tricks so you can use it in your own programs/games/engines.
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
sorry, it's a bit much atm, my brain's running on three cylinders only...
would really the vertical FOV stay unchanged, not rather the horizontal?
or chose some average? (perhaps this was the aim of the question)
an unchange vertical FOV means that a 16:9 User sees 42% more information than a 5:4 user.
42% more in only the horizontal field where most of a game's action happen.
a fixed horizontal FOV would mean, a 5:4 user sees 30% more than a 16:9 user,
and this in the vertical area where less of the game's action takes place.
so, perhaps a slightly growing horizontal FOV and slightly narrowing vertical FOV with increasing aspect ratio would be a nice solution?
@Deedee
"aspect ratio" is the quotient of the two sides.
5:4 has an AR of 1.25 , 4:3 is 1._3 , 16:10 is 1.6 , 16:9 is 1._7
the cinemascope AR of 2.35 means a screen of 47:20
would really the vertical FOV stay unchanged, not rather the horizontal?
or chose some average? (perhaps this was the aim of the question)
an unchange vertical FOV means that a 16:9 User sees 42% more information than a 5:4 user.
42% more in only the horizontal field where most of a game's action happen.
a fixed horizontal FOV would mean, a 5:4 user sees 30% more than a 16:9 user,
and this in the vertical area where less of the game's action takes place.
so, perhaps a slightly growing horizontal FOV and slightly narrowing vertical FOV with increasing aspect ratio would be a nice solution?
@Deedee
"aspect ratio" is the quotient of the two sides.
5:4 has an AR of 1.25 , 4:3 is 1._3 , 16:10 is 1.6 , 16:9 is 1._7
the cinemascope AR of 2.35 means a screen of 47:20
oh... and have a nice day.
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Yes the vertical fov is the fov we talk about. The horizontal one is the aspect ratio (And therefore it is always the same on all displays if the aspect ratio equals the display aspect ratio).Kaeru Gaman wrote:sorry, it's a bit much atm, my brain's running on three cylinders only...
would really the vertical FOV stay unchanged, not rather the horizontal?
or chose some average? (perhaps this was the aim of the question)
an unchange vertical FOV means that a 16:9 User sees 42% more information than a 5:4 user.
42% more in only the horizontal field where most of a game's action happen.
a fixed horizontal FOV would mean, a 5:4 user sees 30% more than a 16:9 user,
and this in the vertical area where less of the game's action takes place.
so, perhaps a slightly growing horizontal FOV and slightly narrowing vertical FOV with increasing aspect ratio would be a nice solution?
@Deedee
"aspect ratio" is the quotient of the two sides.
5:4 has an AR of 1.25 , 4:3 is 1._3 , 16:10 is 1.6 , 16:9 is 1._7
the cinemascope AR of 2.35 means a screen of 47:20
I know. But the horizontal fov is specified through the aspect ratio.
In games they use a matrix like this:
f = atan(fov / 2)
Code: Select all
/ f \
| ------ 0 0 0 |
| aspect |
| |
| 0 f 0 0 |
| |
| zFar+zNear 2*zFar*zNear |
| 0 0 ---------- ------------ |
| zNear-zFar zNear-zFar |
| |
\ 0 0 -1 0 /http://wiki.delphigl.com/index.php/GluPerspective
And there you can also read:
In English:fov - Gibt das Betrachtungsfeld (FOV) in Grad, entlang der Y-Achse, an.
aspect - Gibt den Aspektratio, der das Betrachtungsfeld entlang der X-Achse setzt. Der Aspektratio ist das Verhältnis von Höhe zu Breite.
fov - Specifies the field of view along the y-axis in degree.
aspect - Specifies the aspect ratio, which sets the field of view along the x-axis. The aspectratio is the ratio height:width.
bye,
Daniel
Daniel
I'll be referencing a few terms below, use this page as a reference for those terms (good read too btw):
http://www.widescreengamingforum.com/wiki/index.php/FAQ
The WSGF (Wide Screen Gaming Forum) classify this method as Hor+
However a few games like Mirror's Edge which could have gone for Vert- did not do so, instead Mirror's Edge went with a letterbox solution, Widescreen owners instead get the benefit of less black bars on the screen.
In my opinion Hor+ or Letterboxing are the only two proper ways to handle this. Hor+ utlizes the extra width that wider screens have while keeping the height the same (avoids cutting off the head of characters for example). Letterboxing preserves the designers original vision.
This is the best solution for overhead RTS games for example.
But please be aware that most games these days are designed for 16:9 (Xbox/360/PS3) and then ported to the PC, but they manage to screw things up badly at times. I've seen PC ports where they not only chop off the left and right but reduce the height as well, which is just nuts if you ask me...
It is one of the main reasons people mess around with the FOV on certain PC games in the first place.
Ironically older games which was not a port from console to PC seem to handle widescreen and wide aspect ratios just fine, and what method do they seem to use then? Well... Hor+ actually.
Which goes to show that the "old guys" did things right all along. *laughs*
5:4 and 4:3 screens are dying out though, so we'll more frequently see stuff designed for only 16:9 (which could cause a few minor stretch or cut issues for 16:10 monitor peeps like me).
What's so good about Hor+ method?
Because (made up numbers) there is only like 0.1% of the users in the world that have a view/monitor that is taller than it's wide or stack monitors on top of each other.
99% of the world have a wider than it's tall screen, or multiple views placed besides each other.
Human vision is "wide"
Hor+ is pretty much future proof.
We're slowly creeping towards 2:1 widescreen monitors.
Anyone that don't agree with me is an idiot. (Just kidding
!)
http://www.widescreengamingforum.com/wiki/index.php/FAQ
That is the way that is preferred, as those with wider screens get wider view or more sideview or surroundview.Kaeru Gaman wrote:an unchange vertical FOV means that a 16:9 User sees 42% more information than a 5:4 user.
42% more in only the horizontal field where most of a game's action happen.
The WSGF (Wide Screen Gaming Forum) classify this method as Hor+
The WSGF classify this method as Vert-Kaeru Gaman wrote:a fixed horizontal FOV would mean, a 5:4 user sees 30% more than a 16:9 user,
and this in the vertical area where less of the game's action takes place.
However a few games like Mirror's Edge which could have gone for Vert- did not do so, instead Mirror's Edge went with a letterbox solution, Widescreen owners instead get the benefit of less black bars on the screen.
In my opinion Hor+ or Letterboxing are the only two proper ways to handle this. Hor+ utlizes the extra width that wider screens have while keeping the height the same (avoids cutting off the head of characters for example). Letterboxing preserves the designers original vision.
That would be the best compromize as widescreen users thus gain width but loose height, and narrow screen users loose width but gain height.Kaeru Gaman wrote:so, perhaps a slightly growing horizontal FOV and slightly narrowing vertical FOV with increasing aspect ratio would be a nice solution?
This is the best solution for overhead RTS games for example.
But please be aware that most games these days are designed for 16:9 (Xbox/360/PS3) and then ported to the PC, but they manage to screw things up badly at times. I've seen PC ports where they not only chop off the left and right but reduce the height as well, which is just nuts if you ask me...
It is one of the main reasons people mess around with the FOV on certain PC games in the first place.
Ironically older games which was not a port from console to PC seem to handle widescreen and wide aspect ratios just fine, and what method do they seem to use then? Well... Hor+ actually.
Which goes to show that the "old guys" did things right all along. *laughs*
5:4 and 4:3 screens are dying out though, so we'll more frequently see stuff designed for only 16:9 (which could cause a few minor stretch or cut issues for 16:10 monitor peeps like me).
What's so good about Hor+ method?
Because (made up numbers) there is only like 0.1% of the users in the world that have a view/monitor that is taller than it's wide or stack monitors on top of each other.
99% of the world have a wider than it's tall screen, or multiple views placed besides each other.
Human vision is "wide"
Hor+ is pretty much future proof.
We're slowly creeping towards 2:1 widescreen monitors.
Anyone that don't agree with me is an idiot. (Just kidding
A port of this to PB would be great.Rescator wrote: ...If anyone is really interested in the full code lemme know and I'll write up a PureBasic example/port of my PHP code and post it in Tips'n'Tricks so you can use it in your own programs/games/engines.
Thank You
I was just playing around with you magic formula. In PureBasic I did this:
Code: Select all
pi.f = 3.1415926535897932385 ; value of pi rounded up from 50 decimal places to max places allowed in PB
old_aspect.f = 4/3 ; 4:3 aspect
new_aspect.f = 16/10 ; 16:10 aspect
old_FOV.f = 90
new_fov.f = (ATan(Tan((old_FOV*pi)/360.0)*(new_aspect/old_aspect))*360.0)/pi
Debug new_fov
Using the same values with the fov calculator at http://emsai.net/projects/widescreen/fovcalc/ the return is 100.38885781547
kinda close. I would think that anything greater then two decimal places would be wasted anyway but I would have thought it to come out closer to what the calculator gave. Am I missing something with trying to use your formula?