Class CameraUtil
Provides camera-related utility methods including FOV conversion, visibility queries, frustum calculations, allocation-free viewport helpers, depth linearization, render pipeline detection, factory methods for common camera archetypes, and pipeline-agnostic camera configuration (URP/HDRP/Built-in).
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public static class CameraUtil
Remarks
The active pipeline is detected at runtime via GetActiveRenderPipeline(), and
pipeline-specific settings are applied through reflection (see RenderPipelineInterop),
so this assembly references no URP or HDRP type and a single build works under URP, HDRP,
and the Built-in pipeline. When the active pipeline does not support a requested operation,
the method logs a warning via Log.Warning and takes no further action, so calling
code does not need to check the pipeline type itself before calling these utilities.
Camera factory methods (CreateGameplayCamera(string, LayerMask), CreateUIOverlayCamera(string, int), CreateRenderTextureCamera(string, RenderTexture, LayerMask), CreateMinimapCamera(string, Transform, float)) each create a new UnityEngine.GameObject with a UnityEngine.Camera component and immediately apply pipeline-specific defaults. The returned camera is unparented (except for CreateMinimapCamera(string, Transform, float), which is parented to a follow target) and must be positioned and managed by the caller.
Buffer-filling helpers such as GetFrustumPlanes(Camera, Plane[]) and GetFrustumCorners(Camera, float, Vector3[]) accept pre-allocated arrays so they can be called every frame without triggering garbage collection.
Methods
AddCameraToStack(Camera, Camera)
Adds an overlay camera to a URP base camera's rendering stack so that the overlay is composited on top of the base camera's output each frame.
Declaration
public static void AddCameraToStack(Camera baseCamera, Camera overlayCamera)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | baseCamera | The URP base camera whose stack should receive the overlay. Must be configured as
a |
| Camera | overlayCamera | The URP overlay camera to add to the stack. Must be configured as a
|
Remarks
This operation is specific to URP. On HDRP and the Built-in pipeline, a warning is logged and no changes are made - those pipelines do not use a camera stack in the same sense.
Both cameras are validated before the overlay is added:
-
baseCameramust have its URP render type set toCameraRenderType.Base; otherwise an error is logged and the method returns. -
overlayCameramust have its URP render type set toCameraRenderType.Overlay; otherwise an error is logged and the method returns.
If the overlay is already present in the stack, it is not added a second time.
ConfigureAntiAliasing(Camera, ScyllaAAMode, ScyllaAAQuality)
Configures the anti-aliasing mode and quality on a camera using pipeline-agnostic Scylla enums, translating to the appropriate URP or HDRP settings automatically.
Declaration
public static void ConfigureAntiAliasing(Camera camera, ScyllaAAMode mode, ScyllaAAQuality quality)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to configure. Must not be |
| ScyllaAAMode | mode | The ScyllaAAMode to apply to the camera. |
| ScyllaAAQuality | quality | The ScyllaAAQuality level for the chosen mode. |
Remarks
On URP, ScyllaAAMode is mapped to
UnityEngine.Rendering.Universal.AntialiasingMode and
ScyllaAAQuality to AntialiasingQuality.
On HDRP, ScyllaAAMode is mapped to
HDAdditionalCameraData.AntialiasingMode. Quality is applied only to the
selected mode: TAA maps to TAAQualityLevel, SMAA maps to
SMAAQualityLevel. FXAA and None ignore the quality parameter
on HDRP. An HDAdditionalCameraData component is added if not already present.
On the Built-in Render Pipeline, per-camera AA configuration is not available. A warning is logged and no changes are made.
CreateBasicCamera(string)
Creates a new UnityEngine.GameObject with a bare UnityEngine.Camera component and
returns it. No AudioListener is added.
Declaration
public static Camera CreateBasicCamera(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name assigned to the new camera UnityEngine.GameObject. |
Returns
| Type | Description |
|---|---|
| Camera | The UnityEngine.Camera component on the newly created object. |
Remarks
This factory is deliberately neutral and render-pipeline agnostic: it forces no projection, clear flags, HDR, post-processing, or anti-aliasing settings. The caller configures the camera as needed. Use this for dedicated secondary cameras (for example a demo's own render camera) rather than the scene's main camera (see EnsureMainCamera(string)), so camera creation stays centralized instead of hand-rolling a UnityEngine.GameObject with a UnityEngine.Camera component.
CreateGameplayCamera(string, LayerMask)
Creates a new UnityEngine.GameObject containing a fully configured main gameplay
camera with an AudioListener, HDR rendering, post-processing, and TAA
anti-aliasing enabled, with pipeline-specific defaults applied automatically.
Declaration
public static Camera CreateGameplayCamera(string name, LayerMask cullingMask)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to assign to the new camera UnityEngine.GameObject. |
| LayerMask | cullingMask | The layer mask controlling which layers this camera renders. Use
|
Returns
| Type | Description |
|---|---|
| Camera | The configured UnityEngine.Camera component on the newly created object. |
Remarks
Base camera defaults applied to all pipelines:
- Clear flags:
Skybox - Depth:
0(renders before overlay cameras) - Near clip:
0.01, far clip:1000 - Field of view:
60° - HDR: enabled; MSAA: disabled
URP-specific defaults: render type Base, post-processing on, TAA at High
quality, volume layer mask Default, shadows on, dithering on.
HDRP-specific defaults: clear mode Sky, TAA at High quality, volume mask
Default.
The returned camera is unparented. The caller is responsible for positioning it and optionally reparenting it within the scene hierarchy.
CreateMinimapCamera(string, Transform, float)
Creates a new orthographic top-down camera suitable for minimap rendering, parented to a follow target and oriented to look straight down.
Declaration
public static Camera CreateMinimapCamera(string name, Transform followTarget, float orthographicSize)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to assign to the new camera UnityEngine.GameObject. |
| Transform | followTarget | The UnityEngine.Transform to parent the camera to. The camera will share the target's position (plus a 100-unit vertical offset) and track it automatically. |
| float | orthographicSize | The orthographic half-height in world units. The visible vertical extent of the
minimap view equals |
Returns
| Type | Description |
|---|---|
| Camera | The configured UnityEngine.Camera component on the newly created object. |
Remarks
The camera is parented to followTarget at a local offset of
(0, 100, 0) and rotated 90° around the X axis so that it looks
straight down. This means the camera moves with the follow target automatically
and the tracked area always stays centered on the target.
Base camera defaults:
- Projection: orthographic
- Orthographic size:
orthographicSize(half the visible height in world units) - Clear flags:
SolidColorwith black background - Depth:
10(renders on top of main cameras) - Near clip:
0.1, far clip:500 - HDR: disabled; MSAA: disabled
On URP, render type is Base, post-processing and shadows are off.
On HDRP, clear color mode is Color.
No AudioListener is added. The minimap camera typically renders to a
UnityEngine.RenderTexture that is then displayed in a UI image element.
CreateRenderTextureCamera(string, RenderTexture, LayerMask)
Creates a new UnityEngine.GameObject containing a camera pre-configured to render directly into the provided UnityEngine.RenderTexture target.
Declaration
public static Camera CreateRenderTextureCamera(string name, RenderTexture target, LayerMask cullingMask)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to assign to the new camera UnityEngine.GameObject. |
| RenderTexture | target | The UnityEngine.RenderTexture this camera will render into. Must not be
|
| LayerMask | cullingMask | The layer mask controlling which layers this camera renders. |
Returns
| Type | Description |
|---|---|
| Camera | The configured UnityEngine.Camera component on the newly created object. |
Remarks
Base camera defaults:
- Clear flags:
SolidColorwith transparent background - Depth:
-1(renders before main cameras) - Near clip:
0.1, far clip:1000 - Field of view:
60° - HDR: enabled; MSAA: disabled
- Target texture:
target
On URP, render type is Base, post-processing is off, shadows are on.
On HDRP, clear color mode is Color.
No AudioListener is added. The returned camera is unparented. The caller
is responsible for positioning the camera and managing the lifetime of
target.
CreateUIOverlayCamera(string, int)
Creates a new UnityEngine.GameObject containing a UI overlay camera configured to
render only the UI layer, clearing depth only so it composites on top of any
base camera below it.
Declaration
public static Camera CreateUIOverlayCamera(string name, int depth)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to assign to the new camera UnityEngine.GameObject. |
| int | depth | Camera depth value that controls render order; cameras with higher depth values render on top of those with lower values (Built-in pipeline). On URP the render order is determined by the base camera's stack order instead. |
Returns
| Type | Description |
|---|---|
| Camera | The configured UnityEngine.Camera component on the newly created object. |
Remarks
Base camera defaults:
- Clear flags:
Depth(color from lower cameras is preserved) - Culling mask:
UIlayer only - Near clip:
0.1, far clip:100 - HDR: disabled; MSAA: disabled
On URP, clear flags are overridden to Nothing (full transparent overlay) and
the render type is set to Overlay. The camera must be added to a Base
camera's stack via AddCameraToStack(Camera, Camera) to be rendered.
On HDRP, clear color mode is set to None.
No AudioListener is added. The returned camera is unparented.
EnsureMainCamera(string)
Returns the current UnityEngine.Camera.main, or creates a minimal one if the scene
has no main camera. A newly created camera gets a UnityEngine.Camera and an
AudioListener and is tagged MainCamera.
Declaration
public static Camera EnsureMainCamera(string name = "Main Camera")
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name assigned to the camera UnityEngine.GameObject when one is created. |
Returns
| Type | Description |
|---|---|
| Camera | The existing or newly created main UnityEngine.Camera. |
Remarks
This factory is deliberately neutral and render-pipeline agnostic: it forces no projection, clear flags, HDR, post-processing, or anti-aliasing settings. The caller configures those on the returned camera as needed (for example via SetPostProcessingEnabled(Camera, bool) and ConfigureAntiAliasing(Camera, ScyllaAAMode, ScyllaAAQuality)). Use this instead of hand-rolling a UnityEngine.GameObject with a UnityEngine.Camera component so camera creation stays centralized.
FOVToFocalLength(float, float)
Converts a vertical field of view angle to the equivalent cinematic focal length for a given sensor height.
Declaration
public static float FOVToFocalLength(float verticalFOV, float sensorHeight = 24)
Parameters
| Type | Name | Description |
|---|---|---|
| float | verticalFOV | Vertical FOV in degrees to convert. |
| float | sensorHeight | Film/sensor gate height in millimeters. Defaults to |
Returns
| Type | Description |
|---|---|
| float | The focal length in millimeters corresponding to the specified FOV and sensor. |
Remarks
The formula is focalLength = sensorHeight / (2 * tan(verticalFOV / 2)),
which is the standard thin-lens relationship used in cinematography. The result
is expressed in the same unit as sensorHeight (millimeters by
default). Use this when bridging Unity's FOV-based camera with tools that describe
lenses in focal lengths.
FocalLengthToFOV(float, float)
Converts a cinematic focal length to the equivalent vertical field of view angle for a given sensor height.
Declaration
public static float FocalLengthToFOV(float focalLength, float sensorHeight = 24)
Parameters
| Type | Name | Description |
|---|---|---|
| float | focalLength | Focal length in millimeters. Must be greater than zero. |
| float | sensorHeight | Film/sensor gate height in millimeters. Defaults to |
Returns
| Type | Description |
|---|---|
| float | The vertical FOV in degrees, suitable for assigning to UnityEngine.Camera.fieldOfView. |
Remarks
The inverse of FOVToFocalLength(float, float). The formula is
verticalFOV = 2 * atan(sensorHeight / (2 * focalLength)).
Use this when importing camera settings described in millimeter focal lengths
(e.g. from a visual effects pipeline or a real-world lens spec) and applying them
to Unity's UnityEngine.Camera.fieldOfView.
GetActiveRenderPipeline()
Detects and returns the render pipeline currently active in the project by inspecting UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline at runtime.
Declaration
public static ScyllaRenderPipeline GetActiveRenderPipeline()
Returns
| Type | Description |
|---|---|
| ScyllaRenderPipeline | The ScyllaRenderPipeline value corresponding to the currently active pipeline. Returns BuiltIn both when no SRP asset is assigned and as a fallback for unrecognized SRP assets. |
Remarks
Detection is performed by inspecting the type of the active RenderPipelineAsset,
walking its base-type chain so that a project-specific subclass (e.g. a custom asset
deriving from UniversalRenderPipelineAsset) is still recognized rather than
misdetected as Built-in:
nullasset -> BuiltIn- Asset type or an ancestor named "Universal..." -> URP
- Asset type or an ancestor named "HDRenderPipeline..." -> HDRP
- Any other SRP asset -> BuiltIn (fallback)
This method walks a short type chain on each call. If you need the pipeline type frequently, cache the result rather than querying every frame.
GetFOVToFrameBounds(Bounds, Vector3, float)
Computes the minimum vertical FOV required to fully frame a world-space bounding box as seen from a given camera position, taking both the horizontal and vertical angular extents into account.
Declaration
public static float GetFOVToFrameBounds(Bounds bounds, Vector3 cameraPosition, float aspectRatio)
Parameters
| Type | Name | Description |
|---|---|---|
| Bounds | bounds | The world-space axis-aligned bounding box to frame. |
| Vector3 | cameraPosition | The world-space position from which the camera is viewing. |
| float | aspectRatio | The camera's aspect ratio expressed as |
Returns
| Type | Description |
|---|---|
| float | The vertical FOV in degrees that is the minimum angle needed for the entire
|
Remarks
The method constructs a view-space coordinate system aligned with the vector from
cameraPosition to the bounds center, then projects all eight AABB
corners onto the view-space up and right axes. The largest vertical and horizontal
half-angles are found, and the required vertical FOV is the greater of: (a) the
direct vertical angular extent, or (b) the horizontal angular extent converted to
vertical via the aspect ratio. This ensures the entire bounds fits within the frame
regardless of orientation.
Returns 179° in two degenerate cases: if cameraPosition
is within 1 mm of the bounds center (distance near zero), or if any corner projects
behind the camera (depth < 0.001).
Typical usage: animate UnityEngine.Camera.fieldOfView toward the returned value to implement a smooth zoom-to-fit or multi-target framing effect.
GetFrustumCorners(Camera, float, Vector3[])
Computes the four world-space corners of the camera's view frustum cross-section at a given distance along the camera's forward axis, filling a caller-supplied buffer without allocating.
Declaration
public static void GetFrustumCorners(Camera camera, float distance, Vector3[] corners)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera defining the projection and transform. |
| float | distance | Distance from the camera's position along its local forward axis at which the cross-section corners are evaluated. For perspective cameras a larger distance produces a larger rectangle; for orthographic cameras the size is constant. |
| Vector3[] | corners | A pre-allocated
|
Remarks
For perspective cameras, the half-extents at the specified depth are computed from
the vertical FOV using tan(fieldOfView / 2) * distance. For orthographic
cameras, UnityEngine.Camera.orthographicSize is used directly and the result is
independent of distance.
Typical uses include constructing shadow caster volumes, building geometry that fills the screen at a known depth, or visualizing the frustum cross-section in a scene gizmo.
GetFrustumPlanes(Camera, Plane[])
Fills a caller-supplied 6-element buffer with the camera's current frustum planes,
avoiding the heap allocation that the standard
GeometryUtility.CalculateFrustumPlanes(Camera) overload incurs.
Declaration
public static void GetFrustumPlanes(Camera camera, Plane[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera whose view-projection matrix defines the frustum. |
| Plane[] | buffer | A pre-allocated |
Remarks
Allocate the buffer once (e.g. as a field) and pass it here each frame before calling IsBoundsVisible(Bounds, Plane[]). Plane order follows the Unity convention: [0] left, [1] right, [2] bottom, [3] top, [4] near, [5] far.
GetScreenSpaceBounds(Camera, Bounds)
Projects all eight corners of a world-space axis-aligned bounding box through the camera and returns the screen-pixel rectangle that encloses the entire projection.
Declaration
public static Rect GetScreenSpaceBounds(Camera camera, Bounds worldBounds)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to project through. |
| Bounds | worldBounds | The world-space axis-aligned bounding box to project. |
Returns
| Type | Description |
|---|---|
| Rect | A UnityEngine.Rect in screen pixels (origin at bottom-left, matching Unity's screen-space convention) that encloses the visible projection of the bounds. |
Remarks
All eight corners of the AABB are projected via Camera.WorldToScreenPoint.
Corners whose projected z-coordinate is negative (behind the camera) are skipped to
avoid inverting the bounding rectangle. The result is the smallest axis-aligned
screen-space rectangle that contains all visible projected corners.
Typical uses include positioning world-space health bars, constructing 2D selection highlights around 3D objects, and culling UI elements whose target objects are off-screen.
Note: if every corner is behind the camera the returned rect will have
float.MaxValue as its position and float.MinValue-derived dimensions
(i.e. negative size), which is effectively an invalid rect. Callers should guard
against this case by checking IsPointVisible(Camera, Vector3) or
IsBoundsVisible(Bounds, Plane[]) first.
GetVisibleWorldSize(Camera, float)
Returns the width and height of the visible world area at a given distance from the camera, in world units.
Declaration
public static Vector2 GetVisibleWorldSize(Camera camera, float distance)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera defining the projection and aspect ratio. |
| float | distance | Distance from the camera's position along its forward axis. Only affects the result for perspective cameras; ignored for orthographic cameras. |
Returns
| Type | Description |
|---|---|
| Vector2 | A UnityEngine.Vector2 where |
Remarks
For perspective cameras the visible area grows linearly with depth:
height = 2 * distance * tan(fieldOfView / 2),
width = height * aspect.
For orthographic cameras the area is constant regardless of
distance: height = orthographicSize * 2.
Typical uses include scaling world-space UI elements so they always fill a fixed proportion of the screen, or determining how much world content is visible at a specific depth.
HorizontalToVerticalFOV(float, float)
Converts a horizontal field of view angle to the equivalent vertical field of view for a given aspect ratio.
Declaration
public static float HorizontalToVerticalFOV(float horizontalFOV, float aspectRatio)
Parameters
| Type | Name | Description |
|---|---|---|
| float | horizontalFOV | Horizontal FOV in degrees to convert. |
| float | aspectRatio | The camera's aspect ratio expressed as |
Returns
| Type | Description |
|---|---|
| float | The equivalent vertical FOV in degrees, suitable for assigning to UnityEngine.Camera.fieldOfView. |
Remarks
The inverse of VerticalToHorizontalFOV(float, float). Use this when a desired horizontal framing angle is known (e.g. from a design document or cinematic spec) and needs to be applied to Unity's UnityEngine.Camera.fieldOfView, which expects the vertical angle.
IsBoundsVisible(Bounds, Plane[])
Tests whether a world-space axis-aligned bounding box intersects or lies inside the camera frustum described by the provided frustum planes.
Declaration
public static bool IsBoundsVisible(Bounds bounds, Plane[] frustumPlanes)
Parameters
| Type | Name | Description |
|---|---|---|
| Bounds | bounds | The world-space axis-aligned bounding box to test. |
| Plane[] | frustumPlanes | A 6-element |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This is a thin wrapper over GeometryUtility.TestPlanesAABB. The significant
benefit of using this method together with GetFrustumPlanes(Camera, Plane[]) is that
the frustum planes can be computed once per frame and reused across many bounds
tests, avoiding repeated calls to GeometryUtility.CalculateFrustumPlanes(Camera)
which allocates a new Plane[6] array on every invocation.
IsHDRPActive()
Determines whether the High Definition Render Pipeline (HDRP) is currently active. Convenience wrapper around GetActiveRenderPipeline().
Declaration
public static bool IsHDRPActive()
Returns
| Type | Description |
|---|---|
| bool |
|
IsPointVisible(Camera, Vector3)
Determines whether a world-space point falls within the camera's viewport and between its near and far clip planes.
Declaration
public static bool IsPointVisible(Camera camera, Vector3 worldPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera whose frustum defines the visibility region. |
| Vector3 | worldPoint | The world-space position to test. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Camera.WorldToViewportPoint alone is insufficient for a correct visibility test
because it returns viewport coordinates that appear within the [0, 1] range even for
points that are behind the camera (the z component goes negative in that case). This
method explicitly guards against the behind-camera case by checking
viewportPoint.z > 0 before testing the x/y bounds.
This test does not account for scene occlusion - a point that passes the frustum test may still be obscured by geometry. For occlusion queries, use IsBoundsVisible(Bounds, Plane[]) with a physics overlap check, or a GPU occlusion query approach.
IsURPActive()
Determines whether the Universal Render Pipeline (URP) is currently active. Convenience wrapper around GetActiveRenderPipeline().
Declaration
public static bool IsURPActive()
Returns
| Type | Description |
|---|---|
| bool |
|
LinearizeDepth(float, float, float)
Converts a non-linear (hyperbolic) depth buffer value to linear world-space depth using the camera's near and far clip plane distances.
Declaration
public static float LinearizeDepth(float rawDepth, float nearClip, float farClip)
Parameters
| Type | Name | Description |
|---|---|---|
| float | rawDepth | The non-linear depth sample read from the depth buffer, in the [0, 1] range.
Assumes standard depth convention (0 = near, 1 = far). Pass
|
| float | nearClip | The camera's near clip plane distance in world units.
Must be positive and less than |
| float | farClip | The camera's far clip plane distance in world units.
Must be greater than |
Returns
| Type | Description |
|---|---|
| float | The linearized depth in world units, ranging from |
Remarks
Perspective projection maps world depth non-linearly into the [0, 1] depth buffer
range. The relationship is:
linearDepth = (near * far) / (far - rawDepth * (far - near)).
This method assumes the standard (non-reversed) depth convention where 0
maps to the near plane and 1 maps to the far plane. Most modern GPU
platforms and Unity's URP/HDRP use reversed-Z by default (near = 1, far = 0) to
improve floating-point precision. When reading from a reversed-Z depth buffer,
pass 1.0f - rawDepth as the rawDepth argument.
Use UnityEngine.Camera.nearClipPlane and UnityEngine.Camera.farClipPlane to obtain the required clip distances from a camera.
RemoveCameraFromStack(Camera, Camera)
Removes an overlay camera from a URP base camera's rendering stack.
Declaration
public static void RemoveCameraFromStack(Camera baseCamera, Camera overlayCamera)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | baseCamera | The URP base camera whose stack should be modified. Must be configured as a
|
| Camera | overlayCamera | The overlay camera to remove. If not currently in the stack, the call is a no-op. |
Remarks
This operation is specific to URP. On HDRP and the Built-in pipeline, a warning is
logged and no changes are made. If baseCamera is not a URP Base
camera, an error is logged and the method returns without modifying the stack.
If overlayCamera is not present in the stack, the call is a no-op.
RenderCameraToTexture(Camera, int, int, TextureFormat)
Synchronously renders the camera's view into a new UnityEngine.Texture2D and returns it. Suitable for screenshots, preview thumbnails, and offline image capture.
Declaration
public static Texture2D RenderCameraToTexture(Camera camera, int width, int height, TextureFormat format = TextureFormat.RGB24)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to render from. Must not be |
| int | width | Width of the output texture in pixels. Must be greater than zero. |
| int | height | Height of the output texture in pixels. Must be greater than zero. |
| TextureFormat | format | The UnityEngine.TextureFormat for the resulting texture. Defaults to UnityEngine.TextureFormat.RGB24. Use UnityEngine.TextureFormat.RGBA32 if alpha channel data is required. |
Returns
| Type | Description |
|---|---|
| Texture2D | A new UnityEngine.Texture2D of the specified dimensions containing the rendered image. The caller owns this object and must destroy it when done. |
Remarks
The method acquires a temporary UnityEngine.RenderTexture from the pool (via
RenderTexture.GetTemporary), sets it as the camera's render target, calls
Camera.Render() immediately, reads the pixels back to CPU memory, then
restores both the camera's previous render target and the previous active
UnityEngine.RenderTexture before releasing the temporary texture.
This is a blocking GPU readback operation. For large textures or high frame-rate
scenarios, consider using AsyncGPUReadback.Request to avoid stalling the
CPU while waiting for the GPU to finish rendering.
The caller is responsible for destroying the returned UnityEngine.Texture2D when it is no longer needed to avoid a memory leak.
SetBackgroundColor(Camera, Color)
Sets the background color on a camera, keeping both the base UnityEngine.Camera.backgroundColor and any pipeline-specific color data in sync.
Declaration
public static void SetBackgroundColor(Camera camera, Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to configure. Must not be |
| Color | color | The background color to apply. For best results in HDR pipelines, provide a
linear-space color; the HDRP path will apply it as-is to
|
Remarks
On all pipelines, UnityEngine.Camera.backgroundColor is set to
color directly. On HDRP, if the camera has an
HDAdditionalCameraData component, backgroundColorHDR is also set to
the linear-space equivalent of the color via Color.linear, which is required
for physically correct HDR sky/background blending.
The HDRP path applies its setting through reflection; intended for setup or infrequent changes, not per-frame use. Prefer a Volume-based background or a shader for a per-frame animated background color rather than calling this every frame.
SetPostProcessingEnabled(Camera, bool)
Enables or disables post-processing on a camera, using the appropriate pipeline API.
Declaration
public static void SetPostProcessingEnabled(Camera camera, bool enabled)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to configure. Must not be |
| bool | enabled |
|
Remarks
On URP, sets UniversalAdditionalCameraData.renderPostProcessing.
On HDRP, enables custom rendering settings and toggles
FrameSettingsField.Postprocess in the camera's custom frame settings. An
HDAdditionalCameraData component is added to the camera if not already present.
On the Built-in Render Pipeline, a warning is logged and no changes are made because
post-processing is controlled globally through the post-processing stack, not
per-camera.
Applies a pipeline setting through reflection (the HDRP path especially); intended for setup or infrequent toggles, not per-frame use. Do not call it every frame.
SetTemporalAASharpening(Camera, float)
Sets the Contrast Adaptive Sharpening (CAS) strength applied by Temporal Anti-Aliasing on a camera. Only meaningful when the camera's AA mode is TAA; other modes ignore the value.
Declaration
public static void SetTemporalAASharpening(Camera camera, float sharpening)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to configure. Must not be |
| float | sharpening | CAS strength in the 0 to 1 range; clamped. 0 disables sharpening, 1 is maximum. |
Remarks
On URP this writes UniversalAdditionalCameraData.taaSettings.contrastAdaptiveSharpening.
On HDRP, post-TAA sharpening is governed by the TAA quality preset rather than a
per-camera scalar, so this is a no-op. On the Built-in Render Pipeline a warning is logged.
Applies a pipeline setting through reflection; intended for setup or infrequent changes, not per-frame use. Do not drive it from a per-frame update or a continuously-dragged UI slider, which would allocate each call.
VerticalToHorizontalFOV(float, float)
Converts a vertical field of view angle to its equivalent horizontal field of view for a given aspect ratio.
Declaration
public static float VerticalToHorizontalFOV(float verticalFOV, float aspectRatio)
Parameters
| Type | Name | Description |
|---|---|---|
| float | verticalFOV | Vertical FOV in degrees. This is Unity's native camera FOV field. |
| float | aspectRatio | The camera's aspect ratio expressed as |
Returns
| Type | Description |
|---|---|
| float | The equivalent horizontal FOV in degrees. |
Remarks
Uses the standard perspective projection relationship:
horizontalFOV = 2 * atan(tan(verticalFOV / 2) * aspectRatio).
Unity's UnityEngine.Camera.fieldOfView is the vertical FOV, so this method is
useful when an API or UI needs to express or display the horizontal angle instead.