Overview
The camera coordinate system defines the view space. The camera points towards its -z axis and is oriented such that its top side is in the direction of +y, and its right side in the direction of +x.Creation and Destruction
In Filament, Camera is a component that must be associated with an entity. To do so, useEngine::createCamera(Entity). A Camera component is destroyed using Engine::destroyCameraComponent(Entity).
Projection Modes
Perspective projection - objects get smaller as they are farther from the camera
Orthonormal projection - preserves distances regardless of depth
Field of View Direction
The field-of-view angle is defined on the vertical axis
The field-of-view angle is defined on the horizontal axis
Projection Methods
setProjection (Frustum)
Sets the projection matrix from a frustum defined by six planes.Type of projection to use (PERSPECTIVE or ORTHO)
Distance in world units from the camera to the left plane at the near plane
Distance in world units from the camera to the right plane at the near plane
Distance in world units from the camera to the bottom plane at the near plane
Distance in world units from the camera to the top plane at the near plane
Distance in world units from the camera to the near plane. Must be > 0 for PERSPECTIVE or != far for ORTHO
Distance in world units from the camera to the far plane. Must be > near for PERSPECTIVE or != near for ORTHO
setProjection (Field of View)
Utility to set the projection matrix from the field-of-view.Full field-of-view in degrees. Must be between 0 and 180
Aspect ratio (width/height). Must be > 0
Distance in world units from the camera to the near plane. Must be > 0
Distance in world units from the camera to the far plane. Must be > near
Direction of the fovInDegrees parameter
setLensProjection
Utility to set the projection matrix from the focal length.Lens’s focal length in millimeters. Must be > 0
Aspect ratio (width/height). Must be > 0
Distance in world units from the camera to the near plane. Must be > 0
Distance in world units from the camera to the far plane. Must be > near
setCustomProjection
Sets a custom projection matrix.Custom projection matrix used for rendering and culling. Must define an NDC system matching OpenGL convention
Distance in world units from the camera to the near plane
Distance in world units from the camera to the far plane. Must not equal near
setCustomEyeProjection
Sets a custom projection matrix for each eye (for stereoscopic rendering).Array of projection matrices, only the first config.stereoscopicEyeCount are read
Size of the projection matrix array. Must be >= config.stereoscopicEyeCount
Custom projection matrix for culling, must encompass both eyes
Distance in world units from the camera to the culling near plane. Must be > 0
Distance in world units from the camera to the culling far plane. Must be > near
Transform Methods
setModelMatrix
Sets the camera’s model matrix (position and orientation).The camera position and orientation provided as a rigid transform matrix. Must be a rigid transform
lookAt
Sets the camera’s model matrix using position, target, and up vector.The position of the camera in world space
The point in world space the camera is looking at
A unit vector denoting the camera’s “up” direction
setEyeModelMatrix
Set the position of an eye relative to this Camera (for stereoscopic rendering).The index of the eye to set. Must be < config.stereoscopicEyeCount
The model matrix for an individual eye
Exposure Settings
setExposure (Manual)
Sets this camera’s exposure (default is f/16, 1/125s, 100 ISO).Aperture in f-stops, clamped between 0.5 and 64. Lower values increase exposure. Realistic values are between 0.95 and 32
Shutter speed in seconds, clamped between 1/25,000 and 60. Lower values increase exposure. Realistic values are between 1/8000 and 30
Sensitivity in ISO, clamped between 10 and 204,800. Higher values increase exposure. Realistic values are between 50 and 25600
setExposure (Direct)
Sets this camera’s exposure directly.Direct exposure value. Sets aperture to 1.0, shutter speed to 1.2, and computes sensitivity to match
Query Methods
getProjectionMatrix
Returns the projection matrix used for rendering.The index of the eye to return the projection matrix for. Must be < config.stereoscopicEyeCount
The projection matrix used for rendering (far plane is at infinity)
getCullingProjectionMatrix
Returns the projection matrix used for culling (far plane is finite).The projection matrix set by setProjection or setLensProjection
getNear
Returns the frustum’s near plane distance.Near plane distance in world units
getCullingFar
Returns the frustum’s far plane used for culling.Far plane distance in world units
getModelMatrix
Returns the camera’s model matrix (world transform).The camera’s pose in world space as a rigid transform. Parent transforms are taken into account
getViewMatrix
Returns the camera’s view matrix (inverse of the model matrix).The view matrix
getPosition
Returns the camera’s position in world space.Camera position
getLeftVector
Returns the camera’s normalized left vector.Normalized left vector
getUpVector
Returns the camera’s normalized up vector.Normalized up vector
getForwardVector
Returns the camera’s forward vector.Forward vector (points in -z direction)
getFieldOfViewInDegrees
Returns the camera’s field of view in degrees.Which direction to compute the FOV for (VERTICAL or HORIZONTAL)
Field of view in degrees
getFrustum
Returns the camera’s culling Frustum in world space.The culling frustum
getEntity
Returns the entity representing this camera.The camera’s entity
getAperture
Returns this camera’s aperture in f-stops.Aperture value
getShutterSpeed
Returns this camera’s shutter speed in seconds.Shutter speed
getSensitivity
Returns this camera’s sensitivity in ISO.ISO sensitivity
getFocalLength
Returns the focal length in meters for a 35mm camera.Focal length in meters
Depth of Field
setFocusDistance
Sets the camera focus distance (used by Depth-of-field PostProcessing effect).Distance from the camera to the plane of focus in world units. Must be positive and larger than the near clipping plane
getFocusDistance
Returns the focus distance in world units.Focus distance
Utility Methods
setScaling
Sets an additional matrix that scales the projection matrix.Diagonal of the 2x2 scaling matrix to be applied after the projection matrix
getScaling
Returns the scaling amount used to scale the projection matrix.The diagonal of the scaling matrix applied after the projection matrix
setShift
Sets an additional matrix that shifts the projection matrix.x and y translation added to the projection matrix, specified in NDC coordinates
getShift
Returns the shift amount used to translate the projection matrix.The 2D translation x and y offsets applied after the projection matrix
Static Helper Methods
projection (Field of View)
Returns the projection matrix from the field-of-view.Direction of the fovInDegrees parameter
Full field-of-view in degrees. Must be between 0 and 180
Aspect ratio (width/height). Must be > 0
Distance in world units from the camera to the near plane. Must be > 0
Distance in world units from the camera to the far plane. Must be > near
The computed projection matrix
projection (Focal Length)
Returns the projection matrix from the focal length.Lens’s focal length in millimeters. Must be > 0
Aspect ratio (width/height). Must be > 0
Distance in world units from the camera to the near plane. Must be > 0
Distance in world units from the camera to the far plane. Must be > near
The computed projection matrix
inverseProjection
Returns the inverse of a projection matrix.The projection matrix to inverse
The inverse of the projection matrix
computeEffectiveFocalLength
Helper to compute the effective focal length taking into account the focus distance.Focal length in any unit (e.g. meters or millimeters)
Focus distance in same unit as focalLength
The effective focal length in same unit as focalLength
computeEffectiveFov
Helper to compute the effective field-of-view taking into account the focus distance.Full field of view in degrees
Focus distance in meters
Effective full field of view in degrees
Best Practices
Choosing the Near Plane
The near plane distance greatly affects depth-buffer precision. Make sure to pick the highest near plane distance possible. Example precision at various distances for a 32-bit float depth buffer:| near (m) | 1 m | 10 m | 100 m | 1 Km |
|---|---|---|---|---|
| 0.001 | 7.2e-5 | 0.0043 | 0.4624 | 48.58 |
| 0.01 | 6.9e-6 | 0.0001 | 0.0430 | 4.62 |
| 0.1 | 3.6e-7 | 7.0e-5 | 0.0072 | 0.43 |
| 1.0 | 0 | 3.8e-6 | 0.0007 | 0.07 |