Vixen
02b45cc4
csharp
public struct Camera

What an entity sees. Its position and orientation come from its transform.

Read the guide page for this →

As a scene component

Size
56 bytes — 240 rows in a 16 KB chunk, alone on the archetype

Remarks

A camera is a component and not an object, so an entity can be one, and so a scene can have any number of them without the engine holding a list. Which one renders is the renderer's decision, made from Order and the entity being enabled.

[DataContract], because a level places its cameras — that is what gives it a name a .vxscene can write and a serializer a compiled one can be made of — and [Component], because the pair of them is what declares it to SceneComponentRegistry. A game's own components say the same two things the same way and need nothing else.

It is a physical camera, and there is no other kind. A sensor and a focal length are a field of view; an aperture, a shutter and an ISO are an exposure value; and the aperture is in both lists, which is why they cannot be separate components. This used to be two — a Camera holding an angle and a PhysicalCamera holding a lens — and an entity carrying both had two answers to one question, with a rule buried in the extraction system about which won. Now there is one set of numbers and everything is derived from it: the projection, the exposure, and the defocus.

⚠ FieldOfView is a view onto FocalLength, not a field. Reading it computes the angle the lens and the sensor give; writing it solves back for the focal length that produces that angle. So every line that ever said Camera.Perspective with { FieldOfView = x } still means what it meant, and a scene file stores the lens rather than the angle — which is the number that also decides the depth of field.

⚠ A zeroed component is not a camera. A sensor of zero width has an infinite field of view, a far plane of zero has no depth range at all, and an aperture of zero has an exposure of minus infinity — so Perspective is what a caller starts from, the same rule ControlRotation.Default already follows. HasLens is what asks, and CameraExtractionSystem is what asks it.

Fields and properties (21)

  • public float FocalLength

    The lens's focal length in millimetres.

  • public float SensorWidth

    The sensor's width in millimetres. 36 is a full-frame stills camera.

  • public float SensorHeight

    The sensor's height in millimetres. 24 goes with a width of 36.

  • public float Aperture

    The f-number. Smaller is a wider opening, more light and less depth of field.

  • public float ShutterTime

    How long the shutter is open, in seconds.

  • public float Sensitivity

    The ISO.

  • public float FocusDistance

    What the lens is focused on, in metres. Zero focuses at infinity.

  • public int BladeCount

    How many diaphragm blades, which is the shape an out-of-focus highlight takes.

  • public float NearPlane

    Distance to the near plane.

  • public float FarPlane

    Distance to the far plane.

  • public bool Orthographic

    Whether the projection is orthographic.

  • public float OrthographicHeight

    The height the orthographic view covers, in world units.

  • public float AspectRatio

    Width over height. Zero means "ask the target", which the renderer fills in.

  • public int Order

    Which camera renders first. Lower is earlier.

  • public static Camera Perspective

    A sensible perspective camera: 60° vertical on full frame, from 0.1 to 1000, at f/2.8 and 1/60 at ISO 100.

  • public static Camera Orthographic2D

    A sensible orthographic camera covering ten world units of height.

  • public float FieldOfView

    Vertical field of view, in radians. Ignored when Orthographic.

  • public readonly bool HasLens

    Whether this describes a lens at all.

  • public readonly float HorizontalFieldOfView

    The horizontal field of view, in radians.

  • public readonly float SensorAspectRatio

    The aspect ratio the sensor has, which is not AspectRatio.

  • public readonly float Ev100

    The exposure value at ISO 100 this camera's settings produce.

Methods (4)

  • public static Camera WithLens(float focalLength)

    A camera named by its lens rather than by its angle, on a full-frame sensor.

  • public static Camera WithLens(float focalLength, float sensorWidth, float sensorHeight)

    The same, on a sensor that is not full frame.

  • public readonly float CircleOfConfusion(float distance)

    How wide the circle of confusion is for a point at a given distance, in metres.

  • public static float FocalLengthFor(float fieldOfView, float sensorHeight)

    The focal length that frames a given vertical angle on a given sensor height.

Used by (39)

  • CameraDirectorSystemVixen.Engine
  • CameraDirectorTestsVixen.Engine.Tests
  • CameraExtractionSystemVixen.Rendering
  • CameraExtractionTestsVixen.Rendering.Tests
  • CameraLensVixen.Engine
  • CameraMathVixen.Engine
  • ComponentRegistrationVixen.Engine
  • ComponentRegistrationTestsVixen.Engine.Tests
  • DepthOfFieldRendererVixen.Rendering.PostFx
  • LensFlareRendererVixen.Rendering.PostFx
  • LocalExposureRendererVixen.Rendering.PostFx
  • MotionBlurRendererVixen.Rendering.PostFx
  • PhysicalCameraTestsVixen.Rendering.Tests
  • PlayerCameraTestsVixen.Engine.Tests
  • PlayerCamerasVixen.Engine
  • PostEffectTestsVixen.Rendering.PostFx.Tests
  • RenderCameraVixen.Rendering
  • RigVixen.Engine.Tests
  • SceneAndPrefabTestsVixen.Engine.Tests
  • SceneAssetTestsVixen.Engine.Tests
  • TonemapRendererVixen.Rendering.PostFx
  • TypeRegistrationVixen.Engine
  • Vixen_Engine_Cameras_CameraSerializerVixen.Engine
  • AddComponentMenuTestsVixen.Editor.App.Tests
  • BehaviorSceneTestsVixen.Editor.SceneView.Tests
  • ComponentGizmoTestsVixen.Editor.SceneView.Tests
  • ComponentTestsVixen.Editor.App.Tests
  • ComponentsViewVixen.Editor.App
  • CreateMenuTestsVixen.Editor.App.Tests
  • EditorApplicationVixen.Editor.App
  • HostedRendererTestsVixen.App.Tests
  • InspectorPanelTestsVixen.Editor.App.Tests
  • LightTestsVixen.Editor.SceneView.Tests
  • MaterialIconsVixen.Editor.App
  • SceneDocumentVixen.Editor.SceneView
  • SceneImporterTestsVixen.Editor.Assets.Tests
  • SceneManifestTestsVixen.Editor.Assets.Tests
  • SceneSerializerTestsVixen.Editor.SceneView.Tests
  • StandardIconsVixen.Editor.App