A semi-transparent darkened rectangle rendered over a background image using SNES color math and HDMA-driven window boundaries. No input – the effect is static.
Ported from PVSnesLib "TransparentWindow" example by Digifox.
No interactive controls. The darkened rectangle is displayed statically.
Then open transparent_window.sfc in your emulator (Mesen2 recommended).
This combines three SNES hardware features:
The key insight: windows can control where color math applies independently from where they mask background layers.
REG_WOBJSEL = 0x20 enables Window 1 for the color math regionREG_TMW = 0 – no background layers are masked by the windowTwo HDMA channels define the rectangle shape by driving WH0 ($2126) and WH1 ($2127):
The tables use repeat mode (bit 7 set in the line count byte) for the rectangle segment. Even though the values are constant across those scanlines, repeat mode ensures WH0/WH1 are re-written every line. This is required because WH0/WH1 are write-only PPU registers.
| Register | Value | Effect |
|---|---|---|
| CGWSEL ($2130) | 0x10 | Apply math inside color window only, use fixed color |
| CGADSUB ($2131) | 0x82 | Subtract mode, BG2 participates |
| COLDATA ($2132) | 0xEC | Subtract intensity 12 from R+G+B (moderate darkening) |
The SNES window system serves two independent purposes:
This example uses only the color math window, leaving BG masking untouched. The background is fully visible everywhere, but the rectangular region gets darkened.
This technique is used in RPGs for dialog boxes (darken the area behind text), menu overlays, and spotlight effects. It costs zero CPU time – all hardware.
| File | Purpose |
|---|---|
main.c | HDMA tables, color math setup, window config |
data.asm | Background tiles, tilemap, and palette data |
res/background.png | Source background image |
Makefile | LIB_MODULES := console sprite dma background window colormath hdma math |
RECT_X and RECT_Y offsets and rebuild the tables.effects/window – Triangle-shaped HDMA window (BG masking, not color math)effects/transparency – Color math without windows (full-screen effects)