Logo: Imposters

Imposters

Communautéit
Nebulavenus
imposters

Add imposter billboard LOD with baked multi-angle atlas to an SDL GPU project

Iwwersiicht

EditeurNebulavenus
Repositoryforge-gpu
Skill-Nummimposters
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 Imposters 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/imposters
  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/imposters .claude/skills/imposters
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Imposters 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 Imposters automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Imposters 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.

imposters

Add distance-based LOD to a scene by replacing far 3D instances with camera-facing billboard imposters. Near objects render as full meshes; beyond a transition zone they render as textured quads sampled from a pre-baked multi-angle atlas.

Prerequisites

  • common/scene/forge_scene.h with terrain and instanced mesh support
  • common/shapes/forge_shapes.h (procedural geometry for bake source)
  • Compiled imposter shaders: imposter_bake.vert/frag and imposter.vert/frag
  • Include shapes before scene (terrain API is gated on FORGE_SHAPES_H)

Data structures

c
/* Per-instance data for imposter billboards — 96 bytes, vertex buffer slot 1 */
typedef struct ImposterInstance {
    mat4  transform;    /* 64B — world position + scale                  */
    float atlas_uv[4]; /* 16B — u_offset, v_offset, u_scale, v_scale    */
    float alpha;        /* 4B  — cross-fade alpha [0..1]                 */
    float color[3];     /* 12B — RGB tint (multiplied with atlas)        */
} ImposterInstance;

/* Push constants for the imposter vertex shader (slot 0) */
typedef struct ImposterVertUniforms {
    mat4  vp;           /* camera view-projection matrix                 */
    float cam_pos[3];   /* world-space camera position for billboard facing */
    float _pad;         /* explicit padding to 80 bytes                  */
} ImposterVertUniforms;

/* Push constants for the bake vertex shader (slot 0) — one MVP per angle */
typedef struct BakeVertUniforms {
    mat4 mvp;
} BakeVertUniforms;

/* Push constants for the bake fragment shader (slot 0, space3) */
typedef struct BakeFragUniforms {
    float base_color[4]; /* RGBA base color for trunk or crown draw call */
    float light_dir[3];  /* world-space light direction (normalized)     */
    float ambient;       /* ambient light floor [0, 1]                   */
} BakeFragUniforms;

Atlas layout

c
#define ATLAS_FRAMES      8     /* azimuth angles at 45° intervals */
#define ATLAS_COLS        4     /* frames per row                  */
#define ATLAS_ROWS        2
#define ATLAS_FRAME_SIZE  256   /* pixels per cell                 */
#define ATLAS_WIDTH       (ATLAS_COLS * ATLAS_FRAME_SIZE)  /* 1024 */
#define ATLAS_HEIGHT      (ATLAS_ROWS * ATLAS_FRAME_SIZE)  /* 512  */

Frames are laid out row-major: [0][1][2][3] / [4][5][6][7]. Frame 0 is at azimuth 0, each subsequent frame adds TAU / ATLAS_FRAMES.

Atlas baking procedure

Baking is a one-shot startup operation. Create and destroy the bake pipeline inside the bake function — only the atlas texture and sampler persist.

c
/* 1. Create atlas texture: COLOR_TARGET + SAMPLER usage */
tex_info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
tex_info.width  = ATLAS_WIDTH;
tex_info.height = ATLAS_HEIGHT;
tex_info.usage  = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER;

/* 2. Create depth texture: D32_FLOAT, DEPTH_STENCIL_TARGET usage only */

/* 3. Create bake pipeline */
/*    - Color target: R8G8B8A8_UNORM, blending disabled               */
/*    - Depth: D32_FLOAT, write + test with LESS                      */
/*    - Vertex input: ForgeSceneVertex (FLOAT3 pos at 0, FLOAT3 normal at 12) */
/*    - Back-face cull: BACK (tree mesh is solid)                     */

/* 4. One render pass covers all 8 frames — viewport + scissor change per frame */
SDL_GPUColorTargetInfo ct = { .load_op = SDL_GPU_LOADOP_CLEAR,
                               .clear_color = {0,0,0,0} }; /* transparent black */

