Attention: Here be dragons (unstable version)

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Redot.

Mode7ScanlineOverride

Inherits: Resource < RefCounted < Object

A resource that holds per-scanline transform data for Mode 7 perspective rendering.

Description

A Resource used by Mode7Sprite2D to store one entry in the per-scanline "scanline table" that drives Mode 7-style perspective and rotation effects.

The Super Nintendo was able to apply a different transformation to each scanline (output row), enabling perspective projection effects like the distant ground plane in racing games. This class exposes that capability through intuitive properties: a 2x2 affine matrix (rotation, scale, skew), a pivot point, and optional color modulation.

Interpolation modes determine how adjacent entries in the override array are blended:

  • None: Nearest-neighbor snap — each row uses exactly this entry's transform with no blending between rows. Best for scripted or fully manual transformations where every scanline is set individually.

  • Lerp: Linear interpolation between adjacent entries in the override array. The shader smoothly blends transforms, pivots, and modulate colors across all intervening scanlines. Add any number of overrides to create gradual transitions.

  • Projection: Perspective projection via per-scanline inverse-depth interpolation. Uses the first entry (index 0) as the top/horizon anchor and the last entry as the bottom/close anchor. Designed specifically for use with exactly 2 overrides — one at the horizon line and one closer to the camera.

The transforms are stored canonically as a Transform2D, but you can also read/write decomposed rotation, scale, and skew properties for convenience. Values below 0.00001 are clamped internally to prevent division-by-zero artifacts during inverse-depth interpolation.

Properties

Color

modulate

Color(1, 1, 1, 1)

Vector2

pivot

Vector2(0.5, 0.5)

float

rotation

0.0

Vector2

scale

Vector2(1, 1)

float

skew

0.0

Transform2D

transform

Transform2D(1, 0, 0, 1, 0, 0)


Property Descriptions

Color modulate = Color(1, 1, 1, 1) 🔗

  • void set_modulate(value: Color)

  • Color get_modulate()

Per-scanline color tint and alpha/intensity. The shader lerps this between adjacent overrides (just like the transform), enabling gradual fade-to-black into the distance for depth, bloom glow effects, or any per-band color correction. Fully supports RGBA — set alpha to blend the sprite transparently at specific scanline ranges.


Vector2 pivot = Vector2(0.5, 0.5) 🔗

The vanishing point in normalized [0..1] texture UV space around which the transform is applied. Defaults to center ((0.5, 0.5)). Set closer to an edge to make that edge appear nearer or farther in perspective mode.


float rotation = 0.0 🔗

  • void set_rotation(value: float)

  • float get_rotation()

Rotation angle in degrees, decomposed from transform. Provides a more intuitive interface than editing matrix columns directly for simple rotational adjustments.


Vector2 scale = Vector2(1, 1) 🔗

Scale factor applied along the X and Y axes, decomposed from transform. Values below 0.00001. are clamped internally to prevent division-by-zero artifacts during inverse-depth (Projection) interpolation. Adjust scale to zoom in or out on the Mode 7 plane — smaller values bring the horizon closer.


float skew = 0.0 🔗

Skew angle in degrees, decomposed from transform. Tilts the coordinate grid into a shear transformation. Useful for simulating uneven terrain or angled surfaces.


Transform2D transform = Transform2D(1, 0, 0, 1, 0, 0) 🔗

The canonical transformation matrix stored as two column vectors plus a translation offset: (col0_x, col1_x, off_x), (col0_y, col1_y, off_y).

Column 0 and Column 1 form the 2x2 affine matrix controlling rotation and scale. Adjust these to rotate or stretch the background plane.

Skew — changing the off-diagonal elements tilts the coordinate grid into a shear.

Translation offset (x0, y0) shifts where the Mode 7 plane appears on screen, analogous to moving the camera position.