Supporting material availability
This catalog copy contains the inline guidance below, but does not include the following supporting paths. They are external prerequisites, not bundled files:
./references/shader-basics.md
./references/sdf2d-reference.md
Ask for the original supporting material or an existing installation before using a step that depends on these paths; this catalog does not identify a verified download source for them. Resolve each path relative to that installation, inspect its contents, and verify any applicable license and execution prerequisites. Do not run a command or claim a referenced procedure was followed until its required file exists. Do not fabricate the missing scripts or treat an unrelated file with the same name as equivalent. Independent steps fully documented here can proceed within the user’s authorized scope; report any dependent step as unavailable.
Makepad Shaders Skill
Version: makepad-widgets (dev branch) | Last Updated: 2026-01-19
Check for updates: https://crates.io/crates/makepad-widgets
You are an expert at Makepad shaders. Help users by:
- Writing code: Generate shader code following the patterns below
- Answering questions: Explain shader language, Sdf2d, built-in functions
When to Use
- You need to write or debug Makepad shader code, custom drawing, or SDF-based visuals.
- The task involves
draw_bg, Sdf2d, gradients, effects, or GPU-rendered widget appearance.
- You want Makepad shader patterns and APIs rather than generic GLSL advice.
Documentation
Refer to the local files for detailed documentation:
./references/shader-basics.md - Shader language fundamentals
./references/sdf2d-reference.md - Complete Sdf2d API reference
Advanced Patterns
The upstream _base/ and community pattern collections are not bundled. The table below is an upstream navigation list, not evidence these examples exist locally:
| Pattern |
Description |
| 01-shader-structure |
Shader fundamentals |
| 02-shader-math |
Mathematical functions |
| 03-sdf-shapes |
SDF shape primitives |
| 04-sdf-drawing |
Advanced SDF drawing |
| 05-progress-track |
Progress indicators |
| 09-loading-spinner |
Loading animations |
| 10-hover-effect |
Hover visual effects |
| 11-gradient-effects |
Color gradients |
| 12-shadow-glow |
Shadow and glow |
| 13-disabled-state |
Disabled visuals |
| 14-toggle-checkbox |
Toggle animations |
Community contributions: ./community/
IMPORTANT: Documentation Completeness Check
Before answering questions, Claude MUST:
- Read the relevant reference file(s) listed above
- If file read fails or file is empty:
- Inform user: "本地文档不完整,建议运行
/sync-crate-skills makepad --force 更新文档"
- Use the inline patterns only as version-dependent sketches and label uncertain API details; do not claim unavailable documentation was checked
- If reference file exists, incorporate its content into the answer
Key Patterns
1. Basic Custom Shader
<View> {
show_bg: true
draw_bg: {
// Shader uniforms
color: #FF0000
// Custom pixel shader
fn pixel(self) -> vec4 {
return self.color;
}
}
}
2. Rounded Rectangle with Border
<View> {
show_bg: true
draw_bg: {
color: #333333
border_color: #666666
border_radius: 8.0
border_size: 1.0
fn pixel(self) -> vec4 {
let sdf = Sdf2d::viewport(self.pos * self.rect_size);
sdf.box(1.0, 1.0,
self.rect_size.x - 2.0,
self.rect_size.y - 2.0,
self.border_radius);
sdf.fill_keep(self.color);
sdf.stroke(self.border_color, self.border_size);
return sdf.result;
}
}
}
3. Gradient Background
<View> {
show_bg: true
draw_bg: {
color: #FF0000
color_2: #0000FF
fn pixel(self) -> vec4 {
let t = self.pos.x; // Horizontal gradient
return mix(self.color, self.color_2, t);
}
}
}
4. Circle Shape
<View> {
show_bg: true
draw_bg: {
color: #0066CC
fn pixel(self) -> vec4 {
let sdf = Sdf2d::viewport(self.pos * self.rect_size);
let center = self.rect_size * 0.5;
let radius = min(center.x, center.y) - 1.0;
sdf.circle(center.x, center.y, radius);
sdf.fill(self.color);
return sdf.result;
}
}
}
Shader Structure
| Component |
Description |
draw_* |
Shader container (draw_bg, draw_text, draw_icon) |
| Uniforms |
Typed properties accessible in shader |
fn pixel(self) |
Fragment shader function |
fn vertex(self) |
Vertex shader function (optional) |
Sdf2d |
2D signed distance field helper |
Built-in Variables
| Variable |
Type |
Description |
self.pos |
vec2 |
Normalized position (0-1) |
self.rect_size |
vec2 |
Widget size in pixels |
self.rect_pos |
vec2 |
Widget position |
Sdf2d Quick Reference
| Category |
Functions |
| Shapes |
circle, rect, box, hexagon |
| Paths |
move_to, line_to, close_path |
| Fill/Stroke |
fill, fill_keep, stroke, stroke_keep |
| Boolean |
union, intersect, subtract |
| Transform |
translate, rotate, scale |
| Effects |
glow, glow_keep, gloop |
Built-in Functions (GLSL)
| Category |
Functions |
| Math |
abs, sign, floor, ceil, fract, min, max, clamp |
| Trig |
sin, cos, tan, asin, acos, atan |
| Interp |
mix, step, smoothstep |
| Vector |
length, distance, dot, cross, normalize |
| Exp |
pow, exp, log, sqrt |
When Writing Code
- Always use
show_bg: true to enable background shader
- Use
Sdf2d::viewport() to create SDF context
- Return
vec4 (RGBA) from fn pixel()
- Uniforms must be declared before shader functions
- Use
self. prefix to access uniforms and built-ins
When Answering Questions
- Makepad shaders use Rust-like syntax, compiled to GPU code
- Every widget can have custom shaders (draw_bg, draw_text, etc.)
- Shaders are live-reloaded - edit and see changes instantly
- Sdf2d is the primary tool for 2D shape rendering
- GLSL ES 1.0 built-in functions are available
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: makepad-shaders3description: 'CRITICAL: Use for Makepad shader system. Triggers on:45 makepad shader, makepad draw_bg, Sdf2d, makepad pixel,67 makepad glsl, makepad sdf, draw_quad, makepad gpu,89 makepad 着色器, makepad shader 语法, makepad 绘制1011 '12metadata:13 source: https://skillmd.com/skills/sickn33/makepad-shaders14 aas-risk: critical15 aas-source: community16 aas-date-added: '2026-03-06'17---1819## Supporting material availability2021This catalog copy contains the inline guidance below, but does not include the following supporting paths. They are external prerequisites, not bundled files:2223- `./references/shader-basics.md`24- `./references/sdf2d-reference.md`2526Ask for the original supporting material or an existing installation before using a step that depends on these paths; this catalog does not identify a verified download source for them. Resolve each path relative to that installation, inspect its contents, and verify any applicable license and execution prerequisites. Do not run a command or claim a referenced procedure was followed until its required file exists. Do not fabricate the missing scripts or treat an unrelated file with the same name as equivalent. Independent steps fully documented here can proceed within the user’s authorized scope; report any dependent step as unavailable.272829# Makepad Shaders Skill3031> **Version:** makepad-widgets (dev branch) | **Last Updated:** 2026-01-1932>33> Check for updates: https://crates.io/crates/makepad-widgets3435You are an expert at Makepad shaders. Help users by:36- **Writing code**: Generate shader code following the patterns below37- **Answering questions**: Explain shader language, Sdf2d, built-in functions3839## When to Use40- You need to write or debug Makepad shader code, custom drawing, or SDF-based visuals.41- The task involves `draw_bg`, `Sdf2d`, gradients, effects, or GPU-rendered widget appearance.42- You want Makepad shader patterns and APIs rather than generic GLSL advice.4344## Documentation4546Refer to the local files for detailed documentation:47- `./references/shader-basics.md` - Shader language fundamentals48- `./references/sdf2d-reference.md` - Complete Sdf2d API reference4950## Advanced Patterns5152The upstream `_base/` and community pattern collections are not bundled. The table below is an upstream navigation list, not evidence these examples exist locally:5354| Pattern | Description |55|---------|-------------|56| 01-shader-structure | Shader fundamentals |57| 02-shader-math | Mathematical functions |58| 03-sdf-shapes | SDF shape primitives |59| 04-sdf-drawing | Advanced SDF drawing |60| 05-progress-track | Progress indicators |61| 09-loading-spinner | Loading animations |62| 10-hover-effect | Hover visual effects |63| 11-gradient-effects | Color gradients |64| 12-shadow-glow | Shadow and glow |65| 13-disabled-state | Disabled visuals |66| 14-toggle-checkbox | Toggle animations |6768Community contributions: `./community/`6970## IMPORTANT: Documentation Completeness Check7172**Before answering questions, Claude MUST:**73741. Read the relevant reference file(s) listed above752. If file read fails or file is empty:76 - Inform user: "本地文档不完整,建议运行 `/sync-crate-skills makepad --force` 更新文档"77 - Use the inline patterns only as version-dependent sketches and label uncertain API details; do not claim unavailable documentation was checked783. If reference file exists, incorporate its content into the answer7980## Key Patterns8182### 1. Basic Custom Shader8384```rust85<View> {86 show_bg: true87 draw_bg: {88 // Shader uniforms89 color: #FF00009091 // Custom pixel shader92 fn pixel(self) -> vec4 {93 return self.color;94 }95 }96}97```9899### 2. Rounded Rectangle with Border100101```rust102<View> {103 show_bg: true104 draw_bg: {105 color: #333333106 border_color: #666666107 border_radius: 8.0108 border_size: 1.0109110 fn pixel(self) -> vec4 {111 let sdf = Sdf2d::viewport(self.pos * self.rect_size);112 sdf.box(1.0, 1.0,113 self.rect_size.x - 2.0,114 self.rect_size.y - 2.0,115 self.border_radius);116 sdf.fill_keep(self.color);117 sdf.stroke(self.border_color, self.border_size);118 return sdf.result;119 }120 }121}122```123124### 3. Gradient Background125126```rust127<View> {128 show_bg: true129 draw_bg: {130 color: #FF0000131 color_2: #0000FF132133 fn pixel(self) -> vec4 {134 let t = self.pos.x; // Horizontal gradient135 return mix(self.color, self.color_2, t);136 }137 }138}139```140141### 4. Circle Shape142143```rust144<View> {145 show_bg: true146 draw_bg: {147 color: #0066CC148149 fn pixel(self) -> vec4 {150 let sdf = Sdf2d::viewport(self.pos * self.rect_size);151 let center = self.rect_size * 0.5;152 let radius = min(center.x, center.y) - 1.0;153 sdf.circle(center.x, center.y, radius);154 sdf.fill(self.color);155 return sdf.result;156 }157 }158}159```160161## Shader Structure162163| Component | Description |164|-----------|-------------|165| `draw_*` | Shader container (draw_bg, draw_text, draw_icon) |166| Uniforms | Typed properties accessible in shader |167| `fn pixel(self)` | Fragment shader function |168| `fn vertex(self)` | Vertex shader function (optional) |169| `Sdf2d` | 2D signed distance field helper |170171## Built-in Variables172173| Variable | Type | Description |174|----------|------|-------------|175| `self.pos` | vec2 | Normalized position (0-1) |176| `self.rect_size` | vec2 | Widget size in pixels |177| `self.rect_pos` | vec2 | Widget position |178179## Sdf2d Quick Reference180181| Category | Functions |182|----------|-----------|183| Shapes | `circle`, `rect`, `box`, `hexagon` |184| Paths | `move_to`, `line_to`, `close_path` |185| Fill/Stroke | `fill`, `fill_keep`, `stroke`, `stroke_keep` |186| Boolean | `union`, `intersect`, `subtract` |187| Transform | `translate`, `rotate`, `scale` |188| Effects | `glow`, `glow_keep`, `gloop` |189190## Built-in Functions (GLSL)191192| Category | Functions |193|----------|-----------|194| Math | `abs`, `sign`, `floor`, `ceil`, `fract`, `min`, `max`, `clamp` |195| Trig | `sin`, `cos`, `tan`, `asin`, `acos`, `atan` |196| Interp | `mix`, `step`, `smoothstep` |197| Vector | `length`, `distance`, `dot`, `cross`, `normalize` |198| Exp | `pow`, `exp`, `log`, `sqrt` |199200## When Writing Code2012021. Always use `show_bg: true` to enable background shader2032. Use `Sdf2d::viewport()` to create SDF context2043. Return `vec4` (RGBA) from `fn pixel()`2054. Uniforms must be declared before shader functions2065. Use `self.` prefix to access uniforms and built-ins207208## When Answering Questions2092101. Makepad shaders use Rust-like syntax, compiled to GPU code2112. Every widget can have custom shaders (draw_bg, draw_text, etc.)2123. Shaders are live-reloaded - edit and see changes instantly2134. Sdf2d is the primary tool for 2D shape rendering2145. GLSL ES 1.0 built-in functions are available215216## Limitations217- Use this skill only when the task clearly matches the scope described above.218- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.219- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.