Camera3D
Camera node, displays from a point of view.
Camera node, displays from a point of view.
Camera3D is a special node that displays what is visible from its current location. Cameras register themselves in the nearest Viewport node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the camera will register in the global viewport. In other words, a camera just provides 3D display capabilities to a Viewport, and, without one, a scene registered in that Viewport (or higher viewports) can't be displayed.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Camera3DConstructor
public Camera3D();Properties15
AttributesProperty
public CameraAttributes Attributes { get; set; }The CameraAttributes to use for this camera.
CompositorProperty
public Compositor Compositor { get; set; }The Compositor to use for this camera.
CullMaskProperty
public uint CullMask { get; set; }The culling mask that describes which VisualInstance3D.Layers are rendered by this camera. By default, all 20 user-visible layers are rendered.
Note: Since the Camera3D.CullMask allows for 32 layers to be stored in total, there are an additional 12 layers that are only used internally by the engine and aren't exposed in the editor. Setting Camera3D.CullMask using a script allows you to toggle those reserved layers, which can be useful for editor plugins.
To adjust Camera3D.CullMask more easily using a script, use Camera3D.GetCullMaskValue and Camera3D.SetCullMaskValue.
Note: VoxelGI, SDFGI and LightmapGI will always take all layers into account to determine what contributes to global illumination. If this is an issue, set GeometryInstance3D.GIMode to GeometryInstance3D.GIModeEnum.Disabled for meshes and Light3D.LightBakeMode to Light3D.BakeMode.Disabled for lights to exclude them from global illumination.
CurrentProperty
public bool Current { get; set; }If true, the ancestor Viewport is currently using this camera.
If multiple cameras are in the scene, one will always be made current. For example, if two Camera3D nodes are present in the scene and only one is current, setting one camera's Camera3D.Current to false will cause the other camera to be made current.
DopplerTrackingProperty
public Camera3D.DopplerTrackingEnum DopplerTracking { get; set; }If not Camera3D.DopplerTrackingEnum.Disabled, this camera will simulate the Doppler effect for objects changed in particular _process methods.
Note: The Doppler effect will only be heard on AudioStreamPlayer3Ds if AudioStreamPlayer3D.DopplerTracking is not set to AudioStreamPlayer3D.DopplerTrackingEnum.Disabled.
EnvironmentProperty
public Environment Environment { get; set; }Camera environment override taking priority over WorldEnvironment. null clears the override and restores world-environment selection. Check this property on the active camera if world changes appear ineffective.
FarProperty
public float Far { get; set; }Distance to the camera’s far clipping plane. Do not use raw_depth*Far as a general distance formula: perspective depth is nonlinear and current rendering uses reverse-Z. The example reconstructs distance with the inverse projection matrix and division by W.
FovProperty
public float Fov { get; set; }The camera's field of view (also known as FOV), as an angle in degrees. Only applicable in perspective mode. Since Camera3D.KeepAspect locks one axis, this property sets the field of view on the other axis.
For reference, the default angle for the vertical FOV (75.0) is equivalent to a horizontal FOV of:
- ~91.31 degrees in a 4:3 viewport
- ~101.67 degrees in a 16:10 viewport
- ~107.51 degrees in a 16:9 viewport
- ~121.63 degrees in a 21:9 viewport
FrustumOffsetProperty
public Vector2 FrustumOffset { get; set; }The camera's frustum offset. This can be changed from the default to create "tilted frustum" effects such as Y-shearing.
Note: Only effective if Camera3D.Projection is Camera3D.ProjectionType.Frustum.
HOffsetProperty
public float HOffset { get; set; }The horizontal (X) offset of the camera viewport.
KeepAspectProperty
public Camera3D.KeepAspectEnum KeepAspect { get; set; }The axis to lock during Camera3D.Fov/Camera3D.Size adjustments. Can be either Camera3D.KeepAspectEnum.Width or Camera3D.KeepAspectEnum.Height.
NearProperty
public float Near { get; set; }Distance to the camera’s near clipping plane in world units. This is not the raw depth_texture value. In the accepted spatial example INV_PROJECTION_MATRIX reconstructs surface distances after Near and Far change, while raw depth changes.
ProjectionProperty
public Camera3D.ProjectionType Projection { get; set; }Camera projection type. Perspective uses a perspective projection with Fov; Orthogonal uses an orthographic projection with Size; Frustum defines an offset frustum. The accepted example reconstructs depth in Perspective and Orthogonal using current INV_PROJECTION_MATRIX. Frustum is outside that acceptance.
SizeProperty
public float Size { get; set; }Orthogonal/Frustum projection region size in world units; the corresponding width or height depends on KeepAspect. This is not surface distance. The orthographic control planes retain their reconstructed depth when Size changes and their framing is adjusted accordingly.
VOffsetProperty
public float VOffset { get; set; }The vertical (Y) offset of the camera viewport.
Methods49
ClearCurrentvoid
public void ClearCurrent(bool enableNext = true);If this is the current camera, remove it from being current. If enable_next is true, request to make the next camera current, if any.
| Name | Type | Default |
|---|---|---|
enableNext | bool | true |
GetAttributesCameraAttributes
public CameraAttributes GetAttributes();CameraAttributesGetCameraProjectionProjection
public Projection GetCameraProjection();Returns the projection matrix that this camera uses to render to its associated viewport. The camera must be part of the scene tree to function.
ProjectionGetCameraRidRid
public Rid GetCameraRid();Returns the camera's RID from the RenderingServer.
RidGetCameraTransformTransform3D
public Transform3D GetCameraTransform();Returns the transform of the camera plus the vertical (Camera3D.VOffset) and horizontal (Camera3D.HOffset) offsets; and any other adjustments made to the position and orientation of the camera by subclassed cameras such as XRCamera3D.
Transform3DGetCompositorCompositor
public Compositor GetCompositor();CompositorGetCullMaskuint
public uint GetCullMask();uintGetCullMaskValuebool
public bool GetCullMaskValue(int layerNumber);Returns whether or not the specified layer of the Camera3D.CullMask is enabled, given a layer_number between 1 and 20.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetDopplerTrackingCamera3D.DopplerTrackingEnum
public Camera3D.DopplerTrackingEnum GetDopplerTracking();Camera3D.DopplerTrackingEnumGetEnvironmentEnvironment
public Environment GetEnvironment();EnvironmentGetFarfloat
public float GetFar();floatGetFovfloat
public float GetFov();floatGetFrustumReckfell.Collections.Array<Plane>
public Reckfell.Collections.Array<Plane> GetFrustum();Returns the camera's frustum planes in world space units as an array of Planes in the following order: near, far, left, top, right, bottom. Not to be confused with Camera3D.FrustumOffset.
Reckfell.Collections.Array<Plane>GetFrustumOffsetVector2
public Vector2 GetFrustumOffset();Vector2GetHOffsetfloat
public float GetHOffset();floatGetKeepAspectModeCamera3D.KeepAspectEnum
public Camera3D.KeepAspectEnum GetKeepAspectMode();Camera3D.KeepAspectEnumGetNearfloat
public float GetNear();floatGetProjectionCamera3D.ProjectionType
public Camera3D.ProjectionType GetProjection();Camera3D.ProjectionTypeGetPyramidShapeRidRid
public Rid GetPyramidShapeRid();Returns the RID of a pyramid shape encompassing the camera's view frustum, ignoring the camera's near plane. The tip of the pyramid represents the position of the camera.
RidGetSizefloat
public float GetSize();floatGetVOffsetfloat
public float GetVOffset();floatIsCurrentbool
public bool IsCurrent();boolIsPositionBehindbool
public bool IsPositionBehind(Vector3 worldPoint);Tests whether the world-space point has forward-axis depth less than Near. This includes points between the camera origin and its near plane, not only points on the backward side of the origin. It is a depth test; it does not test the complete frustum or occlusion.
| Name | Type | Default |
|---|---|---|
worldPoint | Vector3 | — |
boolIsPositionInFrustumbool
public bool IsPositionInFrustum(Vector3 worldPoint);Tests a world-space point against the camera frustum planes. Use a camera attached to the scene tree with its viewport configured. A point inside the frustum is not necessarily visible: this method does not query occlusion, geometry coverage or object culling layers.
| Name | Type | Default |
|---|---|---|
worldPoint | Vector3 | — |
boolMakeCurrentvoid
public void MakeCurrent();Makes this camera the current camera for the Viewport (see class description). If the camera node is outside the scene tree, it will attempt to become current once it's added.
ProjectLocalRayNormalVector3
public Vector3 ProjectLocalRayNormal(Vector2 screenPoint);Returns a normal vector from the screen point location directed along the camera. Orthogonal cameras are normalized. Perspective cameras account for perspective, screen width/height, etc.
| Name | Type | Default |
|---|---|---|
screenPoint | Vector2 | — |
Vector3ProjectPositionVector3
public Vector3 ProjectPosition(Vector2 screenPoint, float zDepth);Returns the 3D point in world space that maps to the given 2D coordinate in the Viewport rectangle on a plane that is the given z_depth distance into the scene away from the camera.
| Name | Type | Default |
|---|---|---|
screenPoint | Vector2 | — |
zDepth | float | — |
Vector3ProjectRayNormalVector3
public Vector3 ProjectRayNormal(Vector2 screenPoint);Returns a normal vector in world space, that is the result of projecting a point on the Viewport rectangle by the inverse camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking.
| Name | Type | Default |
|---|---|---|
screenPoint | Vector2 | — |
Vector3ProjectRayOriginVector3
public Vector3 ProjectRayOrigin(Vector2 screenPoint);Returns a 3D position in world space, that is the result of projecting a point on the Viewport rectangle by the inverse camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking.
| Name | Type | Default |
|---|---|---|
screenPoint | Vector2 | — |
Vector3SetAttributesvoid
public void SetAttributes(CameraAttributes env);| Name | Type | Default |
|---|---|---|
env | CameraAttributes | — |
SetCompositorvoid
public void SetCompositor(Compositor compositor);| Name | Type | Default |
|---|---|---|
compositor | Compositor | — |
SetCullMaskvoid
public void SetCullMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetCullMaskValuevoid
public void SetCullMaskValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the Camera3D.CullMask, given a layer_number between 1 and 20.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetCurrentvoid
public void SetCurrent(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetDopplerTrackingvoid
public void SetDopplerTracking(Camera3D.DopplerTrackingEnum mode);| Name | Type | Default |
|---|---|---|
mode | Camera3D.DopplerTrackingEnum | — |
SetEnvironmentvoid
public void SetEnvironment(Environment env);| Name | Type | Default |
|---|---|---|
env | Environment | — |
SetFarvoid
public void SetFar(float far);| Name | Type | Default |
|---|---|---|
far | float | — |
SetFovvoid
public void SetFov(float fov);| Name | Type | Default |
|---|---|---|
fov | float | — |
SetFrustumvoid
public void SetFrustum(float size, Vector2 offset, float zNear, float zFar);Sets the camera projection to frustum mode (see Camera3D.ProjectionType.Frustum), by specifying a Camera3D.Size, an offset, and the z_near and z_far clip planes in world space units. The Camera3D.Size parameter represents the size of the near plane, either its width or height depending on the value of Camera3D.KeepAspect. See also Camera3D.FrustumOffset.
| Name | Type | Default |
|---|---|---|
size | float | — |
offset | Vector2 | — |
zNear | float | — |
zFar | float | — |
SetFrustumOffsetvoid
public void SetFrustumOffset(Vector2 offset);| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
SetHOffsetvoid
public void SetHOffset(float offset);| Name | Type | Default |
|---|---|---|
offset | float | — |
SetKeepAspectModevoid
public void SetKeepAspectMode(Camera3D.KeepAspectEnum mode);| Name | Type | Default |
|---|---|---|
mode | Camera3D.KeepAspectEnum | — |
SetNearvoid
public void SetNear(float near);| Name | Type | Default |
|---|---|---|
near | float | — |
SetOrthogonalvoid
public void SetOrthogonal(float size, float zNear, float zFar);Sets the camera projection to orthogonal mode (see Camera3D.ProjectionType.Orthogonal), by specifying a Camera3D.Size, and the z_near and z_far clip planes in world space units.
As a hint, 3D games that look 2D often use this projection, with Camera3D.Size specified in pixels.
| Name | Type | Default |
|---|---|---|
size | float | — |
zNear | float | — |
zFar | float | — |
SetPerspectivevoid
public void SetPerspective(float fov, float zNear, float zFar);Sets the camera projection to perspective mode (see Camera3D.ProjectionType.Perspective), by specifying a Camera3D.Fov (field of view) angle in degrees, and the z_near and z_far clip planes in world space units.
| Name | Type | Default |
|---|---|---|
fov | float | — |
zNear | float | — |
zFar | float | — |
SetProjectionvoid
public void SetProjection(Camera3D.ProjectionType mode);| Name | Type | Default |
|---|---|---|
mode | Camera3D.ProjectionType | — |
SetSizevoid
public void SetSize(float size);| Name | Type | Default |
|---|---|---|
size | float | — |
SetVOffsetvoid
public void SetVOffset(float offset);| Name | Type | Default |
|---|---|---|
offset | float | — |
UnprojectPositionVector2
public Vector2 UnprojectPosition(Vector3 worldPoint);Returns the 2D coordinate in the Viewport rectangle that maps to the given 3D point in world space.
Note: When using this to position GUI elements over a 3D viewport, use Camera3D.IsPositionBehind to prevent them from appearing if the 3D point is behind the camera:
| Name | Type | Default |
|---|---|---|
worldPoint | Vector3 | — |
Vector2Camera3D.DopplerTrackingEnum
| Value | Description |
|---|---|
Disabled = 0 | Disables Doppler effect simulation (default). |
IdleStep = 1 | Simulate Doppler effect by tracking positions of objects that are changed in |
PhysicsStep = 2 | Simulate Doppler effect by tracking positions of objects that are changed in |
Camera3D.KeepAspectEnum
| Value | Description |
|---|---|
Height = 1 | Preserves the vertical aspect ratio; also known as Hor+ scaling. This is usually the best option for projects running in landscape mode, as wider aspect ratios will automatically benefit from a wider horizontal FOV. |
Width = 0 | Preserves the horizontal aspect ratio; also known as Vert- scaling. This is usually the best option for projects running in portrait mode, as taller aspect ratios will benefit from a wider vertical FOV. |
Camera3D.ProjectionType
| Value | Description |
|---|---|
Frustum = 2 | Frustum projection. This mode allows adjusting |
Orthogonal = 1 | Orthogonal projection, also known as orthographic projection. Objects remain the same size on the screen no matter how far away they are. |
Perspective = 0 | Perspective projection. Objects on the screen becomes smaller when they are far away. |