Nov 9, 2026 · 6 min read
A height map from a flat painting
Raw depth as height
Linear-normalized height
TL;DR
We needed height for a flat terrain painting. Marigold gave us a much better approximation at a listed price of $0.03 per image, but its camera-depth gradient raised the foreground. Subtracting one vertical linear trend gave us usable relief while preserving the local height differences.
A detailed terrain painting can still feel like a poster sliding past the camera. In Riftstorm, the vertically scrolling shooter we're building, I wanted the camera to feel as though it was flying over the ground.
We needed a height map for the painting. The artwork would stay attached to a surface, while its ridges, cracks and buildings changed the surface's shape. The camera could then travel over that fixed terrain.
Brightness gets confused
Our first height guides used the painting's colors and brightness, with smoothing to make a continuous surface. They produced visible geometry, but light and height are easy to confuse. Bright pavement could become a raised area, while a shadow could become a depression.
We tried Marigold V2 through fal's depth-estimation endpoint, first on an alien industrial complex and then on a fractured ice shelf. The estimated depth gave us a much better approximation of the scene's structure. It picked up useful differences between the ground, structures and channels that the earlier guide struggled with.
Original painting
Estimated depth
Normalized height fieldThe source paintings were 887 × 1774 pixels. We submitted them unchanged and requested 880 × 1760 outputs, preserving the proportions while satisfying the endpoint's multiple-of-16 requirement.
The returned image was a color visualization of depth. We decoded its Spectral palette into normalized values rather than converting its brightness to grayscale. That recovered an approximation from the visualization; saving it as floating-point data could not restore precision or the original depth scale lost in the color output.
Depth carries a camera
Even though we requested overhead terrain, the paintings contain perspective. If Marigold reads the scene from that implied photographer's viewpoint, the bottom of the painting should be nearer to the camera.
Nearer pixels are red in this visualization, so a broad transition toward red at the bottom is what we would expect. That was our working explanation for the gradient.
Turning “nearer” into “higher” then raised the whole foreground, making an otherwise useful estimate awkward for terrain. Ordinary ground could climb toward the bottom of the map, carrying its local features with it. Moving the game's camera did not remove a slope already built into the surface.
We first tried correcting the industrial map with a plane fitted through 11 manually chosen service-ground points. We subtracted the plane, clamped negative values to ground level and rescaled the positive relief. I didn't like the result. Edges and other areas were badly distorted, and raw depth looked better, so we turned the correction off.
That attempt changed several things together: the selected ground points, slopes in both directions, clipping and scale. It didn't tell us which change caused each artifact. It gave us a reason to try a smaller correction.
Keep the local relief
With that assumption, we could treat the broad top-to-bottom transition as a baseline and remove it. The ice map's gradient looked approximately linear, so I asked whether we could normalize that trend.
We checked the saved values: we measured the average near-bright value across each full-width row and fitted a straight line from the top of the image to the bottom.
The row averages supported a linear approximation in both maps. We subtracted that fitted line from the saved field. Valleys stayed negative and raised features stayed positive. We kept the original scale, without clipping at ground level or stretching the remaining contrast.
If decoded depth is d, with 0 near and 1 far, the near-bright value is r = 1 − d. For a row coordinate v from 0 at the top to 1 at the bottom, the fitted baseline is b(v) = intercept + slope × v. Our height becomes h = 150 × (r − b(v)), in the viewer's arbitrary units.
Every point in a row loses the same amount, so height differences within that row remain unchanged. Across rows, we remove only the fitted linear component. We fit it once to the entire saved image; scrolling never changes the height of a feature as it enters or leaves the screen.
Playground
Drag Height strength to compare the two surfaces. Scroll moves both views over the terrain.
Industrial map
This version looked much more accurate to me. I settled on 85% height with a 25° camera tilt. Those are artistic viewer settings, rather than measured terrain heights or a calibration of the painting's camera.
The original painting is the texture on a 181 × 361 vertex grid. The height samples stay fixed while the camera moves; none are generated during playback.
What three cents buys
The selected fal endpoint was listed at $0.03 per image for these November 9 tests. We made one depth submission for the industrial map and one for the ice map, with no retries: $0.06 at the published rate. That is a rate calculation, rather than a verified invoice.
At three cents an image, that's a hell of a deal. We got an estimate detailed enough to become useful terrain after a small local correction. Decoding and normalization reused the saved outputs and needed no further model call.
The six cents covers those two depth passes. It excludes artwork generation, development time, earlier experiments, hosting and runtime costs. Depth is prepared ahead of time; the scrolling renderer makes no inference request for each frame.
Where the surface ends
This gives us one height at each position. It cannot represent overhangs, separate layers or hidden sides. Triangles bridge abrupt depth changes, so textures can stretch across edges, especially on industrial structures. Shadows and illustrated perspective are already baked into the painting.
The linear subtraction is an approximation too. It can remove some real terrain slope, and a curved camera-depth trend can remain. Its usefulness here comes from how the corrected surface looks under the camera we intend to use.
The result shown here was reviewed in a WebGL browser prototype. It doesn't establish native-game performance on Apple TV, collision geometry or combat readability. The conspicuous joins between repeated map strips were a separate problem; removing the depth ramp didn't fix those seams.