The OpenGL
®
ES Shading Language
Language Version: 1.00
Document Revision: 17
12 May, 2009
Editor: Robert J. Simpson
(Editor, version 1.00, revisions 1-11: John Kessenich)
ii
Copyright (c) 2006-2009 The Khronos Group Inc. All Rights Reserved.
This specification is protected by copyright laws and contains material proprietary to the Khronos Group,
Inc. It or any components may not be reproduced, republished, distributed, transmitted, displayed,
broadcast or otherwise exploited in any manner without the express prior written permission of Khronos
Group. You may use this specification for implementing the functionality herein, without altering or
removing any trademark, copyright or other notice from the specification, but the receipt or possession of
this specification does not convey any rights to reproduce, disclose, or distribute its contents, or to
manufacture, use, or sell anything that it may describe, in whole or in part.
Khronos Group grants express permission to any current Promoter, Contributor or Adopter member of
Khronos to copy and redistribute UNMODIFIED versions of this specification in any fashion, provided that
NO CHARGE is made for the specification and the latest available update of the specification for any
version of the API is used whenever possible. Such distributed specification may be re-formatted AS
LONG AS the contents of the specification are not changed in any way. The specification may be
incorporated into a product that is sold as long as such product includes significant independent work
developed by the seller. A link to the current version of this specification on the Khronos Group web-site
should be included whenever possible with specification distributions.
Khronos Group makes no, and expressly disclaims any, representations or warranties, express or implied,
regarding this specification, including, without limitation, any implied warranties of merchantability or
fitness for a particular purpose or non-infringement of any intellectual property. Khronos Group makes no,
and expressly disclaims any, warranties, express or implied, regarding the correctness, accuracy,
completeness, timeliness, and reliability of the specification. Under no circumstances will the Khronos
Group, or any of its Promoters, Contributors or Members or their respective partners, officers, directors,
employees, agents or representatives be liable for any damages, whether direct, indirect, special or
consequential damages for lost revenues, lost profits, or otherwise, arising from or in connection with
these materials.
Khronos is a trademark of The Khronos Group Inc. OpenGL is a registered trademark, and
OpenGL ES is a trademark, of Silicon Graphics, Inc.
Version 1.00 Revision 17 (12 May, 2009)
iii
Table of Contents
1 Introduction................................................................................................................................1
1.1 Change History...................................................................................................................1
1.2 Overview............................................................................................................................6
1.3 Error Handling....................................................................................................................6
1.4 Typographical Conventions...............................................................................................7
2 Overview of OpenGL ES Shading.............................................................................................8
2.1 Vertex Processor................................................................................................................8
2.2 Fragment Processor............................................................................................................8
3 Basics.........................................................................................................................................9
3.1 Character Set......................................................................................................................9
3.2 Source Strings....................................................................................................................9
3.3 Logical Phases of compilation.........................................................................................10
3.4 Preprocessor.....................................................................................................................11
3.5 Comments........................................................................................................................15
3.6 Tokens..............................................................................................................................16
3.7 Keywords..........................................................................................................................16
3.8 Identifiers.........................................................................................................................17
4 Variables and Types.................................................................................................................18
4.1 Basic Types......................................................................................................................18
4.1.1 Void..........................................................................................................................19
4.1.2 Booleans...................................................................................................................19
4.1.3 Integers.....................................................................................................................19
4.1.4 Floats........................................................................................................................21
4.1.5 Vectors......................................................................................................................21
4.1.6 Matrices....................................................................................................................22
4.1.7 Samplers...................................................................................................................22
4.1.8 Structures..................................................................................................................22
4.1.9 Arrays.......................................................................................................................24
4.2 Scoping.............................................................................................................................25
4.2.1 Definition of Terms..................................................................................................25
4.2.2 Types of Scope.........................................................................................................25
4.2.3 Redeclaring Variables...............................................................................................26
4.2.4 Shared Globals..........................................................................................................26
4.2.5 Global Scope............................................................................................................27
4.2.6 Name spaces and Hiding..........................................................................................27
4.2.7 Redeclarations and Redefinitions Within the Same Scope......................................27
Version 1.00 Revision 17 (12 May, 2009)
iv
4.3 Storage Qualifiers.............................................................................................................29
4.3.1 Default Storage Qualifier..........................................................................................29
4.3.2 Constant Qualifier....................................................................................................29
4.3.3 Attribute....................................................................................................................30
4.3.4 Uniform....................................................................................................................30
4.3.5 Varying.....................................................................................................................31
4.4 Parameter Qualifiers.........................................................................................................32
4.5 Precision and Precision Qualifiers...................................................................................32
4.5.1 Range and Precision.................................................................................................32
4.5.2 Precision Qualifiers..................................................................................................33
4.5.3 Default Precision Qualifiers.....................................................................................35
4.5.4 Available Precision Qualifiers..................................................................................36
4.6 Variance and the Invariant Qualifier................................................................................36
4.6.1 The Invariant Qualifier.............................................................................................37
4.6.2 Invariance Within Shaders........................................................................................38
4.6.3 Invariance of Constant Expressions.........................................................................39
4.6.4 Invariance and Linkage.............................................................................................39
4.7 Order of Qualification......................................................................................................39
5 Operators and Expressions.......................................................................................................40
5.1 Operators..........................................................................................................................40
5.2 Array Subscripting...........................................................................................................41
5.3 Function Calls..................................................................................................................41
5.4 Constructors.....................................................................................................................41
5.4.1 Conversion and Scalar Constructors........................................................................41
5.4.2 Vector and Matrix Constructors...............................................................................42
5.4.3 Structure Constructors..............................................................................................43
5.5 Vector Components..........................................................................................................44
5.6 Matrix Components..........................................................................................................45
5.7 Structures and Fields........................................................................................................46
5.8 Assignments.....................................................................................................................46
5.9 Expressions......................................................................................................................47
5.10 Constant Expressions.....................................................................................................49
5.11 Vector and Matrix Operations........................................................................................50
5.12 Precisions of operations.................................................................................................51
5.13 Evaluation of expressions..............................................................................................51
6 Statements and Structure..........................................................................................................52
6.1 Function Definitions.........................................................................................................53
Version 1.00 Revision 17 (12 May, 2009)
v
6.1.1 Function Calling Conventions..................................................................................54
6.2 Selection...........................................................................................................................56
6.3 Iteration............................................................................................................................56
6.4 Jumps................................................................................................................................57
7 Built-in Variables.....................................................................................................................59
7.1 Vertex Shader Special Variables......................................................................................59
7.2 Fragment Shader Special Variables.................................................................................60
7.3 Vertex Shader Built-In Attributes....................................................................................61
7.4 Built-In Constants............................................................................................................61
7.5 Built-In Uniform State.....................................................................................................62
8 Built-in Functions....................................................................................................................63
8.1 Angle and Trigonometry Functions..................................................................................64
8.2 Exponential Functions......................................................................................................65
8.3 Common Functions..........................................................................................................66
8.4 Geometric Functions........................................................................................................68
8.5 Matrix Functions..............................................................................................................69
8.6 Vector Relational Functions.............................................................................................70
8.7 Texture Lookup Functions...............................................................................................71
9 Shading Language Grammar....................................................................................................73
10 Issues......................................................................................................................................84
10.1 Vertex Shader Precision.................................................................................................84
10.2 Fragment Shader Precision.............................................................................................84
10.3 Precision Qualifiers........................................................................................................84
10.4 Function and Variable Name Spaces..............................................................................88
10.5 Local Function Declarations and Function Hiding........................................................88
10.6 Overloading main()........................................................................................................88
10.7 Error Reporting..............................................................................................................88
10.8 Structure Declarations....................................................................................................89
10.9 Embedded Structure Definitions....................................................................................89
10.10 Redefining Built-in Functions......................................................................................90
10.11 Constant Expressions...................................................................................................90
10.12 Varying Linkage...........................................................................................................91
10.13 gl_Position....................................................................................................................91
10.14 Pre-processor................................................................................................................91
10.15 Phases of Compilation..................................................................................................92
10.16 Maximum Number of Varyings...................................................................................92
10.17 Unsized Array Declarations.........................................................................................93
Version 1.00 Revision 17 (12 May, 2009)