Height Map Terrain
Add height map terrain to an SDL GPU project using forge_scene.h terrain ground mode with vertex displacement, slope-based texture splatting, and self-shadowing
от Nebulavenus★ 51 звезда на GitHub
Установить Height Map Terrain в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
height-map-terrain
Add height-displaced terrain ground to a forge_scene.h project. The terrain replaces the grid floor with a mesh whose vertices are displaced by a heightmap, with slope/height-based texture splatting and PCF shadow receiving.
Prerequisites
common/math/forge_math.h(noise functions:forge_noise_fbm2d)common/shapes/forge_shapes.h(plane mesh generation)common/scene/forge_scene.h(terrain ground mode)
Include order (critical)
forge_shapes.h MUST be included BEFORE forge_scene.h. The terrain API
is guarded by #ifdef FORGE_SHAPES_H -- if shapes is not included first,
all terrain types, config fields, and functions are compiled out silently.
#define FORGE_MATH_IMPLEMENTATION
#include "math/forge_math.h"
#define FORGE_SHAPES_IMPLEMENTATION
#include "shapes/forge_shapes.h" /* BEFORE scene */
#define FORGE_SCENE_IMPLEMENTATION
#include "scene/forge_scene.h"
Generating a heightmap
Procedural generation with fBm noise:
#define HEIGHTMAP_SIZE 256
float *heightmap = SDL_malloc(HEIGHTMAP_SIZE * HEIGHTMAP_SIZE * sizeof(float));
float min_h = 1e30f, max_h = -1e30f;
for (int y = 0; y < HEIGHTMAP_SIZE; y++) {
for (int x = 0; x < HEIGHTMAP_SIZE; x++) {
float nx = ((float)x / (float)(HEIGHTMAP_SIZE - 1)) * 3.0f;
float ny = ((float)y / (float)(HEIGHTMAP_SIZE - 1)) * 3.0f;
float h = forge_noise_fbm2d(nx, ny, 42, 6, 2.0f, 0.5f);
heightmap[y * HEIGHTMAP_SIZE + x] = h;
if (h < min_h) min_h = h;
if (h > max_h) max_h = h;
}
}
/* Normalize to [0, 1] -- height_scale in config controls world-space range */
float inv_range = 1.0f / SDL_max(max_h - min_h, 1e-6f);
for (int i = 0; i < HEIGHTMAP_SIZE * HEIGHTMAP_SIZE; i++)
heightmap[i] = (heightmap[i] - min_h) * inv_range;
Or load from a file (single-channel float or 8-bit grayscale converted to float).
Setting up terrain
ForgeSceneConfig cfg = forge_scene_default_config("Terrain Demo");
cfg.terrain_size = 20.0f; /* world-space half-extent */
cfg.terrain_resolution = 256; /* vertices per side */
cfg.terrain_height_scale = 8.0f; /* max Y displacement */
cfg.terrain_texture_repeat = 8.0f; /* UV tiling for splatting */
cfg.terrain_snow_line = 0.7f; /* normalized height for snow layer */
cfg.terrain_slope_threshold = 0.3f; /* slope steepness for rock layer */
forge_scene_init(&state->scene, &cfg, argc, argv);
/* Upload heightmap -- creates mesh, pipeline, and heightmap texture */
if (!forge_scene_set_terrain(&state->scene, heightmap,
HEIGHTMAP_SIZE, HEIGHTMAP_SIZE)) {
SDL_Log("Failed to set terrain");
return SDL_APP_FAILURE;
}
Call forge_scene_set_terrain() again with new data to update the heightmap
at runtime (the mesh and texture are re-uploaded).
Render loop
/* Shadow pass -- terrain casts shadows on itself and nearby objects */
forge_scene_begin_shadow_pass(s);
forge_scene_draw_terrain_shadow(s); /* terrain self-shadowing */
forge_scene_draw_shadow_mesh(s, ...); /* other shadow casters */
forge_scene_end_shadow_pass(s);
/* Main pass -- draw terrain instead of (or alongside) the grid */
forge_scene_begin_main_pass(s);
forge_scene_draw_terrain(s); /* replaces forge_scene_draw_grid */
forge_scene_draw_mesh(s, ...); /* other scene objects */
forge_scene_end_main_pass(s);
Config fields
| Field | Default | Purpose |
|---|---|---|
terrain_size |
20.0 | World-space half-extent (matches grid) |
terrain_resolution |
256 | Vertices per side of the terrain mesh |
terrain_height_scale |
8.0 | Maximum Y displacement in world units |
terrain_texture_repeat |
8.0 | UV tiling factor for splatting textures |
terrain_snow_line |
0.7 | Normalized height threshold for snow layer |
terrain_slope_threshold |
0.3 | Slope steepness threshold for rock layer |
Shader-driven fields (terrain_height_scale, terrain_snow_line,
terrain_slope_threshold, terrain_texture_repeat) can be modified on
scene->config at runtime — changes take effect on the next
forge_scene_draw_terrain() call.
terrain_resolution controls mesh generation and only takes effect when
forge_scene_set_terrain() is called. Changing it after initialization
requires calling forge_scene_set_terrain() again to rebuild the mesh.
Instanced objects on terrain (trees, rocks)
Place objects using slope-based filtering on the heightmap:
for (int y = 1; y < HEIGHTMAP_SIZE - 1 && count < max_trees; y += step) {
for (int x = 1; x < HEIGHTMAP_SIZE - 1 && count < max_trees; x += step) {
/* Central differences for slope */
float dhdx = (heightmap[y * HEIGHTMAP_SIZE + x
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Height Map Terrain?
Add height map terrain to an SDL GPU project using forge_scene.h terrain ground mode with vertex displacement, slope-based texture splatting, and self-shadowing
Как установить скилл Height Map Terrain?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Height Map Terrain запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…