CameraComponentclass

Every scene should have at least one Camera.

object→Component→CameraComponent
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.CameraComponent : Sandbox.Component

Constructors1

Showing 1 constructors

Methods35

Showing 35 methods

public void AddCommandList(Sandbox.Rendering.CommandList buffer, Sandbox.Rendering.Stage stage, int order = 0)PUBLIC

Add a command list to the render

ParameterTypeDescription
bufferCommandList—
stageStage—
order = 0int—
Returns:void—

public T AddEffect(T effect)PUBLIC

Add a custom camera effect (a `Sandbox.CameraEffectSystem.BaseEffect` subclass), targeted at this camera.

ParameterTypeDescription
effectT—
Returns:T—

public System.IDisposable AddHookAfterOpaque(string debugName, int order, System.Action`1<Sandbox.SceneCamera> renderEffect)PUBLICOBSOLETE

Obsolete: Use CommandList

ParameterTypeDescription
debugNamestring—
orderint—
renderEffectAction<SceneCamera>—
Returns:IDisposable—

public System.IDisposable AddHookAfterTransparent(string debugName, int order, System.Action`1<Sandbox.SceneCamera> renderEffect)PUBLICOBSOLETE

Obsolete: Use CommandList

ParameterTypeDescription
debugNamestring—
orderint—
renderEffectAction<SceneCamera>—
Returns:IDisposable—

public System.IDisposable AddHookAfterUI(string debugName, int order, System.Action`1<Sandbox.SceneCamera> renderEffect)PUBLICOBSOLETE

Obsolete: Use CommandList

ParameterTypeDescription
debugNamestring—
orderint—
renderEffectAction<SceneCamera>—
Returns:IDisposable—

public System.IDisposable AddHookBeforeOverlay(string debugName, int order, System.Action`1<Sandbox.SceneCamera> renderEffect)PUBLICOBSOLETE

Obsolete: Use CommandList

ParameterTypeDescription
debugNamestring—
orderint—
renderEffectAction<SceneCamera>—
Returns:IDisposable—

public Sandbox.CameraEffectSystem.BaseEffect AddShake(float amplitude, float frequency, float duration)PUBLIC

