shader_functions.rst 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017
  1. .. _doc_shader_functions:
  2. Built-in functions
  3. ==================
  4. Godot supports a large number of built-in functions, conforming roughly to the
  5. GLSL ES 3.0 specification.
  6. .. note::
  7. The following type aliases only used in documentation to reduce repetitive function declarations.
  8. They can each refer to any of several actual types.
  9. +-----------------+-----------------------------------------------------+--------------------------+
  10. | alias | actual types | glsl documentation alias |
  11. +=================+=====================================================+==========================+
  12. | vec_type | float, vec2, vec3, or vec4 | genType |
  13. +-----------------+-----------------------------------------------------+--------------------------+
  14. | vec_int_type | int, ivec2, ivec3, or ivec4 | genIType |
  15. +-----------------+-----------------------------------------------------+--------------------------+
  16. | vec_uint_type | uint, uvec2, uvec3, or uvec4 | genUType |
  17. +-----------------+-----------------------------------------------------+--------------------------+
  18. | vec_bool_type | bool, bvec2, bvec3, or bvec4 | genBType |
  19. +-----------------+-----------------------------------------------------+--------------------------+
  20. | mat_type | mat2, mat3, or mat4 | mat |
  21. +-----------------+-----------------------------------------------------+--------------------------+
  22. | gvec4_type | vec4, ivec4, or uvec4 | gvec4 |
  23. +-----------------+-----------------------------------------------------+--------------------------+
  24. | gsampler2D | sampler2D, isampler2D, or uSampler2D | gsampler2D |
  25. +-----------------+-----------------------------------------------------+--------------------------+
  26. | gsampler2DArray | sampler2DArray, isampler2DArray, or uSampler2DArray | gsampler2DArray |
  27. +-----------------+-----------------------------------------------------+--------------------------+
  28. | gsampler3D | sampler3D, isampler3D, or uSampler3D | gsampler3D |
  29. +-----------------+-----------------------------------------------------+--------------------------+
  30. If any of these are specified for multiple parameters, they must all be the same type unless otherwise noted.
  31. .. _shading_componentwise:
  32. .. note::
  33. Many functions that accept one or more vectors or matrices perform the described function on each component of the vector/matrix.
  34. Some examples:
  35. .. table::
  36. :class: nowrap-col2 nowrap-col1
  37. :widths: auto
  38. +---------------------------------------+-----------------------------------------------------+
  39. | Operation | Equivalent Scalar Operation |
  40. +=======================================+=====================================================+
  41. | ``sqrt(vec2(4, 64))`` | ``vec2(sqrt(4), sqrt(64))`` |
  42. +---------------------------------------+-----------------------------------------------------+
  43. | ``min(vec2(3, 4), 1)`` | ``vec2(min(3, 1), min(4, 1))`` |
  44. +---------------------------------------+-----------------------------------------------------+
  45. | ``min(vec3(1, 2, 3),vec3(5, 1, 3))`` | ``vec3(min(1, 5), min(2, 1), min(3, 3))`` |
  46. +---------------------------------------+-----------------------------------------------------+
  47. | ``pow(vec3(3, 8, 5 ), 2)`` | ``vec3(pow(3, 2), pow(8, 2), pow(5, 2))`` |
  48. +---------------------------------------+-----------------------------------------------------+
  49. | ``pow(vec3(3, 8, 5), vec3(1, 2, 4))`` | ``vec3(pow(3, 1), pow(8, 2), pow(5, 4))`` |
  50. +---------------------------------------+-----------------------------------------------------+
  51. The `GLSL Language Specification <http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf>`_ says under section 5.10 Vector and Matrix Operations:
  52. With a few exceptions, operations are component-wise. Usually, when an operator operates on a
  53. vector or matrix, it is operating independently on each component of the vector or matrix,
  54. in a component-wise fashion. [...] The exceptions are matrix multiplied by vector,
  55. vector multiplied by matrix, and matrix multiplied by matrix. These do not operate component-wise,
  56. but rather perform the correct linear algebraic multiply.
  57. These function descriptions are adapted and modified from
  58. `official OpenGL documentation <https://registry.khronos.org/OpenGL-Refpages/gl4/>`__
  59. originally published by Khronos Group under the
  60. `Open Publication License <https://opencontent.org/openpub>`__.
  61. Each function description links to the corresponding official OpenGL
  62. documentation. Modification history for this page can be found on
  63. `GitHub <https://github.com/godotengine/godot-docs/blob/master/tutorials/shaders/shader_reference/shader_functions.rst>`__.
  64. .. rst-class:: classref-section-separator
  65. ----
  66. .. rst-class:: classref-reftable-group
  67. Trigonometric functions
  68. -----------------------
  69. .. table::
  70. :class: nowrap-col2
  71. :widths: auto
  72. +-----------------+-----------------------------------------------------------------+-----------------------------+
  73. | Return Type | Function | Description / Return value |
  74. +=================+=================================================================+=============================+
  75. | |vec_type| | :ref:`radians<shader_func_radians>`\ (\ |vec_type| degrees) | Convert degrees to radians. |
  76. +-----------------+-----------------------------------------------------------------+-----------------------------+
  77. | |vec_type| | :ref:`degrees<shader_func_degrees>`\ (\ |vec_type| radians) | Convert radians to degrees. |
  78. +-----------------+-----------------------------------------------------------------+-----------------------------+
  79. | |vec_type| | :ref:`sin<shader_func_sin>`\ (\ |vec_type| x) | Sine. |
  80. +-----------------+-----------------------------------------------------------------+-----------------------------+
  81. | |vec_type| | :ref:`cos<shader_func_cos>`\ (\ |vec_type| x) | Cosine. |
  82. +-----------------+-----------------------------------------------------------------+-----------------------------+
  83. | |vec_type| | :ref:`tan<shader_func_tan>`\ (\ |vec_type| x) | Tangent. |
  84. +-----------------+-----------------------------------------------------------------+-----------------------------+
  85. | |vec_type| | :ref:`asin<shader_func_asin>`\ (\ |vec_type| x) | Arc sine. |
  86. +-----------------+-----------------------------------------------------------------+-----------------------------+
  87. | |vec_type| | :ref:`acos<shader_func_acos>`\ (\ |vec_type| x) | Arc cosine. |
  88. +-----------------+-----------------------------------------------------------------+-----------------------------+
  89. | | |vec_type| | | :ref:`atan<shader_func_atan>`\ (\ |vec_type| y_over_x) | Arc tangent. |
  90. | | |vec_type| | | :ref:`atan<shader_func_atan2>`\ (\ |vec_type| y, |vec_type| x)| |
  91. +-----------------+-----------------------------------------------------------------+-----------------------------+
  92. | |vec_type| | :ref:`sinh<shader_func_sinh>`\ (\ |vec_type| x) | Hyperbolic sine. |
  93. +-----------------+-----------------------------------------------------------------+-----------------------------+
  94. | |vec_type| | :ref:`cosh<shader_func_cosh>`\ (\ |vec_type| x) | Hyperbolic cosine. |
  95. +-----------------+-----------------------------------------------------------------+-----------------------------+
  96. | |vec_type| | :ref:`tanh<shader_func_tanh>`\ (\ |vec_type| x) | Hyperbolic tangent. |
  97. +-----------------+-----------------------------------------------------------------+-----------------------------+
  98. | |vec_type| | :ref:`asinh<shader_func_asinh>`\ (\ |vec_type| x) | Arc hyperbolic sine. |
  99. +-----------------+-----------------------------------------------------------------+-----------------------------+
  100. | |vec_type| | :ref:`acosh<shader_func_acosh>`\ (\ |vec_type| x) | Arc hyperbolic cosine. |
  101. +-----------------+-----------------------------------------------------------------+-----------------------------+
  102. | |vec_type| | :ref:`atanh<shader_func_atanh>`\ (\ |vec_type| x) | Arc hyperbolic tangent. |
  103. +-----------------+-----------------------------------------------------------------+-----------------------------+
  104. .. rst-class:: classref-descriptions-group
  105. Trigonometric function descriptions
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. .. _shader_func_radians:
  108. .. rst-class:: classref-method
  109. |vec_type| **radians**\ (\ |vec_type| degrees) :ref:`🔗<shader_func_radians>`
  110. |componentwise|
  111. Converts a quantity specified in degrees into radians, with the formula
  112. ``degrees * (PI / 180)``.
  113. :param degrees:
  114. The quantity, in degrees, to be converted to radians.
  115. :return:
  116. The input ``degrees`` converted to radians.
  117. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/radians.xhtml
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _shader_func_degrees:
  121. .. rst-class:: classref-method
  122. |vec_type| **degrees**\ (\ |vec_type| radians) :ref:`🔗<shader_func_degrees>`
  123. |componentwise|
  124. Converts a quantity specified in radians into degrees, with the formula
  125. ``radians * (180 / PI)``
  126. :param radians:
  127. The quantity, in radians, to be converted to degrees.
  128. :return:
  129. The input ``radians`` converted to degrees.
  130. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/degrees.xhtml
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _shader_func_sin:
  134. .. rst-class:: classref-method
  135. |vec_type| **sin**\ (\ |vec_type| angle) :ref:`🔗<shader_func_sin>`
  136. |componentwise|
  137. Returns the trigonometric sine of ``angle``.
  138. :param angle:
  139. The quantity, in radians, of which to return the sine.
  140. :return:
  141. The sine of ``angle``.
  142. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sin.xhtml
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _shader_func_cos:
  146. .. rst-class:: classref-method
  147. |vec_type| **cos**\ (\ |vec_type| angle) :ref:`🔗<shader_func_cos>`
  148. |componentwise|
  149. Returns the trigonometric cosine of ``angle``.
  150. :param angle:
  151. The quantity, in radians, of which to return the cosine.
  152. :return:
  153. The cosine of ``angle``.
  154. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/cos.xhtml
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _shader_func_tan:
  158. .. rst-class:: classref-method
  159. |vec_type| **tan**\ (\ |vec_type| angle) :ref:`🔗<shader_func_tan>`
  160. |componentwise|
  161. Returns the trigonometric tangent of ``angle``.
  162. :param angle:
  163. The quantity, in radians, of which to return the tangent.
  164. :return:
  165. The tangent of ``angle``.
  166. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/tan.xhtml
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _shader_func_asin:
  170. .. rst-class:: classref-method
  171. |vec_type| **asin**\ (\ |vec_type| x) :ref:`🔗<shader_func_asin>`
  172. |componentwise|
  173. Arc sine, or inverse sine.
  174. Calculates the angle whose sine is ``x`` and is in the range ``[-PI/2, PI/2]``.
  175. The result is undefined if ``x < -1`` or ``x > 1``.
  176. :param x:
  177. The value whose arc sine to return.
  178. :return:
  179. The angle whose trigonometric sine is ``x``.
  180. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/asin.xhtml
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _shader_func_acos:
  184. .. rst-class:: classref-method
  185. |vec_type| **acos**\ (\ |vec_type| x) :ref:`🔗<shader_func_acos>`
  186. |componentwise|
  187. Arc cosine, or inverse cosine.
  188. Calculates the angle whose cosine is ``x`` and is in the range ``[0, PI]``.
  189. The result is undefined if ``x < -1`` or ``x > 1``.
  190. :param x:
  191. The value whose arc cosine to return.
  192. :return:
  193. The angle whose trigonometric cosine is ``x``.
  194. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/acos.xhtml
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _shader_func_atan:
  198. .. rst-class:: classref-method
  199. |vec_type| **atan**\ (\ |vec_type| y_over_x) :ref:`🔗<shader_func_atan>`
  200. |componentwise|
  201. Calculates the arc tangent given a tangent value of ``y/x``.
  202. .. Note::
  203. Because of the sign ambiguity, the function cannot determine with certainty in
  204. which quadrant the angle falls only by its tangent value. If you need to know the
  205. quadrant, use :ref:`atan(vec_type y, vec_type x)<shader_func_atan2>`.
  206. :param y_over_x:
  207. The fraction whose arc tangent to return.
  208. :return:
  209. The trigonometric arc-tangent of ``y_over_x`` and is
  210. in the range ``[-PI/2, PI/2]``.
  211. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/atan.xhtml
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _shader_func_atan2:
  215. .. rst-class:: classref-method
  216. |vec_type| **atan**\ (\ |vec_type| y, |vec_type| x) :ref:`🔗<shader_func_atan2>`
  217. |componentwise|
  218. Calculates the arc tangent given a numerator and denominator. The signs of
  219. ``y`` and ``x`` are used to determine the quadrant that the angle lies in.
  220. The result is undefined if ``x == 0``.
  221. Equivalent to :ref:`atan2() <class_@GlobalScope_method_atan2>` in GDScript.
  222. :param y:
  223. The numerator of the fraction whose arc tangent to return.
  224. :param x:
  225. The denominator of the fraction whose arc tangent to return.
  226. :return:
  227. The trigonometric arc tangent of ``y/x`` and is in
  228. the range ``[-PI, PI]``.
  229. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/atan.xhtml
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _shader_func_sinh:
  233. .. rst-class:: classref-method
  234. |vec_type| **sinh**\ (\ |vec_type| x) :ref:`🔗<shader_func_sinh>`
  235. |componentwise|
  236. Calculates the hyperbolic sine using ``(e^x - e^-x)/2``.
  237. :param x:
  238. The value whose hyperbolic sine to return.
  239. :return:
  240. The hyperbolic sine of ``x``.
  241. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sinh.xhtml
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _shader_func_cosh:
  245. .. rst-class:: classref-method
  246. |vec_type| **cosh**\ (\ |vec_type| x) :ref:`🔗<shader_func_cosh>`
  247. |componentwise|
  248. Calculates the hyperbolic cosine using ``(e^x + e^-x)/2``.
  249. :param x:
  250. The value whose hyperbolic cosine to return.
  251. :return:
  252. The hyperbolic cosine of ``x``.
  253. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/cosh.xhtml
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _shader_func_tanh:
  257. .. rst-class:: classref-method
  258. |vec_type| **tanh**\ (\ |vec_type| x) :ref:`🔗<shader_func_tanh>`
  259. |componentwise|
  260. Calculates the hyperbolic tangent using ``sinh(x)/cosh(x)``.
  261. :param x:
  262. The value whose hyperbolic tangent to return.
  263. :return:
  264. The hyperbolic tangent of ``x``.
  265. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/tanh.xhtml
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _shader_func_asinh:
  269. .. rst-class:: classref-method
  270. |vec_type| **asinh**\ (\ |vec_type| x) :ref:`🔗<shader_func_asinh>`
  271. |componentwise|
  272. Calculates the arc hyperbolic sine of ``x``, or the inverse of ``sinh``.
  273. :param x:
  274. The value whose arc hyperbolic sine to return.
  275. :return:
  276. The arc hyperbolic sine of ``x``.
  277. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/asinh.xhtml
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _shader_func_acosh:
  281. .. rst-class:: classref-method
  282. |vec_type| **acosh**\ (\ |vec_type| x) :ref:`🔗<shader_func_acosh>`
  283. |componentwise|
  284. Calculates the arc hyperbolic cosine of ``x``, or the non-negative inverse of ``cosh``.
  285. The result is undefined if ``x < 1``.
  286. :param x:
  287. The value whose arc hyperbolic cosine to return.
  288. :return:
  289. The arc hyperbolic cosine of ``x``.
  290. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/acosh.xhtml
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _shader_func_atanh:
  294. .. rst-class:: classref-method
  295. |vec_type| **atanh**\ (\ |vec_type| x) :ref:`🔗<shader_func_atanh>`
  296. |componentwise|
  297. Calculates the arc hyperbolic tangent of ``x``, or the inverse of ``tanh``.
  298. The result is undefined if ``abs(x) > 1``.
  299. :param x:
  300. The value whose arc hyperbolic tangent to return.
  301. :return:
  302. The arc hyperbolic tangent of ``x``.
  303. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/atanh.xhtml
  304. .. rst-class:: classref-section-separator
  305. ----
  306. .. rst-class:: classref-reftable-group
  307. Exponential and math functions
  308. ------------------------------
  309. .. table::
  310. :class: nowrap-col2
  311. :widths: auto
  312. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  313. | Return Type | Function | Description / Return value |
  314. +=====================+====================================================================================================+=================================================================+
  315. | |vec_type| | :ref:`pow<shader_func_pow>`\ (\ |vec_type| x, |vec_type| y) | Power (undefined if ``x < 0`` or if ``x == 0`` and ``y <= 0``). |
  316. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  317. | |vec_type| | :ref:`exp<shader_func_exp>`\ (\ |vec_type| x) | Base-e exponential. |
  318. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  319. | |vec_type| | :ref:`exp2<shader_func_exp2>`\ (\ |vec_type| x) | Base-2 exponential. |
  320. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  321. | |vec_type| | :ref:`log<shader_func_log>`\ (\ |vec_type| x) | Natural (base-e) logarithm. |
  322. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  323. | |vec_type| | :ref:`log2<shader_func_log2>`\ (\ |vec_type| x) | Base-2 logarithm. |
  324. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  325. | |vec_type| | :ref:`sqrt<shader_func_sqrt>`\ (\ |vec_type| x) | Square root. |
  326. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  327. | |vec_type| | :ref:`inversesqrt<shader_func_inversesqrt>`\ (\ |vec_type| x) | Inverse square root. |
  328. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  329. | | |vec_type| | | :ref:`abs<shader_func_abs>`\ (\ |vec_type| x) | Absolute value (returns positive value if negative). |
  330. | | |vec_int_type| | | :ref:`abs<shader_func_abs>`\ (\ |vec_int_type| x) | |
  331. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  332. | |vec_type| | :ref:`sign<shader_func_sign>`\ (\ |vec_type| x) | Returns ``1.0`` if positive, ``-1.0`` if negative, |
  333. | | | ``0.0`` otherwise. |
  334. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  335. | |vec_int_type| | :ref:`sign<shader_func_sign>`\ (\ |vec_int_type| x) | Returns ``1`` if positive, ``-1`` if negative, |
  336. | | | ``0`` otherwise. |
  337. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  338. | |vec_type| | :ref:`floor<shader_func_floor>`\ (\ |vec_type| x) | Rounds to the integer below. |
  339. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  340. | |vec_type| | :ref:`round<shader_func_round>`\ (\ |vec_type| x) | Rounds to the nearest integer. |
  341. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  342. | |vec_type| | :ref:`roundEven<shader_func_roundEven>`\ (\ |vec_type| x) | Rounds to the nearest even integer. |
  343. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  344. | |vec_type| | :ref:`trunc<shader_func_trunc>`\ (\ |vec_type| x) | Truncation. |
  345. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  346. | |vec_type| | :ref:`ceil<shader_func_ceil>`\ (\ |vec_type| x) | Rounds to the integer above. |
  347. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  348. | |vec_type| | :ref:`fract<shader_func_fract>`\ (\ |vec_type| x) | Fractional (returns ``x - floor(x)``). |
  349. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  350. | | |vec_type| | | :ref:`mod<shader_func_mod>`\ (\ |vec_type| x, |vec_type| y) | Modulo (division remainder). |
  351. | | |vec_type| | | :ref:`mod<shader_func_mod>`\ (\ |vec_type| x, float y) | |
  352. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  353. | |vec_type| | :ref:`modf<shader_func_modf>`\ (\ |vec_type| x, out |vec_type| i) | Fractional of ``x``, with ``i`` as integer part. |
  354. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  355. | | |vec_type| | | :ref:`min<shader_func_min>`\ (\ |vec_type| a, |vec_type| b) | Lowest value between ``a`` and ``b``. |
  356. | | |vec_type| | | :ref:`min<shader_func_min>`\ (\ |vec_type| a, float b) | |
  357. | | |vec_int_type| | | :ref:`min<shader_func_min>`\ (\ |vec_int_type| a, |vec_int_type| b) | |
  358. | | |vec_int_type| | | :ref:`min<shader_func_min>`\ (\ |vec_int_type| a, int b) | |
  359. | | |vec_uint_type| | | :ref:`min<shader_func_min>`\ (\ |vec_uint_type| a, |vec_uint_type| b) | |
  360. | | |vec_uint_type| | | :ref:`min<shader_func_min>`\ (\ |vec_uint_type| a, uint b) | |
  361. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  362. | | |vec_type| | | :ref:`max<shader_func_max>`\ (\ |vec_type| a, |vec_type| b) | Highest value between ``a`` and ``b``. |
  363. | | |vec_type| | | :ref:`max<shader_func_max>`\ (\ |vec_type| a, float b) | |
  364. | | |vec_int_type| | | :ref:`max<shader_func_max>`\ (\ |vec_int_type| a, |vec_int_type| b) | |
  365. | | |vec_int_type| | | :ref:`max<shader_func_max>`\ (\ |vec_int_type| a, int b) | |
  366. | | |vec_uint_type| | | :ref:`max<shader_func_max>`\ (\ |vec_uint_type| a, |vec_uint_type| b) | |
  367. | | |vec_uint_type| | | :ref:`max<shader_func_max>`\ (\ |vec_uint_type| a, uint b) | |
  368. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  369. | | |vec_type| | | :ref:`clamp<shader_func_clamp>`\ (\ |vec_type| x, |vec_type| min, |vec_type| max) | Clamps ``x`` between ``min`` and ``max`` (inclusive). |
  370. | | |vec_type| | | :ref:`clamp<shader_func_clamp>`\ (\ |vec_type| x, float min, float max) | |
  371. | | |vec_int_type| | | :ref:`clamp<shader_func_clamp>`\ (\ |vec_int_type| x, |vec_int_type| min, |vec_int_type| max) | |
  372. | | |vec_int_type| | | :ref:`clamp<shader_func_clamp>`\ (\ |vec_int_type| x, int min, int max) | |
  373. | | |vec_uint_type| | | :ref:`clamp<shader_func_clamp>`\ (\ |vec_uint_type| x, |vec_uint_type| min, |vec_uint_type| max) | |
  374. | | |vec_uint_type| | | :ref:`clamp<shader_func_clamp>`\ (\ |vec_uint_type| x, uint min, uint max) | |
  375. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  376. | | |vec_type| | | :ref:`mix<shader_func_mix>`\ (\ |vec_type| a, |vec_type| b, |vec_type| c) | Linear interpolate between ``a`` and ``b`` by ``c``. |
  377. | | |vec_type| | | :ref:`mix<shader_func_mix>`\ (\ |vec_type| a, |vec_type| b, float c) | |
  378. | | |vec_type| | | :ref:`mix<shader_func_mix>`\ (\ |vec_type| a, |vec_type| b, |vec_bool_type| c) | |
  379. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  380. | |vec_type| | :ref:`fma<shader_func_fma>`\ (\ |vec_type| a, |vec_type| b, |vec_type| c) | Fused multiply-add operation: ``(a * b + c)`` |
  381. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  382. | | |vec_type| | | :ref:`step<shader_func_step>`\ (\ |vec_type| a, |vec_type| b) | ``b < a ? 0.0 : 1.0`` |
  383. | | |vec_type| | | :ref:`step<shader_func_step>`\ (\ float a, |vec_type| b) | |
  384. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  385. | | |vec_type| | | :ref:`smoothstep<shader_func_smoothstep>`\ (\ |vec_type| a, |vec_type| b, |vec_type| c) | Hermite interpolate between ``a`` and ``b`` by ``c``. |
  386. | | |vec_type| | | :ref:`smoothstep<shader_func_smoothstep>`\ (\ float a, float b, |vec_type| c) | |
  387. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  388. | |vec_bool_type| | :ref:`isnan<shader_func_isnan>`\ (\ |vec_type| x) | Returns ``true`` if scalar or vector component is ``NaN``. |
  389. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  390. | |vec_bool_type| | :ref:`isinf<shader_func_isinf>`\ (\ |vec_type| x) | Returns ``true`` if scalar or vector component is ``INF``. |
  391. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  392. | |vec_int_type| | :ref:`floatBitsToInt<shader_func_floatBitsToInt>`\ (\ |vec_type| x) | ``float`` to ``int`` bit copying, no conversion. |
  393. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  394. | |vec_uint_type| | :ref:`floatBitsToUint<shader_func_floatBitsToUint>`\ (\ |vec_type| x) | ``float`` to ``uint`` bit copying, no conversion. |
  395. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  396. | |vec_type| | :ref:`intBitsToFloat<shader_func_intBitsToFloat>`\ (\ |vec_int_type| x) | ``int`` to ``float`` bit copying, no conversion. |
  397. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  398. | |vec_type| | :ref:`uintBitsToFloat<shader_func_uintBitsToFloat>`\ (\ |vec_uint_type| x) | ``uint`` to ``float`` bit copying, no conversion. |
  399. +---------------------+----------------------------------------------------------------------------------------------------+-----------------------------------------------------------------+
  400. .. rst-class:: classref-descriptions-group
  401. Exponential and math function descriptions
  402. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403. .. _shader_func_pow:
  404. .. rst-class:: classref-method
  405. |vec_type| **pow**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_pow>`
  406. |componentwise|
  407. Raises ``x`` to the power of ``y``.
  408. The result is undefined if ``x < 0`` or if ``x == 0`` and ``y <= 0``.
  409. :param x:
  410. The value to be raised to the power ``y``.
  411. :param y:
  412. The power to which ``x`` will be raised.
  413. :return:
  414. The value of ``x`` raised to the ``y`` power.
  415. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/pow.xhtml
  416. .. rst-class:: classref-item-separator
  417. ----
  418. .. _shader_func_exp:
  419. .. rst-class:: classref-method
  420. |vec_type| **exp**\ (\ |vec_type| x) :ref:`🔗<shader_func_exp>`
  421. |componentwise|
  422. Raises ``e`` to the power of ``x``, or the the natural exponentiation.
  423. Equivalent to ``pow(e, x)``.
  424. :param x:
  425. The value to exponentiate.
  426. :return:
  427. The natural exponentiation of ``x``.
  428. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/exp.xhtml
  429. .. rst-class:: classref-item-separator
  430. ----
  431. .. _shader_func_exp2:
  432. .. rst-class:: classref-method
  433. |vec_type| **exp2**\ (\ |vec_type| x) :ref:`🔗<shader_func_exp2>`
  434. |componentwise|
  435. Raises ``2`` to the power of ``x``.
  436. Equivalent to ``pow(2.0, x)``.
  437. :param x:
  438. The value of the power to which ``2`` will be raised.
  439. :return:
  440. ``2`` raised to the power of x.
  441. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/exp2.xhtml
  442. .. rst-class:: classref-item-separator
  443. ----
  444. .. _shader_func_log:
  445. .. rst-class:: classref-method
  446. |vec_type| **log**\ (\ |vec_type| x) :ref:`🔗<shader_func_log>`
  447. |componentwise|
  448. Returns the natural logarithm of ``x``, i.e. the value ``y`` which satisfies ``x == pow(e, y)``.
  449. The result is undefined if ``x <= 0``.
  450. :param x:
  451. The value of which to take the natural logarithm.
  452. :return:
  453. The natural logarithm of ``x``.
  454. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/log.xhtml
  455. .. rst-class:: classref-item-separator
  456. ----
  457. .. _shader_func_log2:
  458. .. rst-class:: classref-method
  459. |vec_type| **log2**\ (\ |vec_type| x) :ref:`🔗<shader_func_log2>`
  460. |componentwise|
  461. Returns the base-2 logarithm of ``x``, i.e. the value ``y`` which satisfies ``x == pow(2, y)``.
  462. The result is undefined if ``x <= 0``.
  463. :param x:
  464. The value of which to take the base-2 logarithm.
  465. :return:
  466. The base-2 logarithm of ``x``.
  467. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/log2.xhtml
  468. .. rst-class:: classref-item-separator
  469. ----
  470. .. _shader_func_sqrt:
  471. .. rst-class:: classref-method
  472. |vec_type| **sqrt**\ (\ |vec_type| x) :ref:`🔗<shader_func_sqrt>`
  473. |componentwise|
  474. Returns the square root of ``x``.
  475. The result is undefined if ``x < 0``.
  476. :param x:
  477. The value of which to take the square root.
  478. :return:
  479. The square root of ``x``.
  480. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sqrt.xhtml
  481. .. rst-class:: classref-item-separator
  482. ----
  483. .. _shader_func_inversesqrt:
  484. .. rst-class:: classref-method
  485. |vec_type| **inversesqrt**\ (\ |vec_type| x) :ref:`🔗<shader_func_inversesqrt>`
  486. |componentwise|
  487. Returns the inverse of the square root of ``x``, or ``1.0 / sqrt(x)``.
  488. The result is undefined if ``x <= 0``.
  489. :param x:
  490. The value of which to take the inverse of the square root.
  491. :return:
  492. The inverse of the square root of ``x``.
  493. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/inversesqrt.xhtml
  494. .. rst-class:: classref-item-separator
  495. ----
  496. .. _shader_func_abs:
  497. .. rst-class:: classref-method
  498. |vec_type| **abs**\ (\ |vec_type| x) :ref:`🔗<shader_func_abs>`
  499. .. rst-class:: classref-method
  500. |vec_int_type| **abs**\ (\ |vec_int_type| x) :ref:`🔗<shader_func_abs>`
  501. |componentwise|
  502. Returns the absolute value of ``x``. Returns ``x`` if ``x`` is positive, otherwise returns ``-1 * x``.
  503. :param x:
  504. The value of which to return the absolute.
  505. :return:
  506. The absolute value of ``x``.
  507. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/abs.xhtml
  508. .. rst-class:: classref-item-separator
  509. ----
  510. .. _shader_func_sign:
  511. .. rst-class:: classref-method
  512. |vec_type| **sign**\ (\ |vec_type| x) :ref:`🔗<shader_func_sign>`
  513. .. rst-class:: classref-method
  514. |vec_int_type| **sign**\ (\ |vec_int_type| x) :ref:`🔗<shader_func_sign>`
  515. |componentwise|
  516. Returns ``-1`` if ``x < 0``, ``0`` if ``x == 0``, and ``1`` if ``x > 0``.
  517. :param x:
  518. The value from which to extract the sign.
  519. :return:
  520. The sign of ``x``.
  521. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sign.xhtml
  522. .. rst-class:: classref-item-separator
  523. ----
  524. .. _shader_func_floor:
  525. .. rst-class:: classref-method
  526. |vec_type| **floor**\ (\ |vec_type| x) :ref:`🔗<shader_func_floor>`
  527. |componentwise|
  528. Returns a value equal to the nearest integer that is less than or equal to ``x``.
  529. :param x:
  530. The value to floor.
  531. :return:
  532. The nearest integer that is less than or equal to ``x``.
  533. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floor.xhtml
  534. .. rst-class:: classref-item-separator
  535. ----
  536. .. _shader_func_round:
  537. .. rst-class:: classref-method
  538. |vec_type| **round**\ (\ |vec_type| x) :ref:`🔗<shader_func_round>`
  539. |componentwise|
  540. Rounds ``x`` to the nearest integer.
  541. .. note::
  542. Rounding of values with a fractional part of ``0.5`` is implementation-dependent.
  543. This includes the possibility that ``round(x)`` returns the same value as
  544. ``roundEven(x)``for all values of ``x``.
  545. :param x:
  546. The value to round.
  547. :return:
  548. The rounded value.
  549. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/round.xhtml
  550. .. rst-class:: classref-item-separator
  551. ----
  552. .. _shader_func_roundEven:
  553. .. rst-class:: classref-method
  554. |vec_type| **roundEven**\ (\ |vec_type| x) :ref:`🔗<shader_func_roundEven>`
  555. |componentwise|
  556. Rounds ``x`` to the nearest integer. A value with a fractional part of ``0.5``
  557. will always round toward the nearest even integer.
  558. For example, both ``3.5`` and ``4.5`` will round to ``4.0``.
  559. :param x:
  560. The value to round.
  561. :return:
  562. The rounded value.
  563. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/roundEven.xhtml
  564. .. rst-class:: classref-item-separator
  565. ----
  566. .. _shader_func_trunc:
  567. .. rst-class:: classref-method
  568. |vec_type| **trunc**\ (\ |vec_type| x) :ref:`🔗<shader_func_trunc>`
  569. |componentwise|
  570. Truncates ``x``. Returns a value equal to the nearest integer to ``x`` whose
  571. absolute value is not larger than the absolute value of ``x``.
  572. :param x:
  573. The value to evaluate.
  574. :return:
  575. The truncated value.
  576. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/trunc.xhtml
  577. .. rst-class:: classref-item-separator
  578. ----
  579. .. _shader_func_ceil:
  580. .. rst-class:: classref-method
  581. |vec_type| **ceil**\ (\ |vec_type| x) :ref:`🔗<shader_func_ceil>`
  582. |componentwise|
  583. Returns a value equal to the nearest integer that is greater than or equal to ``x``.
  584. :param x:
  585. The value to evaluate.
  586. :return:
  587. The ceiling-ed value.
  588. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/ceil.xhtml
  589. .. rst-class:: classref-item-separator
  590. ----
  591. .. _shader_func_fract:
  592. .. rst-class:: classref-method
  593. |vec_type| **fract**\ (\ |vec_type| x) :ref:`🔗<shader_func_fract>`
  594. |componentwise|
  595. Returns the fractional part of ``x``.
  596. This is calculated as ``x - floor(x)``.
  597. :param x:
  598. The value to evaluate.
  599. :return:
  600. The fractional part of ``x``.
  601. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fract.xhtml
  602. .. rst-class:: classref-item-separator
  603. ----
  604. .. _shader_func_mod:
  605. .. rst-class:: classref-method
  606. |vec_type| **mod**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_mod>`
  607. .. rst-class:: classref-method
  608. |vec_type| **mod**\ (\ |vec_type| x, float y) :ref:`🔗<shader_func_mod>`
  609. |componentwise|
  610. Returns the value of ``x modulo y``.
  611. This is also sometimes called the remainder.
  612. This is computed as ``x - y * floor(x/y)``.
  613. :param x:
  614. The value to evaluate.
  615. :return:
  616. The value of ``x modulo y``.
  617. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mod.xhtml
  618. .. rst-class:: classref-item-separator
  619. ----
  620. .. _shader_func_modf:
  621. .. rst-class:: classref-method
  622. |vec_type| **modf**\ (\ |vec_type| x, out |vec_type| i) :ref:`🔗<shader_func_modf>`
  623. |componentwise|
  624. Separates a floating-point value ``x`` into its integer and fractional parts.
  625. The fractional part of the number is returned from the function.
  626. The integer part (as a floating-point quantity) is returned in the output parameter ``i``.
  627. :param x:
  628. The value to separate.
  629. :param out i:
  630. A variable that receives the integer part of ``x``.
  631. :return:
  632. The fractional part of the number.
  633. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/modf.xhtml
  634. .. rst-class:: classref-item-separator
  635. ----
  636. .. _shader_func_min:
  637. .. rst-class:: classref-method
  638. |vec_type| **min**\ (\ |vec_type| a, |vec_type| b) :ref:`🔗<shader_func_min>`
  639. .. rst-class:: classref-method
  640. |vec_type| **min**\ (\ |vec_type| a, float b) :ref:`🔗<shader_func_min>`
  641. .. rst-class:: classref-method
  642. |vec_int_type| **min**\ (\ |vec_int_type| a, |vec_int_type| b) :ref:`🔗<shader_func_min>`
  643. .. rst-class:: classref-method
  644. |vec_int_type| **min**\ (\ |vec_int_type| a, int b) :ref:`🔗<shader_func_min>`
  645. .. rst-class:: classref-method
  646. |vec_uint_type| **min**\ (\ |vec_uint_type| a, |vec_uint_type| b) :ref:`🔗<shader_func_min>`
  647. .. rst-class:: classref-method
  648. |vec_uint_type| **min**\ (\ |vec_uint_type| a, uint b) :ref:`🔗<shader_func_min>`
  649. |componentwise|
  650. Returns the minimum of two values ``a`` and ``b``.
  651. Returns ``b`` if ``b < a``, otherwise returns ``a``.
  652. :param a:
  653. The first value to compare.
  654. :param b:
  655. The second value to compare.
  656. :return:
  657. The minimum value.
  658. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/min.xhtml
  659. .. rst-class:: classref-item-separator
  660. ----
  661. .. _shader_func_max:
  662. .. rst-class:: classref-method
  663. |vec_type| **max**\ (\ |vec_type| a, |vec_type| b) :ref:`🔗<shader_func_max>`
  664. .. rst-class:: classref-method
  665. |vec_type| **max**\ (\ |vec_type| a, float b) :ref:`🔗<shader_func_max>`
  666. .. rst-class:: classref-method
  667. |vec_uint_type| **max**\ (\ |vec_uint_type| a, |vec_uint_type| b) :ref:`🔗<shader_func_max>`
  668. .. rst-class:: classref-method
  669. |vec_uint_type| **max**\ (\ |vec_uint_type| a, uint b) :ref:`🔗<shader_func_max>`
  670. .. rst-class:: classref-method
  671. |vec_int_type| **max**\ (\ |vec_int_type| a, |vec_int_type| b) :ref:`🔗<shader_func_max>`
  672. .. rst-class:: classref-method
  673. |vec_int_type| **max**\ (\ |vec_int_type| a, int b) :ref:`🔗<shader_func_max>`
  674. |componentwise|
  675. Returns the maximum of two values ``a`` and ``b``.
  676. It returns ``b`` if ``b > a``, otherwise it returns ``a``.
  677. :param a:
  678. The first value to compare.
  679. :param b:
  680. The second value to compare.
  681. :return:
  682. The maximum value.
  683. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/max.xhtml
  684. .. rst-class:: classref-item-separator
  685. ----
  686. .. _shader_func_clamp:
  687. .. rst-class:: classref-method
  688. |vec_type| **clamp**\ (\ |vec_type| x, |vec_type| minVal, |vec_type| maxVal) :ref:`🔗<shader_func_clamp>`
  689. .. rst-class:: classref-method
  690. |vec_type| **clamp**\ (\ |vec_type| x, float minVal, float maxVal) :ref:`🔗<shader_func_clamp>`
  691. .. rst-class:: classref-method
  692. |vec_int_type| **clamp**\ (\ |vec_int_type| x, |vec_int_type| minVal, |vec_int_type| maxVal) :ref:`🔗<shader_func_clamp>`
  693. .. rst-class:: classref-method
  694. |vec_int_type| **clamp**\ (\ |vec_int_type| x, int minVal, int maxVal) :ref:`🔗<shader_func_clamp>`
  695. .. rst-class:: classref-method
  696. |vec_uint_type| **clamp**\ (\ |vec_uint_type| x, |vec_uint_type| minVal, |vec_uint_type| maxVal) :ref:`🔗<shader_func_clamp>`
  697. .. rst-class:: classref-method
  698. |vec_uint_type| **clamp**\ (\ |vec_uint_type| x, uint minVal, uint maxVal) :ref:`🔗<shader_func_clamp>`
  699. |componentwise|
  700. Returns the value of ``x`` constrained to the range ``minVal`` to ``maxVal``.
  701. The returned value is computed as ``min(max(x, minVal), maxVal)``.
  702. :param x:
  703. The value to constrain.
  704. :param minVal:
  705. The lower end of the range into which to constrain ``x``.
  706. :param maxVal:
  707. The upper end of the range into which to constrain ``x``.
  708. :return:
  709. The clamped value.
  710. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/clamp.xhtml
  711. .. rst-class:: classref-item-separator
  712. ----
  713. .. _shader_func_mix:
  714. .. rst-class:: classref-method
  715. |vec_type| **mix**\ (\ |vec_type| a, |vec_type| b, |vec_type| c) :ref:`🔗<shader_func_mix>`
  716. .. rst-class:: classref-method
  717. |vec_type| **mix**\ (\ |vec_type| a, |vec_type| b, float c) :ref:`🔗<shader_func_mix>`
  718. |componentwise|
  719. Performs a linear interpolation between ``a`` and ``b`` using ``c`` to weight between them.
  720. Computed as ``a * (1 - c) + b * c``.
  721. Equivalent to :ref:`lerp() <class_@GlobalScope_method_lerp>` in GDScript.
  722. :param a:
  723. The start of the range in which to interpolate.
  724. :param b:
  725. The end of the range in which to interpolate.
  726. :param c:
  727. The value to use to interpolate between ``a`` and ``b``.
  728. :return:
  729. The interpolated value.
  730. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mix.xhtml
  731. .. rst-class:: classref-item-separator
  732. ----
  733. .. rst-class:: classref-method
  734. |vec_type| **mix**\ (\ |vec_type| a, |vec_type| b, |vec_bool_type| c) :ref:`🔗<shader_func_mix>`
  735. Selects either value ``a`` or value ``b`` based on the value of ``c``.
  736. For a component of ``c`` that is false, the corresponding component of ``a`` is returned.
  737. For a component of ``c`` that is true, the corresponding component of ``b`` is returned.
  738. Components of ``a`` and ``b`` that are not selected are allowed to be invalid floating-point values and will have no effect on the results.
  739. If ``a``, ``b``, and ``c`` are vector types the operation is performed :ref:`component-wise <shading_componentwise>`.
  740. ie. ``mix(vec2(42, 314), vec2(9.8, 6e23), bvec2(true, false)))`` will return ``vec2(9.8, 314)``.
  741. :param a:
  742. Value returned when ``c`` is false.
  743. :param b:
  744. Value returned when ``c`` is true.
  745. :param c:
  746. The value used to select between ``a`` and ``b``.
  747. :return:
  748. The interpolated value.
  749. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mix.xhtml
  750. .. rst-class:: classref-item-separator
  751. ----
  752. .. _shader_func_fma:
  753. .. rst-class:: classref-method
  754. |vec_type| **fma**\ (\ |vec_type| a, |vec_type| b, |vec_type| c) :ref:`🔗<shader_func_fma>`
  755. |componentwise|
  756. Performs, where possible, a fused multiply-add operation, returning ``a * b + c``. In use cases where the
  757. return value is eventually consumed by a variable declared as precise:
  758. - ``fma()`` is considered a single operation, whereas the expression ``a * b + c`` consumed by a variable declared as precise is considered two operations.
  759. - The precision of ``fma()`` can differ from the precision of the expression ``a * b + c``.
  760. - ``fma()`` will be computed with the same precision as any other ``fma()`` consumed by a precise variable,
  761. giving invariant results for the same input values of a, b and c.
  762. Otherwise, in the absence of precise consumption, there are no special constraints on the number of operations
  763. or difference in precision between ``fma()`` and the expression ``a * b + c``.
  764. :param a:
  765. The first value to be multiplied.
  766. :param b:
  767. The second value to be multiplied.
  768. :param c:
  769. The value to be added to the result.
  770. :return:
  771. The value of ``a * b + c``.
  772. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fma.xhtml
  773. .. rst-class:: classref-item-separator
  774. ----
  775. .. _shader_func_step:
  776. .. rst-class:: classref-method
  777. |vec_type| **step**\ (\ |vec_type| a, |vec_type| b) :ref:`🔗<shader_func_step>`
  778. .. rst-class:: classref-method
  779. |vec_type| **step**\ (\ float a, |vec_type| b) :ref:`🔗<shader_func_step>`
  780. |componentwise|
  781. Generates a step function by comparing b to a.
  782. Equivalent to ``if (b < a) { return 0.0; } else { return 1.0; }``.
  783. For element i of the return value, 0.0 is returned if b[i] < a[i], and 1.0 is returned otherwise.
  784. :param a:
  785. The location of the edge of the step function.
  786. :param b:
  787. The value to be used to generate the step function.
  788. :return:
  789. ``0.0`` or ``1.0``.
  790. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/step.xhtml
  791. .. rst-class:: classref-item-separator
  792. ----
  793. .. _shader_func_smoothstep:
  794. .. rst-class:: classref-method
  795. |vec_type| **smoothstep**\ (\ |vec_type| a, |vec_type| b, |vec_type| c) :ref:`🔗<shader_func_smoothstep>`
  796. .. rst-class:: classref-method
  797. |vec_type| **smoothstep**\ (\ float a, float b, |vec_type| c) :ref:`🔗<shader_func_smoothstep>`
  798. |componentwise|
  799. Performs smooth Hermite interpolation between ``0`` and ``1`` when a < c < b.
  800. This is useful in cases where a threshold function with a smooth transition is desired.
  801. Smoothstep is equivalent to:
  802. ::
  803. vec_type t;
  804. t = clamp((c - a) / (b - a), 0.0, 1.0);
  805. return t * t * (3.0 - 2.0 * t);
  806. Results are undefined if ``a >= b``.
  807. :param a:
  808. The value of the lower edge of the Hermite function.
  809. :param b:
  810. The value of the upper edge of the Hermite function.
  811. :param c:
  812. The source value for interpolation.
  813. :return:
  814. The interpolated value.
  815. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/smoothstep.xhtml
  816. .. rst-class:: classref-item-separator
  817. ----
  818. .. _shader_func_isnan:
  819. .. rst-class:: classref-method
  820. |vec_bool_type| **isnan**\ (\ |vec_type| x) :ref:`🔗<shader_func_isnan>`
  821. |componentwise|
  822. For each element i of the result, returns ``true`` if x[i] is positive
  823. or negative floating-point NaN (Not a Number) and false otherwise.
  824. :param x:
  825. The value to test for NaN.
  826. :return:
  827. ``true`` or ``false``.
  828. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/isnan.xhtml
  829. .. rst-class:: classref-item-separator
  830. ----
  831. .. _shader_func_isinf:
  832. .. rst-class:: classref-method
  833. |vec_bool_type| **isinf**\ (\ |vec_type| x) :ref:`🔗<shader_func_isinf>`
  834. |componentwise|
  835. For each element i of the result, returns ``true`` if x[i] is positive or negative
  836. floating-point infinity and false otherwise.
  837. :param x:
  838. The value to test for infinity.
  839. :return:
  840. ``true`` or ``false``.
  841. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/isinf.xhtml
  842. .. rst-class:: classref-item-separator
  843. ----
  844. .. _shader_func_floatBitsToInt:
  845. .. rst-class:: classref-method
  846. |vec_int_type| **floatBitsToInt**\ (\ |vec_type| x) :ref:`🔗<shader_func_floatBitsToInt>`
  847. |componentwise|
  848. Returns the encoding of the floating-point parameters as ``int``.
  849. The floating-point bit-level representation is preserved.
  850. :param x:
  851. The value whose floating-point encoding to return.
  852. :return:
  853. The floating-point encoding of ``x``.
  854. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floatBitsToInt.xhtml
  855. .. rst-class:: classref-item-separator
  856. ----
  857. .. _shader_func_floatBitsToUint:
  858. .. rst-class:: classref-method
  859. |vec_uint_type| **floatBitsToUint**\ (\ |vec_type| x) :ref:`🔗<shader_func_floatBitsToUint>`
  860. |componentwise|
  861. Returns the encoding of the floating-point parameters as ``uint``.
  862. The floating-point bit-level representation is preserved.
  863. :param x:
  864. The value whose floating-point encoding to return.
  865. :return:
  866. The floating-point encoding of ``x``.
  867. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floatBitsToInt.xhtml
  868. .. rst-class:: classref-item-separator
  869. ----
  870. .. _shader_func_intBitsToFloat:
  871. .. rst-class:: classref-method
  872. |vec_type| **intBitsToFloat**\ (\ |vec_int_type| x) :ref:`🔗<shader_func_intBitsToFloat>`
  873. |componentwise|
  874. Converts a bit encoding to a floating-point value. Opposite of `floatBitsToInt<shader_func_floatBitsToInt>`
  875. If the encoding of a ``NaN`` is passed in ``x``, it will not signal and the resulting value will be undefined.
  876. If the encoding of a floating-point infinity is passed in parameter ``x``, the resulting floating-point value is
  877. the corresponding (positive or negative) floating-point infinity.
  878. :param x:
  879. The bit encoding to return as a floating-point value.
  880. :return:
  881. A floating-point value.
  882. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/intBitsToFloat.xhtml
  883. .. rst-class:: classref-item-separator
  884. ----
  885. .. _shader_func_uintBitsToFloat:
  886. .. rst-class:: classref-method
  887. |vec_type| **uintBitsToFloat**\ (\ |vec_uint_type| x) :ref:`🔗<shader_func_uintBitsToFloat>`
  888. |componentwise|
  889. Converts a bit encoding to a floating-point value. Opposite of `floatBitsToUint<shader_func_floatBitsToUint>`
  890. If the encoding of a ``NaN`` is passed in ``x``, it will not signal and the resulting value will be undefined.
  891. If the encoding of a floating-point infinity is passed in parameter ``x``, the resulting floating-point value is
  892. the corresponding (positive or negative) floating-point infinity.
  893. :param x:
  894. The bit encoding to return as a floating-point value.
  895. :return:
  896. A floating-point value.
  897. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/intBitsToFloat.xhtml
  898. .. rst-class:: classref-section-separator
  899. ----
  900. .. rst-class:: classref-reftable-group
  901. Geometric functions
  902. -------------------
  903. .. table::
  904. :class: nowrap-col2
  905. :widths: auto
  906. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  907. | float | :ref:`length<shader_func_length>`\ (\ |vec_type| x) | Vector length. |
  908. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  909. | float | :ref:`distance<shader_func_distance>`\ (\ |vec_type| a, |vec_type| b) | Distance between vectors i.e ``length(a - b)``. |
  910. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  911. | float | :ref:`dot<shader_func_dot>`\ (\ |vec_type| a, |vec_type| b) | Dot product. |
  912. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  913. | vec3 | :ref:`cross<shader_func_cross>`\ (\ vec3 a, vec3 b) | Cross product. |
  914. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  915. | |vec_type| | :ref:`normalize<shader_func_normalize>`\ (\ |vec_type| x) | Normalize to unit length. |
  916. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  917. | vec3 | :ref:`reflect<shader_func_reflect>`\ (\ vec3 I, vec3 N) | Reflect. |
  918. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  919. | vec3 | :ref:`refract<shader_func_refract>`\ (\ vec3 I, vec3 N, float eta) | Refract. |
  920. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  921. | |vec_type| | :ref:`faceforward<shader_func_faceforward>`\ (\ |vec_type| N, |vec_type| I, |vec_type| Nref) | If ``dot(Nref, I)`` < 0, return ``N``, otherwise ``-N``. |
  922. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  923. | |mat_type| | :ref:`matrixCompMult<shader_func_matrixCompMult>`\ (\ |mat_type| x, |mat_type| y) | Matrix component multiplication. |
  924. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  925. | |mat_type| | :ref:`outerProduct<shader_func_outerProduct>`\ (\ |vec_type| column, |vec_type| row) | Matrix outer product. |
  926. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  927. | |mat_type| | :ref:`transpose<shader_func_transpose>`\ (\ |mat_type| m) | Transpose matrix. |
  928. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  929. | float | :ref:`determinant<shader_func_determinant>`\ (\ |mat_type| m) | Matrix determinant. |
  930. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  931. | |mat_type| | :ref:`inverse<shader_func_inverse>`\ (\ |mat_type| m) | Inverse matrix. |
  932. +------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------+
  933. .. rst-class:: classref-descriptions-group
  934. Geometric function descriptions
  935. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  936. .. _shader_func_length:
  937. .. rst-class:: classref-method
  938. float **length**\ (\ |vec_type| x) :ref:`🔗<shader_func_length>`
  939. Returns the length of the vector.
  940. ie. ``sqrt(x[0] * x[0] + x[1] * x[1] + ... + x[n] * x[n])``
  941. :param x:
  942. The vector
  943. :return:
  944. The length of the vector.
  945. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/length.xhtml
  946. .. rst-class:: classref-item-separator
  947. ----
  948. .. _shader_func_distance:
  949. .. rst-class:: classref-method
  950. float **distance**\ (\ |vec_type| a, |vec_type| b) :ref:`🔗<shader_func_distance>`
  951. Returns the distance between the two points a and b.
  952. i.e., ``length(b - a);``
  953. :param a:
  954. The first point.
  955. :param b:
  956. The second point.
  957. :return:
  958. The scalar distance between the points
  959. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/distance.xhtml
  960. .. rst-class:: classref-item-separator
  961. ----
  962. .. _shader_func_dot:
  963. .. rst-class:: classref-method
  964. float **dot**\ (\ |vec_type| a, |vec_type| b) :ref:`🔗<shader_func_dot>`
  965. Returns the dot product of two vectors, ``a`` and ``b``.
  966. i.e., ``a.x * b.x + a.y * b.y + ...``
  967. :param a:
  968. The first vector.
  969. :param b:
  970. The second vector.
  971. :return:
  972. The dot product.
  973. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/dot.xhtml
  974. .. rst-class:: classref-item-separator
  975. ----
  976. .. _shader_func_cross:
  977. .. rst-class:: classref-method
  978. vec3 **cross**\ (\ vec3 a, vec3 b) :ref:`🔗<shader_func_cross>`
  979. Returns the cross product of two vectors.
  980. i.e.::
  981. vec2( a.y * b.z - b.y * a.z,
  982. a.z * b.x - b.z * a.x,
  983. a.x * b.z - b.x * a.y)
  984. :param a:
  985. The first vector.
  986. :param b:
  987. The second vector.
  988. :return:
  989. The cross product of ``a`` and ``b``.
  990. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/cross.xhtml
  991. .. rst-class:: classref-item-separator
  992. ----
  993. .. _shader_func_normalize:
  994. .. rst-class:: classref-method
  995. |vec_type| **normalize**\ (\ |vec_type| x) :ref:`🔗<shader_func_normalize>`
  996. Returns a vector with the same direction as ``x`` but with length ``1.0``.
  997. :param x:
  998. The vector to normalize.
  999. :return:
  1000. The normalized vector.
  1001. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/normalize.xhtml
  1002. .. rst-class:: classref-item-separator
  1003. ----
  1004. .. _shader_func_reflect:
  1005. .. rst-class:: classref-method
  1006. vec3 **reflect**\ (\ vec3 I, vec3 N) :ref:`🔗<shader_func_reflect>`
  1007. Calculate the reflection direction for an incident vector.
  1008. For a given incident vector ``I`` and surface normal ``N`` reflect returns the reflection direction calculated as ``I - 2.0 * dot(N, I) * N``.
  1009. .. Note::
  1010. ``N`` should be normalized in order to achieve the desired result.
  1011. :param I:
  1012. The incident vector.
  1013. :param N:
  1014. The normal vector.
  1015. :return:
  1016. The reflection vector.
  1017. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/reflect.xhtml
  1018. .. rst-class:: classref-item-separator
  1019. ----
  1020. .. _shader_func_refract:
  1021. .. rst-class:: classref-method
  1022. vec3 **refract**\ (\ vec3 I, vec3 N, float eta) :ref:`🔗<shader_func_refract>`
  1023. Calculate the refraction direction for an incident vector.
  1024. For a given incident vector ``I``, surface normal ``N`` and ratio of indices of refraction, ``eta``, refract returns the refraction vector, ``R``.
  1025. ``R`` is calculated as:
  1026. ::
  1027. k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
  1028. if (k < 0.0)
  1029. R = genType(0.0); // or genDType(0.0)
  1030. else
  1031. R = eta * I - (eta * dot(N, I) + sqrt(k)) * N;
  1032. .. Note::
  1033. The input parameters I and N should be normalized in order to achieve the desired result.
  1034. :param I:
  1035. The incident vector.
  1036. :param N:
  1037. The normal vector.
  1038. :param eta:
  1039. The ratio of indices of refraction.
  1040. :return:
  1041. The refraction vector.
  1042. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/refract.xhtml
  1043. .. rst-class:: classref-item-separator
  1044. ----
  1045. .. _shader_func_faceforward:
  1046. .. rst-class:: classref-method
  1047. |vec_type| **faceforward**\ (\ |vec_type| N, |vec_type| I, |vec_type| Nref) :ref:`🔗<shader_func_faceforward>`
  1048. Returns a vector pointing in the same direction as another.
  1049. Orients a vector to point away from a surface as defined by its normal.
  1050. If ``dot(Nref, I) < 0`` faceforward returns ``N``, otherwise it returns ``-N``.
  1051. :param N:
  1052. The vector to orient.
  1053. :param I:
  1054. The incident vector.
  1055. :param Nref:
  1056. The reference vector.
  1057. :return:
  1058. The oriented vector.
  1059. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/faceforward.xhtml
  1060. .. rst-class:: classref-item-separator
  1061. ----
  1062. .. _shader_func_matrixCompMult:
  1063. .. rst-class:: classref-method
  1064. |mat_type| **matrixCompMult**\ (\ |mat_type| x, |mat_type| y) :ref:`🔗<shader_func_matrixCompMult>`
  1065. Perform a :ref:`component-wise <shading_componentwise>` multiplication of two matrices.
  1066. Performs a component-wise multiplication of two matrices, yielding a result
  1067. matrix where each component, ``result[i][j]`` is computed as the scalar
  1068. product of ``x[i][j]`` and ``y[i][j]``.
  1069. :param x:
  1070. The first matrix multiplicand.
  1071. :param y:
  1072. The second matrix multiplicand.
  1073. :return:
  1074. The resultant matrix.
  1075. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/matrixCompMult.xhtml
  1076. .. rst-class:: classref-item-separator
  1077. ----
  1078. .. _shader_func_outerProduct:
  1079. .. rst-class:: classref-method
  1080. |mat_type| **outerProduct**\ (\ |vec_type| column, |vec_type| row) :ref:`🔗<shader_func_outerProduct>`
  1081. Calculate the outer product of a pair of vectors.
  1082. Does a linear algebraic matrix multiply ``column * row``, yielding a matrix whose number of
  1083. rows is the number of components in ``column`` and whose number of columns is the number of
  1084. components in ``row``.
  1085. :param column:
  1086. The column vector for multiplication.
  1087. :param row:
  1088. The row vector for multiplication.
  1089. :return:
  1090. The outer product matrix.
  1091. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/outerProduct.xhtml
  1092. .. rst-class:: classref-item-separator
  1093. ----
  1094. .. _shader_func_transpose:
  1095. .. rst-class:: classref-method
  1096. |mat_type| **transpose**\ (\ |mat_type| m) :ref:`🔗<shader_func_transpose>`
  1097. Calculate the transpose of a matrix.
  1098. :param m:
  1099. The matrix to transpose.
  1100. :return:
  1101. A new matrix that is the transpose of the input matrix ``m``.
  1102. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/transpose.xhtml
  1103. .. rst-class:: classref-item-separator
  1104. ----
  1105. .. _shader_func_determinant:
  1106. .. rst-class:: classref-method
  1107. float **determinant**\ (\ |mat_type| m) :ref:`🔗<shader_func_determinant>`
  1108. Calculate the determinant of a matrix.
  1109. :param m:
  1110. The matrix.
  1111. :return:
  1112. The determinant of the input matrix ``m``.
  1113. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/determinant.xhtml
  1114. .. rst-class:: classref-item-separator
  1115. ----
  1116. .. _shader_func_inverse:
  1117. .. rst-class:: classref-method
  1118. |mat_type| **inverse**\ (\ |mat_type| m) :ref:`🔗<shader_func_inverse>`
  1119. Calculate the inverse of a matrix.
  1120. The values in the returned matrix are undefined if ``m`` is singular or poorly-conditioned (nearly singular).
  1121. :param m:
  1122. The matrix of which to take the inverse.
  1123. :return:
  1124. A new matrix which is the inverse of the input matrix ``m``.
  1125. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/inverse.xhtml
  1126. .. rst-class:: classref-section-separator
  1127. ----
  1128. .. rst-class:: classref-reftable-group
  1129. Comparison functions
  1130. --------------------
  1131. .. table::
  1132. :class: nowrap-col2
  1133. :widths: auto
  1134. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1135. | |vec_bool_type| | :ref:`lessThan<shader_func_lessThan>`\ (\ |vec_type| x, |vec_type| y) | Bool vector comparison on < int/uint/float vectors. |
  1136. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1137. | |vec_bool_type| | :ref:`greaterThan<shader_func_greaterThan>`\ (\ |vec_type| x, |vec_type| y) | Bool vector comparison on > int/uint/float vectors. |
  1138. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1139. | |vec_bool_type| | :ref:`lessThanEqual<shader_func_lessThanEqual>`\ (\ |vec_type| x, |vec_type| y) | Bool vector comparison on <= int/uint/float vectors. |
  1140. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1141. | |vec_bool_type| | :ref:`greaterThanEqual<shader_func_greaterThanEqual>`\ (\ |vec_type| x, |vec_type| y) | Bool vector comparison on >= int/uint/float vectors. |
  1142. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1143. | |vec_bool_type| | :ref:`equal<shader_func_equal>`\ (\ |vec_type| x, |vec_type| y) | Bool vector comparison on == int/uint/float vectors. |
  1144. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1145. | |vec_bool_type| | :ref:`notEqual<shader_func_notEqual>`\ (\ |vec_type| x, |vec_type| y) | Bool vector comparison on != int/uint/float vectors. |
  1146. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1147. | bool | :ref:`any<shader_func_any>`\ (\ |vec_bool_type| x) | ``true`` if any component is ``true``, ``false`` otherwise. |
  1148. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1149. | bool | :ref:`all<shader_func_all>`\ (\ |vec_bool_type| x) | ``true`` if all components are ``true``, ``false`` otherwise. |
  1150. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1151. | |vec_bool_type| | :ref:`not<shader_func_not>`\ (\ |vec_bool_type| x) | Invert boolean vector. |
  1152. +-----------------+-----------------------------------------------------------------------------------------+---------------------------------------------------------------+
  1153. .. rst-class:: classref-descriptions-group
  1154. Comparison function descriptions
  1155. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1156. .. _shader_func_lessThan:
  1157. .. rst-class:: classref-method
  1158. |vec_bool_type| **lessThan**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_lessThan>`
  1159. Performs a :ref:`component-wise<shading_componentwise>` less-than comparison of two vectors.
  1160. :param x:
  1161. The first vector to compare.
  1162. :param y:
  1163. The second vector to compare.
  1164. :return:
  1165. A boolean vector in which each element ``i`` is computed as ``x[i] < y[i]``.
  1166. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/lessThan.xhtml
  1167. .. rst-class:: classref-item-separator
  1168. ----
  1169. .. _shader_func_greaterThan:
  1170. .. rst-class:: classref-method
  1171. |vec_bool_type| **greaterThan**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_greaterThan>`
  1172. Performs a :ref:`component-wise<shading_componentwise>` greater-than comparison of two vectors.
  1173. :param x:
  1174. The first vector to compare.
  1175. :param y:
  1176. The second vector to compare.
  1177. :return:
  1178. A boolean vector in which each element ``i`` is computed as ``x[i] > y[i]``.
  1179. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/greaterThan.xhtml
  1180. .. rst-class:: classref-item-separator
  1181. ----
  1182. .. _shader_func_lessThanEqual:
  1183. .. rst-class:: classref-method
  1184. |vec_bool_type| **lessThanEqual**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_lessThanEqual>`
  1185. Performs a :ref:`component-wise<shading_componentwise>` less-than-or-equal comparison of two vectors.
  1186. :param x:
  1187. The first vector to compare.
  1188. :param y:
  1189. The second vector to compare.
  1190. :return:
  1191. A boolean vector in which each element ``i`` is computed as ``x[i] <= y[i]``.
  1192. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/lessThanEqual.xhtml
  1193. .. rst-class:: classref-item-separator
  1194. ----
  1195. .. _shader_func_greaterThanEqual:
  1196. .. rst-class:: classref-method
  1197. |vec_bool_type| **greaterThanEqual**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_greaterThanEqual>`
  1198. Performs a :ref:`component-wise<shading_componentwise>` greater-than-or-equal comparison of two vectors.
  1199. :param x:
  1200. The first vector to compare.
  1201. :param y:
  1202. The second vector to compare.
  1203. :return:
  1204. A boolean vector in which each element ``i`` is computed as ``x[i] >= y[i]``.
  1205. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/greaterThanEqual.xhtml
  1206. .. rst-class:: classref-item-separator
  1207. ----
  1208. .. _shader_func_equal:
  1209. .. rst-class:: classref-method
  1210. |vec_bool_type| **equal**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_equal>`
  1211. Performs a :ref:`component-wise<shading_componentwise>` equal-to comparison of two vectors.
  1212. :param x:
  1213. The first vector to compare.
  1214. :param y:
  1215. The second vector to compare.
  1216. :return:
  1217. A boolean vector in which each element ``i`` is computed as ``x[i] == y[i]``.
  1218. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/equal.xhtml
  1219. .. rst-class:: classref-item-separator
  1220. ----
  1221. .. _shader_func_notEqual:
  1222. .. rst-class:: classref-method
  1223. |vec_bool_type| **notEqual**\ (\ |vec_type| x, |vec_type| y) :ref:`🔗<shader_func_notEqual>`
  1224. Performs a :ref:`component-wise<shading_componentwise>` not-equal-to comparison of two vectors.
  1225. :param x:
  1226. The first vector for comparison.
  1227. :param y:
  1228. The second vector for comparison.
  1229. :return:
  1230. A boolean vector in which each element ``i`` is computed as ``x[i] != y[i]``.
  1231. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/notEqual.xhtml
  1232. .. rst-class:: classref-item-separator
  1233. ----
  1234. .. _shader_func_any:
  1235. .. rst-class:: classref-method
  1236. bool **any**\ (\ |vec_bool_type| x) :ref:`🔗<shader_func_any>`
  1237. Returns ``true`` if any element of a boolean vector is ``true``, ``false`` otherwise.
  1238. Functionally equivalent to:
  1239. ::
  1240. bool any(bvec x) { // bvec can be bvec2, bvec3 or bvec4
  1241. bool result = false;
  1242. int i;
  1243. for (i = 0; i < x.length(); ++i) {
  1244. result |= x[i];
  1245. }
  1246. return result;
  1247. }
  1248. :param x:
  1249. The vector to be tested for truth.
  1250. :return:
  1251. True if any element of x is true and false otherwise.
  1252. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/any.xhtml
  1253. .. rst-class:: classref-item-separator
  1254. ----
  1255. .. _shader_func_all:
  1256. .. rst-class:: classref-method
  1257. bool **all**\ (\ |vec_bool_type| x) :ref:`🔗<shader_func_all>`
  1258. Returns ``true`` if all elements of a boolean vector are ``true``, ``false`` otherwise.
  1259. Functionally equivalent to:
  1260. ::
  1261. bool all(bvec x) // bvec can be bvec2, bvec3 or bvec4
  1262. {
  1263. bool result = true;
  1264. int i;
  1265. for (i = 0; i < x.length(); ++i)
  1266. {
  1267. result &= x[i];
  1268. }
  1269. return result;
  1270. }
  1271. :param x:
  1272. The vector to be tested for truth.
  1273. :return:
  1274. ``true`` if all elements of ``x`` are ``true`` and ``false`` otherwise.
  1275. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/all.xhtml
  1276. .. rst-class:: classref-item-separator
  1277. ----
  1278. .. _shader_func_not:
  1279. .. rst-class:: classref-method
  1280. |vec_bool_type| **not**\ (\ |vec_bool_type| x) :ref:`🔗<shader_func_not>`
  1281. Logically invert a boolean vector.
  1282. :param x:
  1283. The vector to be inverted.
  1284. :return:
  1285. A new boolean vector for which each element i is computed as !x[i].
  1286. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/not.xhtml
  1287. .. rst-class:: classref-section-separator
  1288. ----
  1289. .. rst-class:: classref-reftable-group
  1290. Texture functions
  1291. -----------------
  1292. .. table::
  1293. :class: nowrap-col2
  1294. :widths: auto
  1295. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1296. | | ivec2 | | :ref:`textureSize<shader_func_textureSize>`\ (\ |gsampler2D| s, int lod) | Get the size of a texture. |
  1297. | | ivec2 | | :ref:`textureSize<shader_func_textureSize>`\ (\ samplerCube s, int lod) | |
  1298. | | ivec2 | | :ref:`textureSize<shader_func_textureSize>`\ (\ samplerCubeArray s, int lod) | |
  1299. | | ivec3 | | :ref:`textureSize<shader_func_textureSize>`\ (\ |gsampler2DArray| s, int lod) | |
  1300. | | ivec3 | | :ref:`textureSize<shader_func_textureSize>`\ (\ |gsampler3D| s, int lod) | |
  1301. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1302. | | vec2 | | :ref:`textureQueryLod<shader_func_textureQueryLod>`\ (\ |gsampler2D| s, vec2 p) | Compute the level-of-detail that would be used to sample from a |
  1303. | | vec3 | | :ref:`textureQueryLod<shader_func_textureQueryLod>`\ (\ |gsampler2DArray| s, vec2 p) | texture. |
  1304. | | vec2 | | :ref:`textureQueryLod<shader_func_textureQueryLod>`\ (\ |gsampler3D| s, vec3 p) | |
  1305. | | vec2 | | :ref:`textureQueryLod<shader_func_textureQueryLod>`\ (\ samplerCube s, vec3 p) | |
  1306. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1307. | | int | | :ref:`textureQueryLevels<shader_func_textureQueryLevels>`\ (\ |gsampler2D| s) | Get the number of accessible mipmap levels of a texture. |
  1308. | | int | | :ref:`textureQueryLevels<shader_func_textureQueryLevels>`\ (\ |gsampler2DArray| s) | |
  1309. | | int | | :ref:`textureQueryLevels<shader_func_textureQueryLevels>`\ (\ |gsampler3D| s) | |
  1310. | | int | | :ref:`textureQueryLevels<shader_func_textureQueryLevels>`\ (\ samplerCube s) | |
  1311. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1312. | | |gvec4_type| | | :ref:`texture<shader_func_texture>`\ (\ |gsampler2D| s, vec2 p [, float bias] ) | Performs a texture read. |
  1313. | | |gvec4_type| | | :ref:`texture<shader_func_texture>`\ (\ |gsampler2DArray| s, vec3 p [, float bias] ) | |
  1314. | | |gvec4_type| | | :ref:`texture<shader_func_texture>`\ (\ |gsampler3D| s, vec3 p [, float bias] ) | |
  1315. | | vec4 | | :ref:`texture<shader_func_texture>`\ (\ samplerCube s, vec3 p [, float bias] ) | |
  1316. | | vec4 | | :ref:`texture<shader_func_texture>`\ (\ samplerCubeArray s, vec4 p [, float bias] ) | |
  1317. | | vec4 | | :ref:`texture<shader_func_texture>`\ (\ samplerExternalOES s, vec2 p [, float bias] ) | |
  1318. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1319. | | |gvec4_type| | | :ref:`textureProj<shader_func_textureProj>`\ (\ |gsampler2D| s, vec3 p [, float bias] ) | Performs a texture read with projection. |
  1320. | | |gvec4_type| | | :ref:`textureProj<shader_func_textureProj>`\ (\ |gsampler2D| s, vec4 p [, float bias] ) | |
  1321. | | |gvec4_type| | | :ref:`textureProj<shader_func_textureProj>`\ (\ |gsampler3D| s, vec4 p [, float bias] ) | |
  1322. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1323. | | |gvec4_type| | | :ref:`textureLod<shader_func_textureLod>`\ (\ |gsampler2D| s, vec2 p, float lod) | Performs a texture read at custom mipmap. |
  1324. | | |gvec4_type| | | :ref:`textureLod<shader_func_textureLod>`\ (\ |gsampler2DArray| s, vec3 p, float lod) | |
  1325. | | |gvec4_type| | | :ref:`textureLod<shader_func_textureLod>`\ (\ |gsampler3D| s, vec3 p, float lod) | |
  1326. | | vec4 | | :ref:`textureLod<shader_func_textureLod>`\ (\ samplerCube s, vec3 p, float lod) | |
  1327. | | vec4 | | :ref:`textureLod<shader_func_textureLod>`\ (\ samplerCubeArray s, vec4 p, float lod) | |
  1328. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1329. | | |gvec4_type| | | :ref:`textureProjLod<shader_func_textureProjLod>`\ (\ |gsampler2D| s, vec3 p, float lod) | Performs a texture read with projection/LOD. |
  1330. | | |gvec4_type| | | :ref:`textureProjLod<shader_func_textureProjLod>`\ (\ |gsampler2D| s, vec4 p, float lod) | |
  1331. | | |gvec4_type| | | :ref:`textureProjLod<shader_func_textureProjLod>`\ (\ |gsampler3D| s, vec4 p, float lod) | |
  1332. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1333. | | |gvec4_type| | | :ref:`textureGrad<shader_func_textureGrad>`\ (\ |gsampler2D| s, vec2 p, vec2 dPdx, vec2 dPdy) | Performs a texture read with explicit gradients. |
  1334. | | |gvec4_type| | | :ref:`textureGrad<shader_func_textureGrad>`\ (\ |gsampler2DArray| s, vec3 p, vec2 dPdx, vec2 dPdy) | |
  1335. | | |gvec4_type| | | :ref:`textureGrad<shader_func_textureGrad>`\ (\ |gsampler3D| s, vec3 p, vec2 dPdx, vec2 dPdy) | |
  1336. | | vec4 | | :ref:`textureGrad<shader_func_textureGrad>`\ (\ samplerCube s, vec3 p, vec3 dPdx, vec3 dPdy) | |
  1337. | | vec4 | | :ref:`textureGrad<shader_func_textureGrad>`\ (\ samplerCubeArray s, vec3 p, vec3 dPdx, vec3 dPdy) | |
  1338. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1339. | | |gvec4_type| | | :ref:`textureProjGrad<shader_func_textureProjGrad>`\ (\ |gsampler2D| s, vec3 p, vec2 dPdx, vec2 dPdy) | Performs a texture read with projection/LOD and with explicit |
  1340. | | |gvec4_type| | | :ref:`textureProjGrad<shader_func_textureProjGrad>`\ (\ |gsampler2D| s, vec4 p, vec2 dPdx, vec2 dPdy) | |
  1341. | | |gvec4_type| | | :ref:`textureProjGrad<shader_func_textureProjGrad>`\ (\ |gsampler3D| s, vec4 p, vec3 dPdx, vec3 dPdy) | |
  1342. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1343. | | |gvec4_type| | | :ref:`texelFetch<shader_func_texelFetch>`\ (\ |gsampler2D| s, ivec2 p, int lod) | Fetches a single texel using integer coordinates. |
  1344. | | |gvec4_type| | | :ref:`texelFetch<shader_func_texelFetch>`\ (\ |gsampler2DArray| s, ivec3 p, int lod) | |
  1345. | | |gvec4_type| | | :ref:`texelFetch<shader_func_texelFetch>`\ (\ |gsampler3D| s, ivec3 p, int lod) | |
  1346. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1347. | | |gvec4_type| | | :ref:`textureGather<shader_func_textureGather>`\ (\ |gsampler2D| s, vec2 p [, int comps] ) | Gathers four texels from a texture. |
  1348. | | |gvec4_type| | | :ref:`textureGather<shader_func_textureGather>`\ (\ |gsampler2DArray| s, vec3 p [, int comps] ) | |
  1349. | | vec4 | | :ref:`textureGather<shader_func_textureGather>`\ (\ samplerCube s, vec3 p [, int comps] ) | |
  1350. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1351. | |vec_type| | :ref:`dFdx<shader_func_dFdx>`\ (\ |vec_type| p) | Derivative with respect to ``x`` window coordinate, |
  1352. | | | automatic granularity. |
  1353. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1354. | |vec_type| | :ref:`dFdxCoarse<shader_func_dFdxCoarse>`\ (\ |vec_type| p) | Derivative with respect to ``x`` window coordinate, |
  1355. | | | course granularity. |
  1356. | | | |
  1357. | | | Not available when using the Compatibility renderer. |
  1358. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1359. | |vec_type| | :ref:`dFdxFine<shader_func_dFdxFine>`\ (\ |vec_type| p) | Derivative with respect to ``x`` window coordinate, |
  1360. | | | fine granularity. |
  1361. | | | |
  1362. | | | Not available when using the Compatibility renderer. |
  1363. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1364. | |vec_type| | :ref:`dFdy<shader_func_dFdy>`\ (\ |vec_type| p) | Derivative with respect to ``y`` window coordinate, |
  1365. | | | automatic granularity. |
  1366. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1367. | |vec_type| | :ref:`dFdyCoarse<shader_func_dFdyCoarse>`\ (\ |vec_type| p) | Derivative with respect to ``y`` window coordinate, |
  1368. | | | course granularity. |
  1369. | | | |
  1370. | | | Not available when using the Compatibility renderer. |
  1371. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1372. | |vec_type| | :ref:`dFdyFine<shader_func_dFdyFine>`\ (\ |vec_type| p) | Derivative with respect to ``y`` window coordinate, |
  1373. | | | fine granularity. |
  1374. | | | |
  1375. | | | Not available when using the Compatibility renderer. |
  1376. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1377. | |vec_type| | :ref:`fwidth<shader_func_fwidth>`\ (\ |vec_type| p) | Sum of absolute derivative in ``x`` and ``y``. |
  1378. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1379. | |vec_type| | :ref:`fwidthCoarse<shader_func_fwidthCoarse>`\ (\ |vec_type| p) | Sum of absolute derivative in ``x`` and ``y``. |
  1380. | | | |
  1381. | | | Not available when using the Compatibility renderer. |
  1382. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1383. | |vec_type| | :ref:`fwidthFine<shader_func_fwidthFine>`\ (\ |vec_type| p) | Sum of absolute derivative in ``x`` and ``y``. |
  1384. | | | |
  1385. | | | Not available when using the Compatibility renderer. |
  1386. +------------------+---------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  1387. .. rst-class:: classref-descriptions-group
  1388. Texture function descriptions
  1389. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1390. .. _shader_func_textureSize:
  1391. .. rst-class:: classref-method
  1392. ivec2 **textureSize**\ (\ |gsampler2D| s, int lod) :ref:`🔗<shader_func_textureSize>`
  1393. .. rst-class:: classref-method
  1394. ivec2 **textureSize**\ (\ samplerCube s, int lod) :ref:`🔗<shader_func_textureSize>`
  1395. .. rst-class:: classref-method
  1396. ivec2 **textureSize**\ (\ samplerCubeArray s, int lod) :ref:`🔗<shader_func_textureSize>`
  1397. .. rst-class:: classref-method
  1398. ivec3 **textureSize**\ (\ |gsampler2DArray| s, int lod) :ref:`🔗<shader_func_textureSize>`
  1399. .. rst-class:: classref-method
  1400. ivec3 **textureSize**\ (\ |gsampler3D| s, int lod) :ref:`🔗<shader_func_textureSize>`
  1401. Retrieves the dimensions of a level of a texture.
  1402. Returns the dimensions of level ``lod`` (if present) of the texture bound to sampler.
  1403. The components in the return value are filled in, in order, with the width, height and depth
  1404. of the texture. For the array forms, the last component of the return value is
  1405. the number of layers in the texture array.
  1406. :param s:
  1407. The sampler to which the texture whose dimensions to retrieve is bound.
  1408. :param lod:
  1409. The level of the texture for which to retrieve the dimensions.
  1410. :return:
  1411. The dimensions of level ``lod`` (if present) of the texture bound to sampler.
  1412. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureSize.xhtml
  1413. .. rst-class:: classref-item-separator
  1414. ----
  1415. .. _shader_func_textureQueryLod:
  1416. .. rst-class:: classref-method
  1417. vec2 **textureQueryLod**\ (\ |gsampler2D| s, vec2 p) :ref:`🔗<shader_func_textureQueryLod>`
  1418. .. rst-class:: classref-method
  1419. vec2 **textureQueryLod**\ (\ |gsampler2DArray| s, vec2 p) :ref:`🔗<shader_func_textureQueryLod>`
  1420. .. rst-class:: classref-method
  1421. vec2 **textureQueryLod**\ (\ |gsampler3D| s, vec3 p) :ref:`🔗<shader_func_textureQueryLod>`
  1422. .. rst-class:: classref-method
  1423. vec2 **textureQueryLod**\ (\ samplerCube s, vec3 p) :ref:`🔗<shader_func_textureQueryLod>`
  1424. .. note:: Available only in the fragment shader.
  1425. Compute the level-of-detail that would be used to sample from a texture.
  1426. The mipmap array(s) that would be accessed is returned in the x component of
  1427. the return value. The computed level-of-detail relative to the base level is
  1428. returned in the y component of the return value.
  1429. If called on an incomplete texture, the result of the operation is undefined.
  1430. :param s:
  1431. The sampler to which the texture whose level-of-detail will be queried is bound.
  1432. :param p:
  1433. The texture coordinates at which the level-of-detail will be queried.
  1434. :return:
  1435. See description.
  1436. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureQueryLod.xhtml
  1437. .. rst-class:: classref-item-separator
  1438. ----
  1439. .. _shader_func_textureQueryLevels:
  1440. .. rst-class:: classref-method
  1441. int **textureQueryLevels**\ (\ |gsampler2D| s) :ref:`🔗<shader_func_textureQueryLevels>`
  1442. .. rst-class:: classref-method
  1443. int **textureQueryLevels**\ (\ |gsampler2DArray| s) :ref:`🔗<shader_func_textureQueryLevels>`
  1444. .. rst-class:: classref-method
  1445. int **textureQueryLevels**\ (\ |gsampler3D| s) :ref:`🔗<shader_func_textureQueryLevels>`
  1446. .. rst-class:: classref-method
  1447. int **textureQueryLevels**\ (\ samplerCube s) :ref:`🔗<shader_func_textureQueryLevels>`
  1448. Compute the number of accessible mipmap levels of a texture.
  1449. If called on an incomplete texture, or if no texture is associated with sampler, ``0`` is returned.
  1450. :param s:
  1451. The sampler to which the texture whose mipmap level count will be queried is bound.
  1452. :return:
  1453. The number of accessible mipmap levels in the texture, or ``0``.
  1454. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureQueryLevels.xhtml
  1455. .. rst-class:: classref-item-separator
  1456. ----
  1457. .. _shader_func_texture:
  1458. .. rst-class:: classref-method
  1459. |gvec4_type| **texture**\ (\ |gsampler2D| s, vec2 p [, float bias] ) :ref:`🔗<shader_func_texture>`
  1460. .. rst-class:: classref-method
  1461. |gvec4_type| **texture**\ (\ |gsampler2DArray| s, vec3 p [, float bias] ) :ref:`🔗<shader_func_texture>`
  1462. .. rst-class:: classref-method
  1463. |gvec4_type| **texture**\ (\ |gsampler3D| s, vec3 p [, float bias] ) :ref:`🔗<shader_func_texture>`
  1464. .. rst-class:: classref-method
  1465. vec4 **texture**\ (\ samplerCube s, vec3 p [, float bias] ) :ref:`🔗<shader_func_texture>`
  1466. .. rst-class:: classref-method
  1467. vec4 **texture**\ (\ samplerCubeArray s, vec4 p [, float bias] ) :ref:`🔗<shader_func_texture>`
  1468. .. rst-class:: classref-method
  1469. vec4 **texture**\ (\ samplerExternalOES s, vec2 p [, float bias] ) :ref:`🔗<shader_func_texture>`
  1470. Retrieves texels from a texture.
  1471. Samples texels from the texture bound to ``s`` at texture coordinate ``p``. An optional bias, specified in ``bias`` is
  1472. included in the level-of-detail computation that is used to choose mipmap(s) from which to sample.
  1473. For shadow forms, the last component of ``p`` is used as Dsub and the array layer is specified in the second to last
  1474. component of ``p``. (The second component of ``p`` is unused for 1D shadow lookups.)
  1475. For non-shadow variants, the array layer comes from the last component of P.
  1476. :param s:
  1477. The sampler to which the texture from which texels will be retrieved is bound.
  1478. :param p:
  1479. The texture coordinates at which texture will be sampled.
  1480. :param bias:
  1481. An optional bias to be applied during level-of-detail computation.
  1482. :return:
  1483. A texel.
  1484. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/texture.xhtml
  1485. .. rst-class:: classref-item-separator
  1486. ----
  1487. .. _shader_func_textureProj:
  1488. .. rst-class:: classref-method
  1489. |gvec4_type| **textureProj**\ (\ |gsampler2D| s, vec3 p [, float bias] ) :ref:`🔗<shader_func_textureProj>`
  1490. .. rst-class:: classref-method
  1491. |gvec4_type| **textureProj**\ (\ |gsampler2D| s, vec4 p [, float bias] ) :ref:`🔗<shader_func_textureProj>`
  1492. .. rst-class:: classref-method
  1493. |gvec4_type| **textureProj**\ (\ |gsampler3D| s, vec4 p [, float bias] ) :ref:`🔗<shader_func_textureProj>`
  1494. Perform a texture lookup with projection.
  1495. The texture coordinates consumed from ``p``, not including the last component of ``p``, are
  1496. divided by the last component of ``p``. The resulting 3rd component of ``p`` in the shadow
  1497. forms is used as Dref. After these values are computed, the texture lookup proceeds as in texture.
  1498. :param s:
  1499. The sampler to which the texture from which texels will be retrieved is bound.
  1500. :param p:
  1501. The texture coordinates at which texture will be sampled.
  1502. :param bias:
  1503. Optional bias to be applied during level-of-detail computation.
  1504. :return:
  1505. A texel.
  1506. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureProj.xhtml
  1507. .. rst-class:: classref-item-separator
  1508. ----
  1509. .. _shader_func_textureLod:
  1510. .. rst-class:: classref-method
  1511. |gvec4_type| **textureLod**\ (\ |gsampler2D| s, vec2 p, float lod) :ref:`🔗<shader_func_textureLod>`
  1512. .. rst-class:: classref-method
  1513. |gvec4_type| **textureLod**\ (\ |gsampler2DArray| s, vec3 p, float lod) :ref:`🔗<shader_func_textureLod>`
  1514. .. rst-class:: classref-method
  1515. |gvec4_type| **textureLod**\ (\ |gsampler3D| s, vec3 p, float lod) :ref:`🔗<shader_func_textureLod>`
  1516. .. rst-class:: classref-method
  1517. vec4 **textureLod**\ (\ samplerCube s, vec3 p, float lod) :ref:`🔗<shader_func_textureLod>`
  1518. .. rst-class:: classref-method
  1519. vec4 **textureLod**\ (\ samplerCubeArray s, vec4 p, float lod) :ref:`🔗<shader_func_textureLod>`
  1520. Performs a texture lookup at coordinate ``p`` from the texture bound to sampler with
  1521. an explicit level-of-detail as specified in ``lod``. ``lod`` specifies λbase and sets the
  1522. partial derivatives as follows:
  1523. ::
  1524. δu/δx=0, δv/δx=0, δw/δx=0
  1525. δu/δy=0, δv/δy=0, δw/δy=0
  1526. :param s:
  1527. The sampler to which the texture from which texels will be retrieved is bound.
  1528. :param p:
  1529. The texture coordinates at which texture will be sampled.
  1530. :param lod:
  1531. The explicit level-of-detail.
  1532. :return:
  1533. A texel.
  1534. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureLod.xhtml
  1535. .. rst-class:: classref-item-separator
  1536. ----
  1537. .. _shader_func_textureProjLod:
  1538. .. rst-class:: classref-method
  1539. |gvec4_type| **textureProjLod**\ (\ |gsampler2D| s, vec3 p, float lod) :ref:`🔗<shader_func_textureProjLod>`
  1540. .. rst-class:: classref-method
  1541. |gvec4_type| **textureProjLod**\ (\ |gsampler2D| s, vec4 p, float lod) :ref:`🔗<shader_func_textureProjLod>`
  1542. .. rst-class:: classref-method
  1543. |gvec4_type| **textureProjLod**\ (\ |gsampler3D| s, vec4 p, float lod) :ref:`🔗<shader_func_textureProjLod>`
  1544. Performs a texture lookup with projection from an explicitly specified level-of-detail.
  1545. The texture coordinates consumed from P, not including the last component of ``p``, are
  1546. divided by the last component of ``p``. The resulting 3rd component of ``p`` in the shadow
  1547. forms is used as Dref. After these values are computed, the texture lookup proceeds as in
  1548. `textureLod<shader_func_textureLod>`, with ``lod`` used to specify the level-of-detail from
  1549. which the texture will be sampled.
  1550. :param s:
  1551. The sampler to which the texture from which texels will be retrieved is bound.
  1552. :param p:
  1553. The texture coordinates at which texture will be sampled.
  1554. :param lod:
  1555. The explicit level-of-detail from which to fetch texels.
  1556. :return:
  1557. a texel
  1558. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureProjLod.xhtml
  1559. .. rst-class:: classref-item-separator
  1560. ----
  1561. .. _shader_func_textureGrad:
  1562. .. rst-class:: classref-method
  1563. |gvec4_type| **textureGrad**\ (\ |gsampler2D| s, vec2 p, vec2 dPdx, vec2 dPdy) :ref:`🔗<shader_func_textureGrad>`
  1564. .. rst-class:: classref-method
  1565. |gvec4_type| **textureGrad**\ (\ |gsampler2DArray| s, vec3 p, vec2 dPdx, vec2 dPdy) :ref:`🔗<shader_func_textureGrad>`
  1566. .. rst-class:: classref-method
  1567. |gvec4_type| **textureGrad**\ (\ |gsampler3D| s, vec3 p, vec2 dPdx, vec2 dPdy) :ref:`🔗<shader_func_textureGrad>`
  1568. .. rst-class:: classref-method
  1569. vec4 **textureGrad**\ (\ samplerCube s, vec3 p, vec3 dPdx, vec3 dPdy) :ref:`🔗<shader_func_textureGrad>`
  1570. .. rst-class:: classref-method
  1571. vec4 **textureGrad**\ (\ samplerCubeArray s, vec3 p, vec3 dPdx, vec3 dPdy) :ref:`🔗<shader_func_textureGrad>`
  1572. Performs a texture lookup at coordinate ``p`` from the texture bound to sampler with explicit texture coordinate gradiends as specified in ``dPdx`` and ``dPdy``. Set:
  1573. - ``δs/δx=δp/δx`` for a 1D texture, ``δp.s/δx`` otherwise
  1574. - ``δs/δy=δp/δy`` for a 1D texture, ``δp.s/δy`` otherwise
  1575. - ``δt/δx=0.0`` for a 1D texture, ``δp.t/δx`` otherwise
  1576. - ``δt/δy=0.0`` for a 1D texture, ``δp.t/δy`` otherwise
  1577. - ``δr/δx=0.0`` for a 1D or 2D texture, ``δp.p/δx`` otherwise
  1578. - ``δr/δy=0.0`` for a 1D or 2D texture, ``δp.p/δy`` otherwise
  1579. For the cube version, the partial derivatives of ``p`` are assumed to be in the coordinate system used before texture coordinates are projected onto the appropriate cube face.
  1580. :param s:
  1581. The sampler to which the texture from which texels will be retrieved is bound.
  1582. :param p:
  1583. The texture coordinates at which texture will be sampled.
  1584. :param dPdx:
  1585. The partial derivative of P with respect to window x.
  1586. :param dPdy:
  1587. The partial derivative of P with respect to window y.
  1588. :return:
  1589. A texel.
  1590. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureGrad.xhtml
  1591. .. rst-class:: classref-item-separator
  1592. ----
  1593. .. _shader_func_textureProjGrad:
  1594. .. rst-class:: classref-method
  1595. |gvec4_type| **textureProjGrad**\ (\ |gsampler2D| s, vec3 p, vec2 dPdx, vec2 dPdy) :ref:`🔗<shader_func_textureProjGrad>`
  1596. .. rst-class:: classref-method
  1597. |gvec4_type| **textureProjGrad**\ (\ |gsampler2D| s, vec4 p, vec2 dPdx, vec2 dPdy) :ref:`🔗<shader_func_textureProjGrad>`
  1598. .. rst-class:: classref-method
  1599. |gvec4_type| **textureProjGrad**\ (\ |gsampler3D| s, vec4 p, vec3 dPdx, vec3 dPdy) :ref:`🔗<shader_func_textureProjGrad>`
  1600. Perform a texture lookup with projection and explicit gradients.
  1601. The texture coordinates consumed from ``p``, not including the last component of ``p``, are divided by the last component of ``p``.
  1602. After these values are computed, the texture lookup proceeds as in `textureGrad<shader_func_textureGrad>`, passing ``dPdx`` and ``dPdy`` as gradients.
  1603. :param s:
  1604. The sampler to which the texture from which texels will be retrieved is bound.
  1605. :param p:
  1606. The texture coordinates at which texture will be sampled.
  1607. :param dPdx:
  1608. The partial derivative of ``p`` with respect to window x.
  1609. :param dPdy:
  1610. The partial derivative of ``p`` with respect to window y.
  1611. :return:
  1612. A texel.
  1613. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureProjGrad.xhtml
  1614. .. rst-class:: classref-item-separator
  1615. ----
  1616. .. _shader_func_texelFetch:
  1617. .. rst-class:: classref-method
  1618. |gvec4_type| **texelFetch**\ (\ |gsampler2D| s, ivec2 p, int lod) :ref:`🔗<shader_func_texelFetch>`
  1619. .. rst-class:: classref-method
  1620. |gvec4_type| **texelFetch**\ (\ |gsampler2DArray| s, ivec3 p, int lod) :ref:`🔗<shader_func_texelFetch>`
  1621. .. rst-class:: classref-method
  1622. |gvec4_type| **texelFetch**\ (\ |gsampler3D| s, ivec3 p, int lod) :ref:`🔗<shader_func_texelFetch>`
  1623. Performs a lookup of a single texel from texture coordinate ``p`` in the texture bound to sampler.
  1624. :param s:
  1625. The sampler to which the texture from which texels will be retrieved is bound.
  1626. :param p:
  1627. The texture coordinates at which texture will be sampled.
  1628. :param lod:
  1629. Specifies the level-of-detail within the texture from which the texel will be fetched.
  1630. :return:
  1631. A texel.
  1632. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/texelFetch.xhtml
  1633. .. rst-class:: classref-item-separator
  1634. ----
  1635. .. _shader_func_textureGather:
  1636. .. rst-class:: classref-method
  1637. |gvec4_type| **textureGather**\ (\ |gsampler2D| s, vec2 p [, int comps] ) :ref:`🔗<shader_func_textureGather>`
  1638. .. rst-class:: classref-method
  1639. |gvec4_type| **textureGather**\ (\ |gsampler2DArray| s, vec3 p [, int comps] ) :ref:`🔗<shader_func_textureGather>`
  1640. .. rst-class:: classref-method
  1641. vec4 **textureGather**\ (\ samplerCube s, vec3 p [, int comps] ) :ref:`🔗<shader_func_textureGather>`
  1642. Gathers four texels from a texture.
  1643. Returns the value:
  1644. ::
  1645. vec4(Sample_i0_j1(p, base).comps,
  1646. Sample_i1_j1(p, base).comps,
  1647. Sample_i1_j0(p, base).comps,
  1648. Sample_i0_j0(p, base).comps);
  1649. :param s:
  1650. The sampler to which the texture from which texels will be retrieved is bound.
  1651. :param p:
  1652. The texture coordinates at which texture will be sampled.
  1653. :param comps:
  1654. *optional* the component of the source texture (0 -> x, 1 -> y, 2 -> z, 3 -> w) that will be used to generate the resulting vector. Zero if not specified.
  1655. :return:
  1656. The gathered texel.
  1657. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureGather.xhtml
  1658. .. rst-class:: classref-item-separator
  1659. ----
  1660. .. _shader_func_dFdx:
  1661. .. rst-class:: classref-method
  1662. |vec_type| **dFdx**\ (\ |vec_type| p) :ref:`🔗<shader_func_dFdx>`
  1663. .. note:: Available only in the fragment shader.
  1664. Returns the partial derivative of ``p`` with respect to the window x coordinate using local differencing.
  1665. Returns either :ref:`dFdxCoarse<shader_func_dFdxCoarse>` or :ref:`dFdxFine<shader_func_dfdxFine>`.
  1666. The implementation may choose which calculation to perform based upon factors
  1667. such as performance or the value of the API ``GL_FRAGMENT_SHADER_DERIVATIVE_HINT`` hint.
  1668. .. warning::
  1669. Expressions that imply higher order derivatives such as ``dFdx(dFdx(n))``
  1670. have undefined results, as do mixed-order derivatives such as ``dFdx(dFdy(n))``.
  1671. :param p:
  1672. The expression of which to take the partial derivative.
  1673. .. note:: It is assumed that the expression ``p`` is continuous and therefore expressions evaluated via non-uniform control flow may be undefined.
  1674. :return:
  1675. The partial derivative of ``p``.
  1676. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/dFdx.xhtml
  1677. .. rst-class:: classref-item-separator
  1678. ----
  1679. .. _shader_func_dFdxCoarse:
  1680. .. rst-class:: classref-method
  1681. |vec_type| **dFdxCoarse**\ (\ |vec_type| p) :ref:`🔗<shader_func_dFdxCoarse>`
  1682. .. note::
  1683. Available only in the fragment shader.
  1684. Not available when using the Compatibility renderer.
  1685. Returns the partial derivative of ``p`` with respect to the window x coordinate.
  1686. Calculates derivatives using local differencing based on the value of ``p``
  1687. for the current fragment's neighbors, and will possibly, but not necessarily,
  1688. include the value for the current fragment. That is, over a given area, the
  1689. implementation can compute derivatives in fewer unique locations than would
  1690. be allowed for the corresponding :ref:`dFdxFine<shader_func_dFdxFine>` function.
  1691. .. warning::
  1692. Expressions that imply higher order derivatives such as ``dFdx(dFdx(n))``
  1693. have undefined results, as do mixed-order derivatives such as ``dFdx(dFdy(n))``.
  1694. :param p:
  1695. The expression of which to take the partial derivative.
  1696. .. note:: It is assumed that the expression ``p`` is continuous and therefore
  1697. expressions evaluated via non-uniform control flow may be undefined.
  1698. :return:
  1699. The partial derivative of ``p``.
  1700. https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
  1701. .. rst-class:: classref-item-separator
  1702. ----
  1703. .. _shader_func_dFdxFine:
  1704. .. rst-class:: classref-method
  1705. |vec_type| **dFdxFine**\ (\ |vec_type| p) :ref:`🔗<shader_func_dFdxFine>`
  1706. .. note::
  1707. Available only in the fragment shader.
  1708. Not available when using the Compatibility renderer.
  1709. Returns the partial derivative of ``p`` with respect to the window x coordinate.
  1710. Calculates derivatives using local differencing based on the value of ``p`` for the current fragment and its immediate neighbor(s).
  1711. .. warning::
  1712. Expressions that imply higher order derivatives such as ``dFdx(dFdx(n))``
  1713. have undefined results, as do mixed-order derivatives such as ``dFdx(dFdy(n))``.
  1714. :param p:
  1715. The expression of which to take the partial derivative.
  1716. .. note:: It is assumed that the expression ``p`` is continuous and therefore expressions evaluated via non-uniform control flow may be undefined.
  1717. :return:
  1718. The partial derivative of ``p``.
  1719. https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
  1720. .. rst-class:: classref-item-separator
  1721. ----
  1722. .. _shader_func_dFdy:
  1723. .. rst-class:: classref-method
  1724. |vec_type| **dFdy**\ (\ |vec_type| p) :ref:`🔗<shader_func_dFdy>`
  1725. .. note:: Available only in the fragment shader.
  1726. Returns the partial derivative of ``p`` with respect to the window y coordinate using local differencing.
  1727. Returns either :ref:`dFdyCoarse<shader_func_dFdyCoarse>` or :ref:`dFdyFine<shader_func_dfdyFine>`.
  1728. The implementation may choose which calculation to perform based upon factors
  1729. such as performance or the value of the API ``GL_FRAGMENT_SHADER_DERIVATIVE_HINT`` hint.
  1730. .. warning::
  1731. Expressions that imply higher order derivatives such as ``dFdx(dFdx(n))``
  1732. have undefined results, as do mixed-order derivatives such as ``dFdx(dFdy(n))``.
  1733. :param p:
  1734. The expression of which to take the partial derivative.
  1735. .. note:: It is assumed that the expression ``p`` is continuous and therefore expressions evaluated via non-uniform control flow may be undefined.
  1736. :return:
  1737. The partial derivative of ``p``.
  1738. https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
  1739. .. rst-class:: classref-item-separator
  1740. ----
  1741. .. _shader_func_dFdyCoarse:
  1742. .. rst-class:: classref-method
  1743. |vec_type| **dFdyCoarse**\ (\ |vec_type| p) :ref:`🔗<shader_func_dFdyCoarse>`
  1744. .. note::
  1745. Available only in the fragment shader.
  1746. Not available when using the Compatibility renderer.
  1747. Returns the partial derivative of ``p`` with respect to the window y coordinate.
  1748. Calculates derivatives using local differencing based on the value of ``p`` for the current fragment's neighbors, and will possibly,
  1749. but not necessarily, include the value for the current fragment. That is, over a given area, the implementation can compute derivatives in fewer unique locations than
  1750. would be allowed for the corresponding dFdyFine and dFdyFine functions.
  1751. .. warning:: Expressions that imply higher order derivatives such as ``dFdx(dFdx(n))`` have undefined results, as do mixed-order derivatives such as ``dFdx(dFdy(n))``.
  1752. :param p:
  1753. The expression of which to take the partial derivative.
  1754. .. note:: It is assumed that the expression ``p`` is continuous and therefore expressions evaluated via non-uniform control flow may be undefined.
  1755. :return:
  1756. The partial derivative of ``p``.
  1757. https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
  1758. .. rst-class:: classref-item-separator
  1759. ----
  1760. .. _shader_func_dFdyFine:
  1761. .. rst-class:: classref-method
  1762. |vec_type| **dFdyFine**\ (\ |vec_type| p) :ref:`🔗<shader_func_dFdyFine>`
  1763. .. note::
  1764. Available only in the fragment shader.
  1765. Not available when using the Compatibility renderer.
  1766. Returns the partial derivative of ``p`` with respect to the window y coordinate.
  1767. Calculates derivatives using local differencing based on the value of ``p`` for the current fragment and its immediate neighbor(s).
  1768. .. warning:: Expressions that imply higher order derivatives such as ``dFdx(dFdx(n))`` have undefined results, as do mixed-order derivatives such as ``dFdx(dFdy(n))``.
  1769. :param p:
  1770. The expression of which to take the partial derivative.
  1771. .. note:: It is assumed that the expression ``p`` is continuous and therefore expressions evaluated via non-uniform control flow may be undefined.
  1772. :return:
  1773. The partial derivative of ``p``.
  1774. https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
  1775. .. rst-class:: classref-item-separator
  1776. ----
  1777. .. _shader_func_fwidth:
  1778. .. rst-class:: classref-method
  1779. |vec_type| **fwidth**\ (\ |vec_type| p) :ref:`🔗<shader_func_fwidth>`
  1780. Returns the sum of the absolute value of derivatives in x and y.
  1781. Uses local differencing for the input argument ``p``.
  1782. Equivalent to ``abs(dFdx(p)) + abs(dFdy(p))``.
  1783. :param p:
  1784. The expression of which to take the partial derivative.
  1785. :return:
  1786. The partial derivative.
  1787. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fwidth.xhtml
  1788. .. rst-class:: classref-item-separator
  1789. ----
  1790. .. _shader_func_fwidthCoarse:
  1791. .. rst-class:: classref-method
  1792. |vec_type| **fwidthCoarse**\ (\ |vec_type| p) :ref:`🔗<shader_func_fwidthCoarse>`
  1793. .. note::
  1794. Available only in the fragment shader.
  1795. Not available when using the Compatibility renderer.
  1796. Returns the sum of the absolute value of derivatives in x and y.
  1797. Uses local differencing for the input argument p.
  1798. Equivalent to ``abs(dFdxCoarse(p)) + abs(dFdyCoarse(p))``.
  1799. :param p:
  1800. The expression of which to take the partial derivative.
  1801. :return:
  1802. The partial derivative.
  1803. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fwidth.xhtml
  1804. .. rst-class:: classref-item-separator
  1805. ----
  1806. .. _shader_func_fwidthFine:
  1807. .. rst-class:: classref-method
  1808. |vec_type| **fwidthFine**\ (\ |vec_type| p) :ref:`🔗<shader_func_fwidthFine>`
  1809. .. note::
  1810. Available only in the fragment shader.
  1811. Not available when using the Compatibility renderer.
  1812. Returns the sum of the absolute value of derivatives in x and y.
  1813. Uses local differencing for the input argument p.
  1814. Equivalent to ``abs(dFdxFine(p)) + abs(dFdyFine(p))``.
  1815. :param p:
  1816. The expression of which to take the partial derivative.
  1817. :return:
  1818. The partial derivative.
  1819. https://registry.khronos.org/OpenGL-Refpages/gl4/html/fwidth.xhtml
  1820. .. rst-class:: classref-section-separator
  1821. ----
  1822. .. rst-class:: classref-reftable-group
  1823. Packing and unpacking functions
  1824. -------------------------------
  1825. These functions convert floating-point numbers into various sized integers and
  1826. then pack those integers into a single 32bit unsigned integer. The 'unpack'
  1827. functions perform the opposite operation, returning the original
  1828. floating-point numbers.
  1829. .. table::
  1830. :class: nowrap-col2
  1831. :widths: auto
  1832. +------------+------------------------------------------------------------------------+--------------------------------------------------------------+
  1833. | | uint | | :ref:`packHalf2x16<shader_func_packHalf2x16>`\ (\ vec2 v) | Convert two 32-bit floats to 16 bit floats and pack them. |
  1834. | | vec2 | | :ref:`unpackHalf2x16<shader_func_unpackHalf2x16>`\ (\ uint v) | |
  1835. +------------+------------------------------------------------------------------------+--------------------------------------------------------------+
  1836. | | uint | | :ref:`packUnorm2x16<shader_func_packUnorm2x16>`\ (\ vec2 v) | Convert two normalized (range 0..1) 32-bit floats |
  1837. | | vec2 | | :ref:`unpackUnorm2x16<shader_func_unpackUnorm2x16>`\ (\ uint v) | to 16-bit floats and pack them. |
  1838. +------------+------------------------------------------------------------------------+--------------------------------------------------------------+
  1839. | | uint | | :ref:`packSnorm2x16<shader_func_packSnorm2x16>`\ (\ vec2 v) | Convert two signed normalized (range -1..1) 32-bit floats |
  1840. | | vec2 | | :ref:`unpackSnorm2x16<shader_func_unpackSnorm2x16>`\ (\ uint v) | to 16-bit floats and pack them. |
  1841. +------------+------------------------------------------------------------------------+--------------------------------------------------------------+
  1842. | | uint | | :ref:`packUnorm4x8<shader_func_packUnorm4x8>`\ (\ vec4 v) | Convert four normalized (range 0..1) 32-bit floats |
  1843. | | vec4 | | :ref:`unpackUnorm4x8<shader_func_unpackUnorm4x8>`\ (\ uint v) | into 8-bit floats and pack them. |
  1844. +------------+------------------------------------------------------------------------+--------------------------------------------------------------+
  1845. | | uint | | :ref:`packSnorm4x8<shader_func_packSnorm4x8>`\ (\ vec4 v) | Convert four signed normalized (range -1..1) 32-bit floats |
  1846. | | vec4 | | :ref:`unpackSnorm4x8<shader_func_unpackSnorm4x8>`\ (\ uint v) | into 8-bit floats and pack them. |
  1847. +------------+------------------------------------------------------------------------+--------------------------------------------------------------+
  1848. .. rst-class:: classref-descriptions-group
  1849. Packing and unpacking function descriptions
  1850. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1851. .. _shader_func_packHalf2x16:
  1852. .. rst-class:: classref-method
  1853. uint **packHalf2x16**\ (\ vec2 v) :ref:`🔗<shader_func_packHalf2x16>`
  1854. Converts two 32-bit floating-point quantities to 16-bit floating-point
  1855. quantities and packs them into a single 32-bit integer.
  1856. Returns an unsigned integer obtained by converting the components of a two-component floating-point vector to
  1857. the 16-bit floating-point representation found in the OpenGL Specification, and then packing these two
  1858. 16-bit integers into a 32-bit unsigned integer. The first vector component specifies the 16 least-significant
  1859. bits of the result; the second component specifies the 16 most-significant bits.
  1860. :param v:
  1861. A vector of two 32-bit floating-point values that are to be converted to 16-bit representation and packed into the result.
  1862. :return:
  1863. The packed value.
  1864. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packHalf2x16.xhtml
  1865. .. rst-class:: classref-item-separator
  1866. ----
  1867. .. _shader_func_unpackHalf2x16:
  1868. .. rst-class:: classref-method
  1869. vec2 **unpackHalf2x16**\ (\ uint v) :ref:`🔗<shader_func_unpackHalf2x16>`
  1870. Inverse of :ref:`packHalf2x16<shader_func_packHalf2x16>`.
  1871. Unpacks a 32-bit integer into two 16-bit floating-point values, converts them to 32-bit floating-point values, and puts them into a vector.
  1872. The first component of the vector is obtained from the 16 least-significant bits of ``v``; the second component is obtained from the
  1873. 16 most-significant bits of ``v``.
  1874. :param v:
  1875. A single 32-bit unsigned integer containing 2 packed 16-bit floating-point values.
  1876. :return:
  1877. Two unpacked floating-point values.
  1878. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackHalf2x16.xhtml
  1879. .. rst-class:: classref-item-separator
  1880. ----
  1881. .. _shader_func_packUnorm2x16:
  1882. .. rst-class:: classref-method
  1883. uint **packUnorm2x16**\ (\ vec2 v) :ref:`🔗<shader_func_packUnorm2x16>`
  1884. Pack floating-point values into an unsigned integer.
  1885. Converts each component of the normalized floating-point value v into 16-bit integer values and then packs the results into a 32-bit unsigned integer.
  1886. The conversion for component c of ``v`` to fixed-point is performed as follows:
  1887. ::
  1888. round(clamp(c, 0.0, 1.0) * 65535.0)
  1889. The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits.
  1890. :param v:
  1891. A vector of values to be packed into an unsigned integer.
  1892. :return:
  1893. Unsigned 32 bit integer containing the packed encoding of the vector.
  1894. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
  1895. .. rst-class:: classref-item-separator
  1896. ----
  1897. .. _shader_func_unpackUnorm2x16:
  1898. .. rst-class:: classref-method
  1899. vec2 **unpackUnorm2x16**\ (\ uint v) :ref:`🔗<shader_func_unpackUnorm2x16>`
  1900. Unpack floating-point values from an unsigned integer.
  1901. Unpack single 32-bit unsigned integers into a pair of 16-bit unsigned integers.
  1902. Then, each component is converted to a normalized floating-point value to generate the returned two-component vector.
  1903. The conversion for unpacked fixed point value f to floating-point is performed as follows:
  1904. f / 65535.0
  1905. The first component of the returned vector will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits.
  1906. :param v:
  1907. An unsigned integer containing packed floating-point values.
  1908. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
  1909. .. rst-class:: classref-item-separator
  1910. ----
  1911. .. _shader_func_packSnorm2x16:
  1912. .. rst-class:: classref-method
  1913. uint **packSnorm2x16**\ (\ vec2 v) :ref:`🔗<shader_func_packSnorm2x16>`
  1914. Packs floating-point values into an unsigned integer.
  1915. Convert each component of the normalized floating-point value ``v`` into 16-bit integer values and then packs the results into a 32-bit unsigned integer.
  1916. The conversion for component c of ``v`` to fixed-point is performed as follows:
  1917. ::
  1918. round(clamp(c, -1.0, 1.0) * 32767.0)
  1919. The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits.
  1920. :param v:
  1921. A vector of values to be packed into an unsigned integer.
  1922. :return:
  1923. Unsigned 32 bit integer containing the packed encoding of the vector.
  1924. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
  1925. .. rst-class:: classref-item-separator
  1926. ----
  1927. .. _shader_func_unpackSnorm2x16:
  1928. .. rst-class:: classref-method
  1929. vec2 **unpackSnorm2x16**\ (\ uint v) :ref:`🔗<shader_func_unpackSnorm2x16>`
  1930. Unpacks floating-point values from an unsigned integer.
  1931. Unpacks single 32-bit unsigned integers into a pair of 16-bit signed integers.
  1932. Then, each component is converted to a normalized floating-point value to generate the returned two-component vector.
  1933. The conversion for unpacked fixed point value f to floating-point is performed as follows:
  1934. clamp(f / 32727.0, -1.0, 1.0)
  1935. The first component of the returned vector will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits.
  1936. :param v:
  1937. An unsigned integer containing packed floating-point values.
  1938. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
  1939. .. rst-class:: classref-item-separator
  1940. ----
  1941. .. _shader_func_packUnorm4x8:
  1942. .. rst-class:: classref-method
  1943. uint **packUnorm4x8**\ (\ vec4 v) :ref:`🔗<shader_func_packUnorm4x8>`
  1944. Packs floating-point values into an unsigned integer.
  1945. Converts each component of the normalized floating-point value ``v`` into 16-bit integer values and then packs the results into a 32-bit unsigned integer.
  1946. The conversion for component c of ``v`` to fixed-point is performed as follows:
  1947. ::
  1948. round(clamp(c, 0.0, 1.0) * 255.0)
  1949. The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits.
  1950. :param v:
  1951. A vector of values to be packed into an unsigned integer.
  1952. :return:
  1953. Unsigned 32 bit integer containing the packed encoding of the vector.
  1954. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
  1955. .. rst-class:: classref-item-separator
  1956. ----
  1957. .. _shader_func_unpackUnorm4x8:
  1958. .. rst-class:: classref-method
  1959. vec4 **unpackUnorm4x8**\ (\ uint v) :ref:`🔗<shader_func_unpackUnorm4x8>`
  1960. Unpacks floating-point values from an unsigned integer.
  1961. Unpacks single 32-bit unsigned integers into four 8-bit unsigned integers.
  1962. Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
  1963. The conversion for unpacked fixed point value f to floating-point is performed as follows:
  1964. f / 255.0
  1965. The first component of the returned vector will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits.
  1966. :param v:
  1967. An unsigned integer containing packed floating-point values.
  1968. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
  1969. .. rst-class:: classref-item-separator
  1970. ----
  1971. .. _shader_func_packSnorm4x8:
  1972. .. rst-class:: classref-method
  1973. uint **packSnorm4x8**\ (\ vec4 v) :ref:`🔗<shader_func_packSnorm4x8>`
  1974. Packs floating-point values into an unsigned integer.
  1975. Convert each component of the normalized floating-point value ``v`` into 16-bit integer values and then packs the results into a 32-bit unsigned integer.
  1976. The conversion for component c of ``v`` to fixed-point is performed as follows:
  1977. ::
  1978. round(clamp(c, -1.0, 1.0) * 127.0)
  1979. The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits.
  1980. :param v:
  1981. A vector of values to be packed into an unsigned integer.
  1982. :return:
  1983. Unsigned 32 bit integer containing the packed encoding of the vector.
  1984. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
  1985. .. rst-class:: classref-item-separator
  1986. ----
  1987. .. _shader_func_unpackSnorm4x8:
  1988. .. rst-class:: classref-method
  1989. vec4 **unpackSnorm4x8**\ (\ uint v) :ref:`🔗<shader_func_unpackSnorm4x8>`
  1990. Unpack floating-point values from an unsigned integer.
  1991. Unpack single 32-bit unsigned integers into four 8-bit signed integers.
  1992. Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
  1993. The conversion for unpacked fixed point value f to floating-point is performed as follows:
  1994. clamp(f / 127.0, -1.0, 1.0)
  1995. The first component of the returned vector will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits.
  1996. :param v:
  1997. An unsigned integer containing packed floating-point values.
  1998. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
  1999. .. rst-class:: classref-section-separator
  2000. ----
  2001. .. rst-class:: classref-reftable-group
  2002. Bitwise functions
  2003. -------------------
  2004. .. table::
  2005. :class: nowrap-col2
  2006. :widths: auto
  2007. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2008. | | |vec_int_type| | | :ref:`bitfieldExtract<shader_func_bitfieldExtract>`\ (\ |vec_int_type| value, int offset, int bits) | Extracts a range of bits from an integer. |
  2009. | | |vec_uint_type| | | :ref:`bitfieldExtract<shader_func_bitfieldExtract>`\ (\ |vec_uint_type| value, int offset, int bits) | |
  2010. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2011. | | |vec_int_type| | | :ref:`bitfieldInsert<shader_func_bitfieldInsert>`\ (\ |vec_int_type| base, |vec_int_type| insert, int offset, int bits) | Insert a range of bits into an integer. |
  2012. | | |vec_uint_type| | | :ref:`bitfieldInsert<shader_func_bitfieldInsert>`\ (\ |vec_uint_type| base, |vec_uint_type| insert, int offset, int bits) | |
  2013. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2014. | | |vec_int_type| | | :ref:`bitfieldReverse<shader_func_bitfieldReverse>`\ (\ |vec_int_type| value) | Reverse the order of bits in an integer. |
  2015. | | |vec_uint_type| | | :ref:`bitfieldReverse<shader_func_bitfieldReverse>`\ (\ |vec_uint_type| value) | |
  2016. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2017. | | |vec_int_type| | | :ref:`bitCount<shader_func_bitCount>`\ (\ |vec_int_type| value) | Counts the number of 1 bits in an integer. |
  2018. | | |vec_uint_type| | | :ref:`bitCount<shader_func_bitCount>`\ (\ |vec_uint_type| value) | |
  2019. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2020. | | |vec_int_type| | | :ref:`findLSB<shader_func_findLSB>`\ (\ |vec_int_type| value) | Find the index of the least significant bit set to 1 in an integer. |
  2021. | | |vec_uint_type| | | :ref:`findLSB<shader_func_findLSB>`\ (\ |vec_uint_type| value) | |
  2022. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2023. | | |vec_int_type| | | :ref:`findMSB<shader_func_findMSB>`\ (\ |vec_int_type| value) | Find the index of the most significant bit set to 1 in an integer. |
  2024. | | |vec_uint_type| | | :ref:`findMSB<shader_func_findMSB>`\ (\ |vec_uint_type| value) | |
  2025. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2026. | | |void| | | :ref:`imulExtended<shader_func_imulExtended>`\ (\ |vec_int_type| x, |vec_int_type| y, out |vec_int_type| msb, out |vec_int_type| lsb) | Multiplies two 32-bit numbers and produce a 64-bit result. |
  2027. | | |void| | | :ref:`umulExtended<shader_func_umulExtended>`\ (\ |vec_uint_type| x, |vec_uint_type| y, out |vec_uint_type| msb, out |vec_uint_type| lsb) | |
  2028. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2029. | |vec_uint_type| | :ref:`uaddCarry<shader_func_uaddCarry>`\ (\ |vec_uint_type| x, |vec_uint_type| y, out |vec_uint_type| carry) | Adds two unsigned integers and generates carry. |
  2030. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2031. | |vec_uint_type| | :ref:`usubBorrow<shader_func_usubBorrow>`\ (\ |vec_uint_type| x, |vec_uint_type| y, out |vec_uint_type| borrow) | Subtracts two unsigned integers and generates borrow. |
  2032. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2033. | |vec_type| | :ref:`ldexp<shader_func_ldexp>`\ (\ |vec_type| x, out |vec_int_type| exp) | Assemble a floating-point number from a value and exponent. |
  2034. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2035. | |vec_type| | :ref:`frexp<shader_func_frexp>`\ (\ |vec_type| x, out |vec_int_type| exp) | Splits a floating-point number (``x``) into significand integral |
  2036. | | | components |
  2037. +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+
  2038. .. rst-class:: classref-descriptions-group
  2039. Bitwise function descriptions
  2040. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2041. .. _shader_func_bitfieldExtract:
  2042. .. rst-class:: classref-method
  2043. |vec_int_type| **bitfieldExtract**\ (\ |vec_int_type| value, int offset, int bits) :ref:`🔗<shader_func_bitfieldExtract>`
  2044. Extracts a subset of the bits of ``value`` and returns it in the least significant bits of the result.
  2045. The range of bits extracted is ``[offset, offset + bits - 1]``.
  2046. The most significant bits of the result will be set to zero.
  2047. .. note::
  2048. If bits is zero, the result will be zero.
  2049. .. warning::
  2050. The result will be undefined if:
  2051. - offset or bits is negative.
  2052. - if the sum of offset and bits is greater than the number of bits used to store the operand.
  2053. :param value:
  2054. The integer from which to extract bits.
  2055. :param offset:
  2056. The index of the first bit to extract.
  2057. :param bits:
  2058. The number of bits to extract.
  2059. :return:
  2060. Integer with the requested bits.
  2061. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldExtract.xhtml
  2062. .. rst-class:: classref-item-separator
  2063. ----
  2064. .. rst-class:: classref-method
  2065. |vec_uint_type| **bitfieldExtract**\ (\ |vec_uint_type| value, int offset, int bits) :ref:`🔗<shader_func_bitfieldExtract>`
  2066. |componentwise|
  2067. Extracts a subset of the bits of ``value`` and returns it in the least significant bits of the result.
  2068. The range of bits extracted is ``[offset, offset + bits - 1]``.
  2069. The most significant bits will be set to the value of ``offset + base - 1`` (i.e., it is sign extended to the width of the return type).
  2070. .. note::
  2071. If bits is zero, the result will be zero.
  2072. .. warning::
  2073. The result will be undefined if:
  2074. - offset or bits is negative.
  2075. - if the sum of offset and bits is greater than the number of bits used to store the operand.
  2076. :param value:
  2077. The integer from which to extract bits.
  2078. :param offset:
  2079. The index of the first bit to extract.
  2080. :param bits:
  2081. The number of bits to extract.
  2082. :return:
  2083. Integer with the requested bits.
  2084. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldExtract.xhtml
  2085. .. rst-class:: classref-item-separator
  2086. ----
  2087. .. _shader_func_bitfieldInsert:
  2088. .. rst-class:: classref-method
  2089. |vec_uint_type| **bitfieldExtract**\ (\ |vec_uint_type| value, int offset, int bits) :ref:`🔗<shader_func_bitfieldInsert>`
  2090. .. rst-class:: classref-method
  2091. |vec_uint_type| **bitfieldInsert**\ (\ |vec_uint_type| base, |vec_uint_type| insert, int offset, int bits) :ref:`🔗<shader_func_bitfieldInsert>`
  2092. |componentwise|
  2093. Inserts the ``bits`` least significant bits of ``insert`` into ``base`` at offset ``offset``.
  2094. The returned value will have bits [offset, offset + bits + 1] taken from [0, bits - 1] of ``insert`` and
  2095. all other bits taken directly from the corresponding bits of base.
  2096. .. note:: If bits is zero, the result will be the original value of base.
  2097. .. warning::
  2098. The result will be undefined if:
  2099. - offset or bits is negative.
  2100. - if the sum of offset and bits is greater than the number of bits used to store the operand.
  2101. :param base:
  2102. The integer into which to insert ``insert``.
  2103. :param insert:
  2104. The value of the bits to insert.
  2105. :param offset:
  2106. The index of the first bit to insert.
  2107. :param bits:
  2108. The number of bits to insert.
  2109. :return:
  2110. ``base`` with inserted bits.
  2111. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldInsert.xhtml
  2112. .. rst-class:: classref-item-separator
  2113. ----
  2114. .. _shader_func_bitfieldReverse:
  2115. .. rst-class:: classref-method
  2116. |vec_int_type| **bitfieldReverse**\ (\ |vec_int_type| value) :ref:`🔗<shader_func_bitfieldReverse>`
  2117. .. rst-class:: classref-method
  2118. |vec_uint_type| **bitfieldReverse**\ (\ |vec_uint_type| value) :ref:`🔗<shader_func_bitfieldReverse>`
  2119. |componentwise|
  2120. Reverse the order of bits in an integer.
  2121. The bit numbered ``n`` will be taken from bit ``(bits - 1) - n`` of ``value``, where bits is the total number of bits used to represent ``value``.
  2122. :param value:
  2123. The value whose bits to reverse.
  2124. :return:
  2125. ``value`` but with its bits reversed.
  2126. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldReverse.xhtml
  2127. .. rst-class:: classref-item-separator
  2128. ----
  2129. .. _shader_func_bitCount:
  2130. .. rst-class:: classref-method
  2131. |vec_int_type| **bitCount**\ (\ |vec_int_type| value) :ref:`🔗<shader_func_bitCount>`
  2132. .. rst-class:: classref-method
  2133. |vec_uint_type| **bitCount**\ (\ |vec_uint_type| value) :ref:`🔗<shader_func_bitCount>`
  2134. |componentwise|
  2135. Counts the number of 1 bits in an integer.
  2136. :param value:
  2137. The value whose bits to count.
  2138. :return:
  2139. The number of bits that are set to 1 in the binary representation of ``value``.
  2140. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitCount.xhtml
  2141. .. rst-class:: classref-item-separator
  2142. ----
  2143. .. _shader_func_findLSB:
  2144. .. rst-class:: classref-method
  2145. |vec_int_type| **findLSB**\ (\ |vec_int_type| value) :ref:`🔗<shader_func_findLSB>`
  2146. .. rst-class:: classref-method
  2147. |vec_uint_type| **findLSB**\ (\ |vec_uint_type| value) :ref:`🔗<shader_func_findLSB>`
  2148. |componentwise|
  2149. Find the index of the least significant bit set to ``1``.
  2150. .. note:: If ``value`` is zero, ``-1`` will be returned.
  2151. :param value:
  2152. The value whose bits to scan.
  2153. :return:
  2154. The bit number of the least significant bit that is set to 1 in the binary representation of value.
  2155. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/findLSB.xhtml
  2156. .. rst-class:: classref-item-separator
  2157. ----
  2158. .. _shader_func_findMSB:
  2159. .. rst-class:: classref-method
  2160. |vec_int_type| **findMSB**\ (\ |vec_int_type| value) :ref:`🔗<shader_func_findMSB>`
  2161. .. rst-class:: classref-method
  2162. |vec_uint_type| **findMSB**\ (\ |vec_uint_type| value) :ref:`🔗<shader_func_findMSB>`
  2163. |componentwise|
  2164. Find the index of the most significant bit set to 1.
  2165. .. note::
  2166. For signed integer types, the sign bit is checked first and then:
  2167. - For positive integers, the result will be the bit number of the most significant bit that is set to 1.
  2168. - For negative integers, the result will be the bit number of the most significant bit set to 0.
  2169. .. note:: For a value of zero or negative 1, -1 will be returned.
  2170. :param value:
  2171. The value whose bits to scan.
  2172. :return:
  2173. The bit number of the most significant bit that is set to 1 in the binary representation of value.
  2174. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/findMSB.xhtml
  2175. .. rst-class:: classref-item-separator
  2176. ----
  2177. .. _shader_func_imulExtended:
  2178. .. rst-class:: classref-method
  2179. |void| **imulExtended**\ (\ |vec_int_type| x, |vec_int_type| y, out |vec_int_type| msb, out |vec_int_type| lsb) :ref:`🔗<shader_func_imulExtended>`
  2180. |componentwise|
  2181. Perform 32-bit by 32-bit signed multiplication to produce a 64-bit result.
  2182. The 32 least significant bits of this product are returned in ``lsb`` and the 32 most significant bits are returned in ``msb``.
  2183. :param x:
  2184. The first multiplicand.
  2185. :param y:
  2186. The second multiplicand.
  2187. :param msb:
  2188. The variable to receive the most significant word of the product.
  2189. :param lsb:
  2190. The variable to receive the least significant word of the product.
  2191. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/umulExtended.xhtml
  2192. .. rst-class:: classref-item-separator
  2193. ----
  2194. .. _shader_func_umulExtended:
  2195. .. rst-class:: classref-method
  2196. |void| **umulExtended**\ (\ |vec_uint_type| x, |vec_uint_type| y, out |vec_uint_type| msb, out |vec_uint_type| lsb) :ref:`🔗<shader_func_umulExtended>`
  2197. |componentwise|
  2198. Perform 32-bit by 32-bit unsigned multiplication to produce a 64-bit result.
  2199. The 32 least significant bits of this product are returned in ``lsb`` and the 32 most significant bits are returned in ``msb``.
  2200. :param x:
  2201. The first multiplicand.
  2202. :param y:
  2203. The second multiplicand.
  2204. :param msb:
  2205. The variable to receive the most significant word of the product.
  2206. :param lsb:
  2207. The variable to receive the least significant word of the product.
  2208. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/umulExtended.xhtml
  2209. .. rst-class:: classref-item-separator
  2210. ----
  2211. .. _shader_func_uaddCarry:
  2212. .. rst-class:: classref-method
  2213. |vec_uint_type| **uaddCarry**\ (\ |vec_uint_type| x, |vec_uint_type| y, out |vec_uint_type| carry) :ref:`🔗<shader_func_uaddCarry>`
  2214. |componentwise|
  2215. Add unsigned integers and generate carry.
  2216. adds two 32-bit unsigned integer variables (scalars or vectors) and generates a 32-bit unsigned integer result, along with a carry output.
  2217. The value carry is .
  2218. :param x:
  2219. The first operand.
  2220. :param y:
  2221. The second operand.
  2222. :param carry:
  2223. 0 if the sum is less than 2\ :sup:`32`, otherwise 1.
  2224. :return:
  2225. ``(x + y) % 2^32``.
  2226. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/uaddCarry.xhtml
  2227. .. rst-class:: classref-item-separator
  2228. ----
  2229. .. _shader_func_usubBorrow:
  2230. .. rst-class:: classref-method
  2231. |vec_uint_type| **usubBorrow**\ (\ |vec_uint_type| x, |vec_uint_type| y, out |vec_uint_type| borrow) :ref:`🔗<shader_func_usubBorrow>`
  2232. |componentwise|
  2233. Subtract unsigned integers and generate borrow.
  2234. :param x:
  2235. The first operand.
  2236. :param y:
  2237. The second operand.
  2238. :param borrow:
  2239. ``0`` if ``x >= y``, otherwise ``1``.
  2240. :return:
  2241. The difference of ``x`` and ``y`` if non-negative, or 2\ :sup:`32` plus that difference otherwise.
  2242. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/usubBorrow.xhtml
  2243. .. rst-class:: classref-item-separator
  2244. ----
  2245. .. _shader_func_ldexp:
  2246. .. rst-class:: classref-method
  2247. |vec_type| **ldexp**\ (\ |vec_type| x, out |vec_int_type| exp) :ref:`🔗<shader_func_ldexp>`
  2248. |componentwise|
  2249. Assembles a floating-point number from a value and exponent.
  2250. .. warning::
  2251. If this product is too large to be represented in the floating-point
  2252. type, the result is undefined.
  2253. :param x:
  2254. The value to be used as a source of significand.
  2255. :param exp:
  2256. The value to be used as a source of exponent.
  2257. :return:
  2258. ``x * 2^exp``
  2259. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/ldexp.xhtml
  2260. .. rst-class:: classref-item-separator
  2261. ----
  2262. .. _shader_func_frexp:
  2263. .. rst-class:: classref-method
  2264. |vec_type| **frexp**\ (\ |vec_type| x, out |vec_int_type| exp) :ref:`🔗<shader_func_frexp>`
  2265. |componentwise|
  2266. Extracts ``x`` into a floating-point significand in the range ``[0.5, 1.0)`` and in integral exponent of two, such that:
  2267. ::
  2268. x = significand * 2 ^ exponent
  2269. For a floating-point value of zero, the significand and exponent are both zero.
  2270. .. warning:: For a floating-point value that is an infinity or a floating-point NaN, the results are undefined.
  2271. :param x:
  2272. The value from which significand and exponent are to be extracted.
  2273. :param exp:
  2274. The variable into which to place the exponent of ``x``.
  2275. :return:
  2276. The significand of ``x``.
  2277. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/frexp.xhtml
  2278. .. rst-class:: classref-section-separator
  2279. ----
  2280. .. |void| replace:: :abbr:`void (No return value.)`
  2281. .. |vec_type| replace:: :abbr:`vec_type (Any of: float, vec2, vec3, vec4)`
  2282. .. |vec_int_type| replace:: :abbr:`vec_int_type (Any of: int, ivec2, ivec3, ivec4)`
  2283. .. |vec_uint_type| replace:: :abbr:`vec_uint_type (Any of: float, uvec2, uvec3, uvec4)`
  2284. .. |vec_bool_type| replace:: :abbr:`vec_bool_type (Any of: bool, bvec2, bvec3, bvec4)`
  2285. .. |gsampler2D| replace:: :abbr:`gsampler2D (Any of: sampler2D, isampler2D, uSampler2D)`
  2286. .. |gsampler2DArray| replace:: :abbr:`gsampler2DArray (Any of: sampler2DArray, isampler2DArray, uSampler2DArray)`
  2287. .. |gsampler3D| replace:: :abbr:`gsampler3D (Any of: sampler3D, isampler3D, uSampler3D)`
  2288. .. |mat_type| replace:: :abbr:`mat_type (Any of: mat2, mat3, mat4)`
  2289. .. |gvec4_type| replace:: :abbr:`gvec4_type (Any of: vec4, ivec4, uvec4)`
  2290. .. |componentwise| replace:: :ref:`Component-wise Function<shading_componentwise>`.