Allowed Characters for GLSL Identifier Names
In the OpenGL Shading Language (GLSL), identifier names for variables, functions, structures, and type names are strictly governed by the official specification to ensure cross-platform compiler compatibility. Identifiers are restricted to a standard subset of ASCII characters, including letters, digits, and underscores. Understanding these character rules, along with naming restrictions such as reserved prefixes and forbidden starting characters, is critical for writing valid GLSL shader programs.
The Permitted Character Set
GLSL identifiers must be constructed exclusively from the following ASCII character set:
- Uppercase English letters:
AthroughZ - Lowercase English letters:
athroughz - Decimal digits:
0through9 - Underscore:
_
No other characters, such as hyphens, spaces, special symbols
($, @, #), or non-ASCII Unicode
characters, are permitted.
Structural Rules for Identifiers
To form a valid identifier, the permitted characters must follow specific structural constraints:
- Initial Character: An identifier cannot start with
a digit (
0–9). It must begin with either an uppercase letter, a lowercase letter, or an underscore. - Case Sensitivity: GLSL is strictly case-sensitive.
The identifiers
colorValue,ColorValue, andCOLORVALUErepresent three distinct identifiers.
Reserved Prefixes and Sequences
Even if an identifier uses the permitted characters, certain patterns are restricted by the compiler:
- The
gl_Prefix: Any identifier beginning withgl_is reserved for use by the OpenGL Shading Language itself (such asgl_Positionorgl_FragCoord). User-defined variables cannot begin withgl_. - Consecutive Underscores: Identifiers containing two
consecutive underscores (
__) are reserved by the GLSL implementation and must not be used in user code.
Keywords and Reserved Words
An identifier composed of permitted characters is still illegal if it
matches any GLSL reserved keyword (such as attribute,
uniform, varying, vec2,
float, or control-flow words like for and
while) or words reserved for future language
extensions.