Rendering effects
After the 3D engine has worked out each pixel’s colour from lights, vertex colours and textures (see The 3D engine), it has a few fixed effects it can apply on the way to the screen. They cost the processor nothing: they are switches and small tables in the 3D engine’s registers. Because the DS has no shaders, these switches are most of what a game can do to change the look of its whole 3D picture.
Toon shading
Section titled “Toon shading”Each polygon has a shading mode. Besides the normal one, two modes use a shared toon table of 32 colours:
- Toon. The polygon’s corner colour is not used as a colour. Its red part (one of 32 levels) picks an entry of the table, and that entry’s colour is used instead. A smooth ramp of light becomes a few flat bands: cartoon shading. With hardware lights, the light’s strength chooses the band.
- Highlight. The table’s colour is added to the normal result instead, which can brighten surfaces into a shine.
One switch chooses toon or highlight for the whole frame; one table serves every polygon. That is why a game that uses toon shading uses it with one look throughout.
PokeLoom does not use the toon table today. Planned (plan 42): a material flag that draws its polygons in toon mode with the DS’s table, on the DS and on desktop.
Polygon IDs
Section titled “Polygon IDs”Every polygon carries a polygon ID from 0 to 63, set with its other attributes. It has two jobs:
- Translucent polygons with the same ID do not draw over each other. Overlapping shadows, made with one ID, stay one shade instead of darkening where they meet.
- Opaque polygons with different IDs are where edge marking draws outlines.
In PokeLoom a material gives its ID with id in pieces.toml (0 is the default, the
ground’s). The sample’s furniture shadows share one:
[furniture.materials.shadow]alpha = 9id = 1Edge marking
Section titled “Edge marking”The DS can outline shapes in its 3D picture. After everything is drawn, it looks at each pixel on the edge of an opaque polygon. If a neighbouring pixel belongs to a polygon with a different ID that lies further away, the edge pixel takes an outline colour.
There are eight outline colours, and the ID picks one by its group of eight: IDs 0 to 7 use the first colour, 8 to 15 the second, and so on. So a game decides what gets outlined by how it numbers its polygons:
- Pieces with the same ID as the ground are not outlined against it.
- Pieces with their own ID get a thin dark line where they stand in front of the ground or of each other: buildings read clearly against a floor of a similar colour.
- The space behind everything (the rear plane) has an ID too, so a room’s walls can be outlined against the empty space around a room.
The line is one pixel wide at the DS’s resolution, and only on the near side of an edge. It is why generation-4 rooms have their crisp, slightly hand-drawn look.
In PokeLoom:
[light]edges = ["#202018", "#303028"] # in game.toml: IDs 0-7, then 8-15; a shorter list repeats its lastedges_rear = 0 # the rear plane's IDA map’s map.toml may give its own edges (or false, for none) and edges_rear.
Without edges there are no outlines. Keys are in the
game.toml and
map.toml references.
Anti-aliasing
Section titled “Anti-aliasing”The edges of polygons on a 256 × 192 screen are visibly stepped. The DS’s anti-aliasing softens them: a pixel on the left or right edge of an opaque polygon is mixed with what lies behind it, in proportion to how much of the pixel the polygon covers. An outline pixel from edge marking is mixed half and half, which makes the outlines lighter and thinner.
It works only on the edges of opaque polygons, and only on their left and right sides; translucent polygons are left alone. It costs nothing at run time.
In PokeLoom it is a game setting, off by default:
[world]antialias = trueThe generation-4 fields are drawn with it on.
The DS has depth fog: each pixel is mixed with a fog colour, more strongly the further it is from the camera. It is set by:
- a colour (and an opacity);
- a start depth, before which there is no fog;
- a step size (the shift), which says how much depth each step of the table covers;
- a density table of 32 entries, each from 0 (no fog) to 127 (all fog).
A pixel’s depth past the start picks two neighbouring entries of the table, and the density is blended between them. Before the start the first entry holds; past the end, the last. The table can be any shape: a straight ramp, a wall of fog at a distance, a thin haze that never closes in. Each polygon says whether it takes fog. The fog can also change only opacity, not colour.
Games use fog for mist and weather, and to hide where the world stops drawing.
In PokeLoom fog belongs to a map, and weather turns it on:
fog = { color = "#c4cad0", start = 29150, shift = 3 } # in map.tomlstart is the depth where it begins (0 at the camera to 32767) and shift how fast it
thickens (0 slowest to 10). The engine’s table is a straight ramp from no fog to 98 %.
Fading in slides that ramp along the table in 127 small steps, one each time the field
is drawn, about four seconds in all (slow = true halves the speed). The defog field
move fades it away. A period of a light table may give its own fog colour (fog in
lights.toml). More on Light, time of day and weather.
Clear colour
Section titled “Clear colour”Where the 3D engine draws nothing, it shows its rear plane: one colour (with an opacity, a polygon ID for edge marking, and whether fog applies). It can also be a picture held in video memory, though few games spend the memory.
PokeLoom’s rear plane is a colour: clear in map.toml, or a period’s own clear in
lights.toml. The rear plane takes no fog, so with fog the engine mixes the fog’s
colour into the clear colour itself, so that the edge of the world fades into the mist
instead of standing out. When a title puts 3D on the lower screen, the rear plane is
made fully transparent so the tile layers behind it show through.
Desktop
Section titled “Desktop”The software renderer applies the same effects in the same order the DS does: translucent polygons, then edge marking, then fog, then anti-aliasing, with the hardware’s rules as melonDS works them out. An outline is drawn against the second nearest surface under its pixel, as the DS keeps it, and an outline over an empty rear plane is left unmixed. The result is compared with melonDS picture by picture.
Planned (plan 42): on desktop, a player may choose smoother fog, outlines scaled to a higher resolution, or modern anti-aliasing. These change only how the game is drawn.