API reference
API reference
Select your platform
No SDKs available
No versions available

OVROverlay Class

Extends MonoBehaviour
Enables efficient rendering of UI elements and media as compositor layers that bypass Unity's rendering pipeline.
Overlays are rendered directly by the VR compositor at native display resolution for improved visual quality. Supports multiple shapes (quad, cylinder, equirect, cubemap), stereo textures, and advanced filtering options. Use for UI elements, HUD components, video playback, and content requiring maximum visual clarity. Works with OVRManager for VR runtime integration and OVRPlugin for native functionality.

Member Enumerations

Enumeration OverlayShape

Geometric shape and projection method for overlay rendering.
Platform support varies by shape. Defines rendering projections from flat quads to 360° environments. Used with currentOverlayShape property. Each shape interprets Transform components differently for positioning, rotation, and scaling. Supports standard surfaces (Quad, Cylinder), 360° content (Cubemap, Equirect), and mixed reality (Passthrough shapes).
Quad
Flat rectangular surface for UI panels and video content.
Cylinder
Cylindrical surface wrapping around user.
Cubemap
360° cube map using 6 faces.
OffcenterCubemap
Off-center cube map with custom positioning.
Equirect
Equirectangular projection for 360° content at infinite distance.
ScaledEquirect
Finite-distance equirectangular projection with depth positioning.
ReconstructionPassthrough
Passthrough overlay displaying real-world environment with reconstruction.
SurfaceProjectedPassthrough
Surface-projected passthrough mapping virtual content onto real surfaces.
Fisheye
Fisheye projection for wide field of view content.
KeyboardHandsPassthrough
Passthrough showing hands over keyboard for mixed reality typing.
KeyboardMaskedHandsPassthrough
Masked passthrough showing hands over keyboard with occlusion handling.

Enumeration OverlayType

Depth ordering and compositing behavior relative to main scene content.
Ordered by compositionDepth within each type. Controls whether overlay renders behind (Underlay), in front (Overlay), or disabled (None) relative to scene content.
None
Disables overlay rendering completely.
Underlay
Renders behind main scene content. Ideal for background environments and skyboxes.
Overlay
Renders in front of main scene content. Most common type for UI elements and HUD components.

Fields

