figma-shaders

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create and update Figma shaders

创建和更新 Figma Shader

Load this skill before every
create_shader
or
update_shader
call. It covers account-library shader authoring through the Figma MCP server. Reading or applying an existing shader does not require this skill.
Shaders have two kinds:
  • effect
    samples and transforms the rendered layer beneath it. Use it for blur, distortion, glow, color grading, pixelation, halftone, or other post-processing.
  • fill
    generates pixels without an input raster. Use it for gradients, patterns, noise, textures, and procedural backgrounds.
Do not silently switch kinds during an update. The
kind
passed to
update_shader
must match the existing shader.
在每次调用
create_shader
或
update_shader
前加载此 skill。它介绍了如何通过 Figma MCP server 编写账户库中的 Shader。读取或应用现有 Shader 不需要加载此 skill。
Shader 分为两种:
  • effect
    对其下方已渲染的图层进行采样和变换。适用于模糊、失真、辉光、色彩分级、像素化、半色调或其他后处理。
  • fill
    在没有输入栅格图的情况下生成像素。适用于渐变、图案、噪声、纹理和程序化背景。
更新时不要在未说明的情况下切换类型。传给
update_shader
的
kind
必须与现有 Shader 的类型一致。

Create workflow

创建流程

  1. Decide whether the request is an effect or fill. Ask only when the visual intent does not resolve the distinction.
  2. Resolve
    planKey
    . Reuse one supplied by the user; otherwise call
    whoami
    . Use the sole eligible plan automatically, or ask the user to choose when several materially different plans are available.
  3. Call
    create_shader
    once with a concise name, description, selected
    kind
    , and
    planKey
    . This creates a starter scaffold, not the requested final shader.
  4. Call
    get_shader
    with the returned
    id
    , then read every source URI. If the client cannot read MCP resources, call
    get_shader
    with
    includeSource: true
    instead. This establishes the runtime imports and the scaffold's fixed metadata contract.
  5. Author the complete replacement
    main.ts
    for the requested result.
  6. Call
    update_shader
    with the returned
    id
    , the same
    kind
    ,
    files: [{ path: "main.ts", content: "..." }]
    , and a specific
    commitMessage
    . Use
    metadata
    when changing the name, description, or animation capabilities. Set
    metadata.isAnimated: true
    when the source reads time-related frame inputs and
    metadata.usesMouse: true
    when it reads
    frame.mousePosition
    .
Never stop after
create_shader
: the starter scaffold is only a structural starting point.
  1. 判断请求属于 effect 还是 fill。仅当视觉意图无法明确区分二者时才询问用户。
  2. 解析
    planKey
    。如果用户已提供,则直接复用;否则调用
    whoami
    。如果只有一个符合条件的套餐,则自动使用;如果有多个实质不同的套餐,则让用户选择。
  3. 使用简洁的名称、描述、选定的
    kind
    和
    planKey
    调用一次
    create_shader
    。这只会创建初始脚手架,而不是用户要求的最终 Shader。
  4. 使用返回的
    id
    调用
    get_shader
    ,然后读取每个源 URI。如果客户端无法读取 MCP resources,则改用
    includeSource: true
    调用
    get_shader
    。这用于确定运行时导入项以及脚手架固定的元数据契约。
  5. 针对预期结果编写完整的替换版
    main.ts
    。
  6. 使用返回的
    id
    、相同的
    kind
    、
    files: [{ path: "main.ts", content: "..." }]
    和具体的
    commitMessage
    调用
    update_shader
    。更改名称、描述或动画能力时,使用
    metadata
    。如果源代码读取与时间相关的帧输入,则设置
    metadata.isAnimated: true
    ;如果源代码读取
    frame.mousePosition
    ,则设置
    metadata.usesMouse: true
    。
绝不能在
create_shader
后停止:初始脚手架只是结构性起点。

Update workflow

更新流程

  1. Identify the shader with
    list_shaders
    , then call
    get_shader
    . Use its
    type
    (
    effect
    or
    fill
    ) as the required update kind.
  2. Read every source URI returned by
    get_shader
    before editing. If the client cannot read MCP resources, call it with
    includeSource: true
    . Treat those files as the current source of truth.
  3. Preserve existing controls and behavior unless the user asks to change them.
  4. Call
    update_shader
    with the complete replacement
    main.ts
    in the
    files
    array, not a diff or partial fragment. An empty
    files
    array is valid only for a metadata-only update.
  1. 使用
    list_shaders
    查找目标 Shader,然后调用
    get_shader
    。使用其
    type
    (
    effect
    或
    fill
    )作为更新时必须使用的 kind。
  2. 编辑前读取
    get_shader
    返回的每个源 URI。如果客户端无法读取 MCP resources,则使用
    includeSource: true
    调用。将这些文件视为当前源代码依据。
  3. 除非用户要求更改,否则保留现有控件和行为。
  4. 调用
    update_shader
    时,在
    files
    数组中提供完整的替换版
    main.ts
    ,而不是差异片段或不完整片段。只有仅更新元数据时,才可以将
    files
    数组设为空。

Authoring rules

