GLSL Specification 4.10.6

download GLSL Specification 4.10.6

of 162

Transcript of GLSL Specification 4.10.6

  • 8/12/2019 GLSL Specification 4.10.6

    1/162

    The OpenGLShading Language

    Language Version: 4.10

    Document Revision: 6

    24-Jul-2010

    Editor: John Kessenich, Intel

    Version 1.1 Authors: John Kessenich, Dave Baldwin, Randi Rost

  • 8/12/2019 GLSL Specification 4.10.6

    2/162

    Copyright (c) 2008-2010 The Khronos Group Inc. All Rights Reserve.

    This speci!ic"tion is protecte #y copyright l"$s "n cont"ins %"teri"l propriet"ry to the Khronos Group&Inc. It or "ny co%ponents %"y not #e reprouce& repu#lishe& istri#ute& tr"ns%itte& ispl"yero"c"st or other$ise e'ploite in "ny %"nner $ithout the e'press prior $ritten per%ission o! KhronosGroup. ou %"y use this speci!ic"tion !or i%ple%enting the !unction"lity therein& $ithout "ltering orre%oving "ny tr"e%"r& copyright or other notice !ro% the speci!ic"tion& #ut the receipt or possession o!this speci!ic"tion oes not convey "ny rights to reprouce& isclose& or istri#ute its contents& or to%"nu!"cture& use& or sell "nything th"t it %"y escri#e& in $hole or in p"rt.

    Khronos Group gr"nts e'press per%ission to "ny current *ro%oter& Contri#utor or Aopter %e%#er o!Khronos to copy "n reistri#ute +,/II/ versions o! this speci!ic"tion in "ny !"shion& provie th"t, CARG is %"e !or the speci!ic"tion "n the l"test "v"il"#le up"te o! the speci!ic"tion !or "nyversion o! the A*I is use $henever possi#le. 3uch istri#ute speci!ic"tion %"y #e re-!or%"tte A34,G A3 the contents o! the speci!ic"tion "re not ch"nge in "ny $"y. The speci!ic"tion %"y #eincorpor"te into " prouct th"t is sol "s long "s such prouct inclues signi!ic"nt inepenent $orevelope #y the seller. A lin to the current version o! this speci!ic"tion on the Khronos Group $e#-siteshoul #e inclue $henever possi#le $ith speci!ic"tion istri#utions.

    Khronos Group %"es no& "n e'pressly iscl"i%s "ny& represent"tions or $"rr"nties& e'press ori%plie& reg"ring this speci!ic"tion& incluing& $ithout li%it"tion& "ny i%plie $"rr"nties o! %erch"nt"#ilityor !itness !or " p"rticul"r purpose or non-in!ringe%ent o! "ny intellectu"l property. Khronos Group %"es

    no& "n e'pressly iscl"i%s "ny& $"rr"nties& e'press or i%plie& reg"ring the correctness& "ccur"cy&co%pleteness& ti%eliness& "n reli"#ility o! the speci!ic"tion. +ner no circu%st"nces $ill the KhronosGroup& or "ny o! its *ro%oters& Contri#utors or e%#ers or their respective p"rtners& o!!icers& irectors&e%ployees& "gents or represent"tives #e li"#le !or "ny "%"ges& $hether irect& inirect& speci"l orconse5uenti"l "%"ges !or lost revenues& lost pro!its& or other$ise& "rising !ro% or in connection $iththese %"teri"ls.

    Khronos& penK/& penKG3& pen6G& penA7& pen34 3 "n pen "re tr"e%"rs o!the Khronos Group Inc. C44A/A is " tr"e%"r o! 3ony Co%puter ntert"in%ent Inc. use #yper%ission #y Khronos. penG4 "n pen4 "re registere tr"e%"rs "n the penG4 3 logo is "tr"e%"r o! 3ilicon Gr"phics Inc. use #y per%ission #y Khronos. All other prouct n"%es& tr"e%"rs&"n9or co%p"ny n"%es "re use solely !or ienti!ic"tion "n #elong to their respective o$ners.

    2

  • 8/12/2019 GLSL Specification 4.10.6

    3/162

    Table of Contents

    1 Introduction.................................................................................................................................1

    1.1 Acknowledgents................................................................................................................!1.! "hanges................................................................................................................................ !

    1.!.1 "hanges #ro revision $...............................................................................................!1.!.! "hanges #ro revision %...............................................................................................&1.!.& "hanges #ro revision &...............................................................................................&1.!.% "hanges #ro revision !...............................................................................................&1.!.$ "hanges #ro revision 1...............................................................................................&1.!.' (uar) o# "hanges #ro Version %.**..................................................................... &

    1.& +verview.............................................................................................................................. %1.% Error andling......................................................................................................................%1.$ -)ograhical "onventions................................................................................................. %

    1.' Derecation.......................................................................................................................... %! +verview o# +en/0 (hading....................................................................................................$

    !.1 Verte 2rocessor.................................................................................................................. $!.! -essellation "ontrol 2rocessor.............................................................................................$!.& -essellation Evaluation 2rocessor........................................................................................'!.% /eoetr) 2rocessor............................................................................................................. '!.$ 3ragent 2rocessor.............................................................................................................. '

    & Basics.......................................................................................................................................... 4&.1 "haracter (et........................................................................................................................ 4&.! (ource (trings...................................................................................................................... 4&.& 2rerocessor......................................................................................................................... 5

    &.% "oents.......................................................................................................................... 1&&.$ -okens................................................................................................................................ 1&&.' Ke)words............................................................................................................................1&&.4 Identi#iers........................................................................................................................... 1$&.5 De#initions..........................................................................................................................1'

    &.5.1 (tatic 6se....................................................................................................................1'&.5.! 6ni#or and 7on86ni#or "ontrol 3low.................................................................. 1'&.5.& D)naicall) 6ni#or Eressions.............................................................................14

    % Varia9les and -)es..................................................................................................................15%.1 Basic -)es........................................................................................................................ 15

    %.1.1 Void............................................................................................................................ !1

    %.1.! Booleans..................................................................................................................... !1%.1.& Integers....................................................................................................................... !!%.1.% 3loats.......................................................................................................................... !%%.1.$ Vectors........................................................................................................................!$%.1.' atrices...................................................................................................................... !$%.1.4 (alers..................................................................................................................... !$

    3

  • 8/12/2019 GLSL Specification 4.10.6

    4/162

    %.1.5 (tructures....................................................................................................................!'%.1.; Arra)s......................................................................................................................... !4%.1.1* Ilicit "onversions................................................................................................ !;

    %.! (coing...............................................................................................................................&*%.& (torage

  • 8/12/2019 GLSL Specification 4.10.6

    5/162

    $.; Eressions........................................................................................................................ 4*$.1* Vector and atri +erations..........................................................................................4&

    ' (tateents and (tructure...........................................................................................................4$

    '.1 3unction De#initions...........................................................................................................4''.1.1 3unction "alling "onventions....................................................................................45'.1.! (u9routines.................................................................................................................5*

    '.! (election.............................................................................................................................51'.& Iteration.............................................................................................................................. 5!'.% Jus..................................................................................................................................5&

    4 Built8in Varia9les......................................................................................................................5%4.1 Built8In 0anguage Varia9les.............................................................................................. 5%

    4.1.1 "oati9ilit) 2ro#ile Built8In 0anguage Varia9les....................................................;!4.! "oati9ilit) 2ro#ile Verte (hader Built8In Inuts......................................................... ;$4.& Built8In "onstants.............................................................................................................. ;$

    4.&.1 "oati9ilit) 2ro#ile Built8In "onstants....................................................................;'4.% Built8In 6ni#or (tate....................................................................................................... ;'

    4.%.1 "oati9ilit) 2ro#ile (tate......................................................................................... ;45 Built8in 3unctions................................................................................................................... 1*1

    5.1 Angle and -rigonoetr) 3unctions..................................................................................1*!5.! Eonential 3unctions......................................................................................................1*%5.& "oon 3unctions.......................................................................................................... 1*$5.% 3loating82oint 2ack and 6nack 3unctions..................................................................... 1115.$ /eoetric 3unctions........................................................................................................ 11&5.' atri 3unctions.............................................................................................................. 11$5.4 Vector Relational 3unctions.............................................................................................114

    5.5 Integer 3unctions..............................................................................................................11;5.; -eture 3unctions.............................................................................................................1!1

    5.;.1 -eture

  • 8/12/2019 GLSL Specification 4.10.6

    6/162

  • 8/12/2019 GLSL Specification 4.10.6

    7/162

    1 Introduction

    -his docuent seci#ies onl) version %.1* o# the +en/0 (hading 0anguage. It re=uires >>VER(I+7>>

    to su9stitute %1*, and re=uires #versionto accet onl) %1*. I# #version is declared with a saller

    nu9er, the language acceted is a revious version o# the shading language, which will 9e suorted

    deending on the version and t)e o# contet in the +en/0 A2I. (ee the +en/0 /rahics ()ste

    (eci#ication, Version %.1, #or details on what language versions are suorted.

    2revious versions o# the +en/0 (hading 0anguage, as well as the +en/0 E( (hading 0anguage, are

    not strict su9sets o# the version seci#ied here, articularl) with resect to recision, nae8hiding rules,

    and treatent o# inter#ace varia9les. (ee the seci#ication corresonding to a articular language version

    #or details seci#ic to that version o# the language.

    All +en/0 /rahics ()ste (eci#ication re#erences in this seci#ication are to version %.1.

    1

  • 8/12/2019 GLSL Specification 4.10.6

    8/162

    1 Introduction

    1.1 Acknowledgments

    -his seci#ication is 9ased on the work o# those who contri9uted to ast versions o# the +en/0

    0anguage (eci#ication, the +en/0 E( !.* 0anguage (eci#ication, and the #ollowing contri9utors tothis version:

    2at Brown, 7vidia

    Je## Bol?, 7vidia

    3rank "hen

    2ierre Boudier, AD

    2iers Daniell, 7vidia

    "hris Dodd, 7vidia

    Eric @erness, 7vidia

    7ick aeel, AD

    Jason /reen, -rans/aing

    Brent Insko, Intel

    Jon 0eechBill 0icea8Kane, AD

    Daniel Koch, -ransgaing

    Barthold 0ichten9elt, 7vidia

    Bruce err), AR

    Ro9ert +hannessian

    Acorn 2oole), 7vidia

    Kevin Rogovin

    Ian Roanick, Intel

    /reg Roth, 7vidia

    /raha (ellers, AD

    Dave (hreiner, AR

    Jere) (andel, Ale

    Ro9ert (ison,

  • 8/12/2019 GLSL Specification 4.10.6

    9/162

    1 Introduction

    1.2.2 Changes from revision

    Added the changes section #or revision &.

    inor udates #or linking o# ultile rogras, s)ncing with the latest etension seci#ication #orsearate shader o9ects /0>ARB>searate>shader>o9ectsF and incororating other editorial

    #eed9ack.

    1.2.! Changes from revision !

    Relaed recision re=uireents #or exp F and srt F.

    3or esta9lishing inter#aces 9etween rogras, no longer allow general glo9al redeclaration o# 9uilt8in

    9lock e9ers outside o# 9lock redeclarations.

    1.2. Changes from revision 2

    Add the inter#ace 9lockgl!er"ragment and redeclaration o# inter#ace 9locks to esta9lish inter#aces

    9etween rogras #or 9uilt8in varia9les.

    6dated soe recisions with range8seci#ic 9ehavior.

    1.2.5 Changes from revision 1

    Added suort #or ultile rogras.

    Edited all use o# GrograG #or consistenc) with suort o# 9oth a single rogra or ultile

    rogras to esta9lish a colete ieline.

    inor graatical #ies.

    1.2." Summar# of Changes from $ersion .%%

    7ote: 7o #eatures were reoved or derecated 9etween versions %.** and %.1*.

    (uort #or artitioning shaders into ultile rogras to rovide light8weight iing o# di##erent

    shader stages.

    Iroved coati9ilit) with the +en/0 E( (hading 0anguage.

    E licitl) state the re=uired recision o# ost oerations.

    Add '%89it #loating8oint attri9utes #or verte shader inuts.

    (uort v iewort arra)s so where t he geoetr) shader selects which viewort arra) will trans#or its

    outut.

    3

  • 8/12/2019 GLSL Specification 4.10.6

    10/162

    1 Introduction

    1.! Overvie&

    -his docuent descri9es #he $%en&L 'ha(ing Language) version %.1*.

    Indeendent coilation units written in this language are calledsha(ers. A%rogramis a colete set o#shaders that are coiled and linked together, coletel) creating one or ore o# the rograa9le

    stages o# the +en/0 ieline. All the shaders #or a single rograa9le stage ust 9e within the sae

    rogra. A colete set o# rograa9le stages can 9e ut into a single rogra or the stages can 9e

    artitioned across ultile rogras. -he ai o# this docuent is to thoroughl) seci#) the rograing

    language. -he +en/0 /rahics ()ste (eci#ication will seci#) the +en/0 entr) oints used to

    aniulate and counicate with rogras and shaders.

    1. 'rror (andling

    "oilers, in general, accet rogras that are ill8#ored, due to the iossi9ilit) o# detecting all ill8

    #ored rogras. 2orta9ilit) is onl) ensured #or well8#ored rogras, which this seci#ication

    descri9es. "oilers are encouraged to detect ill8#ored rogras and issue diagnostic essages, 9ut are

    not re=uired to do so #or all cases. "oilers are re=uired to return essages regarding leicall),

    graaticall), or seanticall) incorrect shaders.

    1.5 T#pographical Conventions

    Italic, 9old, and #ont choices have 9een used in this seci#ication riaril) to irove reada9ilit). "ode

    #ragents use a #ied width #ont. Identi#iers e9edded in tet are italici?ed. Ke)words e9edded in tet

    are 9old. +erators are called 9) their nae, #ollowed 9) their s)9ol in 9old in arentheses. -he

    clari#)ing graar #ragents in the tet use 9old #or literals and italics #or non8terinals. -he o##icial

    graar in section ; (hading 0anguage /raarC uses all caitals #or terinals and lower case #or

    non8terinals.

    1." )eprecation2revious versions o# the +en/0 (hading 0anguage derecated soe #eatures. -hese are clearl) called

    out in this seci#ication as derecatedC. -he) are still resent in this version o# the language, 9ut are

    targeted #or otential reoval in a #uture version o# the shading language. -he +en/0 A2I has a

    #orward coati9ilit) ode that will disallow use o# derecated #eatures. I# coiling in a ode where

    use o# derecated #eatures is disallowed, their use causes coile tie errors. (ee the +en/0 /rahics

    ()ste (eci#ication #or details on what causes derecated language #eatures to 9e acceted or to return

    an error.

    4

  • 8/12/2019 GLSL Specification 4.10.6

    11/162

    2 Overvie& of OpenGL Shading

    -he +en/0 (hading 0anguage is actuall) several closel) related languages. -hese languages are used

    to create shaders #or each o# the rograa9le rocessors contained in the +en/0 rocessing ieline.

    "urrentl), these rocessors are the verte, tessellation control, tessellation evaluation, geoetr), and

    #ragent rocessors.

    6nless otherwise noted in this aer, a language #eature alies to all languages, and coon usage will

    re#er to these languages as a single language. -he seci#ic languages will 9e re#erred to 9) the nae o#

    the rocessor the) target: verte, tessellation control, tessellation evaluation, geoetr), or #ragent.

    ost +en/0 state is not tracked or ade availa9le to shaders. -)icall), user8de#ined varia9les will 9e

    used #or counicating 9etween di##erent stages o# the +en/0 ieline. owever, a sall aount o#state is still tracked and autoaticall) ade availa9le to shaders, and there are a #ew 9uilt8in varia9les #or

    inter#aces 9etween di##erent stages o# the +en/0 ieline.

    2.1 $erte* +rocessor

    -he verte* %rocessoris a rograa9le unit that oerates on incoing vertices and their associated data.

    "oilation units written in the +en/0 (hading 0anguage to run on this rocessor are called verte*

    sha(ers. @hen a colete set o# verte shaders are coiled and linked, the) result in a verte* sha(er

    e*ecuta+lethat runs on the verte rocessor.

    -he verte rocessor oerates on one verte at a tie. It does not relace grahics oerations that re=uire

    knowledge o# several vertices at a tie.

    2.2 Tessellation Control +rocessor

    -he tessellation control rocessor is a rograa9le unit that oerates on a atch o# incoing vertices

    and their associated data, eitting a new outut atch. "oilation units written in the +en/0 (hading

    0anguage to run on this rocessor are called tessellation control shaders. @hen a colete set o#

    tessellation control shaders are coiled and linked, the) result in a tessellation control shader eecuta9le

    that runs on the tessellation control rocessor.

    -he tessellation control shader is invoked #or each verte o# the outut atch. Each invocation can read

    the attri9utes o# an) verte in the inut or outut atches, 9ut can onl) write er8verte attri9utes #or the

    corresonding outut atch verte. -he shader invocations collectivel) roduce a set o# er8atch

    attri9utes #or the outut atch. A#ter all tessellation control shader invocations have coleted, the outut

    vertices and er8atch attri9utes are asse9led to #or a atch to 9e used 9) su9se=uent ieline stages.

    5

  • 8/12/2019 GLSL Specification 4.10.6

    12/162

    2 Overview of OpenGL Shading

    -essellation control shader invocation run ostl) indeendentl), with unde#ined relative eecution order.

    owever, the 9uilt8in #unction 9arrierF can 9e used to control eecution order 9) s)nchroni?ing

    invocations, e##ectivel) dividing tessellation control shader eecution into a set o# hases. -essellation

    control shaders will get unde#ined results i# one invocation reads a er8verte or er8atch attri9utewritten 9) another invocation at an) oint during the sae hase, or i# two invocations attet to write

    di##erent values to the sae er8atch outut in a single hase.

    2.! Tessellation 'valuation +rocessor

    -he tessellation evaluation rocessor is a rograa9le unit that evaluates the osition and other

    attri9utes o# a verte generated 9) the tessellation riitive generator, using a atch o# incoing vertices

    and their associated data. "oilation units written in the +en/0 (hading 0anguage to run on this

    rocessor are called tessellation evaluation shaders. @hen a colete set o# tessellation evaluation

    shaders are coiled and linked, the) result in a tessellation evaluation shader eecuta9le that runs on the

    tessellation evaluation rocessor.

    Each invocation o# the tessellation evaluation eecuta9le coutes the osition and attri9utes o# a singleverte generated 9) the tessellation riitive generator. -he eecuta9le can read the attri9utes o# an)

    verte in the inut atch, lus the tessellation coordinate, which is the relative location o# the verte in the

    riitive 9eing tessellated. -he eecuta9le writes the osition and other attri9utes o# the verte.

    2. Geometr# +rocessor

    -hegeometr, %rocessor is a rograa9le unit that oerates on data #or incoing vertices #or a riitive

    asse9led a#ter verte rocessing and oututs a se=uence o# vertices #oring outut riitives.

    "oilation units written in the +en/0 (hading 0anguage to run on this rocessor are calledgeometr,

    sha(ers. @hen a colete set o# geoetr) shaders are coiled and linked, the) result in ageometr,

    sha(er e*ecuta+le that runs on the geoetr) rocessor.

    A single invocation o# the geoetr) shader eecuta9le on the geoetr) rocessor will oerate on a

    declared inut riitive with a #ied nu9er o# vertices. -his single invocation can eit a varia9le

    nu9er o# vertices that are asse9led into riitives o# a declared outut riitive t)e and assed to

    su9se=uent ieline stages.

    2.5 ,ragment +rocessor

    -hefragment %rocessoris a rograa9le unit that oerates on #ragent values and their associated

    data. "oilation units written in the +en/0 (hading 0anguage to run on this rocessor are called

    fragment sha(ers. @hen a colete set o# #ragent shaders are coiled and linked, the) result in a

    fragment sha(er e*ecuta+lethat runs on the #ragent rocessor.

    A #ragent shader cannot change a #ragentGs *,,F osition. Access to neigh9oring #ragents is not

    allowed. -he values couted 9) the #ragent shader are ultiatel) used to udate #rae9u##er eor)

    or teture eor), deending on the current +en/0 state and the +en/0 coand that caused the

    #ragents to 9e generated.

    6

  • 8/12/2019 GLSL Specification 4.10.6

    13/162

    ! -asics

    !.1 Character Set

    -he source character set used #or the +en/0 shading languages is a su9set o# A("II. It includes the

    #ollowing characters:

    -he letters a!", A!$ and the underscore >F.

    -he nu9ers%!&.

    -he s)9ols eriod .F, lus 'F, dash !F, slash (F, asterisk )F, ercent *F, angled 9rackets +and

    ,F, s=uare 9rackets -and F, arentheses /and 0F, 9races and 2F, caret 3F, vertical 9ar 4F,

    aersand 5F, tilde 6F, e=uals 7F, eclaation oint 8F, colon 9F, seicolon :F, coa $F, and=uestion ark ;F.

    -he nu9er sign #F #or rerocessor use.

    @hite sace: the sace character, hori?ontal ta9, vertical ta9, #or #eed, carriage8return, and line8

    #eed.

    0ines are relevant #or coiler diagnostic essages and the rerocessor. -he) are terinated 9)

    carriage8return or line8#eed. I# 9oth are used together, it will count as onl) a single line terination. 3or

    the reainder o# this docuent, an) o# these co9inations is sil) re#erred to as a new8line. -here is no

    line continuation character.

    In general, the languageHs use o# this character set is case sensitive.

    -here are no character or string data t)es, so no =uoting characters are included.

    -here is no end8o#8#ile character.

    !.2 Source Strings

    -he source #or a single shader is an arra) o# strings o# characters #ro the character set. A single shader

    is ade #ro the concatenation o# these strings. Each string can contain ultile lines, searated 9) new8

    lines. 7o new8lines need 9e resent in a string a single line can 9e #ored #ro ultile strings. 7o

    new8lines or other characters are inserted 9) the ileentation when it concatenates the strings to #or a

    single shader. ultile shaders can 9e linked together to #or a single rogra.

    Diagnostic essages returned #ro coiling a shader ust identi#) 9oth the line nu9er within a string

    and which source string the essage alies to. (ource strings are counted se=uentiall) with the #irst

    string 9eing string *. 0ine nu9ers are one ore than the nu9er o# new8lines that have 9een rocessed.

    7

  • 8/12/2019 GLSL Specification 4.10.6

    14/162

    3 Basics

    !.! +reprocessor

    -here is a rerocessor that rocesses the source strings as art o# the coilation rocess.

    -he colete list o# rerocessor directives is as #ollows.

    #

    #define

    #undef

    #if

    #ifdef

    #ifndef

    #else

    #elif

    #endif

    #error

    #pragma

    #extension

    #version

    #line

    -he #ollowing oerators are also availa9le

    defined

    ##

    Each nu9er sign #F can 9e receded in its line onl) 9) saces or hori?ontal ta9s. It a) also 9e

    #ollowed 9) saces and hori?ontal ta9s, receding the directive. Each directive is terinated 9) a new8

    line. 2rerocessing does not change the nu9er or relative location o# new8lines in a source string.

    -he nu9er sign #F on a line 9) itsel# is ignored. An) directive not listed a9ove will cause a diagnostic

    essage and ake the ileentation treat the shader as ill8#ored.

    #defineand #undef#unctionalit) are de#ined as is standard #or " rerocessors #or acro de#initions

    9oth with and without acro araeters.

    -he #ollowing rede#ined acros are availa9le

    __LINE__

    __FILE__

    __VERSION__

    L/will su9stitute a decial integer constant that is one ore than the nu9er o# receding new8lines in the current source string.

    "L/will su9stitute a decial integer constant that sa)s which source string nu9er is currentl)

    9eing rocessed.

  • 8/12/2019 GLSL Specification 4.10.6

    15/162

    3 Basics

    V/R'$will su9stitute a decial integer re#lecting the version nu9er o# the +en/0 shading

    language. -he version o# the shading language descri9ed in this docuent will haveV/R'$

    su9stitute the decial integer %1*.

    All acro naes containing two consecutive underscores C /0C #ollowed 9) a single underscoreF are also

    reserved.

    #if$ #ifdef$ #ifndef$ #else$ #elif$ and#endifare de#ined to oerate as is standard #or " rerocessors.

    Eressions #ollowing #ifand #elifare #urther restricted to eressions oerating on literal integer

    constants, lus identi#iers consued 9) the definedoerator. It is an error to use #if or #elif on

    eressions containing unde#ined acro naes, other than as arguents to the defined oerator.

    "haracter constants are not suorted. -he oerators availa9le are as #ollows.

    +recedence Operator class Operators ssociativit#

    1 highestF arenthetical grouing F 7A

    ! unar) de#ined 8 L

    Right to 0e#t

    & ultilicative M N O 0e#t to Right

    % additive 8 0e#t to Right

    $ 9it8wise shi#t PP QQ 0e#t to Right

    ' relational P Q P Q 0e#t to Right

    4 e=ualit) L 0e#t to Right

    5 9it8wise and S 0e#t to Right

    ; 9it8wise eclusive or T 0e#t to Right

    1* 9it8wise inclusive or U 0e#t to Right

    11 logical and SS 0e#t to Right

    1! lowestF logical inclusive or U U 0e#t to Right

    -he definedoerator can 9e used in either o# the #ollowing wa)s:

    defined identifier

    defined( identifier )

    -wo tokens in a acro can 9e concatenated into one token using the token asting ##Foerator, as is

    standard #or " rerocessors. -he result ust 9e a valid single token, which will then 9e su9ect to

    acro eansion. -hat is, acro eansion haens onl) a#ter token asting. -here are no other nu9ersign 9ased oerators e.g., no # or#=F, nor is there a si"eofoerator.

    -he seantics o# al)ing oerators to integer literals in the rerocessor atch those standard in the

    " rerocessor, not those in the +en/0 (hading 0anguage.

    !

  • 8/12/2019 GLSL Specification 4.10.6

    16/162

    3 Basics

    2rerocessor eressions will 9e evaluated according to the 9ehavior o# the host rocessor, not the

    rocessor targeted 9) the shader.

    #error will cause the ileentation to ut a diagnostic essage into the shader o9ectHs in#oration log

    section '.1.1! (hader and 2rogra ?@raga is used to reserve ragas #or use 9) #uture revisions o# this language. 7o

    ileentation a) use a raga whose #irst token is S>?@.

    #pragma optimi"eon)

    #pragma optimi"eoff)

    can 9e used to turn o## otii?ations as an aid in develoing and de9ugging shaders. It can onl) 9e used

    outside #unction de#initions. B) de#ault, otii?ation is turned on #or all shaders. -he de9ug raga

    #pragma de$ugon)

    #pragma de$ugoff)

    can 9e used to ena9le coiling and annotating a shader with de9ug in#oration, so that it can 9e used

    with a de9ugger. It can onl) 9e used outside #unction de#initions. B) de#ault, de9ug is turned o##.

    (haders should declare the version o# the language the) are written to. -he language version a shader is

    written to is seci#ied 9)

    #version number profileopt

    where num+erust 9e a version o# the language, #ollowing the sae convention asV/R'$a9ove.

    -he directive #version B1%C is re=uired in an) shader that uses version %.1* o# the language. An)

    num+erreresenting a version o# the language a coiler does not suort will cause an error to 9e

    generated. Version 1.1* o# the language does not re=uire shaders to include this directive, and shaders that

    do not include a #versiondirective will 9e treated as targeting version 1.1*. (haders that seci#)

    #version1** will 9e treated as targeting version 1.** o# the +en/0 E( (hading 0anguage.

    (haders declaring version 1.%*, 1.$*, &.&*, or %.* o# the shading language can 9e linked with shaders

    declaring version %.1* in the sae rogra. (haders targeting earlier versions 1.&* or earlierF o# the

    shading language cannot 9e linked with version %.1* shaders.

    1"

  • 8/12/2019 GLSL Specification 4.10.6

    17/162

    3 Basics

    I# the otional%rofile arguent is rovided, it ust 9e the nae o# an +en/0 ro#ile. "urrentl), there

    are two choices:

    %ore

    %ompati$ilit&

    I# no%rofile arguent is rovided, the de#ault is core. 6nless otherwise seci#ied, this seci#ication is

    docuenting the core ro#ile, and ever)thing seci#ied #or the core ro#ile is also availa9le in the

    coati9ilit) ro#ile. 3eatures seci#ied as 9elonging seci#icall) to the coati9ilit) ro#ile are not

    availa9le in the core ro#ile.

    -here is a 9uilt8in acro de#inition #or each ro#ile the ileentation suorts. All ileentations

    rovide the #ollowing acro:

    #define !L_%ore_profile '

    Ileentations roviding the coati9ilit) ro#ile rovide the #ollowing acro:

    #define !L_%ompati$ilit&_profile '

    -he #versiondirective ust occur in a shader 9e#ore an)thing else, ecet #or coents and white sace.

    11

  • 8/12/2019 GLSL Specification 4.10.6

    18/162

    3 Basics

    B) de#ault, coilers o# this language ust issue coile tie s)ntactic, graatical, and seantic

    errors #or shaders that do not con#or to this seci#ication. An) etended 9ehavior ust #irst 9e ena9led.

    Directives to control the 9ehavior o# the coiler with resect to etensions are declared with the

    #extensiondirective

    #extension extension_name:behavior

    #extension all :behavior

    where e*tensionnameis the nae o# an etension. Etension naes are not docuented in this

    seci#ication. -he token alleans the 9ehavior alies to all etensions suorted 9) the coiler. -he

    +ehavior can 9e one o# the #ollowing

    behavior 'ffect

    re/uire Behave as seci#ied 9) the etension e*tensionname.

    /ive an error on the #extension i# the etension e*tensionname is notsuorted, or i# allis seci#ied.

    enable Behave as seci#ied 9) the etension e*tensionname.

    @arn on the #extensioni# the etension e*tensionnameis not suorted.

    /ive an error on the #extension i# allis seci#ied.

    &arn Behave as seci#ied 9) the etension e*tensionname, ecet issue warningson an) detecta9le use o# that etension, unless such use is suorted 9) otherena9led or re=uired etensions.

    I# all is seci#ied, then warn on all detecta9le uses o# an) etension used.

    @arn on the #extensioni# the etension e*tensionnameis not suorted.

    disable Behave including issuing errors and warningsF as i# the etensione*tensionnameis not art o# the language de#inition.

    I# all is seci#ied, then 9ehavior ust revert 9ack to that o# the non8etendedcore version o# the language 9eing coiled to.

    @arn on the #extension i# the etension e*tensionnameis not suorted.

    -he extensiondirective is a sile, low8level echanis to set the 9ehavior #or each etension. It does

    not de#ine olicies such as which co9inations are aroriate, those ust 9e de#ined elsewhere. +rder

    o# directives atters in setting the 9ehavior #or each etension: Directives that occur later override those

    seen earlier. -he allvariant sets the 9ehavior #or all etensions, overriding all reviousl) issued

    extension directives, 9ut onl) #or the +ehaviorswarnand disable.

    12

  • 8/12/2019 GLSL Specification 4.10.6

    19/162

    3 Basics

    -he initial state o# the coiler is as i# the directive

    #extension all ( disa$le

    was issued, telling the coiler that all error and warning reorting ust 9e done according to thisseci#ication, ignoring an) etensions.

    Each etension can de#ine its allowed granularit) o# scoe. I# nothing is said, the granularit) is a shader

    that is, a single coilation unitF, and the etension directives ust occur 9e#ore an) non8rerocessor

    tokens. I# necessar), the linker can en#orce granularities larger than a single coilation unit, in which

    case each involved shader will have to contain the necessar) etension directive.

    acro eansion is not done on lines containing #extensionand #versiondirectives.

    #lineust have, a#ter acro su9stitution, one o# the #ollowing #ors:

    #line line

    #line line source-string-number

    where line andsource-string-num+er are constant integer eressions. A#ter rocessing this directiveincluding its new8lineF, the ileentation will 9ehave as i# it is coiling at line nu9er lineand

    source string nu9ersource-string-num+er. (u9se=uent source strings will 9e nu9ered se=uentiall),

    until another #linedirective overrides that nu9ering.

    !. Comments

    "oents are deliited 9) NM and MN, or 9) NN and a new8line. -he 9egin coent deliiters NM or NNF are

    not recogni?ed as coent deliiters inside o# a coent, hence coents cannot 9e nested. I# a

    coent resides entirel) within a single line, it is treated s)ntacticall) as a single sace. 7ew8lines are

    not eliinated 9) coents.

    !.5 To0ens-he language is a se=uence o# tokens. A token can 9e

    toen:

    e,wor(

    i(entifier

    integer-constant

    floating-constant

    o%erator

    : 2

    !." e#&ords

    -he #ollowing are the ke)words in the language, and cannot 9e used #or an) other urose than that

    de#ined 9) this docuent:

    attribute const uniform varing

    laout

    13

  • 8/12/2019 GLSL Specification 4.10.6

    20/162

    3 Basics

    centroid flat smooth noperspective

    patch sample

    break continue do for while switch case defaultif else

    subroutine

    in out inout

    float double int void bool true false

    invariant

    discard return

    matD matE matB dmatD dmatE dmatB

    matDxD matDxE matDxB dmatDxD dmatDxE dmatDxB

    matExD matExE matExB dmatExD dmatExE dmatExB matBxD matBxE matBxB dmatBxD dmatBxE dmatBxB

    vecD vecE vecB ivecD ivecE ivecB bvecD bvecE bvecB dvecD dvecE dvecB

    uint uvecD uvecE uvecB

    lowp mediump highp precision

    sampler1? samplerD? samplerE? samplerCube

    sampler1?Shadow samplerD?Shadow samplerCubeShadow

    sampler1?Arra samplerD?Arra

    sampler1?ArraShadow samplerD?ArraShadow

    isampler1? isamplerD? isamplerE? isamplerCube

    isampler1?Arra isamplerD?Arra

    usampler1? usamplerD? usamplerE? usamplerCube

    usampler1?Arra usamplerD?Arra

    samplerD?Fect samplerD?FectShadow isamplerD?Fect usamplerD?Fect

    samplerGuffer isamplerGuffer usamplerGuffer

    samplerD?HS isamplerD?HS usamplerD?HS

    samplerD?HSArra isamplerD?HSArra usamplerD?HSArra

    samplerCubeArra samplerCubeArraShadow isamplerCubeArra usamplerCubeArra

    struct

    14

  • 8/12/2019 GLSL Specification 4.10.6

    21/162

    3 Basics

    -he #ollowing are the ke)words reserved #or #uture use. 6sing the will result in an error:

    common partition active

    asm class union enum tpedef template this packed

    goto

    inline noinline volatile public static extern external interface

    long short half fixed unsigned superp

    input output

    hvecD hvecE hvecB fvecD fvecE fvecB

    samplerE?Fect

    filter

    image1? imageD? imageE? imageCube

    iimage1? iimageD? iimageE? iimageCube

    uimage1? uimageD? uimageE? uimageCube

    image1?Arra imageD?Arra

    iimage1?Arra iimageD?Arra uimage1?Arra uimageD?Arra

    image1?Shadow imageD?Shadow

    image1?ArraShadow imageD?ArraShadow

    imageGuffer iimageGuffer uimageGuffer

    si"eof cast

    namespace using

    row

  • 8/12/2019 GLSL Specification 4.10.6

    22/162

    3 Basics

    non(igit: one o#

    < a b c d e f g h i I k l m n o p r s t u v w x "

    A G C ? J K @ L M N H P O Q R F S > T U V W

    (igit: one o#

    % 1 D E B X Y Z [ &

    Identi#iers starting with gl>C are reserved #or use 9) +en/0, and a) not 9e declared in a shader as

    either a varia9le or a #unction. owever, as noted in the seci#ication, there are soe cases where

    reviousl) declared varia9les can 9e redeclared to change or add soe roert), and redeclared gl>

    naes are allowed to 9e redeclared in a shader onl) #or these seci#ic uroses. ore generall), it is an

    error to redeclare a varia9le, including those starting gl>C.

    !.3 )efinitions

    (oe language rules descri9ed 9elow deend on the #ollowing de#initions.

    !.3.1 Static 4se

    A shader contains astatic useo# orstatic assignmenttoF a varia9le*i#, a#ter rerocessing, the shader

    contains a stateent that would read or writeF*, whether or not run8tie #low o# control will cause that

    stateent to 9e eecuted.

    !.3.2 4niform and on64niform Control ,lo&

    @hen eecuting stateents in a #ragent shader, control #low starts as uniform control flow all #ragents

    enter the sae control ath into mainF. "ontrol #low 9ecoes non-uniform when di##erent #ragents

    take di##erent aths through control8#low stateents selection, iteration, and usF. "ontrol #low

    su9se=uentl) returns to 9eing uni#or a#ter such divergent su98stateents or skied code coletes,until the net tie di##erent control aths are taken.

    3or eale:

    main)

    float a * +++,-- t.is is uniform flo/ %ontrol

    if a 0 $) -- t.is expression is true for some fragments1 not all

    ++++, -- non2uniform flo/ %ontrol

    3 else

    ++++, -- non2uniform flo/ %ontrol

    3

    ++++, -- uniform flo/ %ontrol again

    3

    +ther eales o# non8uni#or #low control can occur within switch stateents and a#ter conditional

    9reaks, continues, earl) returns, and a#ter #ragent discards, when the condition is true #or soe

    #ragents 9ut not others. 0oo iterations that onl) soe #ragents eecute are also non8uni#or #low

    control.

    16

  • 8/12/2019 GLSL Specification 4.10.6

    23/162

    3 Basics

    -his is siilarl) de#ined #or other shader stages, 9ased on the er8instance data ites the) rocess.

    !.3.! )#namicall# 4niform '*pressions

    A #ragent8shader eression is (,namicall, uniform i# all #ragents evaluating it get the sae resulting

    value. @hen loos are involved, this re#ers to the eressionGs value #or the sae loo iteration. @hen

    #unctions are involved, this re#ers to calls #ro the sae call oint.

    -his is siilarl) de#ined #or other shader stages, 9ased on the er8instance data the) rocess.

    7ote that constant eressions are triviall) d)naicall) uni#or. It #ollows that t)ical loo counters

    9ased on these are also d)naicall) uni#or.

    17

  • 8/12/2019 GLSL Specification 4.10.6

    24/162

    $ariables and T#pes

    All varia9les and #unctions ust 9e declared 9e#ore 9eing used. Varia9le and #unction naes are

    identi#iers.

    -here are no de#ault t)es. All varia9le and #unction declarations ust have a declared t)e, and

    otionall) =uali#iers. A varia9le is declared 9) seci#)ing its t)e #ollowed 9) one or ore naes

    searated 9) coas. In an) cases, a varia9le can 9e initiali?ed as art o# its declaration 9) using the

    assignent oerator 7F. -he graar near the end o# this docuent rovides a #ull re#erence #or the

    s)nta o# declaring varia9les.

    6ser8de#ined t)es a) 9e de#ined using structto aggregate a list o# eisting t)es into a single nae.

    -he +en/0 (hading 0anguage is t)e sa#e. -here are no ilicit conversions 9etween t)es, with theecetion that an integer value a) aear where a #loating8oint t)e is eected, and 9e converted to a

    #loating8oint value. Eactl) how and when this can occur is descri9ed in section %.1.1*Ilicit

    "onversionsC and as re#erenced 9) other sections in this seci#ication.

    .1 -asic T#pes

    -he +en/0 (hading 0anguage suorts the #ollowing 9asic data t)es, groued as #ollows.

    -ransarent t)es

    T#pe 7eaning

    void #or #unctions that do not return a value

    bool a conditional t)e, taking on values o# true or #alse

    int a signed integer

    uint an unsigned integer

    float a single #loating8oint scalar

    double a single dou9le8recision #loating oint scalar

    vecD a two8coonent #loating8oint vector

    vecE a three8coonent #loating8oint vector

    vecB a #our8coonent #loating8oint vector

    dvecD a two8coonent dou9le8recision #loating8oint vector

    dvecE a three8coonent dou9le8recision #loating8oint vector

    dvecB a #our8coonent dou9le8recision #loating8oint vector

    bvecD a two8coonent Boolean vector

    bvecE a three8coonent Boolean vector

    1

  • 8/12/2019 GLSL Specification 4.10.6

    25/162

    4 #aria$%es and &'pes

    T#pe 7eaning

    bvecB a #our8coonent Boolean vector

    ivecD a two8coonent signed integer vectorivecE a three8coonent signed integer vector

    ivecB a #our8coonent signed integer vector

    uvecD a two8coonent unsigned integer vector

    uvecE a three8coonent unsigned integer vector

    uvecB a #our8coonent unsigned integer vector

    matD a !W! #loating8oint atri

    matE a &W& #loating8oint atri

    matB a %W% #loating8oint atri

    matDxD sae as a matDmatDxE a #loating8oint atri with ! coluns and & rows

    matDxB a #loating8oint atri with ! coluns and % rows

    matExD a #loating8oint atri with & coluns and ! rows

    matExE sae as a matE

    matExB a #loating8oint atri with & coluns and % rows

    matBxD a #loating8oint atri with % coluns and ! rows

    matBxE a #loating8oint atri with % coluns and & rows

    matBxB sae as a matB

    dmatD a !W! dou9le8recision #loating8oint atridmatE a &W& dou9le8recision #loating8oint atri

    dmatB a %W% dou9le8recision #loating8oint atri

    dmatDxD sae as a dmatD

    dmatDxE a dou9le8recision #loating8oint atri with ! coluns and & rows

    dmatDxB a dou9le8recision #loating8oint atri with ! coluns and % rows

    dmatExD a dou9le8recision #loating8oint atri with & coluns and ! rows

    dmatExE sae as a dmatE

    dmatExB a dou9le8recision #loating8oint atri with & coluns and % rows

    dmatBxD a dou9le8recision #loating8oint atri with % coluns and ! rowsdmatBxE a dou9le8recision #loating8oint atri with % coluns and & rows

    dmatBxB sae as a dmatB

    1!

  • 8/12/2019 GLSL Specification 4.10.6

    26/162

    4 #aria$%es and &'pes

    3loating 2oint (aler -)es oa=ueF

    T#pe 7eaning

    sampler1? a handle #or accessing a 1D teture

    samplerD? a handle #or accessing a !D teture

    samplerE? a handle #or accessing a &D teture

    samplerCube a handle #or accessing a cu9e aed teture

    samplerD?Fect a handle #or accessing a rectangular teture

    sampler1?Shadow a handle #or accessing a 1D deth teture with coarison

    samplerD?Shadow a handle #or accessing a !D deth teture with coarison

    samplerD?FectShadow a handle #or accessing a rectangular teture with coarison

    sampler1?Arra a handle #or accessing a 1D arra) teture

    samplerD?Arra a handle #or accessing a !D arra) teturesampler1?ArraShadow a handle #or accessing a 1D arra) deth teture with coarison

    samplerD?ArraShadow a handle #or accessing a !D arra) deth teture with coarison

    samplerGuffer a handle #or accessing a 9u##er teture

    samplerD?HS a handle #or accessing a !D ulti8sale teture

    samplerD?HSArra a handle #or accessing a !D ulti8sale arra) teture

    samplerCubeShadow a handle #or accessing a cu9e a deth teture with coarison

    samplerCubeArra a handle #or accessing a cu9e a arra) teture

    samplerCubeArraShadow a handle #or accessing a cu9e a arra) deth teture withcoarison

    (igned Integer (aler -)es oa=ueF

    T#pe 7eaning

    isampler1? a handle #or accessing an integer 1D teture

    isamplerD? a handle #or accessing an integer !D teture

    isamplerE? a handle #or accessing an integer &D teture

    isamplerCube a handle #or accessing an integer cu9e aed teture

    isamplerD?Fect a handle #or accessing an integer !D rectangular teture

    isampler1?Arra a handle #or accessing an integer 1D arra) teture

    isamplerD?Arra a handle #or accessing an integer !D arra) teture

    isamplerGuffer a handle #or accessing an integer 9u##er teture

    isamplerD?HS a handle #or accessing an integer !D ulti8sale teture

    isamplerD?HSArra a handle #or accessing an integer !D ulti8sale arra) teture

    2"

  • 8/12/2019 GLSL Specification 4.10.6

    27/162

    4 #aria$%es and &'pes

    T#pe 7eaning

    isamplerCubeArra a handle #or accessing an integer cu9e a arra) teture

    6nsigned Integer (aler -)es oa=ueF

    T#pe 7eaning

    usampler1? a handle #or accessing an unsigned integer 1D teture

    usamplerD? a handle #or accessing an unsigned integer !D teture

    usamplerE? a handle #or accessing an unsigned integer &D teture

    usamplerCube a handle #or accessing an unsigned integer cu9e aed teture

    usamplerD?Fect a handle #or accessing an unsigned integer rectangular teture

    usampler1?Arra a handle #or accessing an unsigned integer 1D arra) teture

    usamplerD?Arra a handle #or accessing an unsigned integer !D arra) teture

    usamplerGuffer a handle #or accessing an unsigned integer 9u##er teture

    usamplerD?HS a handle #or accessing an unsigned integer !D ulti8sale teture

    usamplerD?HSArra a handle #or accessing an unsigned integer !D ulti8sale teturearra)

    usamplerCubeArra a handle #or accessing an unsigned integer cu9e a arra) teture

    In addition, a shader can aggregate these using arra)s and structures to 9uild ore cole t)es.

    -here are no ointer t)es.

    .1.1 $oid3unctions that do not return a value ust 9e declared as void. -here is no de#ault #unction return t)e.

    -he ke)word voidcannot 9e used in an) other declarations ecet #or et) #oral or actual araeter

    listsF.

    .1.2 -ooleans

    -o ake conditional eecution o# code easier to eress, the t)e boolis suorted. -here is no

    eectation that hardware directl) suorts varia9les o# this t)e. It is a genuine Boolean t)e, holding

    onl) one o# two values eaning either true or #alse. -wo ke)words trueand falsecan 9e used as literal

    Boolean constants. Booleans are declared and otionall) initiali?ed as in the #ollow eale:

    $ool su%%ess, -- de%lare 4su%%ess5 to $e a 6oolean

    $ool done * false, -- de%lare and initiali"e 4done5

    -he right side o# the assignent oerator 7 F ust 9e an eression whose t)e is bool.

    Eressions used #or conditional us if$ for$ ;9$ while$ do!whileF ust evaluate to the t)e bool.

    21

  • 8/12/2019 GLSL Specification 4.10.6

    28/162

    4 #aria$%es and &'pes

    .1.! Integers

    (igned and unsigned integer varia9les are #ull) suorted. In this docuent, the ter integer is eant to

    generall) include 9oth signed and unsigned integers. 6nsigned integers have eactl) &! 9its o# recision.

    (igned integers use &! 9its, including a sign 9it, in twoGs coleent #or. +erations resulting in

    over#low or under#low will not cause an) ecetion, nor will the) saturate, rather the) will wraC to )ield

    the low8order &! 9its o# the result.

    Integers are declared and otionall) initiali?ed with integer eressions, as in the #ollowing eale:

    int i1 7 * 89, -- default integer literal t&pe is int

    uint : * ;u, -- 4u5 esta$lis.es t.e t&pe as uint

    22

  • 8/12/2019 GLSL Specification 4.10.6

    29/162

    4 #aria$%es and &'pes

    0iteral integer constants can 9e eressed in decial 9ase 1*F, octal 9ase 5F, or headecial 9ase 1'F

    as #ollows.

    integer-constant :

    (ecimal-constant integer-suffi*o%t

    octal-constant integer-suffi*o%t

    he*a(ecimal-constant integer-suffi*o%t

    integer-suffi*: one o#

    u

    (ecimal-constant :

    nonero-(igit

    (ecimal-constant (igit

    octal-constant :

    %

    octal-constant octal-(igit

    he*a(ecimal-constant :

    *he*a(ecimal-(igit

    *Xhe*a(ecimal-(igit

    he*a(ecimal-constant he*a(ecimal-(igit

    (igit :

    %

    nonero-(igit

    nonero-(igit : one o#

    1 D E B X Y Z [ &

    octal-(igit9 one o#

    % 1 D E B X Y Z

    he*a(ecimal-(igit9one o#

    % 1 D E B X Y Z [ &

    a b c d e f

    A G C ? J K

    7o white sace is allowed 9etween the digits o# an integer constant, including a#ter the leading %or a#ter

    the leading %xor %Vo# a constant, or 9e#ore the su##iuor. @hen the su##i u or is resent, the

    literal has t)e uint,otherwise the t)e is int. A leading unar) inus sign 8F is interreted as an

    arithetic unar) negation, not as art o# the constant.

    It is an error to rovide a literal integer whose agnitude is too large to store in a varia9le o# atchingsigned or unsigned t)e.

    23

  • 8/12/2019 GLSL Specification 4.10.6

    30/162

    4 #aria$%es and &'pes

    .1. ,loats

    (ingle8recision and dou9le8recision #loating oint varia9les are availa9le #or use in a variet) o# scalar

    calculations. 3loating8oint varia9les are de#ined as in the #ollowing eale:

    float a1 $ * '+

  • 8/12/2019 GLSL Specification 4.10.6

    31/162

    4 #aria$%es and &'pes

    .1.5 $ectors

    -he +en/0 (hading 0anguage includes data t)es #or generic !8, &8, and %8coonent vectors o#

    #loating8oint values, integers, or Booleans. 3loating8oint vector varia9les can 9e used to store colors,

    norals, ositions, teture coordinates, teture looku results and the like. Boolean vectors can 9e used

    #or coonent8wise coarisons o# nueric vectors. (oe eales o# vector declaration are:

    ve%9 tex%oord'1 tex%oord9,

    ve%; position,

    ve%8 m&R!6>,

    ive%9 textureLoo:up,

    $ve%; less,

    Initiali?ation o# vectors can 9e done with constructors, which are discussed shortl).

    .1." 7atrices

    -he +en/0 (hading 0anguage has 9uilt8in t)es #or !W!, !W&, !W%, &W!, &W&, &W%, %W!, %W&, and %W%atrices o# #loating8oint nu9ers. atri t)es 9eginning with at have single8recision coonents

    while atri t)es 9eginning with dat have dou9le8recision coonents. -he #irst nu9er in the

    t)e is the nu9er o# coluns, the second is the nu9er o# rows. I# there is onl) one nu9er, the atri

    is s=uare. Eale atri declarations:

    mat9 mat9,

    mat; opt?atrix,

    mat8 vie/1 pro7e%tion,

    mat8x8 vie/, -- an alternate /a& of de%laring a mat8

    mat;x9 m, -- a matrix /it. ; %olumns and 9 ro/s

    dmat8 .ig.@re%ision?V@,

    dmat9x8 dm,

    Initiali?ation o# atri values is done with constructors descri9ed in section $.% "onstructorsC F incolun8aor order.

    .1. Samplers

    (aler t)es e.g., samplerD?F are e##ectivel) oa=ue handles to tetures and their #ilters. -he) are

    used with the 9uilt8in teture #unctions descri9ed in section 5.4 -eture 0ooku 3unctionsC F to seci#)

    which teture to access and how it is to 9e #iltered. -he) can onl) 9e declared as #unction araeters or

    uniformvaria9les see section %.&.$ 6ni#orC F. Ecet #or arra) indeing, structure #ield selection, and

    arentheses, salers are not allowed to 9e oerands in eressions. (alers aggregated into arra)s

    within a shader using s=uare 9rackets - F can onl) 9e indeed with a d)naicall) uni#or integral

    eression, otherwise results are unde#ined. (alers cannot 9e treated as l8values hence cannot 9e used

    as out or inout #unction araeters, nor can the) 9e assigned into. As uni#ors, the) are initiali?ed onl)

    with the +en/0 A2I the) cannot 9e declared with an initiali?er in a shader. As #unction araeters,onl) salers a) 9e assed to salers o# atching t)e. -his ena9les consistenc) checking 9etween

    shader teture accesses and +en/0 teture state 9e#ore a shader is run.

    25

  • 8/12/2019 GLSL Specification 4.10.6

    32/162

    4 #aria$%es and &'pes

    .1.3 Structures

    6ser8de#ined t)es can 9e created 9) aggregating other alread) de#ined t)es into a structure using the

    structke)word. 3or eale,

    stru%t lig.t

    float intensit&,

    ve%; position,

    3 lig.tVar,

    In this eale, light9ecoes the nae o# the new t)e, and lightVar9ecoes a varia9le o# t)e light.

    -o declare varia9les o# the new t)e, use its nae without the ke)word structF.

    lig.t lig.tVar9,

    ore #orall), structures are declared as #ollows. owever, the colete correct graar is as given in

    section ; (hading 0anguage /raarC .

    struct-(efinition :ualifier

    o%t structname

    o%tmem+er-list 2(eclarators

    o%t3

    mem+er-list :

    mem+er-(eclaration3

    mem+er-(eclaration mem+er-list3

    mem+er-(eclaration :

    +asic-t,%e (eclarators3

    where name9ecoes the user8de#ined t)e, and can 9e used to declare varia9les to 9e o# this new t)e.

    -he nameshares the sae nae sace as other varia9les, t)es, and #unctions. All reviousl) visi9le

    varia9les, t)es, constructors, or #unctions with that nae are hidden. -he otional ualifieronl) alies

    to an) (eclarators, and is not art o# the t)e 9eing de#ined #or name.

    (tructures ust have at least one e9er declaration. e9er declarators a) contain recision

    =uali#iers, 9ut a) not contain an) other =uali#iers. Bit #ields are not suorted. e9er t)es ust 9e

    alread) de#ined there are no #orward re#erencesF. e9er declarations cannot contain initiali?ers.

    e9er declarators can contain arra)s. (uch arra)s ust have a si?e seci#ied, and the si?e ust 9e an

    integral constant eression thatGs greater than ?ero see section %.&.& "onstant EressionsCF. Each

    level o# structure has its own nae sace #or naes given in e9er declarators such naes need onl)

    9e uni=ue within that nae sace.

    26

  • 8/12/2019 GLSL Specification 4.10.6

    33/162

    4 #aria$%es and &'pes

    Anon)ous structures are not suorted. E9edded structure de#initions are not suorted.

    stru%t S float f, 3,

    stru%t T

    S, -- Error( anon&mous stru%tures disallo/ed

    stru%t +++ 3, -- Error( em$edded stru%tures disallo/ed

    S s, -- O:a&( nested stru%tures /it. name are allo/ed

    3,

    (tructures can 9e initiali?ed at declaration tie using constructors, as discussed in section $.%.& (tructure

    "onstructorsC .

    .1.8 rra#s

    Varia9les o# the sae t)e can 9e aggregated into arra)s 9) declaring a nae #ollowed 9) 9rackets - F

    enclosing an otional si?e. @hen an arra) si?e is seci#ied in a declaration, it ust 9e an integral constant

    eression see section %.&.& "onstant EressionsC F greater than ?ero. I# an arra) is indeed with aneression that is not an integral constant eression, or i# an arra) is assed as an arguent to a #unction,

    then its si?e ust 9e declared 9e#ore an) such use. It is legal to declare an arra) without a si?e and then

    later re8declare the sae nae as an arra) o# the sae t)e and seci#) a si?e. It is illegal to declare an

    arra) with a si?e, and then later in the sae shaderF inde the sae arra) with an integral constant

    eression greater than or e=ual to the declared si?e. It is also illegal to inde an arra) with a negative

    constant eression. Arra)s declared as #oral araeters in a #unction declaration ust seci#) a si?e.

    6nde#ined 9ehavior results #ro indeing an arra) with a non8constant eression thatHs greater than or

    e=ual to the arra)Hs si?e or less than *. +nl) one8diensional arra)s a) 9e declared. All 9asic t)es and

    structures can 9e #ored into arra)s. (oe eales are:

    float freAuen%iesB;C,

    uniform ve%8 lig.t@ositionB8C,

    lig.t lig.tsBC,%onst int numLig.ts * 9,

    lig.t lig.tsBnumLig.tsC,

    An arra) t)e can 9e #ored 9) seci#)ing a t)e #ollowed 9) s=uare 9rackets Y ZF and including a si?e:

    floatB

  • 8/12/2019 GLSL Specification 4.10.6

    34/162

    4 #aria$%es and &'pes

    and as an alternate wa) o# declaring a varia9le or #unction araeter.

    floatB

  • 8/12/2019 GLSL Specification 4.10.6

    35/162

    4 #aria$%es and &'pes

    .1.1% Implicit Conversions

    In soe situations, an eression and its t)e will 9e ilicitl) converted to a di##erent t)e. -he

    #ollowing ta9le shows all allowed ilicit conversions:

    T#pe of e*pression Can be implicitl# converted to

    int uint

    int

    uint

    float

    intuintfloat

    double

    ivecD uvecD

    ivecE uvecE

    ivecB uvecBivecDuvecD

    vecD

    ivecE

    uvecE

    vecE

    ivecBuvecB

    vecB

    ivecDuvecDvecD

    dvecD

    ivecE

    uvecEvecE

    dvecE

    ivecBuvecBvecB

    dvecB

    matD dmatD

    matE dmatE

    matB dmatB

    matDxE dmatDxE

    matDxB dmatDxB

    matExD dmatExD

    matExB dmatExB

    matBxD dmatBxD

    matBxE dmatBxE

    2!

  • 8/12/2019 GLSL Specification 4.10.6

    36/162

    4 #aria$%es and &'pes

    -here are no ilicit arra) or structure conversions. 3or eale, an arra) o# intcannot 9e ilicitl)

    converted to an arra) o# float.

    @hen an ilicit conversion is done, it is not a re8interretation o# the eressionGs 9it attern, 9ut a

    conversion o# its value to an e=uivalent value in the new t)e. 3or eale, the integer value 8Xwill 9e

    converted to the #loating8oint value 8X.%. Integer values having ore 9its o# recision than a #loating

    oint antissa will lose recision when converted to float.

    @hen er#oring ilicit conversion #or 9inar) oerators, there a) 9e ultile data t)es to which the

    two oerands can 9e converted. 3or eale, when adding an int value to a uint value, 9oth values can

    9e ilicitl) converted to uint, float, and double. In such cases, a #loating8oint t)e is chosen i# either

    oerand has a #loating8oint t)e. +therwise, an unsigned integer t)e is chosen i# either oerand has an

    unsigned integer t)e. +therwise, a signed integer t)e is chosen. I# oerands can 9e ilicitl) converted

    to ultile data t)es deriving #ro the sae 9ase data t)e, the t)e with the sallest coonent si?e is

    used.

    -he conversions in the ta9le a9ove are done onl) as indicated 9) other sections o# this seci#ication.

    .2 Scoping

    -he scoe o# a varia9le is deterined 9) where it is declared. I# it is declared outside all #unction

    de#initions, it has glo9al scoe, which starts #ro where it is declared and ersists to the end o# the shader

    it is declared in. I# it is declared in a whiletest or a for stateent, then it is scoed to the end o# the

    #ollowing su98stateent. +therwise, i# it is declared as a stateent within a coound stateent, it is

    scoed to the end o# that coound stateent. I# it is declared as a araeter in a #unction de#inition, it is

    scoed until the end o# that #unction de#inition. A #unction 9od) has a scoe nested inside the #unctionHs

    de#inition. -he ifstateentHs eression does not allow new varia9les to 9e declared, hence does not

    #or a new scoe.

    3"

  • 8/12/2019 GLSL Specification 4.10.6

    37/162

    4 #aria$%es and &'pes

    @ithin a declaration, the scoe o# a nae starts iediatel) a#ter the initiali?er i# resent or iediatel)

    a#ter the nae 9eing declared i# not. (everal eales:

    int x * ',

    int x * 91 & * x, -- & is initiali"ed to 9

    3

    stru%t S

    int x,

    3,

    S S * S=), -- DSD is onl& visi$le as a stru%t and %onstru%tor

    S, -- DSD is no/ visi$le as a varia$le

    3

    int x * x, -- Error if x .as not $een previousl& defined+

    All varia9le naes, structure t)e naes, and #unction naes in a given scoe share the sae nae sace.

    3unction naes can 9e redeclared in the sae scoe, with the sae or di##erent araeters, without error.

    An ilicitl) si?ed arra) can 9e re8declared in the sae scoe as an arra) o# the sae 9ase t)e.

    +therwise, within one coilation unit, a declared nae cannot 9e redeclared in the sae scoe doing so

    results in a redeclaration error. I# a nested scoe redeclares a nae used in an outer scoe, it hides all

    eisting uses o# that nae. -here is no wa) to access the hidden nae or ake it unhidden, without

    eiting the scoe that hid it.

    -he 9uilt8in #unctions are scoed in a scoe outside the glo9al scoe users declare glo9al varia9les in.

    -hat is, a shaderGs glo9al scoe, availa9le #or user8de#ined #unctions and glo9al varia9les, is nested inside

    the scoe containing the 9uilt8in #unctions. @hen a #unction nae is redeclared in a nested scoe, it hidesall #unctions declared with that nae in the outer scoe. 3unction declarations rotot)esF cannot occur

    inside o# #unctions the) ust 9e at glo9al scoe, or #or the 9uilt8in #unctions, outside the glo9al scoe.

    (hared glo9als are glo9al varia9les declared with the sae nae in indeendentl) coiled units

    shadersF within the sae language e.g., verteF that are linked together when aking a single rogra.

    /lo9als #oring the inter#ace 9etween two di##erent shader languages are discussed in other sections.F

    (hared glo9als share the sae nae sace, and ust 9e declared with the sae t)e. -he) will share the

    sae storage. (hared glo9al arra)s ust have the sae 9ase t)e and the sae elicit si?e. An arra)

    ilicitl) si?ed in one shader can 9e elicitl) si?ed 9) another shader. I# no shader has an elicit si?e

    #or the arra), the largest ilicit si?e is used. (calars ust have eactl) the sae t)e nae and t)e

    de#inition. (tructures ust have the sae nae, se=uence o# t)e naes, and t)e de#initions, and #ield

    naes to 9e considered the sae t)e. -his rule alies recursivel) #or nested or e9edded t)es. All

    initiali?ers #or a shared glo9al ust have the sae value, or a link error will result.

    31

  • 8/12/2019 GLSL Specification 4.10.6

    38/162

    4 #aria$%es and &'pes

    .! Storage 9ualifiers

    Varia9le declarations a) have one storage =uali#ier seci#ied in #ront o# the t)e. -hese are suari?ed

    as

    9ualifier 7eaning

    P none: de#ault Q local readNwrite eor), or an inut araeter to a #unction

    const a coile8tie constant, or a #unction araeter that is read8onl)

    incentroid in

    sample in

    linkage into a shader #ro a revious stage, varia9le is coied inlinkage with centroid 9ased interolationinut linkage with er8sale interolation

    outcentroid outsample out

    linkage out o# a shader to a su9se=uent stage, varia9le is coied outlinkage with centroid 9ased interolationoutut linkage with er8sale interolation

    attribute derecatedlinkage 9etween a verte shader and +en/0 #or er8vertedata

    uniform value does not change across the riitive 9eing rocessed, uni#ors#or the linkage 9etween a shader, +en/0, and the alication

    varingcentroid varing

    derecated linkage 9etween a verte shader and a #ragent shader #orinterolated data

    patch in tessellation evaluation shader inut #or er8atch attri9utes

    patch out tessellation control shader outut #or er8atch attri9utes

    +ututs #ro shader outF and inuts to a shader inF can 9e #urther =uali#ied with one o# these

    interolation =uali#iers

    9ualifier 7eaning

    smooth ersective correct interolation

    flat no interolation

    noperspective linear interolation

    -hese interolation =uali#iers a) onl) recede the =uali#iers in, centroid in, sample in, out, centroid

    out,or sample out in a declaration. -he) do not al) to the derecated storage =uali#iers varing or

    centroid varing. -he) also do not al) to inuts into a verte shader or oututs #ro a #ragent

    shader.

    0ocal varia9les can onl) use the const storage =uali#ier.

    3unction araeters can use const,in, andout =uali#iers, 9ut as%arameter ualifiers. 2araeter

    =uali#iers are discussed in section '.1.1 3unction "alling "onventionsC.

    3unction return t)es and structure #ields do not use storage =uali#iers.

    32

  • 8/12/2019 GLSL Specification 4.10.6

    39/162

    4 #aria$%es and &'pes

    Data t)es #or counication #ro one run o# a shader eecuta9le to its net run to counicate

    9etween #ragents or 9etween verticesF do not eist. -his would revent arallel eecution o# the sae

    shader eecuta9le on ultile vertices or #ragents.

    Initiali?ers a) onl) 9e used in declarations o# glo9als with no storage =uali#ier, with a const=uali#ier or

    with a uniform=uali#ier. /lo9al varia9les without storage =uali#iers that are not initiali?ed in their

    declaration or 9) the alication will not 9e initiali?ed 9) +en/0, 9ut rather will enter main5with

    unde#ined values.

    .!.1 )efault Storage 9ualifier

    I# no =uali#ier is resent on a glo9al varia9le, then the varia9le has no linkage to the alication or shaders

    running on other ieline stages. 3or either glo9al or local un=uali#ied varia9les, the declaration will

    aear to allocate eor) associated with the rocessor it targets. -his varia9le will rovide readNwrite

    access to this allocated eor).

    .!.2 Constant 9ualifier7aed coile8tie constants can 9e declared using the const=uali#ier. An) varia9les =uali#ied as

    constant are read8onl) varia9les #or that shader. Declaring varia9les as constant allows ore descritive

    shaders than using hard8wired nuerical constants. -he const=uali#ier can 9e used with an) o# the 9asic

    data t)es. It is an error to write to a constvaria9le outside o# its declaration, so the) ust 9e initiali?ed

    when declared. 3or eale,

    %onst ve%; ">xis * ve%; =+=1 =+=1 '+=),

    (tructure #ields a) not 9e =uali#ied with const. (tructure varia9les can 9e declared as const, and

    initiali?ed with a structure constructor.

    Initiali?ers #or const declarations ust 9e constant eressions, as de#ined in section %.&.& "onstant

    Eressions.C

    .!.! Constant '*pressions

    A constant e*%ressionis one o#

    a literal value e.g., Xor trueF

    a glo9al or local varia9le =uali#ied as consti.e., not including #unction araetersF

    an eression #ored 9) an oerator on oerands that are all constant eressions, including getting an

    eleent or length o# a constant arra), or a #ield o# a constant structure, or coonents o# a constant

    vector.

    a constructor whose arguents are all constant eressions

    a 9uilt8in #unction call whose arguents are all constant eressions, with the ecetion o# the teturelooku #unctions and the noise #unctions. -he 9uilt8in #unctions dKdx, dKd, and fwidthust return

    * when evaluated inside an initiali?er with an arguent that is a constant eression.

    3unction calls to user8de#ined #unctions non89uilt8in #unctionsF cannot 9e used to #or constant

    eressions.

    33

  • 8/12/2019 GLSL Specification 4.10.6

    40/162

    4 #aria$%es and &'pes

    An integral constant e*%ressionis a constant eression that evaluates to a scalar signed or unsigned

    integer.

    "onstant eressions will 9e evaluated in an invariant wa) so as to create the sae value in ultile

    shaders when the sae constant eressions aear in those shaders. (ee section %.'.1-he Invariant

  • 8/12/2019 GLSL Specification 4.10.6

    41/162

    4 #aria$%es and &'pes

    -essellation control, evaluation, and geoetr) shader inut varia9les get the er8verte values written out

    9) outut varia9les o# the sae naes in the revious active shader stage. 3or these inuts, centroid in

    and interolation =uali#iers are allowed, 9ut have no e##ect. (ince tessellation control, tessellation

    evaluation, and geoetr) shaders oerate on a set o# vertices, each inut var)ing varia9le or inut 9lock,see inter#ace 9locks 9elowF needs to 9e declared as an arra). 3or eale,

    in float fooBC, -- geometr& s.ader input for vertex 4out float foo5

    Each eleent o# such an arra) corresonds to one verte o# the riitive 9eing rocessed. Each arra) can

    otionall) have a si?e declared. -he arra) si?e will 9e set 9), or i# rovided ust 9e consistent withF the

    inut laoutdeclarationsF esta9lishing the t)e o# inut riitive, as descri9ed later in section %.&.5.1

    Inut 0a)out

  • 8/12/2019 GLSL Specification 4.10.6

    42/162

    4 #aria$%es and &'pes

    3ragent inuts are declared as in the #ollowing eales:

    in ve%; normal,

    %entroid in ve%9 Texoord,

    invariant %entroid in ve%8 olor,

    noperspe%tive in float temperature,

    flat in ve%; m&olor,

    noperspe%tive %entroid in ve%9 m&Texoord,

    -he #ragent shader inuts #or an inter#ace with the last active shader in the verte rocessing ieline.

    3or this inter#ace, the last active shader stage outut varia9les and #ragent shader inut varia9les o# the

    sae nae ust atch in t)e and =uali#ication other than out atching to inF.

    @hen an inter#ace 9etween shader stages is #ored using shaders #ro two searate rogra o9ects, it is

    not ossi9le to detect isatches 9etween inuts and oututs when the rogras are linked. @hen there

    are isatches 9etween inuts and oututs on such inter#aces, the values assed across the inter#ace will

    9e artiall) or coletel) unde#ined. (haders can ensure atches across such inter#aces either 9) using

    inut and outut la)out =uali#iers sections %.&.5.1 Inut 0a)out

  • 8/12/2019 GLSL Specification 4.10.6

    43/162

    4 #aria$%es and &'pes

    .!." Outputs

    (hader outut varia9les are declared with a storage =uali#ier using the ke)word out. -he) #or the outut

    inter#ace 9etween the declaring shader and the su9se=uent stages o# the +en/0 ieline. +utut

    varia9les ust 9e declared at glo9al scoe. During shader eecution the) will 9ehave as noral

    un=uali#ied glo9al varia9les. -heir values are coied out to the su9se=uent ieline stage on shader eit.

    +nl) outut varia9les that are read 9) the su9se=uent ieline stage need to 9e written it is allowed to

    have suer#luous declarations o# outut varia9les.

    -here is notan inoutstorage =uali#ier at glo9al scoe #or declaring a single varia9le nae as 9oth inut

    and outut to a shader. +utut varia9les ust 9e declared with di##erent naes than inut varia9les.

    owever, nesting an inut or outut inside an inter#ace 9lock with an instance nae allows the sae

    naes with one re#erenced through a 9lock instance nae.

    Verte, tessellation evaluation, and geoetr) outut varia9les outut er8verte data and are declared

    using the out, centroid out, or sample out storage =uali#iers, or the derecated varingstorage =uali#ier.

    It is an error to use patch out in a verte, tessellation evaluation, or geoetr) shader. +utut varia9les

    can onl) 9e #loating8oint scalars, #loating8oint vectors, atrices, signed or unsigned integers or integervectors, or arra)s or structures o# an) these.

    Individual verte, tessellation evaluation, and geoetr) oututs are declared as in the #ollowing eales:

    out ve%; normal,

    %entroid out ve%9 Texoord,

    invariant %entroid out ve%8 olor,

    noperspe%tive out float temperature, -- var&ing is depre%ated

    flat out ve%; m&olor,

    noperspe%tive %entroid out ve%9 m&Texoord,

    sample out ve%8 perSampleolor,

    -hese can also aear in inter#ace 9locks, as descri9ed in section %.&.4 Inter#ace BlocksC. Inter#ace

    9locks allow siler addition o# arra)s to the inter#ace #ro verte to geoetr) shader. -he) also allow a#ragent shader to have the sae inut inter#ace as a geoetr) shader #or a given verte shader.

    -essellation control shader outut varia9les are a) 9e used to outut er8verte and er8atch data. 2er8

    verte outut varia9les are arra)ed see arra,e( under %.&.% InutsF and declared using outor centroid

    out storage =uali#iers. 2er8atch outut varia9les are declared using the patch outstorage =uali#ier. 2er8

    verte and er8atch outut varia9les can onl) 9e #loating8oint scalars, #loating8oint vectors, atrices,

    signed or unsigned integers or integer vectors, or arra)s or structures o# an) these. (ince tessellation

    control shaders roduce an arra)ed riitive corising ultile vertices, each er8verte outut varia9le

    or outut 9lock, see inter#ace 9locks 9elowF needs to 9e declared as an arra). 3or eale,

    out float fooBC, -- feeds next stage input 4in float fooBC5

    Each eleent o# such an arra) corresonds to one verte o# the riitive 9eing roduced. Each arra) can

    otionall) have a si?e declared. -he arra) si?e will 9e set 9) or i# rovided ust 9e consistent withF the

    outut la)out declarationsF esta9lishing the nu9er o# vertices in the outut atch, as descri9ed later in

    section %.&.5.! +utut 0a)out

  • 8/12/2019 GLSL Specification 4.10.6

    44/162

    4 #aria$%es and &'pes

    As descri9ed under the section %.&.% InutsC a9ove, i# a er8verte outut o# the tessellation control

    shader is itsel# an arra) with ultile values er verte, it ust aear in an outut 9lock see inter#ace

    9locks 9elowF in the tessellation control shader with a 9lock instance nae declared as an arra).

    Each tessellation control shader invocation has a corresonding outut atch verte, and a) assign

    values to er8verte oututs onl) i# the) 9elong to that corresonding verte. I# a er8verte outut

    varia9le is used as an l8value, it is an error i# the eression indicating the verte inde is not the identi#ier

    glnvocationD.

    -he order o# eecution o# a tessellation control shader invocation relative to the other invocations #or the

    sae inut atch is unde#ined unless the 9uilt8in #unction barrierFis used. -his rovides soe control

    over relative eecution order. @hen a shader invocation calls barrierF, its eecution auses until all

    other invocations have reached the sae oint o# eecution. +utut varia9le assignents er#ored 9)

    an) invocation eecuted rior to calling barrierF will 9e visi9le to an) other invocation a#ter the call to

    barrierF returns.

    Because tessellation control shader invocations eecute in unde#ined order 9etween 9arriers, the values o#

    er8verte or er8atch outut varia9les will soeties 9e unde#ined. "onsider the 9eginning and end o#shader eecution and each call to barrierF as s)nchroni?ation oints. -he value o# an outut varia9le

    will 9e unde#ined in an) o# the three #ollowing cases:

    1. At the 9eginning o# eecution.

    !. At each s)nchroni?ation oint, unless

    the value was well8de#ined a#ter the revious s)nchroni?ation oint and was not written 9) an)

    invocation since, or the value was written 9) eactl) one shader invocation since the revious s)nchroni?ation

    oint, or the value was written 9) ultile shader invocations since the revious s)nchroni?ation oint,

    and the last write er#ored 9) all such invocations wrote the sae value.

    &. @hen read 9) a shader invocation, i#

    the value was unde#ined at the revious s)nchroni?ation oint and has not 9een writen 9) the

    sae shader invocation since, or the outut varia9le is written to 9) an) other shader invocation 9etween the revious and net

    s)nchroni?ation oints, even i# that assignent occurs in code #ollowing the read.

    3ragent oututs outut er8#ragent data and are declared using the out storage =uali#ier. It is an error

    to use centroid out,sample out, or patch out in a #ragent shader. 3ragent oututs can onl) 9e float,

    #loating8oint vectors, signed or unsigned integers or integer vectors, or arra)s o# an) these. atrices and

    structures cannot 9e outut. 3ragent oututs are declared as in the #ollowing eales:

    out ve%8 Fragmentolor,

    out uint Luminosit&,

    3

  • 8/12/2019 GLSL Specification 4.10.6

    45/162

    4 #aria$%es and &'pes

    .!. Interface -loc0s

    Inut, outut, and uni#or varia9le declarations can 9e groued into naed inter#ace 9locks to rovide

    coarser granularit) 9acking than is achieva9le with individual declarations. -he) can have an otional

    instance nae, used in the shader to re#erence their e9ers. An outut 9lock o# one rograa9le

    stage is 9acked 9) a corresonding inut 9lock in the su9se=uent rograa9le stage. A uni#or 9lock is

    9acked 9) the alication with a 9u##er o9ect. It is illegal to have an inut 9lock in a verte shader or an

    outut 9lock in a #ragent shader these uses are reserved #or #uture use.

    An inter#ace 9lock is started 9) an in, out, or uniform ke)word, #ollowed 9) a 9lock nae, #ollowed 9)

    an oen curl) 9race F as #ollows:

    interface-+loc :

    la,out-ualifieropt interface-ualifier +loc-name mem+er-list 2instance-nameopt:

    la,out-ualifier :

    laout / la,out-ualifier-i(-list0

    interface-ualifier :in

    out

    uniform

    la,out-ualifier-i(-list

    coa searated list o# la,out-ualifier-i(

    mem+er-list :

    mem+er-(eclaration

    mem+er-(eclaration mem+er-list

    mem+er-(eclaration :

    la,out-ualifieropt ualifiersopt t,%e (eclarators :

    instance-name :

    i(entifier

    i(entifier 7

    i(entifier integral-constant-e*%ression 7

    Each o# the a9ove eleents is discussed 9elow, with the ecetion o# la)out =uali#iers la,out-ualifier5,

    which are de#ined in the net section.

    3irst, an eale,

    uniform Transform

    mat8 ?odelVie/?atrix,

    mat8 ?odelVie/@ro7e%tion?atrix,

    uniform mat; Normal?atrix, -- allo/ed restatement of Aualifier

    float eformation,3,

    -he a9ove esta9lishes a uni#or 9lock naed -rans#orC with #our uni#ors groued inside it.

    3!

  • 8/12/2019 GLSL Specification 4.10.6

    46/162

    4 #aria$%es and &'pes

    -)es and declarators are the sae as #or other inut, outut, and uni#or varia9le declarations outside

    9locks, with these ecetions:

    initiali?ers are not allowed

    saler t)es are not allowed

    structure de#initions cannot 9e nested inside a 9lock

    +therwise, 9uilt8in t)es, reviousl) declared structures, and arra)s o# these are allowed as the t)e o# a

    declarator in the sae anner the) are allowed outside a 9lock.

    I# no otional =uali#ier is used in a e9er8declaration, the =uali#ication o# the varia9le is ust in, out, or

    uniformas deterined 9) interface-ualifier. I# otional =uali#iers are used, the) can include

    interolation and storage =uali#iers and the) ust declare an inut, outut, or uni#or varia9le consistent

    with the inter#ace =uali#ier o# the 9lock: Inut varia9les, outut varia9les, and uni#or varia9les can onl)

    9e in in9locks, out9locks, and uniform9locks, resectivel). Reeating the in, out, or uniform

    inter#ace =uali#ier #or a e9erGs storage =uali#ier is otional. Declarations using the derecated

    attribute and varing=uali#iers are not allowed. 3or eale,

    in ?aterial

    smoot. in ve%8 olor', -- legal1 input inside in $lo%:

    smoot. ve%8 olor9, -- legal1 DinD in.erited from Din ?aterialD

    ve%9 Texoord, -- legal1 Texoord is an input

    uniform float >tten, -- illegal1 mismat%.ed interfa%es

    var&ing ve%9 Texoord9,--illegal1 depre%ated :e&/ords donDt get ne/ uses

    3,

    3or this section, de#ine an interface to 9e one o# these

    All the uni#ors o# a rogra. -his sans all coilation units linked together within one rogra.

    -he 9oundar) 9etween adacent rograa9le ieline stages: -his sans all the oututs in all

    coilation units o# the #irst stage and all the inuts in all coilation units o# the second stage.

    -he 9lock nae +loc-nameFis used to atch inter#aces: an outut 9lock o# one ieline stage will 9e

    atched to an inut 9lock with the sae nae in the su9se=uent ieline stage. 3or uni#or 9locks, the

    alication uses the 9lock nae to identi#) the 9lock. Block naes have no other use within a shader

    9e)ond inter#ace atching it is an error to use a 9lock nae at glo9al scoe #or an)thing other than as a

    9lock nae e.g., use o# a 9lock nae #or a glo9al varia9le nae or #unction nae is currentl) reservedF.

    atched 9lock naes within an inter#ace as de#ined a9oveF ust atch in ters o# having the sae

    nu9er o# declarations with the sae se=uence o# t)es and the sae se=uence o# e9er naes, as well

    as having the sae e9er8wise la)out =uali#ication see net sectionF. 3urtherore, i# a atching 9lock

    is declared as an arra), then the arra) si?es ust also atch or #ollow arra) atching rules #or the

    inter#ace 9etween a verte and a geoetr) shaderF. An) isatch will generate a link error. A 9lock

    nae is allowed to have di##erent de#initions in di##erent inter#aces within the sae shader, allowing, #or

    eale, an inut 9lock and outut 9lock to have the sae nae.

    4"

  • 8/12/2019 GLSL Specification 4.10.6

    47/162

    4 #aria$%es and &'pes

    I# an instance nae instance-nameFis not used, the naes declared inside the 9lock are scoed at the

    glo9al level and accessed as i# the) were declared outside the 9lock. I# an instance nae instance-nameF

    is used, then it uts all the e9ers inside a scoe within its own nae sace, accessed with the #ield

    selector . F oerator analogousl) to structuresF. 3or eale,

    in Lig.t

    ve%8 Lig.t@os,

    ve%; Lig.tolor,

    3,

    in oloredTexture

    ve%8 olor,

    ve%9 Texoord,

    3 ?aterial, -- instan%e name

    ve%; olor, -- different olor t.an ?aterial+olor

    ve%8 Lig.t@os, -- illegal1 alread& defined

    +++

    +++ * Lig.t@os, -- a%%essing Lig.t@os

    +++ * ?aterial+olor, -- a%%essing olor in oloredTexture $lo%:

    +utside the shading language i.e., in the A2IF, e9ers are siilarl) identi#ied ecet the 9lock nae is

    alwa)s used in lace o# the instance nae A2I accesses are to inter#aces, not to shadersF. I# there is no

    instance nae, then the A2I does not use the 9lock nae to access a e9er, ust the e9er nae.

    out Vertex

    ve%8 @osition, -- >@I transform-feed$a%: /ill use 4Vertex+@osition5

    ve%9 Texture,

    3 oords, -- s.ader /ill use 4oords+@osition5

    out Vertex9

    ve%8 olor, -- >@I /ill use 4olor5

    3,

    3or 9locks declared as arra)s, the arra) inde ust also 9e included when accessing e9ers, as in this

    eale

    uniform Transform -- >@I uses 4TransformB9C5 to refer to instan%e 9

    mat8 ?odelVie/?atrix,

    mat8 ?odelVie/@ro7e%tion?atrix,

    float eformation,

    3 transformsB8C,

    +++

    +++ * transformsB9C+?odelVie/?atrix, -- s.ader a%%ess of instan%e 9

    -- >@I uses 4Transform+?odelVie/?atrix5 to Auer& an offset or ot.er Auer&

    3or uni#or 9locks declared as an arra), each individual arra) eleent corresonds to a searate 9u##ero9ect 9acking one instance o# the 9lock. As the arra) si?e indicates the nu9er o# 9u##er o9ects needed,

    uni#or 9lock arra) declarations ust seci#) an arra) si?e. An) integral eression can 9e used to inde

    a uni#or 9lock arra), as er section %.1.; Arra)s.

    41

  • 8/12/2019 GLSL Specification 4.10.6

    48/162

    4 #aria$%es and &'pes

    @hen using +en/0 A2I entr) oints to identi#) the nae o# an individual 9lock in an arra) o# 9locks,

    the nae string ust include an arra) inde e.g., #ransform27F. @hen using +en/0 A2I entr) oints

    to re#er to o##sets or other characteristics o# a 9lock e9er, an arra) inde ust not 9e seci#ied e.g.,

    #ransform.8o(elView8atri*F.

    /eoetr) shader inut 9locks ust 9e declared as arra)s and #ollow the arra) declaration and linking

    rules #or all geoetr) shader inuts. All other inut and outut 9lock arra)s ust seci#) an arra) si?e.

    -here is an ileentation deendent liit on the nu9er o# uni#or 9locks that can 9e used er stage.

    I# this liit is eceeded, it will cause a link error.

    .!.3 La#out 9ualifiers

    0a)out =uali#iers can aear in several #ors o# declar