Controls overlay depth ordering relative to scene content.
Combined with compositionDepth for final render order. Determines whether overlay renders behind, in front, or disabled relative to scene content. Underlay for backgrounds/skyboxes, Overlay for UI/HUD, None to disable rendering completely.
Controls whether texture content is updated every frame (dynamic) or once (static).
Dynamic mode enables video and animated UI but consumes more GPU resources.
Enables protected content rendering to prevent the overlay from appearing in screenshots, recordings, or screen captures.
When true, the layer uses HDCP (High-bandwidth Digital Content Protection) or similar mechanisms to protect copyrighted content. Use for DRM-protected media, copyrighted video content, or sensitive information. May have performance overhead and platform limitations.
Source rectangle for left eye in normalized coordinates (0,0) to (1,1).
For side-by-side stereo: use (0,0,0.5,1). For over-under: use (0,0.5,1,1).
Source rectangle for right eye in normalized coordinates (0,0) to (1,1).
For side-by-side stereo: use (0.5,0,0.5,1). For over-under: use (0,0,1,0.5).
Destination rectangle for left eye in normalized coordinates (0-1).
Requires overrideTextureRectMatrix enabled to take effect.
Destination rectangle for right eye in normalized coordinates (0-1).
Requires overrideTextureRectMatrix enabled to take effect.
Inverts texture coordinates vertically to support legacy content where the texture origin was at the top-left.
Modern VR systems typically use bottom-left as the texture origin, so this property provides backward compatibility. Enable when working with legacy textures or content that appears upside-down in the overlay.
Enables the use of custom source and destination rectangles instead of default full-texture mapping.
When true, the srcRectLeft, srcRectRight, destRectLeft, and destRectRight properties control texture sampling and positioning. Use for stereo layouts, texture atlasing, or custom viewport positioning.
Enables per-layer color adjustment by applying custom color scaling and offset transformations.
When true, allows fine-tuning the visual appearance of overlays without modifying source textures. Use colorScale and colorOffset to control the adjustments. Final color = (SourceColor * colorScale) + colorOffset. More efficient than CPU texture modifications.
RGBA color multiplier applied to the overlay when overridePerLayerColorScaleAndOffset is enabled.
Each component multiplies the corresponding channel in the source texture before colorOffset is applied. Default value (1,1,1,1) applies no scaling. Use for brightness adjustment, color tinting, or transparency fading.
RGBA color offset added to the overlay when overridePerLayerColorScaleAndOffset is enabled.
Each component is added to the corresponding channel after colorScale multiplication. Default value (0,0,0,0) applies no offset. Use for color tinting, brightness boost, or fade to color.
Enables expensive super sampling for maximum image quality.
WARNING: Performance-intensive feature that should only be used when you have sufficient GPU budget and require the highest possible visual quality. Not recommended for most applications. Consider useAutomaticFiltering instead, to achieve better quality filtering when performance headroom allows.
Enables expensive sharpening filter for enhanced edge clarity.
WARNING: Performance-intensive feature that should only be used when you have sufficient GPU budget and require the highest possible visual quality. Not recommended for most applications. Consider useAutomaticFiltering instead, to achieve better quality filtering when performance headroom allows.
Controls overlay visibility.
When true, the overlay is hidden from rendering. Use this property to dynamically show/hide overlays without disabling the component. This is useful when the overlay may be frequently hidden and shown, without the performance hit of full layer teardown and setup.
[Android Only] Enables external surface rendering for advanced video and media integration.
When true, creates an Android Surface object that can be used with MediaPlayer, Camera2 API, or other native Android media frameworks. Use for video playback, camera feeds, or streaming content. External surfaces provide optimal video performance by bypassing Unity's texture management.
[Android Only] Specifies the width in pixels for the external surface when isExternalSurface is enabled.
This dimension determines the resolution of the media content that can be rendered to the surface. Choose dimensions that match your media content resolution for optimal quality. Higher resolutions consume more GPU resources. Some image producers may override these dimensions to match source content size.
[Android Only] Specifies the height in pixels for the external surface when isExternalSurface is enabled.
This dimension determines the resolution of the media content that can be rendered to the surface. Ensure the width/height ratio matches your content's aspect ratio to prevent distortion. Use the lowest resolution that provides acceptable quality. Some image producers may override these dimensions to match source content size.
Controls depth ordering within the same OverlayType.
Lower values render first (behind).
Disables depth buffer-based compositing and forces overlay ordering based solely on compositionDepth and currentOverlayType.
When true, prevents the overlay from being occluded by scene geometry even when "Shared Depth Buffer" is enabled in the VR runtime. Enable for UI elements that should always be visible (HUD, menus). Disable for 3D UI that should interact with scene geometry.
Specifies the pixel format for the overlay layer's texture data.
Controls color depth, precision, and gamma correction behavior. Use sRGB for standard UI/video, floating point for HDR content, linear for custom color management. The system automatically detects HDR formats from texture types. Higher precision formats consume more memory and bandwidth.
Defines the geometric projection and rendering method for the overlay layer.
Each shape provides different ways to display content in 3D space, from flat panels to immersive 360-degree environments. Choose based on content type: Quad for UI/video, Cylinder for wrap-around content, Cubemap/Equirect for 360° content, Passthrough for mixed reality. Some shapes have platform limitations (Cylinder/OffcenterCubemap are mobile-only, Fisheye not supported on OpenXR).
Defines the texture content displayed by the overlay layer for left and right eyes respectively.
Array index 0 contains the left eye texture, index 1 contains the right eye texture. For mono content, only index 0 is used and the same texture is displayed to both eyes. Use Cubemap textures for Cubemap shapes, Texture2D/RenderTexture for others. For dynamic content, use OverrideOverlayTextureInfo() to avoid expensive native pointer lookups per frame.
Specifies whether the texture's alpha channel has been pre-multiplied with the RGB color channels.
This affects alpha blending behavior during overlay composition with scene content. In premultiplied alpha, RGB values are already multiplied by alpha (e.g., red pixel (1,0,0) with 50% alpha becomes (0.5,0,0,0.5)). Enable for modern rendering pipelines that use premultiplied alpha. Disable for standard "straight alpha" textures.
Enables bicubic texture filtering for higher quality image scaling at the cost of increased GPU processing.
Provides smoother visual results compared to standard bilinear filtering when textures are scaled up or down. Use for high-resolution UI elements, text overlays, or detailed images when you have sufficient GPU budget. Consider useAutomaticFiltering to let the runtime decide based on performance characteristics.
Enables legacy cubemap rotation behavior for backward compatibility.
DEPRECATED: This setting will be removed in future versions. Fix your cubemap textures instead of relying on this legacy behavior.
Enables efficient super sampling for improved visual quality with moderate performance impact.
This is a performance-optimized alternative to useExpensiveSuperSample that provides better quality with reasonable GPU cost. Super sampling renders content at higher resolution then downsamples for display, reducing aliasing. Use for text overlays, UI elements with fine details, or when visual quality is prioritized over performance. Cannot be used simultaneously with sharpening filters unless using useAutomaticFiltering.
Enables efficient sharpening filter to enhance edge clarity and text readability with moderate performance impact.
This is a performance-optimized alternative to useExpensiveSharpen that provides good quality enhancement with reasonable GPU cost. Sharpening enhances edge contrast to make content appear crisper. Use for text-heavy UI overlays, soft/blurry images, or content with fine details. Cannot be used simultaneously with super sampling unless using useAutomaticFiltering.
Enables intelligent filtering where the runtime automatically selects optimal image enhancement based on performance headroom and content.
Recommended for most applications.
The Surface object (Android only).
Will be triggered after externalSurfaceTextueObject get created.

