GLSL Creator
The GLSL Creator LOP is a powerful tool for generating, editing, and managing GLSL shaders directly within TouchDesigner. It leverages AI to assist in shader creation based on text prompts, automatically applying and saving shaders, and providing tools for debugging and refinement. This operator simplifies the shader development workflow, making it accessible to users with varying levels of GLSL expertise.
Requirements
Section titled “Requirements”- No additional Python packages required
- Requires a valid OpenAI API key configured in the ChatTD operator
Input/Output
Section titled “Input/Output”Inputs
Section titled “Inputs”- Up to three TOP inputs (optional):
- Used as textures within the generated GLSL shader
- Controlled by
Use Input 0
,Use Input 1
, andUse Input 2
parameters
Outputs
Section titled “Outputs”- GLSL TOP: Rendered result of the generated or loaded GLSL shader
Parameters
Section titled “Parameters”GLSL Creator
Section titled “GLSL Creator”op('glsl_creator').par.Currentsave
Folder Specifies the current project folder for saving and loading shaders. This is a relative path within the Save Folder specified on the Config page.
- Default:
"" (Empty String)
op('glsl_creator').par.Selectproject
Pulse Opens a file dialog to select a project folder, updating the Current GLSL Project parameter.
- Default:
None
op('glsl_creator').par.Activecall
Toggle Indicates whether a shader generation or improvement process is currently active. Prevents concurrent AI calls.
- Default:
Off
op('glsl_creator').par.Cpucooktime
String Displays the CPU cook time of the GLSL TOP.
- Default:
None
op('glsl_creator').par.Gpucooktime
String Displays the GPU cook time of the GLSL TOP.
- Default:
None
op('glsl_creator').par.Killat
Float Bypasses the GLSL TOP if the cook time exceeds this value.
- Default:
0
- Range:
- 0 to 1
op('glsl_creator').par.Average
Toggle Toggles the display of average cook times.
- Default:
Off
op('glsl_creator').par.Operror
Toggle Indicates whether the GLSL TOP has encountered a compilation error.
- Default:
None
op('glsl_creator').par.Heavycookcheck
Pulse Forces the GLSL TOP to cook, useful for debugging.
- Default:
None
op('glsl_creator').par.Editcodeexternal
Pulse Opens the GLSL code in an external text editor.
- Default:
None
op('glsl_creator').par.Editshadercode
Pulse Opens the GLSL code in a TouchDesigner Text DAT viewer.
- Default:
None
op('glsl_creator').par.Generateshader
Pulse Initiates the AI-powered shader generation process based on the Shader Prompt.
- Default:
None
op('glsl_creator').par.Shaderprompt
String The text prompt used to guide the AI in generating the GLSL shader.
- Default:
"" (Empty String)
Agent Constraints
Section titled “Agent Constraints”op('glsl_creator').par.Maxtokens
Integer The maximum number of tokens used by the AI during shader generation. Higher values allow for more complex shaders but may increase processing time and API costs.
- Default:
0
- Range:
- 0 to 1
op('glsl_creator').par.Maxattempts
Integer The maximum number of attempts to generate a shader from the initial prompt.
- Default:
0
- Range:
- 0 to 1
op('glsl_creator').par.Maxfixattempts
Integer The maximum number of attempts to fix a shader that has compilation errors.
- Default:
0
- Range:
- 0 to 1
op('glsl_creator').par.Currentattempt
Integer The current attempt number for shader generation.
- Default:
0
- Range:
- 0 to 1
op('glsl_creator').par.Currentuniformattempt
Integer The current attempt number for uniform setup.
- Default:
0
- Range:
- 0 to 1
op('glsl_creator').par.Checkresults
Pulse Manually checks the results of the shader compilation and applies the shader if Auto Apply is enabled.
- Default:
None
op('glsl_creator').par.Autocheck
Toggle Automatically checks the shader compilation results after each generation or fix attempt.
- Default:
Off
op('glsl_creator').par.Autoapply
Toggle Automatically applies the generated shader code to the GLSL TOP if the compilation is successful.
- Default:
Off
Improve Shader
Section titled “Improve Shader”op('glsl_creator').par.Improvenote
String A text note describing the desired improvements to the current shader.
- Default:
"" (Empty String)
op('glsl_creator').par.Improveshaderimage
Toggle Includes a still of the current shader as context for the AI during the improvement process.
- Default:
Off
op('glsl_creator').par.Differencelevel
Float Controls the level of change during shader improvement. Lower values result in subtle refinements, while higher values allow for more radical transformations.
- Default:
0
op('glsl_creator').par.Improveshader
Pulse Initiates the AI-powered shader improvement process based on the Improvement Note.
- Default:
None
GLSL Setup
Section titled “GLSL Setup”op('glsl_creator').par.Time
Float The current time, passed as a uniform to the GLSL shader.
- Default:
0
op('glsl_creator').par.Color
RGBA The color, passed as a uniform to the GLSL shader.
- Default:
[object Object]
op('glsl_creator').par.Mouseuv
UV The mouse UV coordinates, passed as a uniform to the GLSL shader.
- Default:
[object Object]
op('glsl_creator').par.Resolution
XY The custom resolution values used when Output Resolution is set to custom.
- Default:
[object Object]
op('glsl_creator').par.Trueres
XY Displays the actual resolution of the GLSL TOP.
- Default:
[object Object]
op('glsl_creator').par.Useinput0
Toggle Enables or disables the use of the first input TOP as a texture in the GLSL shader.
- Default:
Off
op('glsl_creator').par.Useinput1
Toggle Enables or disables the use of the second input TOP as a texture in the GLSL shader.
- Default:
Off
op('glsl_creator').par.Useinput2
Toggle Enables or disables the use of the third input TOP as a texture in the GLSL shader.
- Default:
Off
Vector Parameters
Section titled “Vector Parameters”op('glsl_creator').par.Vec
Sequence A sequence of vector parameters that can be passed as uniforms to the GLSL shader.
- Default:
None
op('glsl_creator').par.Vec0name
String The name of the vector uniform.
- Default:
None
op('glsl_creator').par.Vec0value
XYZW The values of the vector uniform.
- Default:
[object Object]
op('glsl_creator').par.Vecsync
Pulse Synchronizes the vector parameters between the GLSL Creator and the GLSL TOP.
- Default:
None
Config
Section titled “Config”Config
Section titled “Config”op('glsl_creator').par.Saveshader
Pulse Saves the current shader code and metadata to a new version folder within the project.
- Default:
None
op('glsl_creator').par.Loadshader
Pulse Loads the selected shader version from the project folder.
- Default:
None
op('glsl_creator').par.Autoload
Toggle Automatically loads the selected shader version when the Load Version parameter is changed.
- Default:
Off
op('glsl_creator').par.Savefolder
Folder Specifies the base folder for saving and loading shader projects.
- Default:
None
op('glsl_creator').par.Chattd
OP Specifies the path to the ChatTD operator, which handles communication with the AI API.
- Default:
None
op('glsl_creator').par.Showbuiltin
Toggle Toggles the display of built-in parameters in the parameter dialog.
- Default:
Off
op('glsl_creator').par.Popups
Toggle Enables or disables helpful pop-up messages about the operator.
- Default:
On
op('glsl_creator').par.Clearlog
Pulse Clears the log.
- Default:
None
op('glsl_creator').par.Converttotext
Toggle Converts the log output to text format.
- Default:
Off
op('glsl_creator').par.Reverse
Toggle Reverses the order of log messages.
- Default:
Off
op('glsl_creator').par.Bypass
Toggle Bypasses the GLSL Creator operator.
- Default:
Off
op('glsl_creator').par.Version
String The version number of the GLSL Creator operator.
- Default:
None
op('glsl_creator').par.Lastupdated
String The date the operator was last updated.
- Default:
None
op('glsl_creator').par.Creator
String The creator of the operator.
- Default:
None
op('glsl_creator').par.Website
String The creator's website.
- Default:
None
Performance Considerations
Section titled “Performance Considerations”- Shader complexity directly impacts GPU cook time. Optimize shader code for efficiency.
- High
Max Tokens
values can increase AI processing time. - Using input textures increases GPU memory usage.
Usage Examples
Section titled “Usage Examples”Generating a New Shader
Section titled “Generating a New Shader”- Create a
glsl_creator
LOP. - Enter a prompt in the
Shader Prompt
parameter (e.g., “create a swirling nebula effect”). - Set
Max Tokens
to a desired value (e.g., 2000). - Enable
Auto Apply
if you want the shader to be applied automatically upon successful generation. - Pulse the
Generate Shader
parameter. - If there are compilation errors, check the
Op Error
toggle. You can then enter a note inImprovement Note
(e.g., “fix compilation errors”) and pulseImprove Shader
to attempt a fix.
Improving an Existing Shader
Section titled “Improving an Existing Shader”- Load an existing shader using the
Load Version
andLoad Shader
parameters. - Enter a note in the
Improvement Note
parameter describing the desired changes (e.g., “add more vibrant colors”). - Adjust the
Difference Level
to control the intensity of the changes. - Enable
Include Shader Still
if you want to provide a visual context to the AI. - Pulse the
Improve Shader
parameter.
Using Input Textures
Section titled “Using Input Textures”- Create a
glsl_creator
LOP. - Enable
Use Input 0
,Use Input 1
, orUse Input 2
depending on how many input textures you want to use. - Connect TOPs to the corresponding inputs of the
glsl_creator
LOP. - Update your
Shader Prompt
to utilize the input textures (e.g., “create a shader that blends two input textures with a swirling effect. use sTD2DInputs[0] and sTD2DInputs[1] for the input textures”).
Managing Vector Uniforms
Section titled “Managing Vector Uniforms”- Create a
glsl_creator
LOP. - In the
GLSL Setup
page, locate theVector
sequence parameter. - Set the
Name
andValue
for each vector uniform you want to define. - Pulse
Vector Block Sync
to synchronize these parameters with the GLSL TOP. - Save your shader using
Save Shader
to include the new uniforms.
Common Use Cases
Section titled “Common Use Cases”- Generating custom visual effects for interactive installations
- Creating unique textures and patterns for 3D models
- Developing real-time graphics for live performances
- Prototyping shader ideas quickly using AI assistance
- Debugging and refining existing GLSL shaders
Performance Considerations
Section titled “Performance Considerations”- Shader complexity directly impacts GPU cook time. Optimize shader code for efficiency.
- High
Max Tokens
values can increase AI processing time. - Using input textures increases GPU memory usage.
Usage Examples
Section titled “Usage Examples”Generating a New Shader
Section titled “Generating a New Shader”# Set up shader generationop('glsl_creator').par.Shaderprompt = "create a swirling nebula effect"op('glsl_creator').par.Maxtokens = 2000op('glsl_creator').par.Autoapply = 1
# Generate shaderop('glsl_creator').par.Generateshader.pulse()
# Check for errorsif op('glsl_creator').par.Operror: # Try to fix the shader op('glsl_creator').par.Improvenote = "fix compilation errors" op('glsl_creator').par.Improveshader.pulse()
Improving an Existing Shader
Section titled “Improving an Existing Shader”# Load existing shaderop('glsl_creator').par.Loadversion = "version_1740466694"op('glsl_creator').par.Loadshader.pulse()
# Set up improvementop('glsl_creator').par.Improvenote = "add more vibrant colors"op('glsl_creator').par.Differencelevel = 0.5op('glsl_creator').par.Improveshaderimage = 1
# Improve shaderop('glsl_creator').par.Improveshader.pulse()
Using Input Textures
Section titled “Using Input Textures”# Enable input texturesop('glsl_creator').par.Useinput0 = 1op('glsl_creator').par.Useinput1 = 1
# Connect input TOPsop('glsl_creator').inputConnectors[0].connect(op('texture1'))op('glsl_creator').inputConnectors[1].connect(op('texture2'))
# Update shader prompt to use inputsop('glsl_creator').par.Shaderprompt = """create a shader that blends two input textures with a swirling effect.use sTD2DInputs[0] and sTD2DInputs[1] for the input textures"""
Managing Vector Uniforms
Section titled “Managing Vector Uniforms”# Set up vector uniformop('glsl_creator').par.Vec0name = "gridDensity"op('glsl_creator').par.Vec0valuex = 10op('glsl_creator').par.Vec0valuey = 10
# Sync vector parametersop('glsl_creator').par.Vecsync.pulse()
# Save shader with uniformsop('glsl_creator').par.Saveshader.pulse()
Common Use Cases
Section titled “Common Use Cases”- Generating custom visual effects for interactive installations
- Creating unique textures and patterns for 3D models
- Developing real-time graphics for live performances
- Prototyping shader ideas quickly using AI assistance
- Debugging and refining existing GLSL shaders