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
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
AGI Framework Integration
Adapted for @techwavedev/agi-agent-kit
Original source: antigravity-awesome-skills
Memory-First Protocol
Retrieve prior decisions and patterns to avoid re-discovering solutions. Cache results for instant retrieval in future sessions.
# Check for prior development context before starting
python3 execution/memory_manager.py auto --query "prior work and patterns related to Makepad Shaders"
Storing Results
After completing work, store development decisions for future sessions:
python3 execution/memory_manager.py store \
--content "Completed task with key insights documented for future reference" \
--type decision --project <project> \
--tags makepad-shaders default
Multi-Agent Collaboration
Share outcomes with other agents so the team stays aligned and avoids duplicate work.
python3 execution/cross_agent_context.py store \
--agent "<your-agent>" \
--action "Task completed — results documented and shared with team" \
--project <project>
1---2name: makepad-shaders3description: |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 绘制8---910# Makepad Shaders Skill1112> **Version:** makepad-widgets (dev branch) | **Last Updated:** 2026-01-1913>14> Check for updates: https://crates.io/crates/makepad-widgets1516You are an expert at Makepad shaders. Help users by:17- **Writing code**: Generate shader code following the patterns below18- **Answering questions**: Explain shader language, Sdf2d, built-in functions1920## Documentation2122Refer to the local files for detailed documentation:23- `./references/shader-basics.md` - Shader language fundamentals24- `./references/sdf2d-reference.md` - Complete Sdf2d API reference2526## Advanced Patterns2728For production-ready shader patterns, see the `_base/` directory:2930| Pattern | Description |31|---------|-------------|32| 01-shader-structure | Shader fundamentals |33| 02-shader-math | Mathematical functions |34| 03-sdf-shapes | SDF shape primitives |35| 04-sdf-drawing | Advanced SDF drawing |36| 05-progress-track | Progress indicators |37| 09-loading-spinner | Loading animations |38| 10-hover-effect | Hover visual effects |39| 11-gradient-effects | Color gradients |40| 12-shadow-glow | Shadow and glow |41| 13-disabled-state | Disabled visuals |42| 14-toggle-checkbox | Toggle animations |4344Community contributions: `./community/`4546## IMPORTANT: Documentation Completeness Check4748**Before answering questions, Claude MUST:**49501. Read the relevant reference file(s) listed above512. If file read fails or file is empty:52 - Inform user: "本地文档不完整,建议运行 `/sync-crate-skills makepad --force` 更新文档"53 - Still answer based on SKILL.md patterns + built-in knowledge543. If reference file exists, incorporate its content into the answer5556## Key Patterns5758### 1. Basic Custom Shader5960```rust61<View> {62 show_bg: true63 draw_bg: {64 // Shader uniforms65 color: #FF00006667 // Custom pixel shader68 fn pixel(self) -> vec4 {69 return self.color;70 }71 }72}73```7475### 2. Rounded Rectangle with Border7677```rust78<View> {79 show_bg: true80 draw_bg: {81 color: #33333382 border_color: #66666683 border_radius: 8.084 border_size: 1.08586 fn pixel(self) -> vec4 {87 let sdf = Sdf2d::viewport(self.pos * self.rect_size);88 sdf.box(1.0, 1.0,89 self.rect_size.x - 2.0,90 self.rect_size.y - 2.0,91 self.border_radius);92 sdf.fill_keep(self.color);93 sdf.stroke(self.border_color, self.border_size);94 return sdf.result;95 }96 }97}98```99100### 3. Gradient Background101102```rust103<View> {104 show_bg: true105 draw_bg: {106 color: #FF0000107 color_2: #0000FF108109 fn pixel(self) -> vec4 {110 let t = self.pos.x; // Horizontal gradient111 return mix(self.color, self.color_2, t);112 }113 }114}115```116117### 4. Circle Shape118119```rust120<View> {121 show_bg: true122 draw_bg: {123 color: #0066CC124125 fn pixel(self) -> vec4 {126 let sdf = Sdf2d::viewport(self.pos * self.rect_size);127 let center = self.rect_size * 0.5;128 let radius = min(center.x, center.y) - 1.0;129 sdf.circle(center.x, center.y, radius);130 sdf.fill(self.color);131 return sdf.result;132 }133 }134}135```136137## Shader Structure138139| Component | Description |140|-----------|-------------|141| `draw_*` | Shader container (draw_bg, draw_text, draw_icon) |142| Uniforms | Typed properties accessible in shader |143| `fn pixel(self)` | Fragment shader function |144| `fn vertex(self)` | Vertex shader function (optional) |145| `Sdf2d` | 2D signed distance field helper |146147## Built-in Variables148149| Variable | Type | Description |150|----------|------|-------------|151| `self.pos` | vec2 | Normalized position (0-1) |152| `self.rect_size` | vec2 | Widget size in pixels |153| `self.rect_pos` | vec2 | Widget position |154155## Sdf2d Quick Reference156157| Category | Functions |158|----------|-----------|159| Shapes | `circle`, `rect`, `box`, `hexagon` |160| Paths | `move_to`, `line_to`, `close_path` |161| Fill/Stroke | `fill`, `fill_keep`, `stroke`, `stroke_keep` |162| Boolean | `union`, `intersect`, `subtract` |163| Transform | `translate`, `rotate`, `scale` |164| Effects | `glow`, `glow_keep`, `gloop` |165166## Built-in Functions (GLSL)167168| Category | Functions |169|----------|-----------|170| Math | `abs`, `sign`, `floor`, `ceil`, `fract`, `min`, `max`, `clamp` |171| Trig | `sin`, `cos`, `tan`, `asin`, `acos`, `atan` |172| Interp | `mix`, `step`, `smoothstep` |173| Vector | `length`, `distance`, `dot`, `cross`, `normalize` |174| Exp | `pow`, `exp`, `log`, `sqrt` |175176## When Writing Code1771781. Always use `show_bg: true` to enable background shader1792. Use `Sdf2d::viewport()` to create SDF context1803. Return `vec4` (RGBA) from `fn pixel()`1814. Uniforms must be declared before shader functions1825. Use `self.` prefix to access uniforms and built-ins183184## When Answering Questions1851861. Makepad shaders use Rust-like syntax, compiled to GPU code1872. Every widget can have custom shaders (draw_bg, draw_text, etc.)1883. Shaders are live-reloaded - edit and see changes instantly1894. Sdf2d is the primary tool for 2D shape rendering1905. GLSL ES 1.0 built-in functions are available191192---193194<!-- AGI-INTEGRATION-START -->195196## AGI Framework Integration197198> **Adapted for [@techwavedev/agi-agent-kit](https://www.npmjs.com/package/@techwavedev/agi-agent-kit)**199> Original source: [antigravity-awesome-skills](https://github.com/sickn33/antigravity-awesome-skills)200201### Memory-First Protocol202203Retrieve prior decisions and patterns to avoid re-discovering solutions. Cache results for instant retrieval in future sessions.204205```bash206# Check for prior development context before starting207python3 execution/memory_manager.py auto --query "prior work and patterns related to Makepad Shaders"208```209210### Storing Results211212After completing work, store development decisions for future sessions:213214```bash215python3 execution/memory_manager.py store \216 --content "Completed task with key insights documented for future reference" \217 --type decision --project <project> \218 --tags makepad-shaders default219```220221### Multi-Agent Collaboration222223Share outcomes with other agents so the team stays aligned and avoids duplicate work.224225```bash226python3 execution/cross_agent_context.py store \227 --agent "<your-agent>" \228 --action "Task completed — results documented and shared with team" \229 --project <project>230```231232<!-- AGI-INTEGRATION-END -->