编写规则

  • Before writing the
    main.ts
    replacement, read Shader source authoring. It contains the required module shape, WebGPU lifecycle, supported parameter schemas, effect/fill alpha rules, and WGSL failure checklist.
  • Match animation metadata to the source. Set
    metadata.isAnimated: true
    if
    main.ts
    reads
    frame.time
    ,
    frame.deltaTime
    , or
    frame.frame
    , and set
    metadata.usesMouse: true
    if it reads
    frame.mousePosition
    . Set the corresponding value to
    false
    when removing the last such use.
    update_shader
    applies these metadata fields to the fixed
    features.json
    manifest even though that file cannot be replaced directly.
  • Prefer
    frame.time
    for animation so skipped frames do not change the result. It is an absolute millisecond clock; convert it to seconds with
    Number(frame.time) * 0.001
    when useful.
  • Expose controls for values users are likely to tune per layer; hardcode implementation details.
  • Keep numeric ranges bounded and defaults visually useful.
  • For effects, sample the input raster intentionally. For fills, do not assume an input raster exists.
  • Treat a non-error
    update_shader
    result as success. Record the returned version when present; a successful response may omit it.
  • On a build error, use the returned compiler output to make the smallest source correction and retry once. If it still fails, surface the error instead of repeatedly rewriting the shader.
  • If the tool reports that animation or mouse input is unavailable, treat that as a terminal capability gate: do not retry or attempt to bypass it. Offer to author a static shader whose exposed properties can be keyframed in Motion mode instead.
  • 编写替换版
    main.ts
    前,读取 Shader 源代码编写。其中包含必需的模块结构、WebGPU 生命周期、受支持的参数 schema、effect/fill alpha 规则和 WGSL 失败检查清单。
  • 使动画元数据与源代码保持一致。如果
    main.ts
    读取
    frame.time
    、
    frame.deltaTime
    或
    frame.frame
    ,则设置
    metadata.isAnimated: true
    ;如果读取
    frame.mousePosition
    ,则设置
    metadata.usesMouse: true
    。移除最后一次相关使用时,将对应值设为
    false
    。即使无法直接替换
    features.json
    ,
    update_shader
    仍会将这些元数据字段应用到固定的
    features.json
    清单中。
  • 动画优先使用
    frame.time
    ,这样跳过帧也不会改变结果。它是一个绝对毫秒时钟;如有需要,使用
    Number(frame.time) * 0.001
    转换为秒。
  • 为用户可能按图层调整的值提供控件;实现细节则使用硬编码。
  • 限定数值范围,并确保默认值在视觉上实用。
  • 对于 effect,应有意识地采样输入栅格图;对于 fill,不要假定存在输入栅格图。
  • 将非错误的
    update_shader
    结果视为成功。如果返回了 version,则记录下来;成功响应可能不会包含该字段。
  • 出现构建错误时,根据返回的编译器输出进行最小幅度的源代码修正,并重试一次。如果仍然失败,则报告错误,不要反复重写 Shader。
  • 如果工具报告动画或鼠标输入不可用,将其视为不可绕过的能力边界:不要重试,也不要尝试绕过。此时可以改为提供静态 Shader,其公开属性可在 Motion mode 中设置关键帧。

Completion

完成

Report the shader name, kind, and id, plus the returned version when present. Briefly identify the controls or behavior that were added. Construct and include a clickable URL that opens a new Design file with the unpublished shader ready to try, using the exact shader id as
try-tool-resource-content-id
. Set
try-tool-resource-type
from the shader kind:
gen_effect
for an effect and
gen_fill
for a fill.
https://www.figma.com/file/new?try-tool-resource-content-id=<id>&try-tool-resource-type=<gen_effect|gen_fill>&type=design&mode=design
After presenting the new-file link, ask whether the user wants to open the shader in an existing Figma Design file instead. If yes, reuse a file URL already provided or ask for one, then add the same
try-tool-resource-content-id
and resolved
try-tool-resource-type
query parameters to that URL. Never guess the file URL.
Replace the type placeholder with exactly one value; do not include angle brackets or the pipe in the returned URL.
报告 Shader 名称、kind 和 id,并在存在时报告返回的 version。简要说明新增了哪些控件或行为。构建并包含一个可点击 URL,用于打开新的 Design file,其中未发布的 Shader 已准备好供试用。将准确的 Shader id 用作
try-tool-resource-content-id
。根据 Shader kind 设置
try-tool-resource-type
:effect 对应
gen_effect
,fill 对应
gen_fill
。
https://www.figma.com/file/new?try-tool-resource-content-id=<id>&try-tool-resource-type=<gen_effect|gen_fill>&type=design&mode=design
展示新文件链接后,询问用户是否希望改为在现有 Figma Design file 中打开该 Shader。如果用户同意,复用已提供的文件 URL 或向用户索要一个,然后将相同的
try-tool-resource-content-id
和解析后的
try-tool-resource-type
查询参数添加到该 URL。绝不猜测文件 URL。
将类型占位符替换为且仅替换为一个实际值;返回的 URL 中不得包含尖括号或竖线。