Jump to content

[SOLVED] Imprecision / error in Fov calculation (?)


photo

Recommended Posts

Hi,

 

we've ran into some issues around FoV:

 

post-691-0-75723200-1492950409_thumb.png

 

size is 2560x1440, specified horizontal view angle is 110 degrees, calculated unigine vertical view angle (vfov = hfov * height / width) is 61.875 degrees

 

If I now change the size to 2560x720, but keep our horizontal view angle at 110 degrees I would expect this picture as result:

 

post-691-0-52447900-1492950449_thumb.png

 

However, the actual result is this:

 

post-691-0-03650600-1492950522_thumb.png

 

Note that the calculated unigine vertical view angle is now 30.9375 degrees (or exactly half of 61.875 as expected), but that the horizontal view angle is not in fact 110 degrees. It is less than that as the posts to the left are outside the view.

 

I can modify the view angle to include the posts and have more or less the correct picture:

 

post-691-0-05651800-1492950539_thumb.png

 

However, this needs a vertical view angle of 33.46875 degrees, or 119 degrees horizontally (!).

 

What is happening here??

 

We need accurate view frustum/fov results as we are using a multi-instance multiscreen setup including slightly modified blending/warping. (7 beamers to rear project all four sides of a tractor cabin)

 

 

 

on a related side issue, it seems that setting the projection matrix directly does not update the internal unigine fov value? this means the result of getFov is invalid..

Link to comment

did some more digging, and I did not see that much wrong with the perspective matrix calculation so I was wondering if the frustum/viewport scaling has anything to do with it.

 

I have disabled aspect correction in Viewport and calculate the perspective matrix as:

double aspect_ratio = ((double)gui->getWidth ()) / ((double)gui->getHeight ()) ;
double w = tan (deg2rad (viewPoint->fov / 2.0)) ;
double h = w / aspect_ratio ;

Unigine::Math::mat4 projection =  Unigine::Math::frustum (-w, w, -h, h, 1.0, 1000.0) ;

m_playerDummy->setProjection (projection) ;

with viewPoint->fov being 110 degrees.

 

Now the horizontal view angle is consistent among both sizes / aspect ratios:

 

post-691-0-45574500-1492957248_thumb.png

 

post-691-0-69679900-1492957265_thumb.png

 

 

Note however that the horizontal angle is consistent for these two images, but differs from the original one(!):

 

post-691-0-75723200-1492950409_thumb.png

 

So seems like this one is not displaying 110 degrees either..

 

Link to comment

Hi Silent,

 

yes, I am aware. Which is why I disabled it. After disabling I indeed get correct and predictable results (see my second post). For us, disabling aspect correction is perfectly acceptable (I never understood the rationale behind the scaling anyway).

 

However, the results with aspect ratio correction on do seem to be inconsistent and wrong (see first post). Unless I am wrong somewhere in my results, it is perhaps something that needs fixing that you should take a look at.

 

 

Side question: we are still at 2.3 so the Render class does not yet have the getViewport call. How do I get access to the viewport (from C++)? For testing purposes I have disabled aspect correction in the engine completely, but this is of course not ideal. I would prefer to do it using the setAspectCorrection call.

Link to comment

Hi Esger,

 

setFOV() method initially sets the vertical FOV for the player / camera and so on, not horizontal. Maybe that will make sense? Horizontal FOV you can calculate that way:

float aspect = float(engine.app.getWidth()) / engine.app.getHeight();
float hfov = vfov * aspect;

Right now we don't see any issues with FOV calculations inside engine.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi Silent,

 

yes, I know unigine expects the fov to be the vertical one, we calculate the vertical fov from the horizontal fov.

 

However, there does seem to be something amiss here.

 

image size 2560x1440, vertical fov set to 61.875:

 

post-691-0-75723200-1492950409_thumb.png
 
image size 2560x720, vertical fov set to 30.9375 (or exactly half of 61.875):
 
post-691-0-03650600-1492950522_thumb.png
 
Notice that the horizontal angle should remain identical for these two cases. However, it is not, as is clearly visible by the missing fences in the second picture. Unless I am missing something, this is wrong.
 
The second picture should look like this:
 
post-691-0-52447900-1492950449_thumb.png

 

 

And as already mentioned in an earlier post, disabling aspect ratio correction produces yet another horizontal angle for the same values:

 

post-691-0-69679900-1492957265_thumb.png
 
I believe this one to actually be the correct one. Meaning that both aspect ratio corrected ones are wrong.
 

 

 

Any way to get access to the Viewport in C++ API in 2.3 version?

Link to comment

Hi Silent,

 

the Viewport class does not provide a ::get () or something similar, the Render class has ::getViewport in 2.3.1, but we're still on 2.3. How do I get hold of a ViewportPtr in 2.3?

Link to comment

Hi Silent,

 

that was what I suspected. At the moment it is not feasible to upgrade to unigine 2.3.1 in this stage of the project. Will do so later this year. Then we'll leave the aspect correction completely disabled for now.

Link to comment
×
×
  • Create New...