Two ways to mix two layers: colour addition, and pseudo-hires. More...
#include <snes.h>#include <snes/console.h>#include <snes/video.h>#include <snes/background.h>#include <snes/colormath.h>#include "res/street.inc"#include "res/mist.inc"Macros | |
| #define | BG1_MAP 0x5000 |
| #define | BG1_TILES 0x0000 |
| The street and the mist, converted by the build from res/. | |
| #define | BG3_MAP 0x5400 |
| #define | BG3_TILES 0x4000 |
Functions | |
| int | main (void) |
| Entry point: color math transparency with drifting mist over a street. | |
Variables | |
| u8 | ph_on |
| 1 while the layers are mixed by pseudo-hires instead of addition | |
Two ways to mix two layers: colour addition, and pseudo-hires.
Demonstrates the SNES color math unit by blending two background layers. BG1 (main screen) shows a 4bpp rainy street at night, while BG3 (sub screen) holds 2bpp mist that drifts horizontally. The PPU adds the sub screen pixel colors to the main screen via registers CGWSEL ($2130) and CGADSUB ($2131), producing a translucent overlay effect.
Mode 1 is used with BG3 priority high so the 2bpp mist layer renders above BG1. Color addition is applied to BG1 and the backdrop, meaning the mist colour is numerically added to whatever is underneath.
Press A for the other way the PPU mixes two layers: pseudo-hires (SETINI bit 3). The colour math is switched off, and the PPU interleaves the sub screen (even columns) with the main screen (odd columns) into a 512-pixel line: a 50 % blend that costs no colour math at all, at the price of the horizontal resolution of each layer. A again goes back to addition.
This began as the PVSnesLib Transparency example by Alekmaul; the pseudo-hires mode was the pseudo_hires example, merged here. The street and the mist are ours: the street generated, the mist procedural (wisps of a periodic noise, so they wrap at 256 pixels).
| #define BG1_MAP 0x5000 |
| #define BG1_TILES 0x0000 |
The street and the mist, converted by the build from res/.
A C pointer carries its bank byte, so dmaCopyVram / dmaCopyCGram take the data wherever the linker placed it.
VRAM word addresses: the street's 883 tiles fill $0000-$372F
| #define BG3_MAP 0x5400 |
| #define BG3_TILES 0x4000 |
| int main | ( | void | ) |
Entry point: color math transparency with drifting mist over a street.
Sets up Mode 1 with two background layers:
The SNES color math unit adds the sub screen pixel colors to the main screen, producing a translucent mist overlay. BG3 is given priority high so its tiles render above BG1 in Mode 1's layer ordering.
Horizontal scroll offset for the mist layer (BG3), incremented each frame
| u8 ph_on |
1 while the layers are mixed by pseudo-hires instead of addition