Logo van Forge Stencil Testing

Forge Stencil Testing

Community
Nebulavenus
forge-stencil-testing

Add stencil buffer testing to an SDL GPU project. Configure depth-stencil textures with stencil bits, set up stencil state on pipelines, and use stencil operations for portals, outlines, and per-pixel masking.

Overzicht

UitgeverNebulavenus
Repositoryforge-gpu
Skillnaamforge-stencil-testing
Sterren
46
Forks
7
Meegeleverde bestanden
Alleen instructies
LicentieZlib
Links
  • Instructies in Markdown

    Een SKILL.md-bestand dat het model laadt wanneer nodig, zodat het alleen tokens kost als een verzoek er daadwerkelijk bij past.

  • Werkt met elk LLM

    AI-skills zijn gewone Markdown, geen aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Compleet zonder extra bestanden

    Alles wat het model nodig heeft, staat in de instructies — geen extra bestanden om te synchroniseren.

  • Open source

    Gepubliceerd door Nebulavenus op GitHub. Lees de broninhoud voordat je de skill installeert.

Installatie

Installeer de AI-skill Forge Stencil Testing in TypingMind om deze met elke LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map — het leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/forge-stencil-testing
  4. Schakel de skill in elke chat in waarin je deze beschikbaar wilt hebben.
Plug-ins → Skills → Nieuwe skill → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die 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/forge-stencil-testing .claude/skills/forge-stencil-testing
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Forge Stencil Testing in een willekeurige chat in TypingMind in en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek erbij past, laadt het model zelf de volledige instructies — je hoeft de skill nooit handmatig aan te roepen en deze kost pas tokens wanneer je de skill daadwerkelijk gebruikt.

Het model laadt Forge Stencil Testing automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Forge Stencil Testing niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

Stencil Testing

Add stencil buffer support to an SDL GPU project. This skill covers depth-stencil texture format selection, pipeline stencil state configuration, and common stencil techniques (portals, outlines, debug visualization).

Based on GPU Lesson 34.

When to use

  • You need per-pixel masking to control where fragments are drawn
  • You want a portal or window showing a different scene
  • You want object outlines for selection or highlighting
  • You need to combine multiple rendering effects with per-pixel control

Depth-stencil texture format

The depth-stencil texture must include stencil bits. Use SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT (24-bit depth + 8-bit stencil) as the primary choice, with SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT as fallback.

c
/* Check for D24_UNORM_S8_UINT support first */
SDL_GPUTextureFormat depth_stencil_fmt;
if (SDL_GPUTextureSupportsFormat(device,
        SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT,
        SDL_GPU_TEXTURETYPE_2D,
        SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET)) {
    depth_stencil_fmt = SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT;
} else {
    depth_stencil_fmt = SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
}

Without the _S8_UINT suffix, there is no stencil buffer and all stencil operations silently do nothing.

Pipeline stencil state

Stencil testing is configured on the pipeline, not in shaders:

c
SDL_GPUGraphicsPipelineCreateInfo pi = { /* ... */ };
pi.depth_stencil_state.enable_stencil_test = true;
pi.depth_stencil_state.front_stencil_state = (SDL_GPUStencilOpState){
    .fail_op      = SDL_GPU_STENCILOP_KEEP,
    .pass_op      = SDL_GPU_STENCILOP_REPLACE,
    .depth_fail_op = SDL_GPU_STENCILOP_KEEP,
    .compare_op   = SDL_GPU_COMPAREOP_ALWAYS,
};
pi.depth_stencil_state.back_stencil_state =
    pi.depth_stencil_state.front_stencil_state;
pi.depth_stencil_state.compare_mask = 0xFF;
pi.depth_stencil_state.write_mask   = 0xFF;

The reference value is set per-draw call:

c
SDL_SetGPUStencilReference(render_pass, reference_value);

Portal technique (4 passes)

  1. Main world pass — Draw regular scene geometry first:

    • Stencil test disabled, normal depth write
    • Establishes depth so the mask respects occlusion
  2. Mask pipeline — Write stencil, no color/depth:

    • compare_op = ALWAYS, pass_op = REPLACE, ref = 1
    • Color write mask = 0, depth write = false
    • Draw an invisible quad filling the portal opening
    • Depth test still active — mask only writes where no closer geometry exists
  3. Portal world pipeline — Draw inside portal only:

    • compare_op = EQUAL, ref = 1, pass_op = KEEP
    • Draw alternate-world objects (only pass where stencil == 1)
  4. Frame pipeline — Draw portal frame geometry:

    • Stencil test disabled or compare_op = ALWAYS
    • Normal color + depth writes

Outline technique (2 pipelines)

  1. Outline write — Draw object normally, writing stencil:

    • compare_op = ALWAYS, pass_op = REPLACE, ref = 2
    • Normal rendering + stencil write
  2. Outline draw — Draw scaled-up object where stencil != ref:

    • compare_op = NOT_EQUAL, ref = 2
    • Scale object 3-5% larger, output solid outline color
    • Only the border ring passes (interior rejected by stencil)

Scale for outlines:

c
mat4 outline_model = mat4_multiply(
    mat4_translate(object_position),
    mat4_multiply(
        mat4_scale_uniform(1.04f),
        mat4_translate(vec3_negate(object_position))
    )
);

