Class TextModeCRTImageRenderer
Runs the CRT simulation over a whole image, such as a camera's picture, instead of a TextMode view. The render pipeline integrations call it; it needs no pipeline itself.
Implements
Inherited Members
Namespace: Scylla.TextMode.CRT
Assembly: ScyllaTextMode.CRT.dll
Syntax
public sealed class TextModeCRTImageRenderer : IDisposable
Remarks
Record(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Vector2Int, TextModeCRTSettings, CRTQualityTier, bool, int, float, TextModeCRTTube, CRTHDRTarget, CRTImageRegion) copies the source into the CRT's own textures, then records the same raster, video signal, afterglow, glow and composite passes TextModeCRTDriver uses, and draws the result over the whole destination, or over the viewport of a CRTImageRegion. The source and the destination may be the same texture.
Pass a TextModeCRTTube to switch the picture on and off, degauss it, or collect burn-in. The burn-in belongs to the renderer and lasts until it is disposed or the tube clears it.
Each instance keeps its own afterglow history, so use one per camera. The history belongs to consecutive frames of one picture; call InvalidateHistory() when the picture changes completely, for example on a camera cut.
The renderer creates its textures and its composite material on the first call to Record(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Vector2Int, TextModeCRTSettings, CRTQualityTier, bool, int, float, TextModeCRTTube, CRTHDRTarget, CRTImageRegion) and keeps them until Dispose(). Call it from the main thread, once per frame per picture.
The following example runs the effect over a render texture from a command buffer.
var renderer = new TextModeCRTImageRenderer();
var tube = new TextModeCRTTube();
var size = new Vector2Int(target.width, target.height);
var cmd = new CommandBuffer();
if (renderer.Record(cmd, source, target, size, settings, CRTQualityTier.Medium, false, 0, 1f, tube))
{
Graphics.ExecuteCommandBuffer(cmd);
}
renderer.Dispose();
cmd.Release();
Properties
HDRHeadroom
Gets the display's headroom for the last recorded frame, peak luminance over paper white, including a manual override. 1 on a standard display.
Declaration
public float HDRHeadroom { get; }
Property Value
| Type | Description |
|---|---|
| float |
HDRMaskActive
Gets whether HDR mask mode was active for the last recorded frame.
Declaration
public bool HDRMaskActive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
ResolvedSettings
Gets the settings used for the last recorded frame, after clamping.
Declaration
public TextModeCRTSettings ResolvedSettings { get; }
Property Value
| Type | Description |
|---|---|
| TextModeCRTSettings |
UseBeamSimulation
Gets or sets whether this picture follows the beam simulator while TextModeCRTBeam runs it. On by default; the in-world monitor turns it off, because a strobing screen inside a 3D scene flickers without making motion clearer.
Declaration
public bool UseBeamSimulation { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Dispose()
Releases the textures and the material. The renderer can be used again afterwards; it creates them anew on the next call to Record(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Vector2Int, TextModeCRTSettings, CRTQualityTier, bool, int, float, TextModeCRTTube, CRTHDRTarget, CRTImageRegion), and the afterglow and burn-in start empty.
Declaration
public void Dispose()
InvalidateHistory()
Forgets the stored afterglow, so the next frame starts from the new picture alone.
Declaration
public void InvalidateHistory()
Record(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Vector2Int, TextModeCRTSettings, CRTQualityTier, bool, int, float, TextModeCRTTube, CRTHDRTarget, CRTImageRegion)
Records the CRT passes for one frame into a command buffer.
Declaration
public bool Record(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, Vector2Int outputSize, TextModeCRTSettings settings, CRTQualityTier tier, bool readabilityClamp, int sourceLines, float displayScale = 1, TextModeCRTTube tube = null, CRTHDRTarget hdr = default, CRTImageRegion region = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | The command buffer to record into. It is left with the destination as render target. |
| RenderTargetIdentifier | source | The picture to show through the tube. |
| RenderTargetIdentifier | destination | Where the tube picture is drawn. It is covered completely, or only inside the viewport
of |
| Vector2Int | outputSize | Size of |
| TextModeCRTSettings | settings | The settings to use. They are copied and clamped, so the caller's instance is not changed. |
| CRTQualityTier | tier | The quality tier. |
| bool | readabilityClamp | Whether to limit the settings that cost legibility. |
| int | sourceLines | A fixed number of scanlines for a low-resolution look, such as 240, or 0 to derive the count from ScanlinePitch. |
| float | displayScale | Display pixels per destination pixel, when the destination is scaled after the CRT has drawn it, for example 1 / render scale in URP. The scanline pitch and the mask are laid out in display pixels, so they come out right after the rescale. 1 when the destination is shown as it is. |
| TextModeCRTTube | tube | The tube to show switching on and off, degaussing and burn-in, or null for a tube that is simply on. One tube can be shared by several renderers. |
| CRTHDRTarget | hdr | What the display reports for this picture and how precisely to capture the source. The default is a standard display with an 8-bit capture. A render pipeline fills it in when its output is HDR, which lets HDR mask mode take over. |
| CRTImageRegion | region | Which part of the source and destination holds the picture, for a pipeline whose textures can be larger than the picture. The default means the picture fills both completely. |
Returns
| Type | Description |
|---|---|
| bool | True if commands were recorded; false if the target has no area or a shader is missing. |
Remarks
The method copies and sanitizes settings, so the caller's instance is
never changed. It creates or resizes the renderer's textures and material if needed,
which happens at call time, while the passes themselves run when the command buffer is
executed. When the beam simulator is running and UseBeamSimulation is on,
the source is copied only once per CRT frame and the composite is drawn on every
refresh. The command buffer ends with the destination set as the render target.