<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Kevin Newman — Blog</title>
    <link>https://www.kevinnewman.ca/blog/</link>
    <description>Experiments, small discoveries, and the stories behind my projects.</description>
    <language>en-ca</language>
    <atom:link href="https://www.kevinnewman.ca/feed.xml" rel="self" type="application/rss+xml" />
    <lastBuildDate>Fri, 06 Nov 2026 00:00:00 GMT</lastBuildDate>
    <item>
      <title>Texturing for the N64</title>
      <link>https://www.kevinnewman.ca/blog/n64-texture-formats/</link>
      <guid isPermaLink="true">https://www.kevinnewman.ca/blog/n64-texture-formats/</guid>
      <pubDate>Fri, 06 Nov 2026 00:00:00 GMT</pubDate>
      <description>How texture formats, vertex colors, and the color combiner shape Pandemonium’s N64 boss room.</description>
      <category>N64</category>
<category>Graphics</category>
<category>Interactive</category>
      <content:encoded><![CDATA[<p>We built <a href="https://www.kevinnewman.ca/projects/pandemonium/">Pandemonium</a>, our N64brew game-jam boss battle, with very little time for optimization. We didn’t get to check every texture’s size or format, and the room wasn’t textured as nicely as we wanted. There was lots of overdraw. Z fighting on the floor. Assets didn't make it into the final build. Usual game-jam chaos.</p>
<p>Revisiting the scene gave us time to improve the artwork and look at what each surface actually needed. The stone floor went from I8 to I4: 4kb down to 2kb, still at 64 × 64. The mesh still supplies its color.</p>
<p>All Pandemonium textures were made by my teammate <a href="https://github.com/Boxingbruin">BoxingBruin</a>.</p>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/scene-comparisons.jpg" alt="Three before-and-after screenshot pairs compare the column and banner, window wall, and carpet views in Pandemonium’s boss room." /><figcaption>Before screenshots on the left, after screenshots on the right. These supplied captures show the overall scene revision, including stonework, columns, banners, and carpet. Camera positions, geometry, and lighting also differ. Open the article to switch between three views in the reveal slider.</figcaption></figure>
<h2>Small textures, tight budget</h2>
<p>A texel (texture element) is one pixel in a texture, so a 64 × 64 texture contains 4,096 texels.</p>
<p>The N64’s graphics hardware has 4kb of texture memory, called TMEM. That is space for textures being used while drawing, rather than a limit on all the artwork in a game. The RDP can only sample texels already loaded there, so textures that exceed that space must be drawn in smaller sections, with new texture data loaded between draws.</p>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/format-families.png" alt="Five format diagrams and diagnostic samples reveal palette banding, independent alpha, and lost color in fine YUV stripes." /><figcaption>Each 64 × 64 test pattern has a color gradient at the top, one-pixel magenta/green stripes in the middle, and an alpha fade at the bottom. RGBA32 is the reference. CI4 reduces the gradient to palette colors. YUV16 averages the stripes’ color and loses alpha. I4: 2kb, IA8: 4kb, CI4: 2kb plus 32b of palette, RGBA32: 16kb, YUV16: 8kb. Packed sizes exclude headers, padding, mipmaps, and compression. These are illustrative conversions. YUV16 is approximate.</figcaption></figure>
<p>Fewer bits can leave room for more texels, at the cost of brightness levels, colors, or transparency precision.</p>
<table>
<thead>
<tr>
<th align="left">Format</th>
<th align="right">Bits / texel</th>
<th align="left">What it stores</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">I4</td>
<td align="right">4</td>
<td align="left">16 brightness levels</td>
</tr>
<tr>
<td align="left">I8</td>
<td align="right">8</td>
<td align="left">256 brightness levels</td>
</tr>
<tr>
<td align="left">IA4</td>
<td align="right">4</td>
<td align="left">3 intensity bits + 1 alpha bit</td>
</tr>
<tr>
<td align="left">IA8</td>
<td align="right">8</td>
<td align="left">4 intensity bits + 4 alpha bits</td>
</tr>
<tr>
<td align="left">IA16</td>
<td align="right">16</td>
<td align="left">8 intensity bits + 8 alpha bits</td>
</tr>
<tr>
<td align="left">CI4</td>
<td align="right">4</td>
<td align="left">An index into a 16-color palette</td>
</tr>
<tr>
<td align="left">CI8</td>
<td align="right">8</td>
<td align="left">An index into a 256-color palette</td>
</tr>
<tr>
<td align="left">RGBA16</td>
<td align="right">16</td>
<td align="left">5 bits per RGB channel + 1 alpha bit</td>
</tr>
<tr>
<td align="left">RGBA32</td>
<td align="right">32</td>
<td align="left">8 bits each for red, green, blue, and alpha</td>
</tr>
<tr>
<td align="left">YUV16</td>
<td align="right">16</td>
<td align="left">Brightness per texel, with U and V shared by a horizontal pair. No alpha</td>
</tr>
</tbody>
</table>
<p>These layouts follow <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/include/surface.h#L105-L118">libdragon’s texture-format definitions</a>.</p>
<h2>Texture dimensions</h2>
<p>BoxingBruin pointed out two rules about width and height that are easy to miss.</p>
<p>To repeat or mirror a texture along an axis, that dimension must be a power of two: 16, 32, 64, and so on. <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/src/rdpq/rdpq_tex.c#L58-L70">libdragon checks this</a> separately for each axis.</p>
<p>Any size that fits in TMEM can still be drawn once. Keep the width to these multiples so each row fills whole 64-bit rows of TMEM:</p>
<table>
<thead>
<tr>
<th align="left">Formats</th>
<th align="right">Width is a multiple of</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">I4, IA4, CI4</td>
<td align="right">16</td>
</tr>
<tr>
<td align="left">I8, IA8, CI8</td>
<td align="right">8</td>
</tr>
<tr>
<td align="left">IA16, RGBA16</td>
<td align="right">4</td>
</tr>
<tr>
<td align="left">RGBA32</td>
<td align="right">4</td>
</tr>
</tbody>
</table>
<p>RGBA32 is split across both halves of TMEM, so it lines up at 4 texels rather than 2. <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/src/rdpq/rdpq_tex.c#L133-L137">libdragon pads rows</a> that don’t line up, which wastes TMEM.</p>
<p>A 40 × 48 RGBA16 texture is 3,840b. Its rows line up and it fits, but it can’t repeat, because neither 40 nor 48 is a power of two. As I4, each 40-texel row is 20b, padded to 24b.</p>
<p>The room has examples. The carpet border is 16 × 64 CI8, and its material mirrors it horizontally, which the 16-texel width allows. The door crests and window frames are 48 × 80 IA8, and the column transition is 32 × 124 I4. Their rows line up, and none of them can repeat vertically.</p>
<h2>Which format would I use?</h2>
<p>I’d start with what the surface needs. Each pair below uses the same source, so you can see what changes when you spend more memory.</p>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/format-choice-guide.png" alt="Four visual comparisons show tinted stone in I4 and I8, carpet palettes in CI4 and CI8, a hard IA4 cutout versus an IA8 fade, and stone at two resolutions." /><figcaption>Choose a format for the surface: I4 or I8 for detail tinted by the mesh, CI4 or CI8 for artwork with its own colors, and IA4 for grayscale cutouts or IA8 for softer alpha. The same I4 stone at 32 × 32 costs 512b, versus 2kb at 64 × 64. Both are also shown at a twelve-pixel screen footprint. CI examples include full RGBA16 palettes. The glow is generated, and these conversions are illustrative.</figcaption></figure>
<p>For colored cutouts, RGBA16 or CI with an RGBA16 palette gives you on/off alpha. YUV16 is a separate case for video frames or photographs: it keeps brightness detail but shares color between neighboring texels, and has no alpha. It uses <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/include/rdpq_mode.h#L346-L362">libdragon’s dedicated YUV conversion mode</a>.</p>
<p>For surfaces that recede into the distance, <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/include/rdpq_mode.h#L830-L856">mipmaps</a> can reduce shimmering. They add storage, so budget for the levels that need to be loaded together.</p>
<h2>Vertex colors</h2>
<p>If you can get away with a simple color then this is definitely the way to go. A grayscale stone texture can still produce a colored floor. The texture supplies fine detail. Colors stored at the mesh’s vertices supply broader variation. The renderer blends those corner colors across the entire triangle, then multiplies the texture by that color:</p>
<pre><code class="language-text">surface RGB = texture intensity × interpolated vertex RGB
</code></pre>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/vertex-color-comparison.png" alt="Three panels show the original main-branch grayscale floor texture, interpolated vertex colors, and their multiplication into a colored floor." /><figcaption>original main-branch 64 × 64 I8 floor texture multiplied by interpolated vertex RGB. It uses 4kb of texel data. Vertex colors carry broad color variation. This technique was already present in the original game. Open the article to change the four corner colors.</figcaption></figure>
<p>For 2kb of raw texels, RGBA16 gives you 32 × 32 pixels, while I4 gives you 64 × 64: four times as many texels. Putting broad color changes in the vertices can preserve a larger grid for surface detail.</p>
<p>Vertex colors do not increase the screen resolution or add texture pixels by themselves. Their gradients follow the mesh, and vertex data also costs memory. The original floor already used this technique, and the revision keeps it.</p>
<h2>How the color combiner builds the material</h2>
<p>The texture format tells us what is stored. The color combiner decides how those samples mix with the other inputs. Vertex colors only affect the result if the material’s formula uses them.</p>
<p>Each cycle runs this formula separately for RGB and alpha:</p>
<pre><code class="language-text">(A − B) × C + D
</code></pre>
<p>The letters are input slots, like the fields in Fast64. Some of the inputs you can choose are:</p>
<ul>
<li><strong>Texture 0 / 1:</strong> Color and alpha sampled from the first or second texture.</li>
<li><strong>Shade:</strong> Vertex color or lighting, blended across the triangle.</li>
<li><strong>Primitive:</strong> A fixed color set by the material or drawing code. Here it tints the columns.</li>
<li><strong>Environment:</strong> A second fixed color the formula can use.</li>
</ul>
<p>The available inputs depend on the slot. See <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/include/rdpq_macros.h#L310-L410">libdragon’s formula and input definitions</a>.</p>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/color-combiner.png" alt="The column material combines a texture with vertex shading, then primitive tint. Other examples show two textures mixed at fifty percent and an IA8 glow with alpha." /><figcaption>The color combiner evaluates (A − B) × C + D separately for RGB and alpha. The column material uses texture × shade, followed by combined × primitive color, with opaque alpha. A one-cycle material can output the texture directly. A two-texture lerp uses (Texture 1 − Texture 0) × amount + Texture 0, then applies shade in cycle 2. Texture alpha only affects transparency when the later blend or alpha-test settings use it. Open the article to change the recipes, tint, and blend amount.</figcaption></figure>
<p>In a two-cycle material, Combined is the first cycle’s output, used as an input to the second. See <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/include/rdpq_macros.h#L474-L495">libdragon’s documentation for the second cycle</a>.</p>
<p>The two-texture blend preset uses</p>
<pre><code class="language-c">(Texture 1 − Texture 0) × amount + Texture 0
</code></pre>
<p>This is a lerp: amount 0 gives Texture 0, amount 1 gives Texture 1. It uses primitive alpha as the mix amount, then applies shade in cycle 2. Both textures must fit in TMEM together. These two 32 × 32 I4 patches use 1kb in total.</p>
<p>On an N64 model, the UVs select the texture samples and the vertex data supplies shade. Fast64 stores the combiner choices in the exported material, which the model pipeline must apply when drawing. Changing the PNG alone cannot change that formula. For the column settings, the equivalent libdragon configuration is:</p>
<pre><code class="language-c">rdpq_mode_combiner(RDPQ_COMBINER2(
    (TEX0, 0, SHADE, 0),       (0, 0, 0, 1),
    (COMBINED, 0, PRIM, 0),   (0, 0, 0, COMBINED)
));
rdpq_set_prim_color(RGBA32(255, 255, 255, 255));
</code></pre>
<p>The combiner is only part of the material. Lighting supplies shade before this step. The later blender handles mixing with the framebuffer. Alpha testing can discard cutout pixels. Standard fog also uses the blender, often borrowing shade alpha for depth, so it needs care alongside custom alpha formulas. See <a href="https://github.com/n64brew/libdragon/blob/f26e1c16145e4d6ad7e391e1306513d684083c02/include/rdpq_mode.h#L413-L467">libdragon’s notes on fog and the combiner</a>.</p>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/models/columns-reference.jpg" alt="The shaft, base, and transition intensity textures above four textured boss-room columns. The model uses 254 triangles and 6.44kb of packed texels." /><figcaption>Shaft: 32 × 128 I8, 4kb. Base: 32 × 32 I4, 512b. Transition: 32 × 124 I4, 1,984b. These sizes total 6,592b across three textures used by separate materials. Open the article to orbit the 254-triangle model and compare texture-only, vertex-color, combined, and wireframe views. The browser viewer approximates N64 intensity materials and three-point filtering, without full RDP emulation.</figcaption></figure>
<h2>What changed in the room?</h2>
<p>The floor’s artwork also changed, so the before-and-after images show more than a format conversion.</p>
<table>
<thead>
<tr>
<th align="left">Surface</th>
<th align="left">Original → updated</th>
<th align="left">Outcome</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Stone floor</td>
<td align="left">64 × 64 I8 → I4</td>
<td align="left">4kb → 2kb of texels</td>
</tr>
<tr>
<td align="left">Carpet border</td>
<td align="left">16 × 64 CI8 in both</td>
<td align="left">Same 1kb base cost, with revised artwork and added mipmaps</td>
</tr>
<tr>
<td align="left">Banner layers</td>
<td align="left">Separate I4 background and IA4 ornament in the local version</td>
<td align="left">Different jobs for brightness and transparency</td>
</tr>
</tbody>
</table>
<p>The carpet still uses CI8. Its mipmaps actually add memory, but help stop the fine pattern shimmering in the distance. The banner layers show another tradeoff, spending bits on independent alpha where a decorative cutout needs it.</p>
<h2>Try the formats yourself</h2>
<figure><img src="https://www.kevinnewman.ca/assets/blog/pandemonium/format-comparison.png" alt="A generated color-gradient, stripe, and alpha test pattern represented in ten texture formats, with packed sizes." /><figcaption>The 64 × 64 diagnostic pattern makes palette banding, alpha precision, and YUV shared color visible. Texel alpha is applied where available. YUV16 is an opaque BT.601 4:2:2 approximation. Sizes include a full RGBA16 palette for CI, before headers, padding, mipmaps, or compression. Open the article to compare this pattern or the newer detailed game artwork at native PNG precision.</figcaption></figure>
<h2>Conclusion</h2>
<p>The floor saves 2kb. The updated room still has more texture data and geometry overall:</p>
<table>
<thead>
<tr>
<th align="left">Room assets</th>
<th align="right">Original</th>
<th align="right">Updated</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Model files</td>
<td align="right">10</td>
<td align="right">12</td>
</tr>
<tr>
<td align="left">Triangles in those models</td>
<td align="right">1,316</td>
<td align="right">2,321</td>
</tr>
<tr>
<td align="left">Material slots across models</td>
<td align="right">32</td>
<td align="right">72</td>
</tr>
<tr>
<td align="left">Unique embedded textures</td>
<td align="right">18</td>
<td align="right">51</td>
</tr>
<tr>
<td align="left">Estimated packed embedded texels</td>
<td align="right">69kb</td>
<td align="right">131.56kb</td>
</tr>
</tbody>
</table>
<p>Asset totals include room effects. Texel estimates exclude palettes, external mipmaps, padding, and headers.</p>
<p>During the jam, getting the game finished took priority. Coming back gave us time to revisit choices like the floor’s format and bring the stonework and banners closer to how we wanted them to look.</p>
<p>I hope this little deep dive into texture formats and the color combiner helps understand some of the finer details of Nintendo64 graphics.</p>]]></content:encoded>
    </item>
  </channel>
</rss>