Clearing stencil

Clear stencil alongside depth when beginning the render pass:

c
SDL_GPUDepthStencilTargetInfo ds_target = {
    .texture       = depth_stencil_texture,
    .load_op       = SDL_GPU_LOADOP_CLEAR,
    .store_op      = SDL_GPU_STOREOP_STORE,
    .clear_depth   = 1.0f,
    .clear_stencil = 0,
    .stencil_load_op  = SDL_GPU_LOADOP_CLEAR,
    .stencil_store_op = SDL_GPU_STOREOP_STORE,
};

Disabling color writes (for mask pipeline)

c
SDL_GPUColorTargetDescription ctd = {
    .format = swapchain_format,
    .blend_state = {
        .color_write_mask = 0,  /* write nothing to color */
    },
};

Key API calls

  • SDL_GPUTextureSupportsFormat() — check depth-stencil format support
  • SDL_CreateGPUTexture() with D24_UNORM_S8_UINT — create depth-stencil target
  • SDL_GPUStencilOpState — configure compare_op, pass_op, fail_op, depth_fail_op
  • SDL_SetGPUStencilReference() — set per-draw stencil reference value
  • SDL_GPUGraphicsPipelineCreateInfo.depth_stencil_state — embed stencil config in pipeline

Common mistakes

  • Missing _S8_UINT suffix — Using D24_UNORM or D32_FLOAT without _S8_UINT creates a texture with no stencil bits. All stencil operations silently do nothing.
  • Forgetting to clear stencil — Set stencil_load_op = SDL_GPU_LOADOP_CLEAR and clear_stencil = 0 on the depth-stencil target info. Without this, stale stencil values from the previous frame cause artifacts.
  • Wrong draw order — Main-world occluders must render before the portal mask so the depth buffer is established. The mask then only writes stencil where no closer geometry exists. Outline writes must happen after the main world so the outline reference value does not collide with the portal reference.
  • Not disabling depth writes for mask — The mask quad must not write depth, or it will occlude objects drawn behind it in the portal world.
  • Forgetting to set both front and back stencil — If back-face culling is off, both front_stencil_state and back_stencil_state must be configured.

Ready-to-use template

c
/* Minimal stencil mask + conditional draw setup */

/* 1. Create depth-stencil texture with stencil bits */
SDL_GPUTextureFormat ds_fmt = SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT;
/* ... create texture with ds_fmt ... */

/* 2. Mask pipeline: write stencil, no color/depth */
SDL_GPUStencilOpState mask_stencil = {
    .fail_op    = SDL_GPU_STENCILOP_KEEP,
    .pass_op    = SDL_GPU_STENCILOP_REPLACE,
    .depth_fail_op = SDL_GPU_STENCILOP_KEEP,
    .compare_op = SDL_GPU_COMPAREOP_ALWAYS,
};
/* pi.depth_stencil_state.enable_stencil_test = true; */
/* pi.depth_stencil_state.front/back = mask_stencil; */
/* color_write_mask = 0, depth_write = false */

/* 3. Conditional pipeline: draw only where stencil matches */
SDL_GPUStencilOpState cond_stencil = {
    .fail_op    = SDL_GPU_STENCILOP_KEEP,
    .pass_op    = SDL_GPU_STENCILOP_KEEP,
    .depth_fail_op = SDL_GPU_STENCILOP_KEEP,
    .compare_op = SDL_GPU_COMPAREOP_EQUAL, /* or NOT_EQUAL */
};

/* 4. At draw time */
SDL_SetGPUStencilReference(render_pass, 1);
/* Draw mask geometry with mask pipeline */
/* Draw scene with conditional pipeline */

Stencil operations reference

OperationEffect
KEEPLeave stencil unchanged
ZEROSet to 0
REPLACESet to reference value
INCREMENT_AND_CLAMPIncrement, clamp to 255
DECREMENT_AND_CLAMPDecrement, clamp to 0
INVERTBitwise NOT
INCREMENT_AND_WRAPIncrement, wrap 255 to 0
DECREMENT_AND_WRAPDecrement, wrap 0 to 255

Cross-references

Veelgestelde vragen

Wat doet de AI-skill Forge Stencil Testing?

Add stencil buffer testing to an SDL GPU project. Configure depth-stencil textures with stencil bits, set up stencil state on pipelines, and use stencil operations for portals, outlines, and per-pixel masking.

Waarom Forge Stencil Testing gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Forge Stencil Testing bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model, en je kunt midden in een chat van model wisselen zonder dat de skill niet meer werkt. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Forge Stencil Testing in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/forge-stencil-testing. TypingMind leest het bestand SKILL.md en installeert het als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Forge Stencil Testing gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Forge Stencil Testing gebruiken?

Zoveel als je wilt. Zolang een model skills ondersteunt, kun je Forge Stencil Testing ermee gebruiken: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama en meer. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Forge Stencil Testing gratis?

Ja. Deze skill is door Nebulavenus op GitHub gepubliceerd onder de licentie Zlib. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. Deze volgt het open Agent Skills-formaat: een bestand met de naam SKILL.md met een naam en beschrijving, plus eventuele scripts, sjablonen of referentiebestanden die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