Shader Programming Glsl
Shader Programming Glsl is an writing AI skill with a core value of Expert guide for writing efficient GLSL shaders (Vertex/Fragment) for web and game engines, covering syntax, uniforms, and common effects. It
helps developers solve real-world problems in the writing domain, boosting
efficiency, automating repetitive tasks, and optimizing workflows.
Expert guide for writing efficient GLSL shaders (Vertex/Fragment) for web and game engines, covering syntax, uniforms, and common effects.
Quick Facts
mkdir -p ./skills/shader-programming-glsl && curl -sfL https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/skills/shader-programming-glsl/SKILL.md -o ./skills/shader-programming-glsl/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# Shader Programming GLSL
Overview
A comprehensive guide to writing GPU shaders using GLSL (OpenGL Shading Language). Learn syntax, uniforms, varying variables, and key mathematical concepts like swizzling and vector operations for visual effects.
When to Use This Skill
- Use when creating custom visual effects in WebGL, Three.js, or game engines.
- Use when optimizing graphics rendering performance.
- Use when implementing post-processing effects (blur, bloom, color correction).
- Use when procedurally generating textures or geometry on the GPU.
Step-by-Step Guide
1. Structure: Vertex vs. Fragment
Understand the pipeline:
- **Vertex Shader**: Transforms 3D coordinates to 2D screen space (`gl_Position`).
- **Fragment Shader**: Colors individual pixels (`gl_FragColor`).
// Vertex Shader (basic)
attribute vec3 position;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}// Fragment Shader (basic)
uniform vec3 color;
void main() {
gl_FragColor = vec4(color, 1.0);
}2. Uniforms and Varyings
- `uniform`: Data constant for all vertices/fragments (passed from CPU).
- `varying`: Data interpolated from vertex to fragment shader.
// Passing UV coordinates
varying vec2 vUv;
// In Vertex Shader
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
// In Fragment Shader
void main() {
// Gradient based on UV
gl_FragColor = vec4(vUv.x, vUv.y, 1.0, 1.0);
}3. Swizzling & Vector Math
Access vector components freely: `vec4 color = vec4(1.0, 0.5, 0.0, 1.0);`
- `color.rgb` -> `vec3(1.0, 0.5, 0.0)`
- `color.zyx` -> `vec3(0.0, 0.5, 1.0)` (reordering)
Examples
Example 1: Simple Raymarching (SDF Sphere)
float sdSphere(vec3 p, float s) {
return length(p) - s;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.0, -3.0); // Ray Origin
vec3 rd = normalize(vec3(uv, 1.0)); // Ray Direction
float t = 0.0;
for(int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
float d = sdSphere(p, 1.0); // Sphere radius 1.0
if(d < 0.001) break;
t += d;
}
vec3 col = vec3(0.0);
if(t < 10.0) {
vec3 p = ro + rd * t;
vec3 normal = normalize(p);
col = normal * 0.5 + 0.5; // Color by normal
}
fragColor = vec4(col, 1.0);
}Best Practices
- ✅ **Do:** Use `mix()` for linear interpolation instead of manual math.
- ✅ **Do:** Use `step()` and `smoothstep()` for thresholding and soft edges (avoid `if` branches).
- ✅ **Do:** Pack data into vectors (`vec4`) to minimize memory access.
- ❌ **Don't:** Use heavy branching (`if-else`) inside loops if possible; it hurts GPU parallelism.
- ❌ **Don't:** Calculate constant values inside the shader; pre-calculate them on the CPU (uniforms).
Troubleshooting
**Problem:** Shader compiles but screen is black.
**Solution:** Check if `gl_Position.w` is correct (usually 1.0). Check if uniforms are actually being set from the host application. Verify UV coordinates are within [0, 1].
🎯 Best For
- UI designers
- Product designers
- Claude users
- Content creators
- Writers
💡 Use Cases
- Generating component mockups
- Creating design system tokens
- Content creation
- Style guide enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Shader Programming Glsl to Your Work
Provide context for your task — paste source material, describe your audience, or share existing work to guide the AI.
- 4
Review and Refine
Edit the AI output for accuracy, tone, and completeness. Add human insight where the AI lacks context.
❓ Frequently Asked Questions
Does this work with Figma?
Some design skills integrate with Figma plugins. Check the Works With section for supported tools.
Can Shader Programming Glsl maintain my brand voice?
Yes — provide style guides or example content in your prompt for consistent brand-aligned output.
How do I install Shader Programming Glsl?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/shader-programming-glsl/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Skipping usability testing
AI-generated designs should be validated with real users before development.
Publishing unedited drafts
AI writing needs human editing for facts, flow, and authentic voice.