Logo: Height Map Terrain

Height Map Terrain

Communautéit
Nebulavenus
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

Iwwersiicht

EditeurNebulavenus
Repositoryforge-gpu
Skill-Nummheight-map-terrain
Stären
46
Forks
7
Matgeliwwert Dateien
Nëmmen Instruktiounen
LizenzZlib
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Nebulavenus huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Height Map Terrain an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/height-map-terrain
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Nebulavenus/forge-gpu.git /tmp/forge-gpu
mkdir -p .claude/skills
cp -r /tmp/forge-gpu/.claude/skills/height-map-terrain .claude/skills/height-map-terrain
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Height Map Terrain an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Height Map Terrain automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Height Map Terrain net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

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.

c
#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:

c
#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

c
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

c
/* 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

FieldDefaultPurpose
terrain_size20.0World-space half-extent (matches grid)
terrain_resolution256Vertices per side of the terrain mesh
terrain_height_scale8.0Maximum Y displacement in world units
terrain_texture_repeat8.0UV tiling factor for splatting textures
terrain_snow_line0.7Normalized height threshold for snow layer
terrain_slope_threshold0.3Slope 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:

c
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 + 1]
                    - heightmap[y * HEIGHTMAP_SIZE + x - 1]) * 0.5f;
        float dhdy = (heightmap[(y + 1) * HEIGHTMAP_SIZE + x]
                    - heightmap[(y - 1) * HEIGHTMAP_SIZE + x]) * 0.5f;
        float slope = SDL_sqrtf(dhdx * dhdx + dhdy * dhdy);

        if (slope > SLOPE_THRESHOLD) continue;  /* too steep */

        /* Map texel to world position */
        float wx = ((float)x / (HEIGHTMAP_SIZE - 1) - 0.5f) * 2.0f * terrain_size;
        float wz = ((float)y / (HEIGHTMAP_SIZE - 1) - 0.5f) * 2.0f * terrain_size;
        float wy = heightmap[y * HEIGHTMAP_SIZE + x] * height_scale;

        /* Build instance transform at (wx, wy, wz) */
        instances[count++] = /* ... */;
    }
}

Use forge_scene_draw_instanced_mesh() or the colored-instance pipeline to render the placed objects.

Common mistakes

  • Wrong include order. If forge_shapes.h is included after forge_scene.h, the terrain API compiles out silently. No errors, no terrain. Always include shapes first.

  • Heightmap not normalized. forge_scene_set_terrain() expects values in [0, 1]. The terrain_height_scale config field controls the world-space range. Raw fBm output spans approximately [-1, 1] and must be remapped.

  • Terrain size vs shadow ortho mismatch. The default shadow ortho extent matches the grid half-size (20.0). If you increase terrain_size, also increase shadow_ortho_size in the config so the shadow map covers the full terrain.

  • Resolution mismatch. terrain_resolution must match the heightmap dimensions passed to forge_scene_set_terrain(). Mismatched values cause incorrect vertex-to-texel mapping and visible seams.

  • Forgetting the shadow pass. Without forge_scene_draw_terrain_shadow(), terrain valleys receive no shadows from terrain peaks. Always include both the shadow and main draw calls.

Reference

  • Source: common/scene/forge_scene.h (terrain API gated on FORGE_SHAPES_H)
  • Shaders: common/scene/shaders/terrain.vert.hlsl, terrain.frag.hlsl, terrain_shadow.vert.hlsl
  • Lesson: lessons/gpu/48-height-map-terrain/
  • Noise functions: common/math/forge_math.h (forge_noise_fbm2d)

Heefeg gestallte Froen

Wat mécht de KI-Skill 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

Firwat Height Map Terrain op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Height Map Terrain besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Height Map Terrain an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/height-map-terrain an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Height Map Terrain benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Height Map Terrain benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Height Map Terrain domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Height Map Terrain gratis?

Jo. Nebulavenus huet de Skill ënner der Lizenz Zlib op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