for (int i = 0; i < ATLAS_FRAMES; i++) {
    float angle = (float)i * (FORGE_TAU / (float)ATLAS_FRAMES);
    vec3 eye = vec3_create(SDL_sinf(angle) * view_dist, slight_elevation,
                           SDL_cosf(angle) * view_dist);
    mat4 view = mat4_look_at(eye, tree_center, world_up);
    mat4 mvp  = mat4_multiply(ortho_proj, view);

    /* Set viewport and scissor to the atlas cell for this frame */
    int cell_x = (i % ATLAS_COLS) * ATLAS_FRAME_SIZE;
    int cell_y = (i / ATLAS_COLS) * ATLAS_FRAME_SIZE;
    /* SDL_SetGPUViewport + SDL_SetGPUScissor ... */

    /* Push BakeVertUniforms with mvp, then draw trunk and crown as separate
     * calls with different BakeFragUniforms base_color values. */
}

/* 5. Submit, SDL_WaitForGPUIdle, then release bake depth + bake pipeline */

/* 6. Create atlas sampler: LINEAR filter, CLAMP_TO_EDGE on U and V
 *    Clamping prevents bleeding between adjacent atlas cells. */

Use mat4_orthographic sized to the model's bounding volume. A slight Y elevation on the camera (≈ 15% of model height) avoids flat top-down angles.

Billboard quad

c
/* Unit quad in XY plane: X from -0.5..+0.5, Y from 0..1, normal +Z */
/* Two CCW triangles: (0,1,2) and (0,2,3) */
verts[0].position = vec3_create(-0.5f, 0.0f, 0.0f);
verts[1].position = vec3_create( 0.5f, 0.0f, 0.0f);
verts[2].position = vec3_create( 0.5f, 1.0f, 0.0f);
verts[3].position = vec3_create(-0.5f, 1.0f, 0.0f);

The vertex shader expands the quad using billboard basis vectors derived from the pivot-to-camera direction projected onto the XZ plane (cylindrical billboard — no vertical tilt).

Imposter pipeline

Two vertex buffer slots are required:

c
/* Slot 0: per-vertex quad geometry */
vb_descs[0].pitch      = sizeof(ForgeSceneVertex); /* 24 bytes */
vb_descs[0].input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
vb_descs[0].instance_step_rate = 0;  /* MUST be 0 in SDL3 GPU */

/* Slot 1: per-instance imposter data */
vb_descs[1].pitch      = sizeof(ImposterInstance); /* 96 bytes */
vb_descs[1].input_rate = SDL_GPU_VERTEXINPUTRATE_INSTANCE;
vb_descs[1].instance_step_rate = 0;

Eight vertex attributes (TEXCOORD0–7):

LocationSlotTypeOffsetPurpose
00FLOAT30Quad position
10FLOAT312Quad normal (unused)
21FLOAT40Transform column 0
31FLOAT416Transform column 1
41FLOAT432Transform column 2
51FLOAT448Transform column 3
61FLOAT464Atlas UV rect
71FLOAT480Alpha (x) + RGB tint (yzw)

Alpha blending: SRC_ALPHA / ONE_MINUS_SRC_ALPHA (standard over-compositing). Disable back-face culling (CULLMODE_NONE) — precision at edge-on angles can flip winding. Depth test and write both enabled.

Per-frame LOD classification

c
float cell_u = 1.0f / (float)ATLAS_COLS;
float cell_v = 1.0f / (float)ATLAS_ROWS;

for each tree {
    float dist = vec3_length(vec3_sub(cam_pos, tree_pos));

    if (dist < lod_far)  /* near or transition — add to near_cpu */
    if (dist > lod_near) /* transition or far — add to far_cpu   */

    /* Azimuth frame selection */
    float angle = SDL_atan2f(diff.x, diff.z);
    if (angle < 0.0f) angle += FORGE_TAU;
    int frame = ((int)(angle / FORGE_TAU * ATLAS_FRAMES + 0.5f)) % ATLAS_FRAMES;

    fi->atlas_uv[0] = (float)(frame % ATLAS_COLS) * cell_u;  /* u offset */
    fi->atlas_uv[1] = (float)(frame / ATLAS_COLS) * cell_v;  /* v offset */
    fi->atlas_uv[2] = cell_u;   /* u scale */
    fi->atlas_uv[3] = cell_v;   /* v scale */

    /* Imposter fades in during transition; mesh stays fully opaque */
    fi->alpha = (dist < lod_far) ? (dist - lod_near) / (lod_far - lod_near) : 1.0f;
}