Properties

[Editor Only] Enables preview visualization of the overlay in the Unity Scene view using a mesh renderer.
This helps with positioning and setup during development but has no effect at runtime. Creates a visual representation for positioning overlays, visualizing size/shape, and debugging placement. Only approximates VR appearance and may not represent all shapes accurately. No impact on runtime performance.
The unique identifier assigned by the VR compositor for this overlay layer.
This handle is used internally to reference the layer in all compositor operations and submissions. Set to 0 initially, positive values indicate active layer, reset to 0 when destroyed. Used for texture submission, property updates, and cleanup operations. Managed on main Unity thread only. A layerId of 0 indicates initialization failure or destroyed state.
Determines texture layout for the overlay layer based on configured textures.
Returns Stereo if separate left/right eye textures are provided on Android, otherwise Mono.
Index of this overlay instance within the global instances registry.
Used for layer composition ordering and efficient overlay management.
Indicates whether the overlay layer is currently visible and successfully submitted to the compositor.
Updated each frame during rendering to reflect the actual visibility state.This property is set to true when the overlay is successfully submitted to the VR compositor and not hidden via the hidden flag. Used to determine whether to disable the associated Renderer component for performance optimization.
See Also
TrySubmitLayer, hidden, rend
Returns the number of textures needed per stage based on the current layout configuration.
Returns 2 for stereo layout (separate left/right eye textures), 1 for mono layout (shared texture).Used to determine array sizes for texture management and processing loops. Stereo layout is only supported on Android platforms with separate eye textures.
static string OpenVROverlayKey[Get]

Protected Fields

