
The goal
You have a journal you can draw in. I wanted the tools to feel like the real thing: a pen and a marker that lay down flat ink, a pencil that gets darker as you go over it, a crayon with some texture, and an eraser that rubs out pencil and crayon but not ink.
I also wanted the journal to be part of the world. It lies on your bedroom floor: pick it up and it flies up to your face, then the drawing view opens over the blurred room. Whatever you draw stays there for next time.
How it works
Each page is a texture (a journal page is 1280 by 905), and all the painting happens on the CPU in plain pixel arrays. I keep three of them: the paper, an erasable ink layer and a permanent ink layer. The texture you see is built from those three, and only the bit that changed is rebuilt each frame.
Every tool is its own settings asset (a ScriptableObject) holding its size, hardness, stamp spacing, grain and which layer it draws on, so adding a new one doesn't need any new code.
1. Cleaning up the input
Raw mouse movement is jittery. The pointer first has to leave a small dead zone, a pixel or so, before the line follows it, which kills the shake. Then the tip chases the pointer on a short spring (about 20 ms for the pencil, 55 ms for the pen), and the points get joined with a centripetal Catmull-Rom spline, which passes through every point, so the curve is smooth. The spring does round sharp corners: by a few pixels with the pencil at a gentle speed, and by more with the pen or a faster hand.


2. Stamping along the line
The line is drawn as a row of soft round stamps, spaced evenly, at 10 to 22% of the stamp's radius depending on the tool, so how fast you move doesn't change how dense the line is. The stamp size follows your speed: slow strokes press harder, so they're fatter, and fast ones get thinner. Each stamp also gets a tiny random wobble so the line doesn't look like a perfect vector.

Inside each stamp, the edge softness comes from the tool's hardness, pencil and crayon get multiplied by the paper's grain so they catch on the texture, and a bit of noise roughens the outer edge.
3. How ink builds up
Stamps don't go straight onto the page. Each stroke has its own coverage buffer, a value from 0 to 255 per pixel. With the pen, each pixel keeps whichever stamp was darkest, so crossing your own line doesn't make it darker. With pencil and crayon the stamps add up, so going over a spot builds it up, to a ceiling: within one stroke, pencil stops at 90% opacity and crayon at 85%.

When you let go, the stroke gets blended into its layer. Pencil and crayon go into the erasable layer, and pen and marker into the permanent one, which sits on top. The eraser only clears the erasable layer, so it never touches ink.
4. Updating the texture
While you draw, the code tracks the rectangle that each frame's stamps touched. It rebuilds just that rectangle, paper then erasable ink then permanent ink with the live stroke mixed in, writes it into the texture, and re-uploads the texture. The maths for the preview and the final blend is the same, so nothing jumps when you let go.

Each page's two ink layers are saved as PNGs in the game's save folder when you turn the page or close the journal, and loaded back over the page art next time you open it.
The diagrams on this page were drawn with Python to show what the code does; the zigzag runs a port of the game's smoothing code. The clip at the top is from the game.