Blend Modes Draft

From SpecNext official Wiki
Jump to: navigation, search

This is a draft as I need to confirm everything behaves on hardware or if there are any quirks.

Layer Blending

Layer Blending on the ZX Spectrum Next allows the visual mixing of the Sprite, Layer 2, and ULA (or Tilemap) layers to produce lighting, shading, or other visual effects.

This is controlled primarily by the layer priority setting Sprite and Layers System Register ($15) and blending source selection ULA Control Register ($68).

Overview

Blending can be enabled using special layer modes referred to as SLU 6 and SLU 7. In these modes, colour values from a "blending" layer (ULA or Tilemap) are added to Layer 2 pixel values and clamped to the 3-bit colour range [0–7].

Blending Modes (SLU 6 & 7)

Set by bits 4–2 of Sprite and Layers System Register ($15):

SLU Value Layer Order / Blending Description Notes
000 S L U Default mode: Sprites over Layer 2 over ULA
001 L S U Layer 2 over Sprites over ULA
010 S U L Sprites over ULA over Layer 2
011 L U S Layer 2 over ULA over Sprites
100 U S L ULA over Sprites over Layer 2
101 U L S ULA over Layer 2 over Sprites
110 (U/T) S (T/U) ( B + L) Blend layer + Layer 2 colours, clamped to [0–7]
111 (U/T) S (T/U) (B + L - 5) Blend layer + Layer 2 - 5, colours clamped to [0–7]

In both SLU 6 and 7:

  • The blending source is selected by bits 6:5 of ULA Control Register ($68)
  • The blended output replaces the separate display of ULA or Tilemap (whichever is selected)

Blend Source Selection ULA Control Register ($68)

ULA Control Register ($68) (104) — ULA Control

(R/W)

Bit Name Description Default
7 Disable ULA output Turns off ULA layer entirely 0
6–5 Blending control for SLU 6 & 7 Selects blend input source 00
00 Use ULA as blend layer
01 No blending (disable blend)
10 Use result of ULA + Tilemap
11 Use Tilemap as blend layer
4 Disable extended key matrix Cancels entries in the 8x5 key matrix 0
3 ULA+ enable Enables enhanced ULA+ mode 0
2 Half-pixel scroll May enable smoother ULA scrolling 0
1 Reserved Must be 0 -
0 Stencil mode Logical AND of ULA + Tilemap unless either is transparent 0

Example Usage

To enable blending of the ULA layer with Layer 2 and show sprites on top:

  1. Set NextReg 0x15 bits 4:2 to 110 (SLU 6)
  2. Set NextReg 0x68 bits 6:5 to 00 (ULA as blend input)

For darker shading effects using SLU 7:

  1. Set NextReg 0x15 bits 4:2 to 111 (SLU 7)
  2. Set NextReg 0x68 bits 6:5 accordingly

Notes

  • Colours are always clamped to 3-bit RGB values [0–7] per channel.
  • SLU 6 blends normally: Blend + Layer2
  • SLU 7 blends with subtraction: Blend + Layer2 - 5 (for dimming)
  • Blending applies only when the chosen blend source is active and visible.
  • Sprites are unaffected by the blending math and remain on top (as per SLU order).

See Also