Skip to main content
GameDev.net gamedev.net
🔒 Locked

fovy in D3DXMatrixPerspectiveFovLH

Started by schupf Oct 20, 2008 at 11:11 AM 10 replies 9.7k views
Original Post
schupf
schupf
One little question about the fovy parameter of D3DXMatrixPerspectiveFovLH. The docu says: fovy [in] Field of view in the y direction, in radians. So fovy is the angle between the top and bottom plane of the frustum. But in my code I juse a fovy of 45° (DEG) and most applications I have seen also use values like 45°. But 45° for the WHOLE angle between top and bottom plane looks really small to me. So is fovy really the whole angle or just the half angle between top and bottom plane?
Evil Steve
Evil Steve
Quote:
Original post by schupf
One little question about the fovy parameter of D3DXMatrixPerspectiveFovLH. The docu says:
fovy
[in] Field of view in the y direction, in radians.

So fovy is the angle between the top and bottom plane of the frustum. But in my code I juse a fovy of 45° (DEG) and most applications I have seen also use values like 45°. But 45° for the WHOLE angle between top and bottom plane looks really small to me. So is fovy really the whole angle or just the half angle between top and bottom plane?
54 degrees is pretty tight, most games ~90 degrees. Define "most applications" - if you look at how the matrix is constructed (At the end of the docs page for D3DXMatrixPerspectiveFovLH), you'll see: yScale = cot(fovY/2); some applications might build a projection matrix manually, and you may specify the half-FOV for them.
schupf
schupf
Now I am really confused. So fovy of D3DXMatrixPerspectiveFovLH is the full angle from the top plane to the bottom plane, isnt it?

So a fovy of 90° should be a normal case. But if I use a fovy of 90° in my application:
D3DXMatrixPerspectiveFovLH(&projMatrix, D3DXToRadian(90), viewRatio, nearPlane, farPlane);
it looks really "strange" (like there is a distortion).

By contrast if I take a fovy of 45° everything looks ok. But a fovy of 45° means just 22.5° degrees from top plane to the view dir, which is actually really small.
How is it possible that the 90° fovy looks so strange (which should be the "normal" setting) and 45° looks so good (which should be too small)??
Evil Steve
Evil Steve
Quote:
Original post by schupf
Now I am really confused. So fovy of D3DXMatrixPerspectiveFovLH is the full angle from the top plane to the bottom plane, isnt it?

So a fovy of 90° should be a normal case. But if I use a fovy of 90° in my application:
D3DXMatrixPerspectiveFovLH(&projMatrix, D3DXToRadian(90), viewRatio, nearPlane, farPlane);
it looks really "strange" (like there is a distortion).

By contrast if I take a fovy of 45° everything looks ok. But a fovy of 45° means just 22.5° degrees from top plane to the view dir, which is actually really small.
How is it possible that the 90° fovy looks so strange (which should be the "normal" setting) and 45° looks so good (which should be too small)??
Yes, fovY is the full angle, not half.
Can you provide a screenshot at all (Upload to imageshack or something, then use HTML to post the image in your post)?
schupf
schupf
Quote:
Can you provide a screenshot at all (Upload to imageshack or something, then use HTML to post the image in your post)?

Of course.
Screenshot with a fovy of 45°: fovy45
Screenshot with a fovy of 90°: fovy90
The distortion is especially visible at the sun. In motion (If I rotate the camera to the left or right) the "distortion" is even more noticable.

I just found this site, where they explain the projection matrix: http://www.codeguru.com/cpp/misc/misc/math/article.php/c10123__3/
At the end of the first site you can read this sentence:
"In Direct3D, you can get a matrix of this form by calling D3DXMatrixPerspectiveFovLH(). This form is particularly useful because you can just set r to the aspect ratio of the window you're rendering in, and a field of view angle of p / 4 is usually fine". I assume that p stands for PI, so he also suggests a fovy of 45°.
Now where I know that fovy means the full angle this is kinda strange to me. Any ideas why 45° looks "good" and 90° looks so strange, even though 90° sound like the most reasonable value?
Evil Steve
Evil Steve
Quote:
Original post by schupf
Quote:
Can you provide a screenshot at all (Upload to imageshack or something, then use HTML to post the image in your post)?

Of course.
Screenshot with a fovy of 45°: fovy45
Screenshot with a fovy of 90°: fovy90
The distortion is especially visible at the sun. In motion (If I rotate the camera to the left or right) the "distortion" is even more noticable.

