Skip to content

BlobscapeLesson 24 of 24

Pixel art that holds still

The pixel scenes are blobs drawn small and snapped to a few colors. That sounds easy, until the light moves. What does pixel art need from a renderer that a photo doesn’t?

Things to try

  1. Try nowTry now: Draw the cottage as a picture under 200 pixels acrossHint: The readout gives the picture’s size.
  2. Up nextLater: Draw it in 4 colors or fewer
  3. Up nextLater: Stop the lantern’s flicker changing pixels, with the view still

Starting the splat engine…

Drawn as 0 blobs, at the screen’s own pixels.

0 of 3 goals done.

Pixels drawn small

Screen pixels to one

Colors snapped to a palette

Palette

Motion from frame to frame

Poses

What you just saw

Small, few colors, and the same from frame to frame

pixel = nearest(palette, color)
colorwhat the blobs add up to in one small pixel, lit as it is this framepalettethe few colors the picture may usenearestthe palette color closest to it, measured as the eye sees color

Pixel mode draws the scene into a small picture, a few screen pixels to each of its own, then turns every pixel into one palette color: the nearest, by how far apart the eye finds two colors rather than by their numbers. Where no color is near, dither sets two neighbors in a pattern that mixes to something between. An outline and lines inside are drawn where colors jump, as a pixel artist would.

A still picture is the easy part. A pixel sitting halfway between two palette colors flips to the other one when the light wavers a little, and a whole wall of them twinkles. Steady pixels let each pixel keep the color it had last frame unless another is clearly closer: real change still shows, flicker doesn’t.

Moving the view moves every edge a fraction of a pixel each frame, so edges crawl. Holding each pose for an eighth or a twelfth of a second, as drawn animation does, gives the eye whole steps instead. The renderer has to help with all of it, because each frame on its own is right: it is the change between frames that reads as wrong.

Take it with you

This picture, as code

The cottage from the last lesson, drawn with the settings you chose, with the engine package.

Install it with npm install @blobscape/engine three.

import { Stage, compileScene, buildVoxels, type SceneDoc } from '@blobscape/engine'

const doc: SceneDoc = {
  "name": "Cottage in pixels",
  "loop": 12,
  "light": { "from": [-0.5, 0.6, 0.6], "ambient": 0.45 },
  "palette": ["#141a33", "#2a2f55", "#4a4f7a", "#2c4a2a", "#4a7a3a", "#7aa84e", "#4a3020", "#6e4a2e", "#a07850", "#d8c09a", "#8a2f2a", "#c0503a", "#ffd166", "#fff3b0"],
  "sky": ["#141a33", "#c0503a"],
  "look": { "dither": 0.1, "glow": 1.5, "outline": true, "edges": true },
  "camera": { "target": [0, 0.45, 0], "distance": 3.6, "azimuth": 25, "elevation": 18 },
  "bones": [{ "name": "tree", "at": [0.75, 0, -0.25] }],
  "parts": [
    {
      "shape": { "kind": "cylinder", "at": [0, -0.2, 0], "height": 0.2, "r": 1.2 },
      "paint": {
        "kind": "faces",
        "top": { "kind": "patches", "size": 0.3, "colors": ["#4a7a3a", "#7aa84e"] },
        "side": "#6e4a2e"
      }
    },
    {
      "shape": { "kind": "box", "at": [-0.3, 0.25, 0], "half": [0.35, 0.25, 0.28] },
      "paint": {
        "kind": "bricks",
        "size": [0.12, 0.06],
        "colors": ["#d8c09a", "#a07850"],
        "line": "#6e4a2e"
      }
    },
    {
      "shape": { "kind": "roof", "at": [-0.3, 0.5, 0], "half": [0.42, 0.34], "height": 0.3 },
      "paint": "#8a2f2a"
    },
    {
      "shape": { "kind": "box", "at": [-0.3, 0.14, 0.28], "half": [0.07, 0.14, 0.02] },
      "paint": "#4a3020"
    },
    {
      "shape": { "kind": "box", "at": [-0.08, 0.3, 0.28], "half": [0.06, 0.06, 0.02] },
      "paint": "#ffd166",
      "glow": true
    },
    {
      "shape": { "kind": "cylinder", "at": [0.75, 0, -0.25], "height": 0.45, "r": 0.05 },
      "paint": "#6e4a2e",
      "bone": "tree"
    },
    {
      "shape": { "kind": "ball", "at": [0.75, 0.62, -0.25], "r": [0.28, 0.3, 0.28] },
      "paint": { "kind": "speckle", "size": 0.05, "colors": ["#2c4a2a", "#4a7a3a", "#7aa84e"] },
      "bone": "tree"
    },
    {
      "shape": { "kind": "cylinder", "at": [0.35, 0, 0.55], "height": 0.5, "r": 0.02 },
      "paint": "#2a2f55"
    },
    {
      "shape": { "kind": "box", "at": [0.35, 0.56, 0.55], "half": [0.045, 0.055, 0.045] },
      "paint": "#ffd166",
      "glow": true
    }
  ],
  "lights": [
    {
      "at": [0.35, 0.56, 0.62],
      "color": "#ffd166",
      "strength": 1.2,
      "range": 1.2,
      "flicker": { "by": 0.3, "times": 24 }
    }
  ]
}

const scene = compileScene(doc)
const stage = await Stage.start(document.querySelector('canvas')!, { lights: true })
stage.setActor(buildVoxels(scene.spec(0.028)))
stage.orbit = scene.orbit
stage.setFloor(0) // the scene brings its own ground
stage.setPoser((sk, t) => {
  scene.pose(sk, t)
  stage.setLights(scene.lights(t))
})

// stage.setPixels(scene.look, 4) would draw it as pixel art, in the look the scene asks for