Height Map Terrainのロゴ

Height Map Terrain

コミュニティ
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

概要

公開者Nebulavenus
リポジトリforge-gpu
スキル名height-map-terrain
スター
46
フォーク
7
同梱ファイル
指示のみ
ライセンスZlib
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    NebulavenusがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Height Map Terrain」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/height-map-terrain
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでHeight Map Terrainを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にHeight Map Terrainを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Height Map Terrainは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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)

よくある質問

AIスキル「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

TypingMindでHeight Map Terrainを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Height Map Terrainはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにHeight Map Terrainをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/height-map-terrainを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Height Map Terrainを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Height Map Terrainで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもHeight Map Terrainを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Height Map Terrain」は無料ですか?

はい。NebulavenusがZlibライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