
In practice, you prepare the palettes as per normal during vblank and then have the PPU look up any palette entry as if it was the backdrop colour mid-frame. Once done, you should restore the scrolling position and nametable selection before turning rendering on again. This can serve to create lines of colours not otherwise available or available otherwise only available to the sprite plane. Basic palette swap shader with the potential to manage up to a 100 colors at the same time.GitHub. While rendering is turned off, it may be marginally useful to point the PPUADDR to one of the 16 palette entries to have the background rendered as that colour. Games that change colors for a status bar can use blank lines at the top of the status bar to similarly avoid visual errors. Indiana Jones hides some potential visual errors by only working where the background is already blank, and only changing the background color. An extra empty line is needed after the palette writes are finished, since there is not enough time in horizontal blank to write 3 colors and restore the PPU address and return to rendering.īecause of these issues, it is best not to use this techniques where sprites may overlap the affected lines. This can be used to change 3 colors in a single horizontal blank, and if rendering is kept off 3 more colors may be updated in each subsequent line. BIT $2007 can be used to skip over the background color, followed by 3 writes to $2007, returning the PPU address to point at the background color again. If the background color is unchanged and stored redundantly at PPU $3F00/4/8/C.While rendering is turned off, and the PPU address is pointing at a palette entry at the same time, this will become the current background color,.(With background rendering on, sprite evaluation will resume but remain hidden.) After the change, one line with background rendering enabled but sprites hidden can be used to flush the invalid sprite evaluation buffer.The write to disable rendering ($2001) should be done after pixel 240 on a scanline to avoid corrupting all sprites on the next frame (see: Errata).Because sprites are evaluated one line in advance, turning off rendering will cause the first line of sprites to be corrupted after re-enabling.Most IRQ or $2001 polling techniques for timing are subject to jitter, varying by about 7 cycles, which cuts into the usable horizontal blank time significantly.Three values can be loaded into the A, X, Y registers in advance of blanking to avoid extra load cycles.Half of the address may be written to $2006 early.NTSC horizontal blank only lasts 21 cycles, which is not enough time to fit all of these steps at once.Ideally, these should be done within or mostly within horizontal blanking to minimize the appearance of visual errors. To write to the palette in the middle of the screen, the following sequence of operations need to be done: Ivan Ironman Stewart's Super Off-Road - on the "Speed Shop" screen, swaps colors for the 4 panels below.Other games using mid frame palette changes: Indiana Jones and the Last Crusade changes its background color many times across the title screen for a gradient sky effect:
#Palette swap download#
I used UI image shader, but the idea will also work for sprites and any other materialsįirst, let’s download built-in shaders for your version of Unity.Changing palette entries in the middle of a frame on the NES is difficult, but marginally possible.Ī few games are known to change palette entries for a status bar region:

It allows to remove the necessity of creating palette images yourself and use Unity inspector for that Shader Instead, it’s focused on using this technique combined with texture generation. This article won’t cover details of palette swapping itself. It also allows to change palettes right in the game which is useful when the same icons can be used with different colors.ĭetailed information about making palette swapping itself can be found at “Makin’ Stuff Look Good” in the video “Shaders Case Study - Pixel Art Palette Swapping”, If sprites in your game use only a limited amount of colors, instead of drawing them colored you can draw them using grayscale and use palette swapping technique to change different grey colors to different actual colors.
