forge-blending
Add alpha blending, alpha testing, or additive blending to an SDL GPU project. Configure blend state, sort transparent objects, and set up clip/discard for…
от Nebulavenus★ 51 звезда на GitHub
Установить forge-blending в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Add transparency and blending to an SDL3 GPU application. Based on Lesson 16.
When to use
- You need transparent or semi-transparent surfaces (glass, windows, UI)
- You need cutout transparency (foliage, fences, decals)
- You need luminous additive effects (fire, lasers, particle trails)
- You need to render glTF models with BLEND or MASK alpha modes
Key API calls
SDL_CreateGPUGraphicsPipeline— blend state inSDL_GPUColorTargetBlendStateSDL_GPU_BLENDFACTOR_SRC_ALPHA/SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA— standard blendSDL_GPU_BLENDFACTOR_ONE— additive blend (dst factor) or premultiplied (src factor)SDL_GPU_BLENDOP_ADD— most common blend operationclip()in HLSL — discard fragments below an alpha threshold
Correct order
- Create pipelines (in
SDL_AppInit)- Opaque pipeline: no blend, depth write ON
- Alpha-test pipeline: no blend, depth write ON, fragment shader uses
clip() - Standard blend pipeline: blend enabled, depth write OFF
- Additive pipeline: blend enabled (ONE dst factor), depth write OFF
- Each frame — draw in this order: a. Opaque geometry (any order) — fills the depth buffer b. Alpha-tested geometry (any order) — clip/discard, writes depth for visible pixels c. Alpha-blended geometry (sorted back-to-front) — reads but does not write depth d. Additive geometry (any order) — commutative, no sorting needed
Key concepts
- Depth write OFF for all blended pipelines — semi-transparent surfaces must not occlude geometry behind them
- Depth test ON for blended pipelines — transparent surfaces still appear behind opaque ones
- Back-to-front sorting required for standard alpha blend (not for additive)
- Same shader works for opaque and blended — the difference is pipeline config
- Alpha test uses a different shader (with
clip()) but no blend state - Cull mode NONE for transparent surfaces — both sides are often visible
Pipeline setup
Standard alpha blend
SDL_GPUColorTargetDescription color_target;
SDL_zero(color_target);
color_target.format = swapchain_format;
color_target.blend_state.enable_blend = true;
/* Color: src * srcAlpha + dst * (1 - srcAlpha) */
color_target.blend_state.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA;
color_target.blend_state.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
color_target.blend_state.color_blend_op = SDL_GPU_BLENDOP_ADD;
/* Alpha: src * 1 + dst * (1 - srcAlpha) */
color_target.blend_state.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE;
color_target.blend_state.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
color_target.blend_state.alpha_blend_op = SDL_GPU_BLENDOP_ADD;
color_target.blend_state.color_write_mask =
SDL_GPU_COLORCOMPONENT_R | SDL_GPU_COLORCOMPONENT_G |
SDL_GPU_COLORCOMPONENT_B | SDL_GPU_COLORCOMPONENT_A;
/* CRITICAL: depth write must be OFF */
pipe.depth_stencil_state.enable_depth_test = true;
pipe.depth_stencil_state.enable_depth_write = false; /* <-- key difference */
pipe.depth_stencil_state.compare_op = SDL_GPU_COMPAREOP_LESS_OR_EQUAL;
Additive blend
/* Only the blend factors differ from standard blend */
color_target.blend_state.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA;
color_target.blend_state.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE; /* additive */
color_target.blend_state.color_blend_op = SDL_GPU_BLENDOP_ADD;
/* Alpha: preserve existing */
color_target.blend_state.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ZERO;
color_target.blend_state.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE;
Premultiplied alpha
/* src factor is ONE (not SRC_ALPHA) because RGB already includes alpha */
color_target.blend_state.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE;
color_target.blend_state.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
Alpha test shader (HLSL)
float4 main(PSInput input) : SV_Target
{
float4 texel = diffuse_tex.Sample(diffuse_smp, input.uv);
float4 color = texel * base_color;
clip(color.a - alpha_cutoff); /* discard if alpha < cutoff */
return color;
}
Back-to-front sorting
Sort by the nearest point on each object's world-space AABB to the camera, not the object center. Center-distance sorting fails when two transparent objects share the same node position (e.g., a flat plane inside a glass box). The AABB nearest-point distance correctly distinguishes them because the box's front face is closer to the camera than the interior plane.
/* Compute mesh-local AABB once during upload (min/max of vertex positions).
* Each frame, transform it to world space with Arvo's method, then sort. */
vec3 w_min, w_max;
transform_aabb(&node->world_transform, prim->aabb_min, prim->aabb_max,
&w_min, &w_max);
/* Clamp camera position to AABB to find nearest point */
float nx = clamp(cam.x, w_min.x, w_max.x);
float ny = clamp(cam.y, w_min
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл forge-blending?
Add alpha blending, alpha testing, or additive blending to an SDL GPU project. Configure blend state, sort transparent objects, and set up clip/discard for cutout transparency.
Как установить скилл forge-blending?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл forge-blending запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…