Imported from rheadsh/audiovisual-production-skills (
td-glsl/SKILL.md). Install upstream withnpx skills add rheadsh/audiovisual-production-skills --skill td-glsl. Copyright stays with the author.
TouchDesigner GLSL Shader Writing
Write GLSL shaders optimized for TouchDesigner's shader operators.
Quick Start
Every TouchDesigner pixel shader needs:
// 1. Uniforms - Only declare what YOU need
uniform float uTime;
// 2. Output - Must be global, before main()
out vec4 fragColor;
// 3. Main function
void main() {
vec4 color = texture(sTD2DInputs[0], vUV.st);
fragColor = TDOutputSwizzle(color);
}
Critical Rules
- Output declaration:
out vec4 fragColor;must be global (beforemain()) - Never declare:
sTD2DInputs[],vUV,vP,vN- TouchDesigner provides these - Always use:
TDOutputSwizzle()for final output - Uniforms workflow: Declare in GLSL + Configure in TD parameter pages
Automatic Variables (DO NOT Declare)
sTD2DInputs[0] // Input textures - just use them!
vUV.st // UV coordinates (0-1)
vP, vN, vColor // Position, normal, vertex color
Must Declare and Configure
TouchDesigner does NOT provide automatic uniforms. You must:
- Declare in shader:
uniform float uTime; - Configure in TD UI (Vectors page):
- Name:
uTime - Type:
float - Value:
absTime.seconds
- Name:
Common Patterns
See examples/PATTERNS.md for ready-to-use templates:
- Basic texture sampling
- Time-based animation
- Multi-input blending
- Generative patterns
- Feedback loops
- Displacement effects
TouchDesigner Functions
// Output (required)
TDOutputSwizzle(vec4 color)
// Noise
TDSimplexNoise(vec2 p)
TDPerlinNoise(vec3 p)
// Color conversion
TDHSVToRGB(vec3 hsv)
TDRGBToHSV(vec3 rgb)
Response Format
When providing shaders, always include:
- GLSL Code with comments
- TouchDesigner Setup instructions:
- Which parameter page (Vectors, Colors, CHOP Uniforms)
- Uniform names and types
- Values or expressions (e.g.,
absTime.seconds)
Common Errors
See reference/TROUBLESHOOTING.md for solutions to:
'fragColor' : undeclared identifier'sTD2DInputs' : redefinition'uTime' : undeclared identifier- Uniforms with no effect
- Black/incorrect output
Additional Resources
- reference/FUNCTIONS.md - Complete API reference
- reference/BEST-PRACTICES.md - Optimization & organization
- examples/COMPLETE.md - Full shader examples
Writing Process
- Start with basic template
- Add uniforms (declare + configure)
- Implement shader logic
- Test incrementally
- Optimize when working