Forge Cascaded Shadow Maps logo

Forge Cascaded Shadow Maps

Community
Nebulavenus
forge-cascaded-shadow-maps

Add cascaded shadow maps with PCF soft shadows to an SDL GPU project

Overview

PublisherNebulavenus
Repositoryforge-gpu
Skill nameforge-cascaded-shadow-maps
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 Cascaded Shadow Maps 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-cascaded-shadow-maps
  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-cascaded-shadow-maps .claude/skills/forge-cascaded-shadow-maps
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Forge Cascaded Shadow Maps 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 Cascaded Shadow Maps 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 Cascaded Shadow Maps 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.

Add directional-light cascaded shadow maps (CSM) with 3x3 PCF soft shadows to an SDL3 GPU application. Based on Lesson 15.

When to use

  • You need directional light shadows covering a large area
  • Single shadow maps lack resolution for your scene
  • You want soft shadow edges without expensive techniques

Key API calls

  • SDL_CreateGPUTexture — shadow map textures (D32_FLOAT, DEPTH_STENCIL_TARGET | SAMPLER)
  • SDL_CreateGPUSampler — NEAREST filter, CLAMP_TO_EDGE for shadow map sampling
  • SDL_CreateGPUGraphicsPipeline — shadow pipeline (depth-only, front-face cull, depth bias)
  • SDL_BeginGPURenderPass / SDL_EndGPURenderPass — one pass per cascade (depth only)
  • SDL_BindGPUFragmentSamplers — bind shadow maps + sampler for scene pass
  • SDL_PushGPUVertexUniformData / SDL_PushGPUFragmentUniformData — per-draw uniforms

Correct order

  1. Create shadow map textures + sampler (in SDL_AppInit)
  2. Create shadow pipeline — depth-only, front-face culling, depth bias
  3. Create scene pipeline — binds shadow maps as fragment samplers
  4. Each frame: a. Compute cascade split depths (logarithmic-linear blend) b. Compute light VP matrix per cascade (frustum corners → light-space AABB) c. Shadow pass: render all casters into each cascade's depth map d. Scene pass: render with shadow maps bound, fragment shader selects cascade by view-space depth

Key concepts

  1. Shadow map textures need DEPTH_STENCIL_TARGET | SAMPLER usage flags
  2. Depth-only render pass: no color targets, only depth attachment
  3. Cascade splits: logarithmic-linear blend for practical depth ranges
  4. Light VP matrices: tight orthographic projection from frustum corners
  5. PCF sampling: 3x3 grid averages shadow/lit for soft edges
  6. Store op MUST be STORE (not DONT_CARE) for shadow map depth passes

Pipeline setup

Shadow pipeline (depth-only)

c
/* No color targets — depth only */
pipe.target_info.num_color_targets        = 0;
pipe.target_info.has_depth_stencil_target = true;
pipe.target_info.depth_stencil_format     = SDL_GPU_TEXTUREFORMAT_D32_FLOAT;

/* Front-face culling reduces peter-panning */
pipe.rasterizer_state.cull_mode = SDL_GPU_CULLMODE_FRONT;

/* Depth bias reduces shadow acne */
pipe.rasterizer_state.depth_bias_constant_factor = 2;
pipe.rasterizer_state.depth_bias_slope_factor    = 2.0f;

Shadow map texture

c
SDL_GPUTextureCreateInfo info;
SDL_zero(info);
info.type   = SDL_GPU_TEXTURETYPE_2D;
info.format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT;
info.usage  = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET |
              SDL_GPU_TEXTUREUSAGE_SAMPLER;  /* key: both flags */
info.width  = 2048;
info.height = 2048;
info.layer_count_or_depth = 1;
info.num_levels           = 1;

Shadow sampler

c
SDL_GPUSamplerCreateInfo smp;
SDL_zero(smp);
smp.min_filter     = SDL_GPU_FILTER_NEAREST;
smp.mag_filter     = SDL_GPU_FILTER_NEAREST;
smp.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
smp.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;

Cascade split algorithm

c
/* Lengyel's logarithmic-linear blend */
for (int i = 0; i < NUM_CASCADES; i++) {
    float p = (float)(i + 1) / (float)NUM_CASCADES;
    float log_split = near * SDL_powf(far / near, p);
    float lin_split = near + (far - near) * p;
    splits[i] = lambda * log_split + (1.0f - lambda) * lin_split;
}

Light VP computation per cascade

  1. Unproject 8 NDC corners via inverse camera VP
  2. Interpolate near/far to get cascade slice corners
  3. Compute cascade center, build light view matrix
  4. Transform corners to light space, find tight AABB
  5. Build orthographic projection from AABB
c
mat4 light_view = mat4_look_at(light_pos, center, up);
/* Transform corners to light space → compute AABB */
mat4 light_proj = mat4_orthographic(min_x, max_x, min_y, max_y,
                                     -max_z, -min_z);
mat4 light_vp = mat4_multiply(light_proj, light_view);

Shadow pass render loop

c
for (int ci = 0; ci < NUM_CASCADES; ci++) {
    SDL_GPUDepthStencilTargetInfo depth;
    SDL_zero(depth);
    depth.texture  = shadow_maps[ci];
    depth.load_op  = SDL_GPU_LOADOP_CLEAR;
    depth.store_op = SDL_GPU_STOREOP_STORE;  /* MUST store */
    depth.clear_depth = 1.0f;

    SDL_GPURenderPass *pass = SDL_BeginGPURenderPass(cmd, NULL, 0, &depth);
    SDL_BindGPUGraphicsPipeline(pass, shadow_pipeline);

    /* Draw all shadow casters with light_vp[ci] * model */
    /* ... */

    SDL_EndGPURenderPass(pass);
}

HLSL shadow sampling (fragment shader)

hlsl
float sample_shadow_pcf(Texture2D shadow_map, SamplerState smp,
                         float2 shadow_uv, float current_depth) {
    float shadow = 0.0;
    [unroll]
    for (int y = -1; y <= 1; y++) {
        [unroll]
        for (int x = -1; x <= 1; x++) {
            float2 offset = float2(x, y) * texel_size;
            float map_depth = shadow_map.Sample(smp, shadow_uv + offset).r;
            shadow += (map_depth >= current_depth - bias) ? 1.0 : 0.0;
        }
    }
    return shadow / 9.0;
}

Common mistakes

  • Forgetting SAMPLER usage flag on shadow map texture — it will not be readable in fragment shaders without it
  • Using DONT_CARE for shadow pass store_op — depth data is discarded and shadow maps will be empty
  • Not flipping Y when converting NDC to UV: shadow_uv.y = 1.0 - shadow_uv.y
  • Missing depth bias — causes shadow acne (moire self-shadowing pattern)
  • Culling back faces in shadow pass — should cull FRONT faces instead to reduce peter-panning
  • Not expanding Z range of the light AABB — shadow casters behind the frustum slice won't cast shadows into it

HLSL register map

text
Vertex uniform slot 0 → register(b0, space1)
Vertex uniform slot 1 → register(b1, space1)
Fragment sampler slot N → register(tN, space2) + register(sN, space2)
Fragment uniform slot 0 → register(b0, space3)

Reference

See: Lesson 15 — Cascaded Shadow Maps

Frequently asked questions

What does the Forge Cascaded Shadow Maps AI skill do?

Add cascaded shadow maps with PCF soft shadows to an SDL GPU project

Why use Forge Cascaded Shadow Maps on TypingMind?

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

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

Which AI models can use Forge Cascaded Shadow Maps?

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 Cascaded Shadow Maps?

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

Is the Forge Cascaded Shadow Maps 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 👇