Forge Stencil Testing logo

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.

Overview

PublisherNebulavenus
Repositoryforge-gpu
Skill nameforge-stencil-testing
Stars
46
Forks
7
Bundled files
Instructions only
LicenseZlib
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by Nebulavenus on GitHub. Read the source before you install it.

Installation

Install the Forge Stencil Testing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/forge-stencil-testing
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

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
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Forge Stencil Testing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Forge Stencil Testing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Forge Stencil Testing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

Frequently asked questions

What does the Forge Stencil Testing AI skill do?

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.

Why use Forge Stencil Testing on TypingMind?

Because you install it once and use it with any model. Forge Stencil Testing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Forge Stencil Testing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Nebulavenus/forge-gpu/tree/main/.claude/skills/forge-stencil-testing. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Forge Stencil Testing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Forge Stencil Testing?

As many as you like. As long as a model supports skills, you can use Forge Stencil Testing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Forge Stencil Testing AI skill free?

Yes. It is published on GitHub by Nebulavenus under the Zlib license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