The Optics section of the UVR Camera Settings component defines the lens of the sensor. Two types of lenses are supported :
The Perfect Pinhole is a model of a pinhole camera : the lens has no physical radius and is perfectly reduced to a single point. Using a pinhole camera, no blur appears in the image when an object is out of focus.
The Lens type is a model of a physical camera : the lens is defined by its radius, the larger the radius the more blur there will be in the image for objects out of focus. A Lens optics requires additional settings :
The Lens Radius is the radius of the optical system, in the same unit as the scene (see the Scene Settings section). If the radius is set to 0, the Perfect Pinhole model will be used instead of the Lens model.
The Focus Distance is the distance at which the image will be sharp, in the same unit as the scene (see the Scene Settings section) : an object that is seen from a distance similar to the focus distance will be sharp, an object that is seen from closer/further away will be blurred.
If the Auto Focus is enabled, the focus distance will be automatically computed so that the point in the middle of the image is sharp. When the autofocus is enabled, 3 additional buttons appear next to the Auto Focus field :
The pen button on the left defines whether the focus point is circled on the image or not,
The pipette button on the right enables you to pick a point on the image that will be use to compute the focus distance (this option is only available when using the Engine view),
The square button in the middle reset the focus point to the center of the image.
Difference between a scene defined with a Perfect Pinhole optical system (left) and a Lens optical system focused on the red sphere (right)
The lens settings can be edited at run time.
The projection defines which part of the scene can be detected by the Camera.
Unity supports two projection modes : Perspective and Orthographic :
When using the Perspective projection, the camera rays are fired from the center of the sensor into the scene with a given field of view that defines the angular section visible to the camera. This mimics an actual pinhole camera.
When using the Orthographic projection, the camera rays are fired from the sensor plane into the scene, with a direction that is parallel to the camera forward axis. The perspective effect is not visible using this projection : the distance between an object and the camera doesn't affect its visible size.
The pinhole camera model (Perspective projection) is characterized by the camera projection matrix. Unity uses a simple version of this matrix (see figure A) defined by the camera field of view (fx, fy) and the optical center (cx, cy) :
The field of view defines the size of the viewport visible to the camera,
The optical center defines the offset between the camera forward axis and its optical center (the center of the final image).
Unity also requires two planes that define the closest (near plane) and furthest (far plane) visible elements for the camera. These planes are not required when using Predict because our rendering algorithm doesn't have minimal or maximal distances, every object in the scene will be visible.
Figure A : simple projection matrix
To get a more precise control over the camera projection, you can use the UVR Projective Camera component. This component enables you to :
Define the camera projection matrix using a focal length instead of a field of view : the focal length f defines the distance between the camera origin and the principal plane, unlike the field of view it does not depend on the sensor ratio (see Figure B).
Define the camera distortion : an actual sensor is never perfect and the optics generate distortion in the final image. Two kinds of distortion can be characterized using polynomial components : the radial and the tangential distorsion (see Figure C). We recommand not using these settings unless you have an actual reference (measurement or model).
Use the camera intrinsic settings defined in a calibration file created in Predict Cam : cameras can be calibrated using actual measurements. The measure defines the camera focal length, optical center, distorsion parameters and resolution. This calibration can be made in Predict Cam, its output is a file containing all these settings. You can then give a reference to this file in the UVR Projective Camera component.
https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html
Figure B : pinhole Camera model
https://www.geeksforgeeks.org/calibratecamera-opencv-in-python/
Figure C : illustration of the radial and tangential distorsions
In real life, imaging with an optical system is subject to diffraction which makes the image of a point not perfect : the diaphragm usually makes the image of a point look like a start. The Point Spread Function (PSF) defines the shape of a single point imaged by the optical system.
If the Expert Mode is enabled, you can specify the PSF with an RGB texture.
Figure A : Example of a PSF texture
Figure B : rendering of a scene without PSF
Figure C : rendering of the same scene as in Figure B, using the PSF defined in Figure A