miaoda-game-heightfield-core
v0.3.1
Published
Engine-independent VoxelSpace-style heightfield ray marcher with skyline occlusion, distance LOD, and terrain-point projection.
Maintainers
Readme
miaoda-game-heightfield-core
Engine-independent height-map terrain projection for retro low-altitude flight, mountain driving, island worlds, and VoxelSpace-style landscapes. It returns visible vertical screen spans; textures, shaders, Canvas, and engine nodes remain renderer-owned.
pnpm add miaoda-game-heightfield-coreconst frame = renderHeightfield(
{sample: (x, y) => terrain.sample(x, y)},
{position: {x: playerX, y: playerY}, heading, height: cameraHeight, fieldOfView: Math.PI / 2, horizonY: 120},
{width: 320, height: 200},
{nearDistance: 2, farDistance: 800, distanceStep: 1, stepGrowth: 0.02},
);
for (const span of frame.spans) renderer.drawVerticalSpan(span.column, span.topY, span.bottomY, palette[span.ref]);Map positions and distances use continuous host-selected world units; heading/FOV are radians, and output screen y points down. The source decides wrapping, clamping, interpolation, and procedural generation. ref may identify a color, material, biome, or any renderer payload.
Positive stepGrowth increases far-distance sampling steps for a coarse LOD. Use projectHeightfieldPoint for sprite or marker ground anchors with the same camera. A height field stores one elevation per map coordinate, so caves, overhangs, and buildings require separate sprites or geometry.
