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
3description: |
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: unknown
9source: community
10metadata:
11 source: https://skillmd.com/skills/arjumaan/makepad-shaders
12---
13
14# Makepad Shaders Skill
15
16> **Version:** makepad-widgets (dev branch) | **Last Updated:** 2026-01-19
17>
18> Check for updates: https://crates.io/crates/makepad-widgets
19
20You are an expert at Makepad shaders. Help users by:
21- **Writing code**: Generate shader code following the patterns below
22- **Answering questions**: Explain shader language, Sdf2d, built-in functions
23
24## When to Use
25- You need to write or debug Makepad shader code, custom drawing, or SDF-based visuals.
26- The task involves `draw_bg`, `Sdf2d`, gradients, effects, or GPU-rendered widget appearance.
27- You want Makepad shader patterns and APIs rather than generic GLSL advice.
28
29## Documentation
30
31Refer to the local files for detailed documentation:
32- `./references/shader-basics.md` - Shader language fundamentals
33- `./references/sdf2d-reference.md` - Complete Sdf2d API reference
34
35## Advanced Patterns
36
37For production-ready shader patterns, see the `_base/` directory:
38
39| Pattern | Description |
40|---------|-------------|
41| 01-shader-structure | Shader fundamentals |
42| 02-shader-math | Mathematical functions |
43| 03-sdf-shapes | SDF shape primitives |
44| 04-sdf-drawing | Advanced SDF drawing |
45| 05-progress-track | Progress indicators |
46| 09-loading-spinner | Loading animations |
47| 10-hover-effect | Hover visual effects |
48| 11-gradient-effects | Color gradients |
49| 12-shadow-glow | Shadow and glow |
50| 13-disabled-state | Disabled visuals |
51| 14-toggle-checkbox | Toggle animations |
52
53Community contributions: `./community/`
54
55## IMPORTANT: Documentation Completeness Check
56
57**Before answering questions, Claude MUST:**
58
591. Read the relevant reference file(s) listed above
602. If file read fails or file is empty:
61 - Inform user: "本地文档不完整,建议运行 `/sync-crate-skills makepad --force` 更新文档"
62 - Still answer based on SKILL.md patterns + built-in knowledge
633. If reference file exists, incorporate its content into the answer
64
65## Key Patterns
66
67### 1. Basic Custom Shader
68
69```rust
70<View> {
71 show_bg: true
72 draw_bg: {
73 // Shader uniforms
74 color: #FF0000
75
76 // Custom pixel shader
77 fn pixel(self) -> vec4 {
78 return self.color;
79 }
80 }
81}
82```
83
84### 2. Rounded Rectangle with Border
85
86```rust
87<View> {
88 show_bg: true
89 draw_bg: {
90 color: #333333
91 border_color: #666666
92 border_radius: 8.0
93 border_size: 1.0
94
95 fn pixel(self) -> vec4 {
96 let sdf = Sdf2d::viewport(self.pos * self.rect_size);
97 sdf.box(1.0, 1.0,
98 self.rect_size.x - 2.0,
99 self.rect_size.y - 2.0,
100 self.border_radius);
101 sdf.fill_keep(self.color);
102 sdf.stroke(self.border_color, self.border_size);
103 return sdf.result;
104 }
105 }
106}
107```
108
109### 3. Gradient Background
110
111```rust
112<View> {
113 show_bg: true
114 draw_bg: {
115 color: #FF0000
116 color_2: #0000FF
117
118 fn pixel(self) -> vec4 {
119 let t = self.pos.x; // Horizontal gradient
120 return mix(self.color, self.color_2, t);
121 }
122 }
123}
124```
125
126### 4. Circle Shape
127
128```rust
129<View> {
130 show_bg: true
131 draw_bg: {
132 color: #0066CC
133
134 fn pixel(self) -> vec4 {
135 let sdf = Sdf2d::viewport(self.pos * self.rect_size);
136 let center = self.rect_size * 0.5;
137 let radius = min(center.x, center.y) - 1.0;
138 sdf.circle(center.x, center.y, radius);
139 sdf.fill(self.color);
140 return sdf.result;
141 }
142 }
143}
144```
145
146## Shader Structure
147
148| Component | Description |
149|-----------|-------------|
150| `draw_*` | Shader container (draw_bg, draw_text, draw_icon) |
151| Uniforms | Typed properties accessible in shader |
152| `fn pixel(self)` | Fragment shader function |
153| `fn vertex(self)` | Vertex shader function (optional) |
154| `Sdf2d` | 2D signed distance field helper |
155
156## Built-in Variables
157
158| Variable | Type | Description |
159|----------|------|-------------|
160| `self.pos` | vec2 | Normalized position (0-1) |
161| `self.rect_size` | vec2 | Widget size in pixels |
162| `self.rect_pos` | vec2 | Widget position |
163
164## Sdf2d Quick Reference
165
166| Category | Functions |
167|----------|-----------|
168| Shapes | `circle`, `rect`, `box`, `hexagon` |
169| Paths | `move_to`, `line_to`, `close_path` |
170| Fill/Stroke | `fill`, `fill_keep`, `stroke`, `stroke_keep` |
171| Boolean | `union`, `intersect`, `subtract` |
172| Transform | `translate`, `rotate`, `scale` |
173| Effects | `glow`, `glow_keep`, `gloop` |
174
175## Built-in Functions (GLSL)
176
177| Category | Functions |
178|----------|-----------|
179| Math | `abs`, `sign`, `floor`, `ceil`, `fract`, `min`, `max`, `clamp` |
180| Trig | `sin`, `cos`, `tan`, `asin`, `acos`, `atan` |
181| Interp | `mix`, `step`, `smoothstep` |
182| Vector | `length`, `distance`, `dot`, `cross`, `normalize` |
183| Exp | `pow`, `exp`, `log`, `sqrt` |
184
185## When Writing Code
186
1871. Always use `show_bg: true` to enable background shader
1882. Use `Sdf2d::viewport()` to create SDF context
1893. Return `vec4` (RGBA) from `fn pixel()`
1904. Uniforms must be declared before shader functions
1915. Use `self.` prefix to access uniforms and built-ins
192
193## When Answering Questions
194
1951. Makepad shaders use Rust-like syntax, compiled to GPU code
1962. Every widget can have custom shaders (draw_bg, draw_text, etc.)
1973. Shaders are live-reloaded - edit and see changes instantly
1984. Sdf2d is the primary tool for 2D shape rendering
1995. GLSL ES 1.0 built-in functions are available
200
201## Limitations
202- Use this skill only when the task clearly matches the scope described above.
203- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
204- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.