shader_functions.rst 144 KB

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