Forge Edge Detection logo

Forge Edge Detection

Community
Nebulavenus
forge-edge-detection

Add Sobel edge detection on G-buffer data (depth + normals via MRT), stencil-based X-ray vision with depth_fail_op, and Fresnel ghost silhouettes with additive blending to an SDL GPU project.

Overview

PublisherNebulavenus
Repositoryforge-gpu
Skill nameforge-edge-detection
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 Edge Detection 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-edge-detection
  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-edge-detection .claude/skills/forge-edge-detection
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Forge Edge Detection 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 Edge Detection 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 Edge Detection 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.

Edge Detection

Add post-process edge detection, stencil X-ray vision, and Fresnel ghost silhouettes to an SDL GPU project. Uses G-buffer MRT output (depth + normals) for Sobel edge detection, depth_fail_op for occluded-object marking, and additive blending for translucent ghost rendering.

Based on GPU Lesson 36.

When to use

  • You want post-process outlines from depth/normal discontinuities
  • You need X-ray vision to reveal occluded objects behind walls
  • You want ghostly translucent silhouettes for hidden geometry
  • You need an alternative to L34's stencil-expansion outlines

Pipeline overview (6 pipelines)

  1. Shadow pipeline — Depth-only pass for shadow mapping
  2. Scene pipeline (MRT) — Renders lit scene to two color targets: color (RT0) and view-space normals (RT1), plus depth-stencil
  3. Grid pipeline (MRT) — Same MRT layout for the floor grid
  4. Edge composite pipeline — Full-screen quad, samples depth + normal textures, runs Sobel filter, composites edges onto the scene
  5. X-ray mark pipeline — Draws occluded objects with depth_fail_op = INCREMENT_AND_WRAP, color_write_mask = 0, writing only to stencil where fragments fail the depth test
  6. Ghost pipeline — Draws the same objects again with stencil test NOT_EQUAL ref=0 and additive blending for Fresnel ghost silhouettes

G-buffer setup (MRT)

The scene pass renders to two color targets simultaneously:

c
/* RT0: scene color (RGBA8) */
/* RT1: view-space normals (RGBA16_FLOAT or RGBA8_SNORM) */
SDL_GPUColorTargetInfo color_targets[2] = {
    { .texture = scene_color_tex, .load_op = SDL_GPU_LOADOP_CLEAR },
    { .texture = normal_tex,      .load_op = SDL_GPU_LOADOP_CLEAR },
};

The fragment shader outputs to both targets:

hlsl
struct PSOutput {
    float4 color  : SV_Target0;
    float4 normal : SV_Target1;
};

Pipeline must declare two color target descriptions to match.

Sobel edge detection

Sample depth and normal textures in a 3x3 neighborhood. Apply Sobel operators (horizontal Gx and vertical Gy kernels) separately to depth and to each normal component. Combine magnitudes:

hlsl
/* Sobel kernels */
/* Gx = [-1 0 1; -2 0 2; -1 0 1] */
/* Gy = [-1 -2 -1; 0 0 0; 1 2 1] */

float depth_edge = sqrt(gx_depth * gx_depth + gy_depth * gy_depth);
float normal_edge = sqrt(gx_nx*gx_nx + gy_nx*gy_nx
                       + gx_ny*gx_ny + gy_ny*gy_ny
                       + gx_nz*gx_nz + gy_nz*gy_nz);

float edge = saturate(depth_edge * depth_scale + normal_edge * normal_scale);

Threshold and composite: final_color = lerp(scene_color, edge_color, edge).

X-ray mark technique (depth_fail_op)

The key insight: depth_fail_op fires when a fragment is behind existing geometry. By drawing the target object with this operation, we mark exactly the pixels where it is occluded.

c
/* X-ray mark pipeline stencil state */
SDL_GPUStencilOpState xray_stencil = {
    .fail_op       = SDL_GPU_STENCILOP_KEEP,
    .pass_op       = SDL_GPU_STENCILOP_KEEP,           /* visible parts: no mark */
    .depth_fail_op = SDL_GPU_STENCILOP_INCREMENT_AND_WRAP, /* occluded: mark */
    .compare_op    = SDL_GPU_COMPAREOP_ALWAYS,
};

Color write mask = 0 and depth write = false. This pass is invisible — it only writes stencil values where the object is hidden behind other geometry.

Ghost silhouette technique

After the X-ray mark pass, draw the object again with:

  • Stencil test: compare_op = NOT_EQUAL, reference = 0 (draw only where marked)
  • Additive blending: src_color_blendfactor = ONE, dst = ONE
  • Fresnel-based opacity: brighter at edges where dot(N, V) is low
hlsl
/* Fresnel ghost effect */
float fresnel = 1.0 - saturate(dot(normal, view_dir));
fresnel = pow(fresnel, fresnel_power);
return float4(ghost_color * fresnel * intensity, 0.0);

The additive blend makes the ghost glow through geometry without needing alpha sorting.

Clearing stencil

Clear stencil alongside depth at the start of 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,
};

Key patterns

PatternValue
depth_fail_opSDL_GPU_STENCILOP_INCREMENT_AND_WRAP
X-ray mark color_write_mask0 (invisible pass)
X-ray mark depth_writefalse
Ghost stencil compare_opSDL_GPU_COMPAREOP_NOT_EQUAL
Ghost stencil reference0
Ghost blendAdditive (SRC=ONE, DST=ONE)
MRT count2 (color + normals)

Key API calls

  • SDL_BeginGPURenderPass(cmd, color_targets, 2, &ds) — MRT with 2 color targets
  • SDL_SetGPUStencilReference(pass, ref) — set stencil compare reference value
  • SDL_DrawGPUPrimitives(pass, 3, 1, 0, 0) — fullscreen triangle (no vertex buffer)
  • SDL_GPU_STENCILOP_INCREMENT_AND_WRAP — depth_fail_op for X-ray marking
  • SDL_GPU_COMPAREOP_NOT_EQUAL — stencil test for ghost pass (ref=0, pass where >0)
  • SDL_GPU_BLENDFACTOR_ONE (src + dst) — additive blending for ghost glow
  • SDL_GPUTextureSupportsFormat — negotiate D24S8 with SAMPLER usage

Common mistakes

  • Forgetting MRT pipeline color target count — The pipeline must declare the same number of color target descriptions as render pass color targets. Mismatched counts cause validation errors or undefined behavior.
  • Wrong depth_fail_op direction — depth_fail_op fires when the fragment is behind existing depth. Make sure the scene depth is already established before the X-ray mark pass.
  • Not disabling depth writes for X-ray mark — If the mark pass writes depth, it corrupts the depth buffer and prevents the ghost pass from rendering correctly.
  • Missing stencil clear — Stale stencil values from the previous frame cause ghost artifacts everywhere. Always clear stencil at pass start.
  • Sobel on linear depth vs hyperbolic depth — Raw depth buffer values are hyperbolic (non-linear). For better edge detection, linearize depth first or adjust the depth scale threshold.

Cross-references

Frequently asked questions

What does the Forge Edge Detection AI skill do?

Add Sobel edge detection on G-buffer data (depth + normals via MRT), stencil-based X-ray vision with depth_fail_op, and Fresnel ghost silhouettes with additive blending to an SDL GPU project.

Why use Forge Edge Detection on TypingMind?

Because you install it once and use it with any model. Forge Edge Detection 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 Edge Detection in TypingMind?

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

Which AI models can use Forge Edge Detection?

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 Edge Detection?

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

Is the Forge Edge Detection 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 👇