forge-3d-picking
Add GPU-based 3D object picking to an SDL GPU project. Implement color-ID picking with offscreen render targets, stencil-ID picking with per-object reference…
от Nebulavenus★ 51 звезда на GitHub
Установить forge-3d-picking в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
3D Picking
Add GPU-based object picking to an SDL GPU project. This skill covers two
picking methods (color-ID and stencil-ID), GPU-to-CPU data transfer with
SDL_DownloadFromGPUTexture, transfer buffer readback, and stencil outline
selection highlighting.
Based on GPU Lesson 37.
When to use
- You need to identify which object the user clicked on in a 3D scene
- You want pixel-perfect selection without CPU-side ray casting
- You need to highlight selected objects with a visible outline
- You want to read data back from the GPU to the CPU
Color-ID picking pipeline
Color-ID picking renders each object with a unique flat color to an offscreen texture, then reads back the single pixel under the cursor to identify the object. This is the recommended approach — it is portable, supports up to 65,535 objects, and the RGBA readback has a consistent byte layout across all GPU backends.
Index-to-color encoding
/* Convert object index to a unique RGB color.
* Index 0 maps to ID 1 (background is (0,0,0) = no object). */
static void index_to_color(int index, float *r, float *g, float *b)
{
int id = index + 1;
*r = (float)((id >> 0) & 0xFF) / 255.0f;
*g = (float)((id >> 8) & 0xFF) / 255.0f;
*b = 0.0f;
}
/* Decode a read-back pixel back to an object index. Returns -1 for background. */
static int color_to_index(Uint8 r, Uint8 g, Uint8 b)
{
(void)b;
int id = (int)r | ((int)g << 8);
if (id == 0) return -1;
return id - 1;
}
Offscreen render target
Create an R8G8B8A8_UNORM texture as the color-ID render target. Do not use
the swapchain format — you need a known pixel layout for reliable CPU readback.
Also create a separate depth buffer for occlusion:
/* Color-ID offscreen target */
SDL_GPUTextureCreateInfo ci;
SDL_zero(ci);
ci.type = SDL_GPU_TEXTURETYPE_2D;
ci.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
ci.width = window_w;
ci.height = window_h;
ci.layer_count_or_depth = 1;
ci.num_levels = 1;
ci.usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
SDL_GPUTexture *id_texture = SDL_CreateGPUTexture(device, &ci);
/* ID pass depth buffer — separate from the main scene depth */
SDL_GPUTextureCreateInfo depth_ci;
SDL_zero(depth_ci);
depth_ci.type = SDL_GPU_TEXTURETYPE_2D;
depth_ci.format = depth_stencil_fmt; /* D24_UNORM_S8_UINT or D32_FLOAT_S8_UINT */
depth_ci.width = window_w;
depth_ci.height = window_h;
depth_ci.layer_count_or_depth = 1;
depth_ci.num_levels = 1;
depth_ci.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
SDL_GPUTexture *id_depth = SDL_CreateGPUTexture(device, &depth_ci);
ID pass shaders
The vertex shader only needs MVP — no lighting outputs:
cbuffer IdVertUniforms : register(b0, space1)
{
column_major float4x4 mvp;
};
struct VSInput
{
float3 position : TEXCOORD0;
float3 normal : TEXCOORD1; /* unused — must match vertex layout */
};
float4 main(VSInput input) : SV_Position
{
return mul(mvp, float4(input.position, 1.0));
}
The fragment shader outputs the flat ID color:
cbuffer IdFragUniforms : register(b0, space3)
{
float4 id_color;
};
float4 main(float4 pos : SV_Position) : SV_Target
{
return id_color;
}
ID pipeline configuration
SDL_GPUColorTargetDescription ct;
SDL_zero(ct);
ct.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
SDL_GPUGraphicsPipelineCreateInfo pi;
SDL_zero(pi);
pi.vertex_shader = id_pass_vert;
pi.fragment_shader = id_pass_frag;
pi.vertex_input_state = scene_vis; /* same vertex layout as scene */
pi.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
pi.rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL;
pi.rasterizer_state.cull_mode = SDL_GPU_CULLMODE_BACK;
pi.rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
pi.depth_stencil_state.compare_op = SDL_GPU_COMPAREOP_LESS;
pi.depth_stencil_state.enable_depth_test = true;
pi.depth_stencil_state.enable_depth_write = true;
pi.depth_stencil_state.enable_stencil_test = false;
pi.target_info.color_target_descriptions = &ct;
pi.target_info.num_color_targets = 1;
pi.target_info.depth_stencil_format = depth_stencil_fmt;
pi.target_info.has_depth_stencil_target = true;
ID pass execution
Only run the ID pass on click frames to avoid wasting GPU time:
if (pick_pending && picking_method == PICK_COLOR_ID) {
SDL_GPUColorTargetInfo id_color_target;
SDL_zero(id_color_target);
id_color_target.texture = id_texture;
id_color_target.load_op = SDL_GPU_LOADOP_CLEAR;
id_color_target.store_op = SDL_GPU_STOREOP_STORE;
/* Clear to (0,0,0,0) — decodes to "no object" */
SDL_GPUDepthStencilTargetInfo id_ds;
SDL_zero(id_ds);
id_ds.texture = id_depth;
id_ds.clear_depth = 1.0f;
id_ds.load_op = SDL_GPU_LOADOP_CLEAR;
id_ds.store_op = SDL_GPU_STOREOP_DONT_CARE;
id_ds.cycle = true;
SDL_GPURenderPass *pass = SDL_BeginGPURenderPass(
cmd, &id_color_target, 1, &id_ds);
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл forge-3d-picking?
Add GPU-based 3D object picking to an SDL GPU project. Implement color-ID picking with offscreen render targets, stencil-ID picking with per-object reference values, GPU-to-CPU readback with transfer buffers, and stencil outline selection highlighting.
Как установить скилл forge-3d-picking?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл forge-3d-picking запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
AnthropicGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
webapp-testing
AnthropicToolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
brand-guidelines
AnthropicApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
web-artifacts-builder
AnthropicSuite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…