Shake this camera - the classic screen shake (Half-Life's env_shake). Every 1/`frequency` seconds a new random offset within `amplitude` world units, settling to nothing over `duration`. A duration of zero shakes until `Sandbox.CameraEffectSystem.BaseEffect.Stop`.

ParameterTypeDescription
amplitudefloat—
frequencyfloat—
durationfloat—
Returns:BaseEffect—

public Sandbox.CameraEffectSystem.BaseEffect AddTilt(Angles angle, float duration, float easeTime = 0.2)PUBLIC

Tilt this camera by `angle`, eased in over `easeTime` and back out before `duration` ends.

ParameterTypeDescription
angleAngles—
durationfloat—
easeTime = 0.2float—
Returns:BaseEffect—

public Sandbox.Rect BBoxToScreenPixels(BBox bounds, bool isBehind)PUBLIC

Given a BBox in world space, will return the screen space rect that totally contains the box.

ParameterTypeDescription
boundsBBox—
isBehindbool—
Returns:Rect—

public Sandbox.Painter BeginHud()PUBLIC

Starts drawing on the camera after post processing. Bounds start at (0, 0) and use the camera's viewport size in pixels. Dispose the painter to append its drawing. Commands are reset at the start of each frame. Finish painting before recording other commands into the HUD command list.

Returns:Painter—

public Sandbox.Painter BeginOverlay()PUBLIC

Starts drawing on the camera after UI. Bounds start at (0, 0) and use the camera's viewport size in pixels. Dispose the painter to append its drawing. Commands are reset at the start of each frame. Finish painting before recording other commands into the overlay command list.

Returns:Painter—

public Matrix CalculateObliqueMatrix(Sandbox.Plane clipPlane)PUBLIC

Calculates a projection matrix with an oblique clip-plane defined in world space.

ParameterTypeDescription
clipPlanePlane—
Returns:Matrix—

public void ComposeView()PUBLIC

Compose this camera's view - the base transform reshaped by every `Sandbox.ICameraModifier` (published on `Sandbox.CameraComponent.View`), then transient effects baked on top for the render. The scene composes every camera once per tick, after Update and bone merging and before PreRender, so anything in PreRender positions against a settled camera. Call it yourself only when you're rendering without ticking the scene and want the composition - otherwise a camera moved after composing just renders from its raw transform.

Returns:void—

public virtual void Reset()PUBLICVIRTUAL

Returns:void—

public Ray ScreenNormalToRay(Vector3 normalPosition)PUBLIC

ParameterTypeDescription
normalPositionVector3—
Returns:Ray—

public Ray ScreenPixelToRay(Vector2 pixelPosition)PUBLIC

ParameterTypeDescription
pixelPositionVector2—
Returns:Ray—

public Vector3 ScreenToWorld(Vector2 screen)PUBLIC

Convert from screen coords to world coords on the near frustum plane.

ParameterTypeDescription
screenVector2—
Returns:Vector3—

public void UpdateSceneCamera(Sandbox.SceneCamera camera, bool includeTags = True)PUBLICPER-FRAME

ParameterTypeDescription
cameraSceneCamera—
includeTags = Truebool—
Returns:void—

Properties29

Showing 29 properties

public Color Sandbox.CameraComponent.BackgroundColor { get; set; }PUBLICGETSET

The background color of this camera's view if there's no 2D Sky in the scene.

Returns:Color—

public System.Nullable`1<Matrix> Sandbox.CameraComponent.CustomProjectionMatrix { get; set; }PUBLICGETSET

Allows specifying a custom projection matrix for this camera

Returns:Nullable<Matrix>—

public System.Nullable`1<Vector2> Sandbox.CameraComponent.CustomSize { get; set; }PUBLICGETSET

Allows specifying a custom aspect ratio for this camera. By default (or when null) the camera size is screen size or render target size.

Returns:Nullable<Vector2>—

public bool Sandbox.CameraComponent.EnablePostProcessing { get; set; }PUBLICGETSET

Enable or disable post processing for this camera.

Returns:bool—

public float Sandbox.CameraComponent.FieldOfView { get; set; }PUBLICGETSET

The field of view of this camera.

Returns:float—

public Sandbox.Rendering.HudPainter Sandbox.CameraComponent.Hud { get; set; }PUBLICGETSETOBSOLETE

Allows drawing on the camera after post processing.

Obsolete: Use BeginHud() instead. Dispose the painter to submit its drawing.

Returns:HudPainter—

public Sandbox.Rendering.CommandList Sandbox.CameraComponent.HudCommandList { get; set; }PUBLICGETSET

Commands drawn after post processing. Reset at the start of each frame.

Returns:CommandList—

public bool Sandbox.CameraComponent.IsMainCamera { get; set; }PUBLICGETSET

Returns true if this is the main game camera.

Returns:bool—

public bool Sandbox.CameraComponent.Orthographic { get; set; }PUBLICGETSET

Whether or not to use orthographic projection instead of perspective.

Returns:bool—

public float Sandbox.CameraComponent.OrthographicHeight { get; set; }PUBLICGETSET

The orthographic size for this camera while `Sandbox.CameraComponent.Orthographic` is set to true.

Returns:float—

public Sandbox.Rendering.HudPainter Sandbox.CameraComponent.Overlay { get; set; }PUBLICGETSETOBSOLETE

Used to draw to the screen. This is drawn on top of everything, so is good for debug overlays etc.

Obsolete: Use BeginOverlay() instead. Dispose the painter to submit its drawing.

Returns:HudPainter—

public Sandbox.Rendering.CommandList Sandbox.CameraComponent.OverlayCommandList { get; set; }PUBLICGETSET

Commands drawn after UI. Reset at the start of each frame.

Returns:CommandList—

public Sandbox.GameObject Sandbox.CameraComponent.PostProcessAnchor { get; set; }PUBLICGETSET

If set then we'll trigger post process volumes from this position, instead of the camera's position.

Returns:GameObject—

public int Sandbox.CameraComponent.Priority { get; set; }PUBLICGETSET

The priority of this camera. Dictates which camera gets rendered on top of another. Higher means it'll be rendered on top.

Returns:int—

public Sandbox.TagSet Sandbox.CameraComponent.RenderExcludeTags { get; set; }PUBLICGETSET

A list of tags that will be checked to exclude specific game objects when rendering this camera.

Returns:TagSet—

public Sandbox.TagSet Sandbox.CameraComponent.RenderTags { get; set; }PUBLICGETSET

A list of tags that will be checked to include specific game objects when rendering this camera. If none are set, it will include everything.

Returns:TagSet—

public Sandbox.Rect Sandbox.CameraComponent.ScreenRect { get; set; }PUBLICGETSET

The size of the viewport, in screen coordinates

Returns:Rect—

public Sandbox.StereoTargetEye Sandbox.CameraComponent.TargetEye { get; set; }PUBLICGETSET

The HMD eye that this camera is targeting. Use `Sandbox.StereoTargetEye.None` for the user's monitor (i.e. the companion window).

Returns:StereoTargetEye—

public Sandbox.CameraView Sandbox.CameraComponent.View { get; set; }PUBLICGETSET

The view this camera composed this frame - the base transform reshaped by every `Sandbox.ICameraModifier`, before transient render effects. Query `Sandbox.CameraView.FieldOfView` from here for zoom-aware logic like scaling look sensitivity while scoped. Final from the camera stage of the tick (after Update, before PreRender) - reading it during Update gives the previous frame's composition.

Returns:CameraView—

public Vector4 Sandbox.CameraComponent.Viewport { get; set; }PUBLICGETSET

The size of the camera represented on the screen. Normalized between 0 and 1.

Returns:Vector4—

public bool Sandbox.CameraComponent.WireframeMode { get; set; }PUBLICGETSET

Render this camera using a wireframe view.

Returns:bool—

public float Sandbox.CameraComponent.ZFar { get; set; }PUBLICGETSET

The camera's far clip plane distance. This is the furthest distance this camera will be able to render. This value totally depends on the game you're making. Shorter the better, sensible ranges would be between about 1000 and 30000, but if you want it to be further out you can balance that out by making ZNear larger.

Returns:float—

public float Sandbox.CameraComponent.ZNear { get; set; }PUBLICGETSET

The camera's near clip plane distance. This is the closest distance this camera will be able to render. A good value for this is about 5. Below 5 and particularly below 1 you're going to start to see a lot of artifacts like z-fighting.

Returns:float—

On this page

Constructorspublic CameraComponent()Methodspublic System.Void AddCommandList(Sandbox.Rendering.CommandList buffer, Sandbox.Rendering.Stage stage, System.Int32 order = 0)public T AddEffect(T effect)public System.IDisposable AddHookAfterOpaque(System.String debugName, System.Int32 order, System.Action`1<Sandbox.SceneCamera> renderEffect)public System.IDisposable AddHookAfterTransparent(System.String debugName, System.Int32 order, System.Action`1<Sandbox.SceneCamera> renderEffect)public System.IDisposable AddHookAfterUI(System.String debugName, System.Int32 order, System.Action`1<Sandbox.SceneCamera> renderEffect)public System.IDisposable AddHookBeforeOverlay(System.String debugName, System.Int32 order, System.Action`1<Sandbox.SceneCamera> renderEffect)public Sandbox.CameraEffectSystem.BaseEffect AddPunch(Angles angles, System.Single frequency = 1, System.Single duration = 0.3, System.Single fovAmplitude = 0)public Sandbox.CameraEffectSystem.BaseEffect AddPunch(Vector3 direction, System.Single amplitude, System.Single frequency = 1, System.Single duration = 0.3, System.Single fovAmplitude = 0)public Sandbox.CameraEffectSystem.BaseEffect AddShake(System.Single amplitude, System.Single frequency, System.Single duration)public Sandbox.CameraEffectSystem.BaseEffect AddTilt(Angles angle, System.Single duration, System.Single easeTime = 0.2)public Sandbox.Rect BBoxToScreenPixels(BBox bounds, System.Boolean isBehind)public Sandbox.Painter BeginHud()public Sandbox.Painter BeginOverlay()public Matrix CalculateObliqueMatrix(Sandbox.Plane clipPlane)public System.Void ClearCommandLists()public System.Void ClearCommandLists(Sandbox.Rendering.Stage stage)public System.Void ComposeView()public Sandbox.Frustum GetFrustum()public Sandbox.Frustum GetFrustum(Sandbox.Rect screenRect, Vector3 screenSize)public Sandbox.Frustum GetFrustum(Sandbox.Rect screenRect)public Vector2 PointToScreenNormal(Vector3 worldPosition, System.Boolean isBehind)public Vector2 PointToScreenNormal(Vector3 worldPosition)public Vector2 PointToScreenPixels(Vector3 worldPosition, System.Boolean isBehind)public Vector2 PointToScreenPixels(Vector3 worldPosition)public System.Void RemoveCommandList(Sandbox.Rendering.CommandList buffer, Sandbox.Rendering.Stage stage)public System.Void RemoveCommandList(Sandbox.Rendering.CommandList buffer)public System.Void RenderToBitmap(Sandbox.Bitmap targetBitmap, System.Boolean renderUI)public System.Void RenderToBitmap(Sandbox.Bitmap targetBitmap)public System.Boolean RenderToTexture(Sandbox.Texture target, Sandbox.Rendering.ViewSetup config = null)public System.Boolean RenderToTexture(Sandbox.Texture target, Sandbox.Texture depthTarget, Sandbox.Rendering.ViewSetup config)public virtual System.Void Reset()public Ray ScreenNormalToRay(Vector3 normalPosition)public Ray ScreenPixelToRay(Vector2 pixelPosition)public Vector3 ScreenToWorld(Vector2 screen)public System.Void UpdateSceneCamera(Sandbox.SceneCamera camera, System.Boolean includeTags = True)Propertiespublic Sandbox.CameraComponent.AutoExposureSetup Sandbox.CameraComponent.AutoExposure { get; set; }public Color Sandbox.CameraComponent.BackgroundColor { get; set; }public Sandbox.ClearFlags Sandbox.CameraComponent.ClearFlags { get; set; }public System.Nullable`1<Matrix> Sandbox.CameraComponent.CustomProjectionMatrix { get; set; }public System.Nullable`1<Vector2> Sandbox.CameraComponent.CustomSize { get; set; }public Sandbox.SceneCameraDebugMode Sandbox.CameraComponent.DebugMode { get; set; }public System.Boolean Sandbox.CameraComponent.EnablePostProcessing { get; set; }public System.Single Sandbox.CameraComponent.FieldOfView { get; set; }public Sandbox.CameraComponent.Axis Sandbox.CameraComponent.FovAxis { get; set; }public Sandbox.Rendering.HudPainter Sandbox.CameraComponent.Hud { get; set; }public Sandbox.Rendering.CommandList Sandbox.CameraComponent.HudCommandList { get; set; }public System.Boolean Sandbox.CameraComponent.IsMainCamera { get; set; }public System.Boolean Sandbox.CameraComponent.Orthographic { get; set; }public System.Single Sandbox.CameraComponent.OrthographicHeight { get; set; }public Sandbox.Rendering.HudPainter Sandbox.CameraComponent.Overlay { get; set; }public Sandbox.Rendering.CommandList Sandbox.CameraComponent.OverlayCommandList { get; set; }public Sandbox.GameObject Sandbox.CameraComponent.PostProcessAnchor { get; set; }public System.Int32 Sandbox.CameraComponent.Priority { get; set; }public Matrix Sandbox.CameraComponent.ProjectionMatrix { get; set; }public Sandbox.TagSet Sandbox.CameraComponent.RenderExcludeTags { get; set; }public Sandbox.TagSet Sandbox.CameraComponent.RenderTags { get; set; }public Sandbox.Texture Sandbox.CameraComponent.RenderTarget { get; set; }public Sandbox.Rect Sandbox.CameraComponent.ScreenRect { get; set; }public Sandbox.StereoTargetEye Sandbox.CameraComponent.TargetEye { get; set; }public Sandbox.CameraView Sandbox.CameraComponent.View { get; set; }public Vector4 Sandbox.CameraComponent.Viewport { get; set; }public System.Boolean Sandbox.CameraComponent.WireframeMode { get; set; }public System.Single Sandbox.CameraComponent.ZFar { get; set; }public System.Single Sandbox.CameraComponent.ZNear { get; set; }Metadata