Logo di 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.

Panoramica

AutoreNebulavenus
Repositoryforge-gpu
Nome della skillforge-stencil-testing
Stelle
46
Fork
7
File inclusi
Solo istruzioni
LicenzaZlib
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • Tutto nelle istruzioni

    Tutto ciò che serve al modello è nelle istruzioni: nessun file aggiuntivo da sincronizzare.

  • Open source

    Pubblicata da Nebulavenus su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Forge Stencil Testing in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/forge-stencil-testing
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Nuova skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella nella cartella delle skill di quell'agente.

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
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Forge Stencil Testing in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Forge Stencil Testing non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Forge Stencil Testing non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

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

Domande frequenti

Cosa fa la skill IA 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.

Perché usare Forge Stencil Testing su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Forge Stencil Testing è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Forge Stencil Testing in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/forge-stencil-testing. TypingMind legge il file SKILL.md e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Forge Stencil Testing?

Qualsiasi modello che colleghi in TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Forge Stencil Testing?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Forge Stencil Testing: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Forge Stencil Testing è gratuita?

Sì. È pubblicata su GitHub da Nebulavenus con licenza Zlib. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, modelli o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