IntPtr[] texturePtrs[Get]
Indicates whether a texture override operation is pending application.
Set to true when OverrideOverlayTextureInfo is called, reset after processing.
Array of texture structures for each eye/stage.
Single entry for mono, two entries for stereo rendering.
Layer descriptor containing the complete specification for the overlay layer as submitted to the compositor.
Defines all rendering parameters including format, size, layout, and feature flags.
Number of texture stages in the compositor swap chain for this overlay layer.
Typically 3 for triple buffering to prevent blocking during texture updates.
GC handle maintaining a pinned reference to the layerId for safe compositor access.
Prevents garbage collection from moving the layerId value while compositor holds a pointer to it.
Native pointer to the pinned layerId value for efficient compositor communication.
Allows VR runtime to directly access and modify the layer ID without managed/native transitions.
Current frame index used for swap chain stage selection and texture update timing.
Increments each frame for dynamic overlays to cycle through available texture stages.
Previous frame index used to detect when texture updates are needed and prevent duplicate processing.
Helps optimize rendering by avoiding redundant texture population within the same frame.
Reference to the Renderer component attached to this GameObject, if any.
Used for backward compatibility and automatic renderer visibility management.

Public Statics

Global registry of all active OVROverlay instances in the scene.
Used by the overlay system to manage layer indices, track overlay lifecycle, and optimize resource allocation. Provides automatic layer index assignment, efficient reuse of destroyed overlay slots, and proper cleanup coordination. Not thread-safe - use only on main Unity thread. Total overlay count can impact VR compositor performance.

Object Data for protected-static-attrib

Shared material used for blitting 2D textures to overlay swap chains.
Contains the shader and settings for efficient texture copying and format conversion.
Array of materials used for blitting individual cubemap faces to overlay swap chains.
Each material extracts and processes a specific face of the cubemap.

Member Functions

delegate void ExternalSurfaceObjectCreated ( )
Overrides the overlay texture information for dynamic texture updates at runtime.
Use this method to efficiently update overlay textures without triggering expensive native texture pointer lookups each frame. GetNativeTexturePtr() is expensive - pre-cache the pointer and use this method instead of directly assigning to textures array.
Parameters
srcTexture
The source texture to display in the overlay
nativePtr
Pre-cached native texture pointer obtained from GetNativeTexturePtr()
node
XR node specifying which eye (LeftEye=0, RightEye=1) to update
Configures texture mapping rectangles for stereo rendering by setting source and destination rectangles for both left and right eyes simultaneously.
Source rectangles define which portion of the input texture is sampled (normalized 0-1 coordinates). Destination rectangles define where the content appears in the final overlay rendering.
Parameters
srcLeft
Source rectangle for left eye texture sampling (normalized 0-1)
srcRight
Source rectangle for right eye texture sampling (normalized 0-1)
destLeft
Destination rectangle for left eye rendering (normalized 0-1)
destRight
Destination rectangle for right eye rendering (normalized 0-1)
Updates the internal texture rectangle matrix for advanced UV coordinate transformations.
Handles coordinate conversions for external surfaces, texture inversion, and fisheye projections. Converts source/destination rectangles into GPU-ready transformation matrices. External surfaces use inverted Y coordinates, fisheye applies -0.5 offset for centering. Populates textureRectMatrix with scale/bias values for compositor UV transformation.
Sets custom color scaling and offset values for the overlay layer and enables color adjustment.
This method provides a convenient way to apply color transformations without manually setting individual properties.Applies the provided scale and offset values. The final color is calculated as: (SourceColor * scale) + offset.
Parameters
scale
RGBA color multiplier values. Default (1,1,1,1) applies no scaling.
offset
RGBA color offset values added after scaling. Default (0,0,0,0) applies no offset.
Resets the editor preview by toggling the previewInEditor setting.
Forces recreation of the preview visualization object with current overlay settings.

Object Data for protected-static-func

Determines if the specified overlay shape requires texture content.
Passthrough shapes don't need textures as they display real-world content.
Parameters
shape
The overlay shape to check
Returns
True if the shape requires texture content, false for passthrough shapes

Protected Functions

