pro3d-space / PRo3D

PRo3D, short for Planetary Robotics 3D Viewer, is an interactive 3D visualization tool allowing planetary scientists to work with high-resolution 3D reconstructions of planetary surfaces.
http://pro3d.space/
GNU Affero General Public License v3.0
38 stars 2 forks source link

Bug: Batch processing / Sequenced Bookmarks Frustum #358

Closed RebeccaNowak closed 8 months ago

RebeccaNowak commented 1 year ago

With the same settings in GUI and Batch Rendering, the field of view of rendered images is not the same as shown in the GUI. Focal length is the same, calculated Frustum is not.

Depending on the aspect ratio of the output image the field of view is wider or narrower in the rendered images than in the GUI.

We have one Frustum directly in Model, and another one in ViewConfigModel. Those two have different values for FoV. The reason for this is, that the frustum in ViewConfigModel is not updated when the size of the RenderControl is changed. Snapshots use the value from ViewConfigModel, but in Viewer the one in Model is used.

RebeccaNowak commented 9 months ago

The underlying problem was this:


Frustum.perspective (hfov.DegreesFromRadians()) near far 1.0
        |> Frustum.withAspect aspect

and

Frustum.perspective (hfov.DegreesFromRadians()) near far aspect

do not have the same result, but were being used interchangeably.

Demonstration of this outside PRo3D:

3: WARNING: Frustum.perspective 60.0 0.1 100.0 0.8
 3: Frustum Model: { left = -0.05773502692
 3:   right = 0.05773502692
 3:   bottom = -0.07216878365
 3:   top = 0.07216878365
 3:   near = 0.1
 3:   far = 100.0
 3:   isOrtho = false }
 3: Frustum Model Aspect: 0.8
 3: Frustum Model Fov: 59.99999999999999
 3: WARNING
 3:   Frustum.perspective 60.0 0.1 100.0 1.0
 3:                            |> Frustum.withAspect 0.8
 3: Frustum Model: { left = -0.04618802154
 3:   right = 0.04618802154
 3:   bottom = -0.05773502692
 3:   top = 0.05773502692
 3:   near = 0.1
 3:   far = 100.0
 3:   isOrtho = false }
 3: Frustum Model Aspect: 0.8
 3: Frustum Model Fov: 49.58256179428978

Reason can be found in Aardvark.Rendering

    let perspective (horizontalFieldOfViewInDegrees : float) (near : float) (far : float) (aspect : float) =
        let d = tan (0.5 * Conversion.RadiansFromDegrees horizontalFieldOfViewInDegrees) * near
        { left = -d; right = +d; bottom = -d / aspect; top = +d / aspect; near = near; far = far; isOrtho = false }
    let withAspect (newAspect : float) ( { left = l; right = r; top = t; bottom = b } as f )  =
        let factor = newAspect / aspect f
        { f with right = factor * r; left  = factor * l }