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
For production-ready shader patterns, see the _base/ directory:
| 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 更新文档"
- Still answer based on SKILL.md patterns + built-in knowledge
- 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-shaders-23description: |4 CRITICAL: Use for Makepad shader system. Triggers on:5 makepad shader, makepad draw_bg, Sdf2d, makepad pixel,6 makepad glsl, makepad sdf, draw_quad, makepad gpu,7 makepad 着色器, makepad shader 语法, makepad 绘制8risk: critical9source: community10date_added: "2026-03-06"11metadata:12 source: https://skillmd.com/skills/iradoweck/makepad-shaders-213---1415## Supporting material availability1617This catalog copy contains the inline guidance below, but does not include the following supporting paths. They are external prerequisites, not bundled files:1819- `./references/shader-basics.md`20- `./references/sdf2d-reference.md`2122Ask 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.232425# Makepad Shaders Skill2627> **Version:** makepad-widgets (dev branch) | **Last Updated:** 2026-01-1928>29> Check for updates: https://crates.io/crates/makepad-widgets3031You are an expert at Makepad shaders. Help users by:32- **Writing code**: Generate shader code following the patterns below33- **Answering questions**: Explain shader language, Sdf2d, built-in functions3435## When to Use36- You need to write or debug Makepad shader code, custom drawing, or SDF-based visuals.37- The task involves `draw_bg`, `Sdf2d`, gradients, effects, or GPU-rendered widget appearance.38- You want Makepad shader patterns and APIs rather than generic GLSL advice.3940## Documentation4142Refer to the local files for detailed documentation:43- `./references/shader-basics.md` - Shader language fundamentals44- `./references/sdf2d-reference.md` - Complete Sdf2d API reference4546## Advanced Patterns4748For production-ready shader patterns, see the `_base/` directory:4950| Pattern | Description |51|---------|-------------|52| 01-shader-structure | Shader fundamentals |53| 02-shader-math | Mathematical functions |54| 03-sdf-shapes | SDF shape primitives |55| 04-sdf-drawing | Advanced SDF drawing |56| 05-progress-track | Progress indicators |57| 09-loading-spinner | Loading animations |58| 10-hover-effect | Hover visual effects |59| 11-gradient-effects | Color gradients |60| 12-shadow-glow | Shadow and glow |61| 13-disabled-state | Disabled visuals |62| 14-toggle-checkbox | Toggle animations |6364Community contributions: `./community/`6566## IMPORTANT: Documentation Completeness Check6768**Before answering questions, Claude MUST:**69701. Read the relevant reference file(s) listed above712. If file read fails or file is empty:72 - Inform user: "本地文档不完整,建议运行 `/sync-crate-skills makepad --force` 更新文档"73 - Still answer based on SKILL.md patterns + built-in knowledge743. If reference file exists, incorporate its content into the answer7576## Key Patterns7778### 1. Basic Custom Shader7980```rust81<View> {82 show_bg: true83 draw_bg: {84 // Shader uniforms85 color: #FF00008687 // Custom pixel shader88 fn pixel(self) -> vec4 {89 return self.color;90 }91 }92}93```9495### 2. Rounded Rectangle with Border9697```rust98<View> {99 show_bg: true100 draw_bg: {101 color: #333333102 border_color: #666666103 border_radius: 8.0104 border_size: 1.0105106 fn pixel(self) -> vec4 {107 let sdf = Sdf2d::viewport(self.pos * self.rect_size);108 sdf.box(1.0, 1.0,109 self.rect_size.x - 2.0,110 self.rect_size.y - 2.0,111 self.border_radius);112 sdf.fill_keep(self.color);113 sdf.stroke(self.border_color, self.border_size);114 return sdf.result;115 }116 }117}118```119120### 3. Gradient Background121122```rust123<View> {124 show_bg: true125 draw_bg: {126 color: #FF0000127 color_2: #0000FF128129 fn pixel(self) -> vec4 {130 let t = self.pos.x; // Horizontal gradient131 return mix(self.color, self.color_2, t);132 }133 }134}135```136137### 4. Circle Shape138139```rust140<View> {141 show_bg: true142 draw_bg: {143 color: #0066CC144145 fn pixel(self) -> vec4 {146 let sdf = Sdf2d::viewport(self.pos * self.rect_size);147 let center = self.rect_size * 0.5;148 let radius = min(center.x, center.y) - 1.0;149 sdf.circle(center.x, center.y, radius);150 sdf.fill(self.color);151 return sdf.result;152 }153 }154}155```156157## Shader Structure158159| Component | Description |160|-----------|-------------|161| `draw_*` | Shader container (draw_bg, draw_text, draw_icon) |162| Uniforms | Typed properties accessible in shader |163| `fn pixel(self)` | Fragment shader function |164| `fn vertex(self)` | Vertex shader function (optional) |165| `Sdf2d` | 2D signed distance field helper |166167## Built-in Variables168169| Variable | Type | Description |170|----------|------|-------------|171| `self.pos` | vec2 | Normalized position (0-1) |172| `self.rect_size` | vec2 | Widget size in pixels |173| `self.rect_pos` | vec2 | Widget position |174175## Sdf2d Quick Reference176177| Category | Functions |178|----------|-----------|179| Shapes | `circle`, `rect`, `box`, `hexagon` |180| Paths | `move_to`, `line_to`, `close_path` |181| Fill/Stroke | `fill`, `fill_keep`, `stroke`, `stroke_keep` |182| Boolean | `union`, `intersect`, `subtract` |183| Transform | `translate`, `rotate`, `scale` |184| Effects | `glow`, `glow_keep`, `gloop` |185186## Built-in Functions (GLSL)187188| Category | Functions |189|----------|-----------|190| Math | `abs`, `sign`, `floor`, `ceil`, `fract`, `min`, `max`, `clamp` |191| Trig | `sin`, `cos`, `tan`, `asin`, `acos`, `atan` |192| Interp | `mix`, `step`, `smoothstep` |193| Vector | `length`, `distance`, `dot`, `cross`, `normalize` |194| Exp | `pow`, `exp`, `log`, `sqrt` |195196## When Writing Code1971981. Always use `show_bg: true` to enable background shader1992. Use `Sdf2d::viewport()` to create SDF context2003. Return `vec4` (RGBA) from `fn pixel()`2014. Uniforms must be declared before shader functions2025. Use `self.` prefix to access uniforms and built-ins203204## When Answering Questions2052061. Makepad shaders use Rust-like syntax, compiled to GPU code2072. Every widget can have custom shaders (draw_bg, draw_text, etc.)2083. Shaders are live-reloaded - edit and see changes instantly2094. Sdf2d is the primary tool for 2D shape rendering2105. GLSL ES 1.0 built-in functions are available211212## Limitations213- Use this skill only when the task clearly matches the scope described above.214- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.215- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.