shader
GLSL Fragment Shaders
Write GPU-accelerated fragment shaders for procedural graphics, textures, and visual effects.
When to Use
- Creating procedural textures (wood, marble, clouds, terrain)
- Drawing shapes with distance fields (SDF)
- Generating patterns, noise, gradients
- Building visual effects and animations
- Writing custom shaders for Three.js, WebGL, Processing
Core Concepts
Fragment shaders execute simultaneously on every pixel. Each thread:
- Receives pixel position via
gl_FragCoord - Returns color via
gl_FragColor(vec4: RGBA 0.0-1.0) - Cannot communicate with other threads (stateless)
Standard Uniforms
uniform float u_time; // Elapsed seconds
uniform vec2 u_resolution; // Canvas size (width, height)
uniform vec2 u_mouse; // Mouse position in pixels
Normalize coordinates: vec2 st = gl_FragCoord.xy / u_resolution;
Essential Functions
| Function | Purpose | Example |
|---|---|---|
mix(a,b,t) |
Linear interpolate | mix(red, blue, 0.5) |
step(edge,x) |
Hard threshold | step(0.5, st.x) |
smoothstep(e0,e1,x) |
Smooth threshold | smoothstep(0.2, 0.8, st.x) |
fract(x) |
Fractional part | fract(st * 3.0) for tiling |
mod(x,y) |
Modulo | mod(st.x, 0.25) |
clamp(x,min,max) |
Constrain value | clamp(col, 0.0, 1.0) |
length(v) |
Vector magnitude | length(st - 0.5) |
distance(a,b) |
Euclidean distance | distance(st, center) |
dot(a,b) |
Dot product | dot(normal, lightDir) |
normalize(v) |
Unit vector | normalize(direction) |
atan(y,x) |
Angle (radians) | atan(st.y-0.5, st.x-0.5) |
sin/cos/pow/abs |
Math | Hardware-accelerated |
Quick Patterns
Circle:
float d = distance(st, vec2(0.5));
float circle = 1.0 - smoothstep(0.2, 0.21, d);
Rectangle:
vec2 bl = step(vec2(0.1), st);
vec2 tr = step(vec2(0.1), 1.0 - st);
float rect = bl.x * bl.y * tr.x * tr.y;
Tiling:
st = fract(st * 4.0); // 4x4 grid
Animation:
float wave = sin(st.x * 10.0 + u_time) * 0.5 + 0.5;
References (Progressive Disclosure)
Fundamentals
references/glsl-fundamentals-data-types-vectors-precision-coordinates.mdreferences/glsl-shaping-functions-step-smoothstep-curves-interpolation.md
Drawing
references/glsl-colors-rgb-hsb-gradients-mixing-color-spaces.mdreferences/glsl-shapes-sdf-circles-rectangles-polar-distance-fields.mdreferences/glsl-shapes-polygon-star-polar-sdf-combinations.md
Procedural
references/glsl-patterns-tiling-fract-matrices-transformations.mdreferences/glsl-pattern-symmetry-truchet-domain-warping.mdreferences/glsl-noise-random-perlin-simplex-cellular-voronoi.mdreferences/glsl-cellular-voronoi-worley-noise-patterns.mdreferences/glsl-fbm-fractional-brownian-motion-turbulence-octaves.mdreferences/glsl-procedural-textures-clouds-marble-wood-terrain.md
API Reference
references/glsl-shader-builtin-functions-complete-api-reference.md
Tools
- Online Editor: editor.thebookofshaders.com
- glslViewer: CLI tool for running .frag files
- glslCanvas: HTML embed for live shaders
- ShaderToy: iTime, iResolution, iMouse uniforms
External Resources
- The Book of Shaders: https://thebookofshaders.com
- LYGIA Library: https://lygia.xyz (reusable shader functions)
- ShaderToy: https://shadertoy.com
- Inigo Quilez Articles: https://iquilezles.org/articles/
More from hotriluan/alkana-dashboard
frontend-design
Create polished frontend interfaces from designs/screenshots/videos. Use for web components, 3D experiences, replicating UI designs, quick prototypes, immersive interfaces, avoiding AI slop.
19ui-ux-pro-max
UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 9 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient. Integrations: shadcn/ui MCP for component search and examples.
3frontend-dev-guidelines
Build React/TypeScript frontends with modern patterns. Use for components, Suspense, lazy loading, useSuspenseQuery, MUI v7 styling, TanStack Router, performance optimization.
3copywriting
Conversion copywriting formulas, headline templates, email copy patterns, landing page structures, CTA optimization, and writing style extraction. Activate for writing high-converting copy, crafting headlines, email campaigns, landing pages, or applying custom writing styles from assets/writing-styles/ directory.
3ui-styling
Style UIs with shadcn/ui components (Radix UI + Tailwind CSS). Use for accessible components, themes, dark mode, responsive layouts, design systems, color customization.
3media-processing
Process media with FFmpeg (video/audio), ImageMagick (images), RMBG (AI background removal). Use for encoding, format conversion, filters, thumbnails, batch processing, HLS/DASH streaming.
3