I just found this site, where they explain the projection matrix: http://www.codeguru.com/cpp/misc/misc/math/article.php/c10123__3/
At the end of the first site you can read this sentence:
"In Direct3D, you can get a matrix of this form by calling D3DXMatrixPerspectiveFovLH(). This form is particularly useful because you can just set r to the aspect ratio of the window you're rendering in, and a field of view angle of p / 4 is usually fine". I assume that p stands for PI, so he also suggests a fovy of 45°.
Now where I know that fovy means the full angle this is kinda strange to me. Any ideas why 45° looks "good" and 90° looks so strange, even though 90° sound like the most reasonable value?
Hmm, that is odd. The matrix used in D3DXMatrixPerspectiveFovLH definitely takes the full FOV as a parameter rather than half. Are you setting the aspect ratio correctly?
schupf
schupf
Yes, the ratio is correct. I opened some DX SDK samples and all of them use a fovy of 45°. I still don't know why 90° look a little bit distorted (especially cause you use this value while creating skyboxes), but it seems like values between 45° and 80° for fovy are standard values.
Evil Steve
Evil Steve
Quote:
Original post by schupf
Yes, the ratio is correct. I opened some DX SDK samples and all of them use a fovy of 45°. I still don't know why 90° look a little bit distorted (especially cause you use this value while creating skyboxes), but it seems like values between 45° and 80° for fovy are standard values.
Hmm, that is odd. I've always used 90 degrees for my FOV and haven't noticed any problems with it.

Still, if 45 degrees works for you, go with that [smile]
schupf
schupf
Quote:
Original post by Evil Steve
Quote:
Original post by schupf
Yes, the ratio is correct. I opened some DX SDK samples and all of them use a fovy of 45°. I still don't know why 90° look a little bit distorted (especially cause you use this value while creating skyboxes), but it seems like values between 45° and 80° for fovy are standard values.
Hmm, that is odd. I've always used 90 degrees for my FOV and haven't noticed any problems with it.

Still, if 45 degrees works for you, go with that [smile]


Hm, could you please try something for me? Open a DX SDK Sample project (for example ShadowVolume10 sample, since I used this too) and change the fov from 45° to 90° (so just chance this line in the project: g_Camera.SetProjParams( D3DX_PI/4, fAspectRatio, 0.1f, 500.0f ); )
Could you tell me if you also think it looks kinda strange with a 90° fovy (especially while rotating the camera)?
KreK
KreK
What you see is a normal perspective distortion. It is impossible to map a 3D scene on a flat plane without some distortion and it exists in all FOVs but it becomes a lot more noticable with higher FOVs. As the angle approaches 180 degrees, the distortion becomes infinitely large because the frustum's near plane also becomes infinitely large.

Most games use vertical FOVs far below 45 degrees. This is obvious when you try to play games across triple screens with Matrox TripleHead2Go where you have these extreme widescreens with aspect ratios of 4:1 or even larger, yet games maintain the same vertical FOV as single screen games even though the maximum horizontal FOV with 3D perspective is 180 degrees, thus showing that the original vertical FOV was below 45 (example of games with such low vertical FOV are Bioshock and Call of Duty 4).
Evil Steve
Evil Steve
Quote:
Original post by schupf
Quote:
Original post by Evil Steve
Quote:
Original post by schupf
Yes, the ratio is correct. I opened some DX SDK samples and all of them use a fovy of 45°. I still don't know why 90° look a little bit distorted (especially cause you use this value while creating skyboxes), but it seems like values between 45° and 80° for fovy are standard values.
Hmm, that is odd. I've always used 90 degrees for my FOV and haven't noticed any problems with it.

Still, if 45 degrees works for you, go with that [smile]


Hm, could you please try something for me? Open a DX SDK Sample project (for example ShadowVolume10 sample, since I used this too) and change the fov from 45° to 90° (so just chance this line in the project: g_Camera.SetProjParams( D3DX_PI/4, fAspectRatio, 0.1f, 500.0f ); )
Could you tell me if you also think it looks kinda strange with a 90° fovy (especially while rotating the camera)?
It does look a bit strange, yes. I think I'm thinking of vertical versus horizontal FOV, I had another look at my code and it's using 60 degrees, not 90 - which is actually quite a bit of a difference. When I change to 90 degrees, it also looks pretty strange.
LeGreg
LeGreg
Quote:
Original post by schupf
Now where I know that fovy means the full angle this is kinda strange to me. Any ideas why 45° looks "good" and 90° looks so strange, even though 90° sound like the most reasonable value?


FOV is an artistic choice (see wide angle vs telephoto lens in photography), as well as a game design choice (in wide angle mode you see more so it is easier or could be seen as "cheating", in zoom mode you see less with a fixed angle so you have to move/rotate your view more which can be a hassle, and you can use wide angles to increase the perception of speed), as well as a physical limitation choice (your fov cannot exceed 180 degrees in planar projection, the actual position of the player to his monitor will determine what looks the more "natural" in strict first person view but you should not limit yourself to it).

Plus taking screenshots and displaying them at a reduced size is not going to give you an accurate idea of what it looks like when the game is full screen.
Does the player play on a TV screen at a few feet, in an IMAX theatre ? Does he wear goggles with LCD screens on them ?

Take all those issues into consideration when deciding on a FOV and don't make the mistake of assuming that there is a "more reasonable value". For example, games like diablo, warcraft, the sims typically use a FOV of near 0 (parallel or near parallel projection).

LeGreg

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.