Trees in the transition zone appear in both arrays — the full mesh renders at full opacity and the imposter fades in on top with increasing alpha. At the far boundary the mesh stops rendering and the imposter takes over.

Rendering order

c
/* 1. Classify instances into near_cpu / far_cpu arrays */
classify_instances(state, cam_pos);

/* 2. Upload both arrays via deferred copy pass */
forge_scene_begin_deferred_uploads(s);
near_buf = forge_scene_upload_buffer_deferred(s, SDL_GPU_BUFFERUSAGE_VERTEX,
               near_cpu, near_count * sizeof(ForgeSceneColoredInstance));
far_buf  = forge_scene_upload_buffer_deferred(s, SDL_GPU_BUFFERUSAGE_VERTEX,
               far_cpu, far_count * sizeof(ImposterInstance));
forge_scene_end_deferred_uploads(s);

/* 3. Shadow pass — terrain + near mesh only (imposters skip shadow casting) */
forge_scene_begin_shadow_pass(s);
forge_scene_draw_terrain_shadow(s);
forge_scene_draw_shadow_mesh_instanced_colored(s, tree_vb, tree_ib,
    tree_index_count, near_buf, near_count);
forge_scene_end_shadow_pass(s);

/* 4. Main pass — terrain, near mesh, then imposter draw */
forge_scene_begin_main_pass(s);
forge_scene_draw_terrain(s);
forge_scene_draw_mesh_instanced_colored(s, tree_vb, tree_ib,
    tree_index_count, near_buf, near_count, white);

/* Switch to imposter pipeline for billboard draw */
SDL_BindGPUGraphicsPipeline(forge_scene_main_pass(s), imposter_pipeline);
SDL_PushGPUVertexUniformData(forge_scene_cmd(s), 0, &ivu, sizeof(ivu));
SDL_BindGPUFragmentSamplers(pass, 0, &atlas_bind, 1);
/* Bind slot 0 = quad_vb, slot 1 = far_buf */
SDL_DrawGPUIndexedPrimitives(pass, 6, far_count, 0, 0, 0);
forge_scene_end_main_pass(s);

/* 5. UI pass */

Heightmap from asset pipeline

c
/* Load pipeline-generated BMP; fall back to procedural fBm if absent */
float *hmap = forge_scene_load_heightmap_image(path, &w, &h);
if (!hmap) {
    /* generate with forge_noise_fbm2d, normalize to [0,1] */
}
forge_scene_set_terrain(&scene, hmap, w, h);

forge_scene_load_heightmap_image reads an 8-bit or 16-bit grayscale BMP and returns a float[] normalized to [0, 1]. The caller owns the allocation and must SDL_free it when done.

Common mistakes

  • instance_step_rate non-zero — SDL3 GPU requires 0 for all slots. VERTEXINPUTRATE_INSTANCE alone controls per-instance advancement.
  • Atlas bleed — use CLAMP_TO_EDGE on both U and V axes of the atlas sampler; REPEAT causes adjacent frame pixels to bleed into each other.
  • Bake pipeline not destroyed — the bake pipeline and depth texture are one-shot. Release them after SDL_WaitForGPUIdle to free GPU memory.
  • Wrong azimuth frame — use atan2(diff.x, diff.z) (not atan2(diff.z, diff.x)). The bake orbit uses (sin(angle), y, cos(angle)), so atan2(x, z) measures from +Z to match frame 0. Swapping the arguments produces a 90-degree offset between bake and selection.
  • Imposters cast no shadows — far imposters are not submitted to the shadow pass. At typical LOD distances the shadow error is imperceptible and avoids a matching shadow billboard pipeline.

Reference

  • Lesson: lessons/gpu/49-imposters/
  • Shaders: lessons/gpu/49-imposters/shaders/imposter.vert/frag.hlsl and imposter_bake.vert/frag.hlsl
  • Heightmap API: common/scene/forge_scene.h (forge_scene_load_heightmap_image)
  • Terrain setup: height-map-terrain skill
  • Instanced rendering: forge-instanced-rendering skill

Heefeg gestallte Froen

Wat mécht de KI-Skill Imposters?

Add imposter billboard LOD with baked multi-angle atlas to an SDL GPU project

Firwat Imposters op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Imposters 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 Imposters an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/imposters 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 Imposters 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 Imposters benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Imposters 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 Imposters 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 👇