Creates a new overlay layer in the VR compositor with the specified parameters.
Handles layer descriptor creation, compositor setup, and instance registry management.
Parameters
mipLevels
Number of mip levels for the layer texture
sampleCount
Sample count for multisampling
etFormat
Texture format for the layer
flags
Layer feature flags
size
Layer texture dimensions
shape
Geometric shape of the overlay
Returns
True if layer creation succeeded, false otherwise
Creates compositor-managed texture swap chains for this overlay layer.
Parameters
useMipmaps
Whether to create textures with mipmap support
size
Dimensions of the textures to create in pixels
isHdr
Whether to use HDR texture format (16-bit floating point)
Returns
True if new textures were created or texture copying is needed for this frame
Destroys all layer textures and cleans up swap chain resources.
Called during layer teardown to free compositor texture memory.
Destroys the overlay layer and releases all associated compositor resources.
Cleans up the layer ID, destroys textures, and removes the overlay from the global instances registry. Performs comprehensive cleanup: hides overlay, removes from registry, destroys layer, releases handles, resets state. Can be called multiple times safely. Automatically invoked by OnDisable, OnDestroy, and TrySubmitLayer when needed.
Validates and caches native texture pointers for overlay rendering.
Ensures application textures are properly prepared and accessible to the VR compositor.
Returns
True if all required textures are valid and ready for rendering
Creates a layer descriptor structure with current overlay configuration for compositor submission.
Analyzes texture properties and overlay settings to generate the appropriate layer specification. Automatically detects HDR formats from texture types, sets feature flags based on enabled properties, and calculates appropriate dimensions from external surfaces or texture dimensions.
Returns
Complete layer descriptor containing format, size, flags, and shape information for the compositor
Calculates the pixel-perfect blit rectangle for texture copying operations.
Converts normalized source rectangles to exact pixel coordinates with appropriate padding. For stereo textures, uses appropriate eye rectangle. For shared textures, calculates union of both eyes. Adds 2-pixel border to handle texture filtering edge cases.
Parameters
eyeId
Eye index (0=left, 1=right) for stereo or shared texture rectangle calculation
width
Target texture width in pixels
height
Target texture height in pixels
invertRect
Whether to invert Y coordinates for different texture coordinate systems
Returns
Pixel-accurate rectangle with 2-pixel padding for safe blitting operations
Performs optimized texture blitting to a specific region using command buffer operations.
Renders the source texture to a sub-region with custom projection and viewport settings. Uses scissor rectangle and viewport offsetting to blit only the necessary region, reducing GPU bandwidth. Integrates with Unity's command buffer system for efficient GPU command submission.
Parameters
src
Source texture to blit from
width
Full target texture width in pixels
height
Full target texture height in pixels
mat
Material/shader to use for the blit operation
rect
Target rectangle in pixel coordinates within the destination texture
Copies application textures to compositor swap chain textures using optimized blitting operations.
Handles format conversion, alpha premultiplication, and texture rectangle processing.
Parameters
mipLevels
Number of mip levels to populate
isHdr
Whether to use HDR rendering format
size
Texture dimensions
sampleCount
MSAA sample count
stage
Swap chain stage index to populate
Returns
True if texture population succeeded
Submits the overlay layer to the VR compositor with configured rendering parameters.
Handles filtering validation, texture matrix updates, and alpha premultiplication settings.
Parameters
overlay
Whether to render as overlay (true) or underlay (false)
headLocked
Whether the overlay is locked to head movement
noDepthBufferTesting
Whether to disable depth buffer testing
pose
World-space pose of the overlay
scale
Scale transformation for the overlay
frameIndex
Frame index for swap chain synchronization
Returns
True if overlay submission succeeded and is visible
Creates or destroys the editor preview object based on previewInEditor setting.
Manages Unity editor visualization for overlay positioning and debugging.

Static Member Functions

Determines whether the specified overlay shape is a passthrough type that displays real-world content.
Passthrough shapes don't require texture content as they render camera or environment data directly.Passthrough shapes include: ReconstructionPassthrough, SurfaceProjectedPassthrough, KeyboardHandsPassthrough, and KeyboardMaskedHandsPassthrough. These shapes are used for mixed reality applications where real-world content is integrated with virtual elements.
Parameters
shape
The overlay shape to check
Returns
True if the shape displays real-world content, false if it requires application textures
Did you find this page helpful?