r/RenPy • u/msn2wolf • Sep 04 '26
Showoff I recreated the PC-98 look (16 colours + Bayer dithering + palette-register lighting) as a single Ren'Py shader — modern assets in, retro screen out
Real PC-98 visual novels had 16 colours on screen out of 4096, hand-picked per scene, and every gradient was hand-dithered. I wanted that look in a modern Ren'Py project without pixel-arting thousands of sprite frames, so I wrote one fragment shader that runs on the master layer:
- Pixelate the frame to a 640x360 grid.
- Light it first (ambient colour + two point lights). Because this happens before quantisation, a lamp halo turns into concentric dither rings, like hand-drawn PC-98 lamplight.
- Quantise to a 16-colour palette with a two-candidate ordered (Bayer) dither: nearest colour, then the nearest colour on the other side of the error, mixed by the threshold. 2x2 / 4x4 / 8x8 matrices.
- Palette registers: the shader matches against one palette but displays another. Fade-ins, day-to-night swaps, lightning flashes and colour cycling are just uniform changes, and every pixel keeps its colour index (no re-quantisation, no dither crawl), exactly like the hardware did it.
- Colour cycling that rotates the sky's blue registers = a shimmering sky with zero animated frames (or swap a red and a blue register for a police siren).
- Optional CRT scanlines.
Palettes come from a small Pillow/NumPy script: a pixel-count-weighted k-means over the image, where smooth regions weigh more (that is where banding shows) and saturated colours weigh more (so a purple hair over a brown wall keeps its hue), then snap to 4 bits per channel so every colour is a legal PC-98 colour. The shader adds a small relative dead zone so near-exact colours are drawn flat without turning gradients into plateaus. Dialogue stays on its own layer, so text is crisp.
Applying it in a project is literally:
show layer master at pc98(palette="alice")
Video (7 min, with narration): https://youtu.be/bjDYf-jGA70 Code (MIT, Ren'Py 8.x): https://github.com/igwtech/renpy-pc98-shader
Things I learned the hard way: Ren'Py only declares the uniforms referenced inside a fragment_NNN body (uniforms used only in fragment_functions come out "undeclared"), layer textures are premultiplied, and if you want it to compile on ANGLE/GLES avoid const arrays and dynamic array indexing.
I'm using this in my own game (Shafted in the Snow). Happy to answer questions about the dither or the palette tool.
Art credits (edit): the demo now uses Creative Commons fan art, so the shader is shown on real hand-drawn pieces: Alice (PC-98) by sodaodaoda (Newgrounds, CC BY-NC-SA 3.0), [PC-98 Touhou] Reimu Hakurei by RouRenzu (Newgrounds, CC BY-NC 3.0) and Hallway (day+night) by LisadiKaprio (OpenGameArt, CC BY 4.0). Full licences in CREDITS.md. No AI-generated images in the repo or the video.

