linalg_hlsl.odin 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. // core:math/linalg/hlsl implements a HLSL-like mathematics library plus numerous other utility procedures
  2. package math_linalg_hlsl
  3. import "core:builtin"
  4. TAU :: 6.28318530717958647692528676655900576
  5. PI :: 3.14159265358979323846264338327950288
  6. E :: 2.71828182845904523536
  7. τ :: TAU
  8. π :: PI
  9. e :: E
  10. SQRT_TWO :: 1.41421356237309504880168872420969808
  11. SQRT_THREE :: 1.73205080756887729352744634150587236
  12. SQRT_FIVE :: 2.23606797749978969640917366873127623
  13. LN2 :: 0.693147180559945309417232121458176568
  14. LN10 :: 2.30258509299404568401799145468436421
  15. FLOAT_EPSILON :: 1e-7
  16. DOUBLE_EPSILON :: 1e-15
  17. // Aliases (not distinct) of types
  18. float :: f32
  19. double :: f64
  20. int :: builtin.i32
  21. uint :: builtin.u32
  22. // Odin matrices are stored internally as Column-Major, which matches the internal layout of HLSL by default
  23. float1x1 :: distinct matrix[1, 1]float
  24. float2x2 :: distinct matrix[2, 2]float
  25. float3x3 :: distinct matrix[3, 3]float
  26. float4x4 :: distinct matrix[4, 4]float
  27. float1x2 :: distinct matrix[1, 2]float
  28. float1x3 :: distinct matrix[1, 3]float
  29. float1x4 :: distinct matrix[1, 4]float
  30. float2x1 :: distinct matrix[2, 1]float
  31. float2x3 :: distinct matrix[2, 3]float
  32. float2x4 :: distinct matrix[2, 4]float
  33. float3x1 :: distinct matrix[3, 1]float
  34. float3x2 :: distinct matrix[3, 2]float
  35. float3x4 :: distinct matrix[3, 4]float
  36. float4x1 :: distinct matrix[4, 1]float
  37. float4x2 :: distinct matrix[4, 2]float
  38. float4x3 :: distinct matrix[4, 3]float
  39. float2 :: distinct [2]float
  40. float3 :: distinct [3]float
  41. float4 :: distinct [4]float
  42. int2 :: distinct [2]int
  43. int3 :: distinct [3]int
  44. int4 :: distinct [4]int
  45. uint2 :: distinct [2]uint
  46. uint3 :: distinct [3]uint
  47. uint4 :: distinct [4]uint
  48. bool2 :: distinct [2]bool
  49. bool3 :: distinct [3]bool
  50. bool4 :: distinct [4]bool
  51. // Double Precision (double) Floating Point Types
  52. double1x1 :: distinct matrix[1, 1]double
  53. double2x2 :: distinct matrix[2, 2]double
  54. double3x3 :: distinct matrix[3, 3]double
  55. double4x4 :: distinct matrix[4, 4]double
  56. double1x2 :: distinct matrix[1, 2]double
  57. double1x3 :: distinct matrix[1, 3]double
  58. double1x4 :: distinct matrix[1, 4]double
  59. double2x1 :: distinct matrix[2, 1]double
  60. double2x3 :: distinct matrix[2, 3]double
  61. double2x4 :: distinct matrix[2, 4]double
  62. double3x1 :: distinct matrix[3, 1]double
  63. double3x2 :: distinct matrix[3, 2]double
  64. double3x4 :: distinct matrix[3, 4]double
  65. double4x1 :: distinct matrix[4, 1]double
  66. double4x2 :: distinct matrix[4, 2]double
  67. double4x3 :: distinct matrix[4, 3]double
  68. double2 :: distinct [2]double
  69. double3 :: distinct [3]double
  70. double4 :: distinct [4]double
  71. int1x1 :: distinct matrix[1, 1]int
  72. int2x2 :: distinct matrix[2, 2]int
  73. int3x3 :: distinct matrix[3, 3]int
  74. int4x4 :: distinct matrix[4, 4]int
  75. int1x2 :: distinct matrix[1, 2]int
  76. int1x3 :: distinct matrix[1, 3]int
  77. int1x4 :: distinct matrix[1, 4]int
  78. int2x1 :: distinct matrix[2, 1]int
  79. int2x3 :: distinct matrix[2, 3]int
  80. int2x4 :: distinct matrix[2, 4]int
  81. int3x1 :: distinct matrix[3, 1]int
  82. int3x2 :: distinct matrix[3, 2]int
  83. int3x4 :: distinct matrix[3, 4]int
  84. int4x1 :: distinct matrix[4, 1]int
  85. int4x2 :: distinct matrix[4, 2]int
  86. int4x3 :: distinct matrix[4, 3]int
  87. cos :: proc{
  88. cos_float,
  89. cos_double,
  90. cos_float2,
  91. cos_float3,
  92. cos_float4,
  93. cos_double2,
  94. cos_double3,
  95. cos_double4,
  96. }
  97. cos_float2 :: proc "c" (x: float2) -> float2 { return {cos(x.x), cos(x.y)} }
  98. cos_float3 :: proc "c" (x: float3) -> float3 { return {cos(x.x), cos(x.y), cos(x.z)} }
  99. cos_float4 :: proc "c" (x: float4) -> float4 { return {cos(x.x), cos(x.y), cos(x.z), cos(x.w)} }
  100. cos_double2 :: proc "c" (x: double2) -> double2 { return {cos(x.x), cos(x.y)} }
  101. cos_double3 :: proc "c" (x: double3) -> double3 { return {cos(x.x), cos(x.y), cos(x.z)} }
  102. cos_double4 :: proc "c" (x: double4) -> double4 { return {cos(x.x), cos(x.y), cos(x.z), cos(x.w)} }
  103. sin :: proc{
  104. sin_float,
  105. sin_double,
  106. sin_float2,
  107. sin_float3,
  108. sin_float4,
  109. sin_double2,
  110. sin_double3,
  111. sin_double4,
  112. }
  113. sin_float2 :: proc "c" (x: float2) -> float2 { return {sin(x.x), sin(x.y)} }
  114. sin_float3 :: proc "c" (x: float3) -> float3 { return {sin(x.x), sin(x.y), sin(x.z)} }
  115. sin_float4 :: proc "c" (x: float4) -> float4 { return {sin(x.x), sin(x.y), sin(x.z), sin(x.w)} }
  116. sin_double2 :: proc "c" (x: double2) -> double2 { return {sin(x.x), sin(x.y)} }
  117. sin_double3 :: proc "c" (x: double3) -> double3 { return {sin(x.x), sin(x.y), sin(x.z)} }
  118. sin_double4 :: proc "c" (x: double4) -> double4 { return {sin(x.x), sin(x.y), sin(x.z), sin(x.w)} }
  119. tan :: proc{
  120. tan_float,
  121. tan_double,
  122. tan_float2,
  123. tan_float3,
  124. tan_float4,
  125. tan_double2,
  126. tan_double3,
  127. tan_double4,
  128. }
  129. tan_float2 :: proc "c" (x: float2) -> float2 { return {tan(x.x), tan(x.y)} }
  130. tan_float3 :: proc "c" (x: float3) -> float3 { return {tan(x.x), tan(x.y), tan(x.z)} }
  131. tan_float4 :: proc "c" (x: float4) -> float4 { return {tan(x.x), tan(x.y), tan(x.z), tan(x.w)} }
  132. tan_double2 :: proc "c" (x: double2) -> double2 { return {tan(x.x), tan(x.y)} }
  133. tan_double3 :: proc "c" (x: double3) -> double3 { return {tan(x.x), tan(x.y), tan(x.z)} }
  134. tan_double4 :: proc "c" (x: double4) -> double4 { return {tan(x.x), tan(x.y), tan(x.z), tan(x.w)} }
  135. acos :: proc{
  136. acos_float,
  137. acos_double,
  138. acos_float2,
  139. acos_float3,
  140. acos_float4,
  141. acos_double2,
  142. acos_double3,
  143. acos_double4,
  144. }
  145. acos_float2 :: proc "c" (x: float2) -> float2 { return {acos(x.x), acos(x.y)} }
  146. acos_float3 :: proc "c" (x: float3) -> float3 { return {acos(x.x), acos(x.y), acos(x.z)} }
  147. acos_float4 :: proc "c" (x: float4) -> float4 { return {acos(x.x), acos(x.y), acos(x.z), acos(x.w)} }
  148. acos_double2 :: proc "c" (x: double2) -> double2 { return {acos(x.x), acos(x.y)} }
  149. acos_double3 :: proc "c" (x: double3) -> double3 { return {acos(x.x), acos(x.y), acos(x.z)} }
  150. acos_double4 :: proc "c" (x: double4) -> double4 { return {acos(x.x), acos(x.y), acos(x.z), acos(x.w)} }
  151. asin :: proc{
  152. asin_float,
  153. asin_double,
  154. asin_float2,
  155. asin_float3,
  156. asin_float4,
  157. asin_double2,
  158. asin_double3,
  159. asin_double4,
  160. }
  161. asin_float2 :: proc "c" (x: float2) -> float2 { return {asin(x.x), asin(x.y)} }
  162. asin_float3 :: proc "c" (x: float3) -> float3 { return {asin(x.x), asin(x.y), asin(x.z)} }
  163. asin_float4 :: proc "c" (x: float4) -> float4 { return {asin(x.x), asin(x.y), asin(x.z), asin(x.w)} }
  164. asin_double2 :: proc "c" (x: double2) -> double2 { return {asin(x.x), asin(x.y)} }
  165. asin_double3 :: proc "c" (x: double3) -> double3 { return {asin(x.x), asin(x.y), asin(x.z)} }
  166. asin_double4 :: proc "c" (x: double4) -> double4 { return {asin(x.x), asin(x.y), asin(x.z), asin(x.w)} }
  167. atan :: proc{
  168. atan_float,
  169. atan_double,
  170. atan_float2,
  171. atan_float3,
  172. atan_float4,
  173. atan_double2,
  174. atan_double3,
  175. atan_double4,
  176. atan2_float,
  177. atan2_double,
  178. atan2_float2,
  179. atan2_float3,
  180. atan2_float4,
  181. atan2_double2,
  182. atan2_double3,
  183. atan2_double4,
  184. }
  185. atan_float2 :: proc "c" (x: float2) -> float2 { return {atan(x.x), atan(x.y)} }
  186. atan_float3 :: proc "c" (x: float3) -> float3 { return {atan(x.x), atan(x.y), atan(x.z)} }
  187. atan_float4 :: proc "c" (x: float4) -> float4 { return {atan(x.x), atan(x.y), atan(x.z), atan(x.w)} }
  188. atan_double2 :: proc "c" (x: double2) -> double2 { return {atan(x.x), atan(x.y)} }
  189. atan_double3 :: proc "c" (x: double3) -> double3 { return {atan(x.x), atan(x.y), atan(x.z)} }
  190. atan_double4 :: proc "c" (x: double4) -> double4 { return {atan(x.x), atan(x.y), atan(x.z), atan(x.w)} }
  191. atan2 :: proc{
  192. atan2_float,
  193. atan2_double,
  194. atan2_float2,
  195. atan2_float3,
  196. atan2_float4,
  197. atan2_double2,
  198. atan2_double3,
  199. atan2_double4,
  200. }
  201. atan2_float2 :: proc "c" (y, x: float2) -> float2 { return {atan2(y.x, x.x), atan2(y.y, x.y)} }
  202. atan2_float3 :: proc "c" (y, x: float3) -> float3 { return {atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z)} }
  203. atan2_float4 :: proc "c" (y, x: float4) -> float4 { return {atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z), atan2(y.w, x.w)} }
  204. atan2_double2 :: proc "c" (y, x: double2) -> double2 { return {atan2(y.x, x.x), atan2(y.y, x.y)} }
  205. atan2_double3 :: proc "c" (y, x: double3) -> double3 { return {atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z)} }
  206. atan2_double4 :: proc "c" (y, x: double4) -> double4 { return {atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z), atan2(y.w, x.w)} }
  207. cosh :: proc{
  208. cosh_float,
  209. cosh_double,
  210. cosh_float2,
  211. cosh_float3,
  212. cosh_float4,
  213. cosh_double2,
  214. cosh_double3,
  215. cosh_double4,
  216. }
  217. cosh_float2 :: proc "c" (x: float2) -> float2 { return {cosh(x.x), cosh(x.y)} }
  218. cosh_float3 :: proc "c" (x: float3) -> float3 { return {cosh(x.x), cosh(x.y), cosh(x.z)} }
  219. cosh_float4 :: proc "c" (x: float4) -> float4 { return {cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)} }
  220. cosh_double2 :: proc "c" (x: double2) -> double2 { return {cosh(x.x), cosh(x.y)} }
  221. cosh_double3 :: proc "c" (x: double3) -> double3 { return {cosh(x.x), cosh(x.y), cosh(x.z)} }
  222. cosh_double4 :: proc "c" (x: double4) -> double4 { return {cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)} }
  223. sinh :: proc{
  224. sinh_float,
  225. sinh_double,
  226. sinh_float2,
  227. sinh_float3,
  228. sinh_float4,
  229. sinh_double2,
  230. sinh_double3,
  231. sinh_double4,
  232. }
  233. sinh_float2 :: proc "c" (x: float2) -> float2 { return {sinh(x.x), sinh(x.y)} }
  234. sinh_float3 :: proc "c" (x: float3) -> float3 { return {sinh(x.x), sinh(x.y), sinh(x.z)} }
  235. sinh_float4 :: proc "c" (x: float4) -> float4 { return {sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)} }
  236. sinh_double2 :: proc "c" (x: double2) -> double2 { return {sinh(x.x), sinh(x.y)} }
  237. sinh_double3 :: proc "c" (x: double3) -> double3 { return {sinh(x.x), sinh(x.y), sinh(x.z)} }
  238. sinh_double4 :: proc "c" (x: double4) -> double4 { return {sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)} }
  239. tanh :: proc{
  240. tanh_float,
  241. tanh_double,
  242. tanh_float2,
  243. tanh_float3,
  244. tanh_float4,
  245. tanh_double2,
  246. tanh_double3,
  247. tanh_double4,
  248. }
  249. tanh_float2 :: proc "c" (x: float2) -> float2 { return {tanh(x.x), tanh(x.y)} }
  250. tanh_float3 :: proc "c" (x: float3) -> float3 { return {tanh(x.x), tanh(x.y), tanh(x.z)} }
  251. tanh_float4 :: proc "c" (x: float4) -> float4 { return {tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)} }
  252. tanh_double2 :: proc "c" (x: double2) -> double2 { return {tanh(x.x), tanh(x.y)} }
  253. tanh_double3 :: proc "c" (x: double3) -> double3 { return {tanh(x.x), tanh(x.y), tanh(x.z)} }
  254. tanh_double4 :: proc "c" (x: double4) -> double4 { return {tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)} }
  255. acosh :: proc{
  256. acosh_float,
  257. acosh_double,
  258. acosh_float2,
  259. acosh_float3,
  260. acosh_float4,
  261. acosh_double2,
  262. acosh_double3,
  263. acosh_double4,
  264. }
  265. acosh_float2 :: proc "c" (x: float2) -> float2 { return {acosh(x.x), acosh(x.y)} }
  266. acosh_float3 :: proc "c" (x: float3) -> float3 { return {acosh(x.x), acosh(x.y), acosh(x.z)} }
  267. acosh_float4 :: proc "c" (x: float4) -> float4 { return {acosh(x.x), acosh(x.y), acosh(x.z), acosh(x.w)} }
  268. acosh_double2 :: proc "c" (x: double2) -> double2 { return {acosh(x.x), acosh(x.y)} }
  269. acosh_double3 :: proc "c" (x: double3) -> double3 { return {acosh(x.x), acosh(x.y), acosh(x.z)} }
  270. acosh_double4 :: proc "c" (x: double4) -> double4 { return {acosh(x.x), acosh(x.y), acosh(x.z), acosh(x.w)} }
  271. asinh :: proc{
  272. asinh_float,
  273. asinh_double,
  274. asinh_float2,
  275. asinh_float3,
  276. asinh_float4,
  277. asinh_double2,
  278. asinh_double3,
  279. asinh_double4,
  280. }
  281. asinh_float2 :: proc "c" (x: float2) -> float2 { return {asinh(x.x), asinh(x.y)} }
  282. asinh_float3 :: proc "c" (x: float3) -> float3 { return {asinh(x.x), asinh(x.y), asinh(x.z)} }
  283. asinh_float4 :: proc "c" (x: float4) -> float4 { return {asinh(x.x), asinh(x.y), asinh(x.z), asinh(x.w)} }
  284. asinh_double2 :: proc "c" (x: double2) -> double2 { return {asinh(x.x), asinh(x.y)} }
  285. asinh_double3 :: proc "c" (x: double3) -> double3 { return {asinh(x.x), asinh(x.y), asinh(x.z)} }
  286. asinh_double4 :: proc "c" (x: double4) -> double4 { return {asinh(x.x), asinh(x.y), asinh(x.z), asinh(x.w)} }
  287. atanh :: proc{
  288. atanh_float,
  289. atanh_double,
  290. atanh_float2,
  291. atanh_float3,
  292. atanh_float4,
  293. atanh_double2,
  294. atanh_double3,
  295. atanh_double4,
  296. }
  297. atanh_float2 :: proc "c" (x: float2) -> float2 { return {atanh(x.x), atanh(x.y)} }
  298. atanh_float3 :: proc "c" (x: float3) -> float3 { return {atanh(x.x), atanh(x.y), atanh(x.z)} }
  299. atanh_float4 :: proc "c" (x: float4) -> float4 { return {atanh(x.x), atanh(x.y), atanh(x.z), atanh(x.w)} }
  300. atanh_double2 :: proc "c" (x: double2) -> double2 { return {atanh(x.x), atanh(x.y)} }
  301. atanh_double3 :: proc "c" (x: double3) -> double3 { return {atanh(x.x), atanh(x.y), atanh(x.z)} }
  302. atanh_double4 :: proc "c" (x: double4) -> double4 { return {atanh(x.x), atanh(x.y), atanh(x.z), atanh(x.w)} }
  303. sqrt :: proc{
  304. sqrt_float,
  305. sqrt_double,
  306. sqrt_float2,
  307. sqrt_float3,
  308. sqrt_float4,
  309. sqrt_double2,
  310. sqrt_double3,
  311. sqrt_double4,
  312. }
  313. sqrt_float2 :: proc "c" (x: float2) -> float2 { return {sqrt(x.x), sqrt(x.y)} }
  314. sqrt_float3 :: proc "c" (x: float3) -> float3 { return {sqrt(x.x), sqrt(x.y), sqrt(x.z)} }
  315. sqrt_float4 :: proc "c" (x: float4) -> float4 { return {sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)} }
  316. sqrt_double2 :: proc "c" (x: double2) -> double2 { return {sqrt(x.x), sqrt(x.y)} }
  317. sqrt_double3 :: proc "c" (x: double3) -> double3 { return {sqrt(x.x), sqrt(x.y), sqrt(x.z)} }
  318. sqrt_double4 :: proc "c" (x: double4) -> double4 { return {sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)} }
  319. rsqrt :: proc{
  320. rsqrt_float,
  321. rsqrt_double,
  322. rsqrt_float2,
  323. rsqrt_float3,
  324. rsqrt_float4,
  325. rsqrt_double2,
  326. rsqrt_double3,
  327. rsqrt_double4,
  328. }
  329. rsqrt_float2 :: proc "c" (x: float2) -> float2 { return {rsqrt(x.x), rsqrt(x.y)} }
  330. rsqrt_float3 :: proc "c" (x: float3) -> float3 { return {rsqrt(x.x), rsqrt(x.y), rsqrt(x.z)} }
  331. rsqrt_float4 :: proc "c" (x: float4) -> float4 { return {rsqrt(x.x), rsqrt(x.y), rsqrt(x.z), rsqrt(x.w)} }
  332. rsqrt_double2 :: proc "c" (x: double2) -> double2 { return {rsqrt(x.x), rsqrt(x.y)} }
  333. rsqrt_double3 :: proc "c" (x: double3) -> double3 { return {rsqrt(x.x), rsqrt(x.y), rsqrt(x.z)} }
  334. rsqrt_double4 :: proc "c" (x: double4) -> double4 { return {rsqrt(x.x), rsqrt(x.y), rsqrt(x.z), rsqrt(x.w)} }
  335. rcp :: proc{
  336. rcp_float,
  337. rcp_double,
  338. rcp_float2,
  339. rcp_float3,
  340. rcp_float4,
  341. rcp_double2,
  342. rcp_double3,
  343. rcp_double4,
  344. }
  345. rcp_float2 :: proc "c" (x: float2) -> float2 { return {rcp(x.x), rcp(x.y)} }
  346. rcp_float3 :: proc "c" (x: float3) -> float3 { return {rcp(x.x), rcp(x.y), rcp(x.z)} }
  347. rcp_float4 :: proc "c" (x: float4) -> float4 { return {rcp(x.x), rcp(x.y), rcp(x.z), rcp(x.w)} }
  348. rcp_double2 :: proc "c" (x: double2) -> double2 { return {rcp(x.x), rcp(x.y)} }
  349. rcp_double3 :: proc "c" (x: double3) -> double3 { return {rcp(x.x), rcp(x.y), rcp(x.z)} }
  350. rcp_double4 :: proc "c" (x: double4) -> double4 { return {rcp(x.x), rcp(x.y), rcp(x.z), rcp(x.w)} }
  351. pow :: proc{
  352. pow_float,
  353. pow_double,
  354. pow_float2,
  355. pow_float3,
  356. pow_float4,
  357. pow_double2,
  358. pow_double3,
  359. pow_double4,
  360. }
  361. pow_float2 :: proc "c" (x, y: float2) -> float2 { return {pow(x.x, y.x), pow(x.y, y.y)} }
  362. pow_float3 :: proc "c" (x, y: float3) -> float3 { return {pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z)} }
  363. pow_float4 :: proc "c" (x, y: float4) -> float4 { return {pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z), pow(x.w, y.w)} }
  364. pow_double2 :: proc "c" (x, y: double2) -> double2 { return {pow(x.x, y.x), pow(x.y, y.y)} }
  365. pow_double3 :: proc "c" (x, y: double3) -> double3 { return {pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z)} }
  366. pow_double4 :: proc "c" (x, y: double4) -> double4 { return {pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z), pow(x.w, y.w)} }
  367. exp :: proc{
  368. exp_float,
  369. exp_double,
  370. exp_float2,
  371. exp_float3,
  372. exp_float4,
  373. exp_double2,
  374. exp_double3,
  375. exp_double4,
  376. }
  377. exp_float2 :: proc "c" (x: float2) -> float2 { return {exp(x.x), exp(x.y)} }
  378. exp_float3 :: proc "c" (x: float3) -> float3 { return {exp(x.x), exp(x.y), exp(x.z)} }
  379. exp_float4 :: proc "c" (x: float4) -> float4 { return {exp(x.x), exp(x.y), exp(x.z), exp(x.w)} }
  380. exp_double2 :: proc "c" (x: double2) -> double2 { return {exp(x.x), exp(x.y)} }
  381. exp_double3 :: proc "c" (x: double3) -> double3 { return {exp(x.x), exp(x.y), exp(x.z)} }
  382. exp_double4 :: proc "c" (x: double4) -> double4 { return {exp(x.x), exp(x.y), exp(x.z), exp(x.w)} }
  383. log :: proc{
  384. log_float,
  385. log_double,
  386. log_float2,
  387. log_float3,
  388. log_float4,
  389. log_double2,
  390. log_double3,
  391. log_double4,
  392. }
  393. log_float2 :: proc "c" (x: float2) -> float2 { return {log(x.x), log(x.y)} }
  394. log_float3 :: proc "c" (x: float3) -> float3 { return {log(x.x), log(x.y), log(x.z)} }
  395. log_float4 :: proc "c" (x: float4) -> float4 { return {log(x.x), log(x.y), log(x.z), log(x.w)} }
  396. log_double2 :: proc "c" (x: double2) -> double2 { return {log(x.x), log(x.y)} }
  397. log_double3 :: proc "c" (x: double3) -> double3 { return {log(x.x), log(x.y), log(x.z)} }
  398. log_double4 :: proc "c" (x: double4) -> double4 { return {log(x.x), log(x.y), log(x.z), log(x.w)} }
  399. log2 :: proc{
  400. log2_float,
  401. log2_double,
  402. log2_float2,
  403. log2_float3,
  404. log2_float4,
  405. log2_double2,
  406. log2_double3,
  407. log2_double4,
  408. }
  409. log2_float2 :: proc "c" (x: float2) -> float2 { return {log2(x.x), log2(x.y)} }
  410. log2_float3 :: proc "c" (x: float3) -> float3 { return {log2(x.x), log2(x.y), log2(x.z)} }
  411. log2_float4 :: proc "c" (x: float4) -> float4 { return {log2(x.x), log2(x.y), log2(x.z), log2(x.w)} }
  412. log2_double2 :: proc "c" (x: double2) -> double2 { return {log2(x.x), log2(x.y)} }
  413. log2_double3 :: proc "c" (x: double3) -> double3 { return {log2(x.x), log2(x.y), log2(x.z)} }
  414. log2_double4 :: proc "c" (x: double4) -> double4 { return {log2(x.x), log2(x.y), log2(x.z), log2(x.w)} }
  415. log10 :: proc{
  416. log10_float,
  417. log10_double,
  418. log10_float2,
  419. log10_float3,
  420. log10_float4,
  421. log10_double2,
  422. log10_double3,
  423. log10_double4,
  424. }
  425. log10_float2 :: proc "c" (x: float2) -> float2 { return {log10(x.x), log10(x.y)} }
  426. log10_float3 :: proc "c" (x: float3) -> float3 { return {log10(x.x), log10(x.y), log10(x.z)} }
  427. log10_float4 :: proc "c" (x: float4) -> float4 { return {log10(x.x), log10(x.y), log10(x.z), log10(x.w)} }
  428. log10_double2 :: proc "c" (x: double2) -> double2 { return {log10(x.x), log10(x.y)} }
  429. log10_double3 :: proc "c" (x: double3) -> double3 { return {log10(x.x), log10(x.y), log10(x.z)} }
  430. log10_double4 :: proc "c" (x: double4) -> double4 { return {log10(x.x), log10(x.y), log10(x.z), log10(x.w)} }
  431. exp2 :: proc{
  432. exp2_float,
  433. exp2_double,
  434. exp2_float2,
  435. exp2_float3,
  436. exp2_float4,
  437. exp2_double2,
  438. exp2_double3,
  439. exp2_double4,
  440. }
  441. exp2_float2 :: proc "c" (x: float2) -> float2 { return {exp2(x.x), exp2(x.y)} }
  442. exp2_float3 :: proc "c" (x: float3) -> float3 { return {exp2(x.x), exp2(x.y), exp2(x.z)} }
  443. exp2_float4 :: proc "c" (x: float4) -> float4 { return {exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)} }
  444. exp2_double2 :: proc "c" (x: double2) -> double2 { return {exp2(x.x), exp2(x.y)} }
  445. exp2_double3 :: proc "c" (x: double3) -> double3 { return {exp2(x.x), exp2(x.y), exp2(x.z)} }
  446. exp2_double4 :: proc "c" (x: double4) -> double4 { return {exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)} }
  447. sign :: proc{
  448. sign_int,
  449. sign_uint,
  450. sign_float,
  451. sign_double,
  452. sign_float2,
  453. sign_float3,
  454. sign_float4,
  455. sign_double2,
  456. sign_double3,
  457. sign_double4,
  458. sign_int2,
  459. sign_int3,
  460. sign_int4,
  461. sign_uint2,
  462. sign_uint3,
  463. sign_uint4,
  464. }
  465. sign_int :: proc "c" (x: int) -> int { return -1 if x < 0 else +1 if x > 0 else 0 }
  466. sign_uint :: proc "c" (x: uint) -> uint { return +1 if x > 0 else 0 }
  467. sign_float2 :: proc "c" (x: float2) -> float2 { return {sign(x.x), sign(x.y)} }
  468. sign_float3 :: proc "c" (x: float3) -> float3 { return {sign(x.x), sign(x.y), sign(x.z)} }
  469. sign_float4 :: proc "c" (x: float4) -> float4 { return {sign(x.x), sign(x.y), sign(x.z), sign(x.w)} }
  470. sign_double2 :: proc "c" (x: double2) -> double2 { return {sign(x.x), sign(x.y)} }
  471. sign_double3 :: proc "c" (x: double3) -> double3 { return {sign(x.x), sign(x.y), sign(x.z)} }
  472. sign_double4 :: proc "c" (x: double4) -> double4 { return {sign(x.x), sign(x.y), sign(x.z), sign(x.w)} }
  473. sign_int2 :: proc "c" (x: int2) -> int2 { return {sign(x.x), sign(x.y)} }
  474. sign_int3 :: proc "c" (x: int3) -> int3 { return {sign(x.x), sign(x.y), sign(x.z)} }
  475. sign_int4 :: proc "c" (x: int4) -> int4 { return {sign(x.x), sign(x.y), sign(x.z), sign(x.w)} }
  476. sign_uint2 :: proc "c" (x: uint2) -> uint2 { return {sign(x.x), sign(x.y)} }
  477. sign_uint3 :: proc "c" (x: uint3) -> uint3 { return {sign(x.x), sign(x.y), sign(x.z)} }
  478. sign_uint4 :: proc "c" (x: uint4) -> uint4 { return {sign(x.x), sign(x.y), sign(x.z), sign(x.w)} }
  479. floor :: proc{
  480. floor_float,
  481. floor_double,
  482. floor_float2,
  483. floor_float3,
  484. floor_float4,
  485. floor_double2,
  486. floor_double3,
  487. floor_double4,
  488. }
  489. floor_float2 :: proc "c" (x: float2) -> float2 { return {floor(x.x), floor(x.y)} }
  490. floor_float3 :: proc "c" (x: float3) -> float3 { return {floor(x.x), floor(x.y), floor(x.z)} }
  491. floor_float4 :: proc "c" (x: float4) -> float4 { return {floor(x.x), floor(x.y), floor(x.z), floor(x.w)} }
  492. floor_double2 :: proc "c" (x: double2) -> double2 { return {floor(x.x), floor(x.y)} }
  493. floor_double3 :: proc "c" (x: double3) -> double3 { return {floor(x.x), floor(x.y), floor(x.z)} }
  494. floor_double4 :: proc "c" (x: double4) -> double4 { return {floor(x.x), floor(x.y), floor(x.z), floor(x.w)} }
  495. round :: proc{
  496. round_float,
  497. round_double,
  498. round_float2,
  499. round_float3,
  500. round_float4,
  501. round_double2,
  502. round_double3,
  503. round_double4,
  504. }
  505. round_float2 :: proc "c" (x: float2) -> float2 { return {round(x.x), round(x.y)} }
  506. round_float3 :: proc "c" (x: float3) -> float3 { return {round(x.x), round(x.y), round(x.z)} }
  507. round_float4 :: proc "c" (x: float4) -> float4 { return {round(x.x), round(x.y), round(x.z), round(x.w)} }
  508. round_double2 :: proc "c" (x: double2) -> double2 { return {round(x.x), round(x.y)} }
  509. round_double3 :: proc "c" (x: double3) -> double3 { return {round(x.x), round(x.y), round(x.z)} }
  510. round_double4 :: proc "c" (x: double4) -> double4 { return {round(x.x), round(x.y), round(x.z), round(x.w)} }
  511. ceil :: proc{
  512. ceil_float,
  513. ceil_double,
  514. ceil_float2,
  515. ceil_float3,
  516. ceil_float4,
  517. ceil_double2,
  518. ceil_double3,
  519. ceil_double4,
  520. }
  521. ceil_float2 :: proc "c" (x: float2) -> float2 { return {ceil(x.x), ceil(x.y)} }
  522. ceil_float3 :: proc "c" (x: float3) -> float3 { return {ceil(x.x), ceil(x.y), ceil(x.z)} }
  523. ceil_float4 :: proc "c" (x: float4) -> float4 { return {ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)} }
  524. ceil_double2 :: proc "c" (x: double2) -> double2 { return {ceil(x.x), ceil(x.y)} }
  525. ceil_double3 :: proc "c" (x: double3) -> double3 { return {ceil(x.x), ceil(x.y), ceil(x.z)} }
  526. ceil_double4 :: proc "c" (x: double4) -> double4 { return {ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)} }
  527. isfinite_float :: proc "c" (x: float) -> bool { return !isinf_float(x) }
  528. isfinite_float2 :: proc "c" (x: float2) -> bool2 { return {isfinite_float(x.x), isfinite_float(x.y)} }
  529. isfinite_float3 :: proc "c" (x: float3) -> bool3 { return {isfinite_float(x.x), isfinite_float(x.y), isfinite_float(x.z)} }
  530. isfinite_float4 :: proc "c" (x: float4) -> bool4 { return {isfinite_float(x.x), isfinite_float(x.y), isfinite_float(x.z), isfinite_float(x.w)} }
  531. isfinite_double :: proc "c" (x: double) -> bool { return !isinf_double(x) }
  532. isfinite_double2 :: proc "c" (x: double2) -> bool2 { return {isfinite_double(x.x), isfinite_double(x.y)} }
  533. isfinite_double3 :: proc "c" (x: double3) -> bool3 { return {isfinite_double(x.x), isfinite_double(x.y), isfinite_double(x.z)} }
  534. isfinite_double4 :: proc "c" (x: double4) -> bool4 { return {isfinite_double(x.x), isfinite_double(x.y), isfinite_double(x.z), isfinite_double(x.w)} }
  535. // isfinite is the opposite of isinf and returns true if the number is neither positive-infinite or negative-infinite
  536. isfinite :: proc{
  537. isfinite_float,
  538. isfinite_float2,
  539. isfinite_float3,
  540. isfinite_float4,
  541. isfinite_double,
  542. isfinite_double2,
  543. isfinite_double3,
  544. isfinite_double4,
  545. }
  546. isinf_float :: proc "c" (x: float) -> bool { return x * 0.5 == x }
  547. isinf_float2 :: proc "c" (x: float2) -> bool2 { return {isinf_float(x.x), isinf_float(x.y)} }
  548. isinf_float3 :: proc "c" (x: float3) -> bool3 { return {isinf_float(x.x), isinf_float(x.y), isinf_float(x.z)} }
  549. isinf_float4 :: proc "c" (x: float4) -> bool4 { return {isinf_float(x.x), isinf_float(x.y), isinf_float(x.z), isinf_float(x.w)} }
  550. isinf_double :: proc "c" (x: double) -> bool { return x * 0.5 == x }
  551. isinf_double2 :: proc "c" (x: double2) -> bool2 { return {isinf_double(x.x), isinf_double(x.y)} }
  552. isinf_double3 :: proc "c" (x: double3) -> bool3 { return {isinf_double(x.x), isinf_double(x.y), isinf_double(x.z)} }
  553. isinf_double4 :: proc "c" (x: double4) -> bool4 { return {isinf_double(x.x), isinf_double(x.y), isinf_double(x.z), isinf_double(x.w)} }
  554. // isinf is the opposite of isfinite and returns true if the number is either positive-infinite or negative-infinite
  555. isinf :: proc{
  556. isinf_float,
  557. isinf_float2,
  558. isinf_float3,
  559. isinf_float4,
  560. isinf_double,
  561. isinf_double2,
  562. isinf_double3,
  563. isinf_double4,
  564. }
  565. isnan_float2 :: proc "c" (x: float2) -> bool2 { return {isnan_float(x.x), isnan_float(x.y)} }
  566. isnan_float3 :: proc "c" (x: float3) -> bool3 { return {isnan_float(x.x), isnan_float(x.y), isnan_float(x.z)} }
  567. isnan_float4 :: proc "c" (x: float4) -> bool4 { return {isnan_float(x.x), isnan_float(x.y), isnan_float(x.z), isnan_float(x.w)} }
  568. isnan_double2 :: proc "c" (x: double2) -> bool2 { return {isnan_double(x.x), isnan_double(x.y)} }
  569. isnan_double3 :: proc "c" (x: double3) -> bool3 { return {isnan_double(x.x), isnan_double(x.y), isnan_double(x.z)} }
  570. isnan_double4 :: proc "c" (x: double4) -> bool4 { return {isnan_double(x.x), isnan_double(x.y), isnan_double(x.z), isnan_double(x.w)} }
  571. // isnan returns true if the input value is the special case of Not-A-Number
  572. isnan :: proc{
  573. isnan_float,
  574. isnan_float2,
  575. isnan_float3,
  576. isnan_float4,
  577. isnan_double,
  578. isnan_double2,
  579. isnan_double3,
  580. isnan_double4,
  581. }
  582. fmod :: proc{
  583. fmod_float,
  584. fmod_double,
  585. fmod_float2,
  586. fmod_float3,
  587. fmod_float4,
  588. fmod_double2,
  589. fmod_double3,
  590. fmod_double4,
  591. }
  592. fmod_float2 :: proc "c" (x, y: float2) -> float2 { return {fmod(x.x, y.x), fmod(x.y, y.y)} }
  593. fmod_float3 :: proc "c" (x, y: float3) -> float3 { return {fmod(x.x, y.x), fmod(x.y, y.y), fmod(x.z, y.z)} }
  594. fmod_float4 :: proc "c" (x, y: float4) -> float4 { return {fmod(x.x, y.x), fmod(x.y, y.y), fmod(x.z, y.z), fmod(x.w, y.w)} }
  595. fmod_double2 :: proc "c" (x, y: double2) -> double2 { return {fmod(x.x, y.x), fmod(x.y, y.y)} }
  596. fmod_double3 :: proc "c" (x, y: double3) -> double3 { return {fmod(x.x, y.x), fmod(x.y, y.y), fmod(x.z, y.z)} }
  597. fmod_double4 :: proc "c" (x, y: double4) -> double4 { return {fmod(x.x, y.x), fmod(x.y, y.y), fmod(x.z, y.z), fmod(x.w, y.w)} }
  598. frac :: proc{
  599. frac_float,
  600. frac_double,
  601. frac_float2,
  602. frac_float3,
  603. frac_float4,
  604. frac_double2,
  605. frac_double3,
  606. frac_double4,
  607. }
  608. frac_float2 :: proc "c" (x: float2) -> float2 { return {frac(x.x), frac(x.y)} }
  609. frac_float3 :: proc "c" (x: float3) -> float3 { return {frac(x.x), frac(x.y), frac(x.z)} }
  610. frac_float4 :: proc "c" (x: float4) -> float4 { return {frac(x.x), frac(x.y), frac(x.z), frac(x.w)} }
  611. frac_double2 :: proc "c" (x: double2) -> double2 { return {frac(x.x), frac(x.y)} }
  612. frac_double3 :: proc "c" (x: double3) -> double3 { return {frac(x.x), frac(x.y), frac(x.z)} }
  613. frac_double4 :: proc "c" (x: double4) -> double4 { return {frac(x.x), frac(x.y), frac(x.z), frac(x.w)} }
  614. radians :: proc{
  615. radians_float,
  616. radians_double,
  617. radians_float2,
  618. radians_float3,
  619. radians_float4,
  620. radians_double2,
  621. radians_double3,
  622. radians_double4,
  623. }
  624. radians_float :: proc "c" (degrees: float) -> float { return degrees * TAU / 360.0 }
  625. radians_double :: proc "c" (degrees: double) -> double { return degrees * TAU / 360.0 }
  626. radians_float2 :: proc "c" (degrees: float2) -> float2 { return degrees * TAU / 360.0 }
  627. radians_float3 :: proc "c" (degrees: float3) -> float3 { return degrees * TAU / 360.0 }
  628. radians_float4 :: proc "c" (degrees: float4) -> float4 { return degrees * TAU / 360.0 }
  629. radians_double2 :: proc "c" (degrees: double2) -> double2 { return degrees * TAU / 360.0 }
  630. radians_double3 :: proc "c" (degrees: double3) -> double3 { return degrees * TAU / 360.0 }
  631. radians_double4 :: proc "c" (degrees: double4) -> double4 { return degrees * TAU / 360.0 }
  632. degrees :: proc{
  633. degrees_float,
  634. degrees_double,
  635. degrees_float2,
  636. degrees_float3,
  637. degrees_float4,
  638. degrees_double2,
  639. degrees_double3,
  640. degrees_double4,
  641. }
  642. degrees_float :: proc "c" (radians: float) -> float { return radians * 360.0 / TAU }
  643. degrees_double :: proc "c" (radians: double) -> double { return radians * 360.0 / TAU }
  644. degrees_float2 :: proc "c" (radians: float2) -> float2 { return radians * 360.0 / TAU }
  645. degrees_float3 :: proc "c" (radians: float3) -> float3 { return radians * 360.0 / TAU }
  646. degrees_float4 :: proc "c" (radians: float4) -> float4 { return radians * 360.0 / TAU }
  647. degrees_double2 :: proc "c" (radians: double2) -> double2 { return radians * 360.0 / TAU }
  648. degrees_double3 :: proc "c" (radians: double3) -> double3 { return radians * 360.0 / TAU }
  649. degrees_double4 :: proc "c" (radians: double4) -> double4 { return radians * 360.0 / TAU }
  650. min :: proc{
  651. min_int,
  652. min_uint,
  653. min_float,
  654. min_double,
  655. min_float2,
  656. min_float3,
  657. min_float4,
  658. min_double2,
  659. min_double3,
  660. min_double4,
  661. min_int2,
  662. min_int3,
  663. min_int4,
  664. min_uint2,
  665. min_uint3,
  666. min_uint4,
  667. }
  668. min_int :: proc "c" (x, y: int) -> int { return builtin.min(x, y) }
  669. min_uint :: proc "c" (x, y: uint) -> uint { return builtin.min(x, y) }
  670. min_float :: proc "c" (x, y: float) -> float { return builtin.min(x, y) }
  671. min_double :: proc "c" (x, y: double) -> double { return builtin.min(x, y) }
  672. min_float2 :: proc "c" (x, y: float2) -> float2 { return {min(x.x, y.x), min(x.y, y.y)} }
  673. min_float3 :: proc "c" (x, y: float3) -> float3 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)} }
  674. min_float4 :: proc "c" (x, y: float4) -> float4 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)} }
  675. min_double2 :: proc "c" (x, y: double2) -> double2 { return {min(x.x, y.x), min(x.y, y.y)} }
  676. min_double3 :: proc "c" (x, y: double3) -> double3 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)} }
  677. min_double4 :: proc "c" (x, y: double4) -> double4 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)} }
  678. min_int2 :: proc "c" (x, y: int2) -> int2 { return {min(x.x, y.x), min(x.y, y.y)} }
  679. min_int3 :: proc "c" (x, y: int3) -> int3 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)} }
  680. min_int4 :: proc "c" (x, y: int4) -> int4 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)} }
  681. min_uint2 :: proc "c" (x, y: uint2) -> uint2 { return {min(x.x, y.x), min(x.y, y.y)} }
  682. min_uint3 :: proc "c" (x, y: uint3) -> uint3 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)} }
  683. min_uint4 :: proc "c" (x, y: uint4) -> uint4 { return {min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)} }
  684. max :: proc{
  685. max_int,
  686. max_uint,
  687. max_float,
  688. max_double,
  689. max_float2,
  690. max_float3,
  691. max_float4,
  692. max_double2,
  693. max_double3,
  694. max_double4,
  695. max_int2,
  696. max_int3,
  697. max_int4,
  698. max_uint2,
  699. max_uint3,
  700. max_uint4,
  701. }
  702. max_int :: proc "c" (x, y: int) -> int { return builtin.max(x, y) }
  703. max_uint :: proc "c" (x, y: uint) -> uint { return builtin.max(x, y) }
  704. max_float :: proc "c" (x, y: float) -> float { return builtin.max(x, y) }
  705. max_double :: proc "c" (x, y: double) -> double { return builtin.max(x, y) }
  706. max_float2 :: proc "c" (x, y: float2) -> float2 { return {max(x.x, y.x), max(x.y, y.y)} }
  707. max_float3 :: proc "c" (x, y: float3) -> float3 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)} }
  708. max_float4 :: proc "c" (x, y: float4) -> float4 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)} }
  709. max_double2 :: proc "c" (x, y: double2) -> double2 { return {max(x.x, y.x), max(x.y, y.y)} }
  710. max_double3 :: proc "c" (x, y: double3) -> double3 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)} }
  711. max_double4 :: proc "c" (x, y: double4) -> double4 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)} }
  712. max_int2 :: proc "c" (x, y: int2) -> int2 { return {max(x.x, y.x), max(x.y, y.y)} }
  713. max_int3 :: proc "c" (x, y: int3) -> int3 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)} }
  714. max_int4 :: proc "c" (x, y: int4) -> int4 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)} }
  715. max_uint2 :: proc "c" (x, y: uint2) -> uint2 { return {max(x.x, y.x), max(x.y, y.y)} }
  716. max_uint3 :: proc "c" (x, y: uint3) -> uint3 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)} }
  717. max_uint4 :: proc "c" (x, y: uint4) -> uint4 { return {max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)} }
  718. clamp :: proc{
  719. clamp_int,
  720. clamp_uint,
  721. clamp_float,
  722. clamp_double,
  723. clamp_float2,
  724. clamp_float3,
  725. clamp_float4,
  726. clamp_double2,
  727. clamp_double3,
  728. clamp_double4,
  729. clamp_int2,
  730. clamp_int3,
  731. clamp_int4,
  732. clamp_uint2,
  733. clamp_uint3,
  734. clamp_uint4,
  735. }
  736. clamp_int :: proc "c" (x, y, z: int) -> int { return builtin.clamp(x, y, z) }
  737. clamp_uint :: proc "c" (x, y, z: uint) -> uint { return builtin.clamp(x, y, z) }
  738. clamp_float :: proc "c" (x, y, z: float) -> float { return builtin.clamp(x, y, z) }
  739. clamp_double :: proc "c" (x, y, z: double) -> double { return builtin.clamp(x, y, z) }
  740. clamp_float2 :: proc "c" (x, y, z: float2) -> float2 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y)} }
  741. clamp_float3 :: proc "c" (x, y, z: float3) -> float3 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z)} }
  742. clamp_float4 :: proc "c" (x, y, z: float4) -> float4 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z), clamp(x.w, y.w, z.w)} }
  743. clamp_double2 :: proc "c" (x, y, z: double2) -> double2 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y)} }
  744. clamp_double3 :: proc "c" (x, y, z: double3) -> double3 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z)} }
  745. clamp_double4 :: proc "c" (x, y, z: double4) -> double4 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z), clamp(x.w, y.w, z.w)} }
  746. clamp_int2 :: proc "c" (x, y, z: int2) -> int2 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y)} }
  747. clamp_int3 :: proc "c" (x, y, z: int3) -> int3 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z)} }
  748. clamp_int4 :: proc "c" (x, y, z: int4) -> int4 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z), clamp(x.w, y.w, z.w)} }
  749. clamp_uint2 :: proc "c" (x, y, z: uint2) -> uint2 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y)} }
  750. clamp_uint3 :: proc "c" (x, y, z: uint3) -> uint3 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z)} }
  751. clamp_uint4 :: proc "c" (x, y, z: uint4) -> uint4 { return {clamp(x.x, y.x, z.x), clamp(x.y, y.y, z.y), clamp(x.z, y.z, z.z), clamp(x.w, y.w, z.w)} }
  752. saturate :: proc{
  753. saturate_int,
  754. saturate_uint,
  755. saturate_float,
  756. saturate_double,
  757. saturate_float2,
  758. saturate_float3,
  759. saturate_float4,
  760. saturate_double2,
  761. saturate_double3,
  762. saturate_double4,
  763. saturate_int2,
  764. saturate_int3,
  765. saturate_int4,
  766. saturate_uint2,
  767. saturate_uint3,
  768. saturate_uint4,
  769. }
  770. saturate_int :: proc "c" (v: int) -> int { return builtin.clamp(v, 0, 1) }
  771. saturate_uint :: proc "c" (v: uint) -> uint { return builtin.clamp(v, 0, 1) }
  772. saturate_float :: proc "c" (v: float) -> float { return builtin.clamp(v, 0, 1) }
  773. saturate_double :: proc "c" (v: double) -> double { return builtin.clamp(v, 0, 1) }
  774. saturate_float2 :: proc "c" (v: float2) -> float2 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1)} }
  775. saturate_float3 :: proc "c" (v: float3) -> float3 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1)} }
  776. saturate_float4 :: proc "c" (v: float4) -> float4 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1), builtin.clamp(v.w, 0, 1)} }
  777. saturate_double2 :: proc "c" (v: double2) -> double2 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1)} }
  778. saturate_double3 :: proc "c" (v: double3) -> double3 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1)} }
  779. saturate_double4 :: proc "c" (v: double4) -> double4 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1), builtin.clamp(v.w, 0, 1)} }
  780. saturate_int2 :: proc "c" (v: int2) -> int2 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1)} }
  781. saturate_int3 :: proc "c" (v: int3) -> int3 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1)} }
  782. saturate_int4 :: proc "c" (v: int4) -> int4 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1), builtin.clamp(v.w, 0, 1)} }
  783. saturate_uint2 :: proc "c" (v: uint2) -> uint2 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1)} }
  784. saturate_uint3 :: proc "c" (v: uint3) -> uint3 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1)} }
  785. saturate_uint4 :: proc "c" (v: uint4) -> uint4 { return {builtin.clamp(v.x, 0, 1), builtin.clamp(v.y, 0, 1), builtin.clamp(v.z, 0, 1), builtin.clamp(v.w, 0, 1)} }
  786. lerp :: proc{
  787. lerp_float,
  788. lerp_double,
  789. lerp_float2,
  790. lerp_float3,
  791. lerp_float4,
  792. lerp_double2,
  793. lerp_double3,
  794. lerp_double4,
  795. }
  796. lerp_float :: proc "c" (x, y, t: float) -> float { return x*(1-t) + y*t }
  797. lerp_double :: proc "c" (x, y, t: double) -> double { return x*(1-t) + y*t }
  798. lerp_float2 :: proc "c" (x, y, t: float2) -> float2 { return {lerp(x.x, y.x, t.x), lerp(x.y, y.y, t.y)} }
  799. lerp_float3 :: proc "c" (x, y, t: float3) -> float3 { return {lerp(x.x, y.x, t.x), lerp(x.y, y.y, t.y), lerp(x.z, y.z, t.z)} }
  800. lerp_float4 :: proc "c" (x, y, t: float4) -> float4 { return {lerp(x.x, y.x, t.x), lerp(x.y, y.y, y.y), lerp(x.z, y.z, t.z), lerp(x.w, y.w, t.w)} }
  801. lerp_double2 :: proc "c" (x, y, t: double2) -> double2 { return {lerp(x.x, y.x, t.x), lerp(x.y, y.y, t.y)} }
  802. lerp_double3 :: proc "c" (x, y, t: double3) -> double3 { return {lerp(x.x, y.x, t.x), lerp(x.y, y.y, t.y), lerp(x.z, y.z, t.z)} }
  803. lerp_double4 :: proc "c" (x, y, t: double4) -> double4 { return {lerp(x.x, y.x, t.x), lerp(x.y, y.y, y.y), lerp(x.z, y.z, t.z), lerp(x.w, y.w, t.w)} }
  804. step :: proc{
  805. step_float,
  806. step_double,
  807. step_float2,
  808. step_float3,
  809. step_float4,
  810. step_double2,
  811. step_double3,
  812. step_double4,
  813. }
  814. step_float :: proc "c" (edge, x: float) -> float { return 0 if x < edge else 1 }
  815. step_double :: proc "c" (edge, x: double) -> double { return 0 if x < edge else 1 }
  816. step_float2 :: proc "c" (edge, x: float2) -> float2 { return {step(edge.x, x.x), step(edge.y, x.y)} }
  817. step_float3 :: proc "c" (edge, x: float3) -> float3 { return {step(edge.x, x.x), step(edge.y, x.y), step(edge.z, x.z)} }
  818. step_float4 :: proc "c" (edge, x: float4) -> float4 { return {step(edge.x, x.x), step(edge.y, x.y), step(edge.z, x.z), step(edge.w, x.w)} }
  819. step_double2 :: proc "c" (edge, x: double2) -> double2 { return {step(edge.x, x.x), step(edge.y, x.y)} }
  820. step_double3 :: proc "c" (edge, x: double3) -> double3 { return {step(edge.x, x.x), step(edge.y, x.y), step(edge.z, x.z)} }
  821. step_double4 :: proc "c" (edge, x: double4) -> double4 { return {step(edge.x, x.x), step(edge.y, x.y), step(edge.z, x.z), step(edge.w, x.w)} }
  822. smoothstep :: proc{
  823. smoothstep_float,
  824. smoothstep_double,
  825. smoothstep_float2,
  826. smoothstep_float3,
  827. smoothstep_float4,
  828. smoothstep_double2,
  829. smoothstep_double3,
  830. smoothstep_double4,
  831. }
  832. smoothstep_float :: proc "c" (edge0, edge1, x: float) -> float {
  833. y := clamp(((x-edge0) / (edge1 - edge0)), 0, 1)
  834. return y * y * (3 - 2*y)
  835. }
  836. smoothstep_double :: proc "c" (edge0, edge1, x: double) -> double {
  837. y := clamp(((x-edge0) / (edge1 - edge0)), 0, 1)
  838. return y * y * (3 - 2*y)
  839. }
  840. smoothstep_float2 :: proc "c" (edge0, edge1, x: float2) -> float2 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y)} }
  841. smoothstep_float3 :: proc "c" (edge0, edge1, x: float3) -> float3 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z)} }
  842. smoothstep_float4 :: proc "c" (edge0, edge1, x: float4) -> float4 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z), smoothstep(edge0.w, edge1.w, x.w)} }
  843. smoothstep_double2 :: proc "c" (edge0, edge1, x: double2) -> double2 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y)} }
  844. smoothstep_double3 :: proc "c" (edge0, edge1, x: double3) -> double3 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z)} }
  845. smoothstep_double4 :: proc "c" (edge0, edge1, x: double4) -> double4 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z), smoothstep(edge0.w, edge1.w, x.w)} }
  846. abs :: proc{
  847. abs_int,
  848. abs_uint,
  849. abs_float,
  850. abs_double,
  851. abs_float2,
  852. abs_float3,
  853. abs_float4,
  854. abs_double2,
  855. abs_double3,
  856. abs_double4,
  857. abs_int2,
  858. abs_int3,
  859. abs_int4,
  860. abs_uint2,
  861. abs_uint3,
  862. abs_uint4,
  863. }
  864. abs_int :: proc "c" (x: int) -> int { return builtin.abs(x) }
  865. abs_uint :: proc "c" (x: uint) -> uint { return x }
  866. abs_float :: proc "c" (x: float) -> float { return builtin.abs(x) }
  867. abs_double :: proc "c" (x: double) -> double { return builtin.abs(x) }
  868. abs_float2 :: proc "c" (x: float2) -> float2 { return {abs(x.x), abs(x.y)} }
  869. abs_float3 :: proc "c" (x: float3) -> float3 { return {abs(x.x), abs(x.y), abs(x.z)} }
  870. abs_float4 :: proc "c" (x: float4) -> float4 { return {abs(x.x), abs(x.y), abs(x.z), abs(x.w)} }
  871. abs_double2 :: proc "c" (x: double2) -> double2 { return {abs(x.x), abs(x.y)} }
  872. abs_double3 :: proc "c" (x: double3) -> double3 { return {abs(x.x), abs(x.y), abs(x.z)} }
  873. abs_double4 :: proc "c" (x: double4) -> double4 { return {abs(x.x), abs(x.y), abs(x.z), abs(x.w)} }
  874. abs_int2 :: proc "c" (x: int2) -> int2 { return {abs(x.x), abs(x.y)} }
  875. abs_int3 :: proc "c" (x: int3) -> int3 { return {abs(x.x), abs(x.y), abs(x.z)} }
  876. abs_int4 :: proc "c" (x: int4) -> int4 { return {abs(x.x), abs(x.y), abs(x.z), abs(x.w)} }
  877. abs_uint2 :: proc "c" (x: uint2) -> uint2 { return x }
  878. abs_uint3 :: proc "c" (x: uint3) -> uint3 { return x }
  879. abs_uint4 :: proc "c" (x: uint4) -> uint4 { return x }
  880. dot :: proc{
  881. dot_int,
  882. dot_uint,
  883. dot_float,
  884. dot_double,
  885. dot_float2,
  886. dot_float3,
  887. dot_float4,
  888. dot_double2,
  889. dot_double3,
  890. dot_double4,
  891. dot_int2,
  892. dot_int3,
  893. dot_int4,
  894. dot_uint2,
  895. dot_uint3,
  896. dot_uint4,
  897. }
  898. dot_int :: proc "c" (a, b: int) -> int { return a*b }
  899. dot_uint :: proc "c" (a, b: uint) -> uint { return a*b }
  900. dot_float :: proc "c" (a, b: float) -> float { return a*b }
  901. dot_double :: proc "c" (a, b: double) -> double { return a*b }
  902. dot_float2 :: proc "c" (a, b: float2) -> float { return a.x*b.x + a.y*b.y }
  903. dot_float3 :: proc "c" (a, b: float3) -> float { return a.x*b.x + a.y*b.y + a.z*b.z }
  904. dot_float4 :: proc "c" (a, b: float4) -> float { return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w }
  905. dot_double2 :: proc "c" (a, b: double2) -> double { return a.x*b.x + a.y*b.y }
  906. dot_double3 :: proc "c" (a, b: double3) -> double { return a.x*b.x + a.y*b.y + a.z*b.z }
  907. dot_double4 :: proc "c" (a, b: double4) -> double { return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w }
  908. dot_int2 :: proc "c" (a, b: int2) -> int { return a.x*b.x + a.y*b.y }
  909. dot_int3 :: proc "c" (a, b: int3) -> int { return a.x*b.x + a.y*b.y + a.z*b.z }
  910. dot_int4 :: proc "c" (a, b: int4) -> int { return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w }
  911. dot_uint2 :: proc "c" (a, b: uint2) -> uint { return a.x*b.x + a.y*b.y }
  912. dot_uint3 :: proc "c" (a, b: uint3) -> uint { return a.x*b.x + a.y*b.y + a.z*b.z }
  913. dot_uint4 :: proc "c" (a, b: uint4) -> uint { return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w }
  914. length :: proc{
  915. length_float,
  916. length_double,
  917. length_float2,
  918. length_float3,
  919. length_float4,
  920. length_double2,
  921. length_double3,
  922. length_double4,
  923. }
  924. length_float :: proc "c" (x: float) -> float { return builtin.abs(x) }
  925. length_double :: proc "c" (x: double) -> double { return builtin.abs(x) }
  926. length_float2 :: proc "c" (x: float2) -> float { return sqrt(x.x*x.x + x.y*x.y) }
  927. length_float3 :: proc "c" (x: float3) -> float { return sqrt(x.x*x.x + x.y*x.y + x.z*x.z) }
  928. length_float4 :: proc "c" (x: float4) -> float { return sqrt(x.x*x.x + x.y*x.y + x.z*x.z + x.w*x.w) }
  929. length_double2 :: proc "c" (x: double2) -> double { return sqrt(x.x*x.x + x.y*x.y) }
  930. length_double3 :: proc "c" (x: double3) -> double { return sqrt(x.x*x.x + x.y*x.y + x.z*x.z) }
  931. length_double4 :: proc "c" (x: double4) -> double { return sqrt(x.x*x.x + x.y*x.y + x.z*x.z + x.w*x.w) }
  932. distance :: proc{
  933. distance_float,
  934. distance_double,
  935. distance_float2,
  936. distance_float3,
  937. distance_float4,
  938. distance_double2,
  939. distance_double3,
  940. distance_double4,
  941. }
  942. distance_float :: proc "c" (x, y: float) -> float { return length(y-x) }
  943. distance_double :: proc "c" (x, y: double) -> double { return length(y-x) }
  944. distance_float2 :: proc "c" (x, y: float2) -> float { return length(y-x) }
  945. distance_float3 :: proc "c" (x, y: float3) -> float { return length(y-x) }
  946. distance_float4 :: proc "c" (x, y: float4) -> float { return length(y-x) }
  947. distance_double2 :: proc "c" (x, y: double2) -> double { return length(y-x) }
  948. distance_double3 :: proc "c" (x, y: double3) -> double { return length(y-x) }
  949. distance_double4 :: proc "c" (x, y: double4) -> double { return length(y-x) }
  950. cross :: proc{
  951. cross_float3,
  952. cross_double3,
  953. cross_int3,
  954. }
  955. cross_float3 :: proc "c" (a, b: float3) -> (c: float3) {
  956. c.x = a.y*b.z - b.y*a.z
  957. c.y = a.z*b.x - b.z*a.x
  958. c.z = a.x*b.y - b.x*a.y
  959. return
  960. }
  961. cross_double3 :: proc "c" (a, b: double3) -> (c: double3) {
  962. c.x = a.y*b.z - b.y*a.z
  963. c.y = a.z*b.x - b.z*a.x
  964. c.z = a.x*b.y - b.x*a.y
  965. return
  966. }
  967. cross_int3 :: proc "c" (a, b: int3) -> (c: int3) {
  968. c.x = a.y*b.z - b.y*a.z
  969. c.y = a.z*b.x - b.z*a.x
  970. c.z = a.x*b.y - b.x*a.y
  971. return
  972. }
  973. normalize :: proc{
  974. normalize_float,
  975. normalize_double,
  976. normalize_float2,
  977. normalize_float3,
  978. normalize_float4,
  979. normalize_double2,
  980. normalize_double3,
  981. normalize_double4,
  982. }
  983. normalize_float :: proc "c" (x: float) -> float { return 1.0 }
  984. normalize_double :: proc "c" (x: double) -> double { return 1.0 }
  985. normalize_float2 :: proc "c" (x: float2) -> float2 { return x / length(x) }
  986. normalize_float3 :: proc "c" (x: float3) -> float3 { return x / length(x) }
  987. normalize_float4 :: proc "c" (x: float4) -> float4 { return x / length(x) }
  988. normalize_double2 :: proc "c" (x: double2) -> double2 { return x / length(x) }
  989. normalize_double3 :: proc "c" (x: double3) -> double3 { return x / length(x) }
  990. normalize_double4 :: proc "c" (x: double4) -> double4 { return x / length(x) }
  991. faceforward :: proc{
  992. faceforward_float,
  993. faceforward_double,
  994. faceforward_float2,
  995. faceforward_float3,
  996. faceforward_float4,
  997. faceforward_double2,
  998. faceforward_double3,
  999. faceforward_double4,
  1000. }
  1001. faceforward_float :: proc "c" (N, I, Nref: float) -> float { return N if dot(I, Nref) < 0 else -N }
  1002. faceforward_double :: proc "c" (N, I, Nref: double) -> double { return N if dot(I, Nref) < 0 else -N }
  1003. faceforward_float2 :: proc "c" (N, I, Nref: float2) -> float2 { return N if dot(I, Nref) < 0 else -N }
  1004. faceforward_float3 :: proc "c" (N, I, Nref: float3) -> float3 { return N if dot(I, Nref) < 0 else -N }
  1005. faceforward_float4 :: proc "c" (N, I, Nref: float4) -> float4 { return N if dot(I, Nref) < 0 else -N }
  1006. faceforward_double2 :: proc "c" (N, I, Nref: double2) -> double2 { return N if dot(I, Nref) < 0 else -N }
  1007. faceforward_double3 :: proc "c" (N, I, Nref: double3) -> double3 { return N if dot(I, Nref) < 0 else -N }
  1008. faceforward_double4 :: proc "c" (N, I, Nref: double4) -> double4 { return N if dot(I, Nref) < 0 else -N }
  1009. reflect :: proc{
  1010. reflect_float,
  1011. reflect_double,
  1012. reflect_float2,
  1013. reflect_float3,
  1014. reflect_float4,
  1015. reflect_double2,
  1016. reflect_double3,
  1017. reflect_double4,
  1018. }
  1019. reflect_float :: proc "c" (I, N: float) -> float { return I - 2*N*dot(N, I) }
  1020. reflect_double :: proc "c" (I, N: double) -> double { return I - 2*N*dot(N, I) }
  1021. reflect_float2 :: proc "c" (I, N: float2) -> float2 { return I - 2*N*dot(N, I) }
  1022. reflect_float3 :: proc "c" (I, N: float3) -> float3 { return I - 2*N*dot(N, I) }
  1023. reflect_float4 :: proc "c" (I, N: float4) -> float4 { return I - 2*N*dot(N, I) }
  1024. reflect_double2 :: proc "c" (I, N: double2) -> double2 { return I - 2*N*dot(N, I) }
  1025. reflect_double3 :: proc "c" (I, N: double3) -> double3 { return I - 2*N*dot(N, I) }
  1026. reflect_double4 :: proc "c" (I, N: double4) -> double4 { return I - 2*N*dot(N, I) }
  1027. refract :: proc{
  1028. refract_float,
  1029. refract_double,
  1030. refract_float2,
  1031. refract_float3,
  1032. refract_float4,
  1033. refract_double2,
  1034. refract_double3,
  1035. refract_double4,
  1036. }
  1037. refract_float :: proc "c" (i, n, eta: float) -> float {
  1038. cosi := dot(-i, n)
  1039. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1040. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1041. return t * float(int(cost2 > 0))
  1042. }
  1043. refract_double :: proc "c" (i, n, eta: double) -> double {
  1044. cosi := dot(-i, n)
  1045. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1046. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1047. return t * double(int(cost2 > 0))
  1048. }
  1049. refract_float2 :: proc "c" (i, n, eta: float2) -> float2 {
  1050. cosi := dot(-i, n)
  1051. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1052. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1053. return t * float2{float(int(cost2.x > 0)), float(int(cost2.y > 0))}
  1054. }
  1055. refract_float3 :: proc "c" (i, n, eta: float3) -> float3 {
  1056. cosi := dot(-i, n)
  1057. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1058. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1059. return t * float3{float(int(cost2.x > 0)), float(int(cost2.y > 0)), float(int(cost2.z > 0))}
  1060. }
  1061. refract_float4 :: proc "c" (i, n, eta: float4) -> float4 {
  1062. cosi := dot(-i, n)
  1063. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1064. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1065. return t * float4{float(int(cost2.x > 0)), float(int(cost2.y > 0)), float(int(cost2.z > 0)), float(int(cost2.w > 0))}
  1066. }
  1067. refract_double2 :: proc "c" (i, n, eta: double2) -> double2 {
  1068. cosi := dot(-i, n)
  1069. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1070. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1071. return t * double2{double(int(cost2.x > 0)), double(int(cost2.y > 0))}
  1072. }
  1073. refract_double3 :: proc "c" (i, n, eta: double3) -> double3 {
  1074. cosi := dot(-i, n)
  1075. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1076. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1077. return t * double3{double(int(cost2.x > 0)), double(int(cost2.y > 0)), double(int(cost2.z > 0))}
  1078. }
  1079. refract_double4 :: proc "c" (i, n, eta: double4) -> double4 {
  1080. cosi := dot(-i, n)
  1081. cost2 := 1 - eta*eta*(1 - cosi*cosi)
  1082. t := eta*i + ((eta*cosi - sqrt(abs(cost2))) * n)
  1083. return t * double4{double(int(cost2.x > 0)), double(int(cost2.y > 0)), double(int(cost2.z > 0)), double(int(cost2.w > 0))}
  1084. }
  1085. scalarTripleProduct :: proc{
  1086. scalarTripleProduct_float3,
  1087. scalarTripleProduct_double3,
  1088. scalarTripleProduct_int3,
  1089. }
  1090. scalarTripleProduct_float3 :: proc "c" (a, b, c: float3) -> float { return dot(a, cross(b, c)) }
  1091. scalarTripleProduct_double3 :: proc "c" (a, b, c: double3) -> double { return dot(a, cross(b, c)) }
  1092. scalarTripleProduct_int3 :: proc "c" (a, b, c: int3) -> int { return dot(a, cross(b, c)) }
  1093. vectorTripleProduct :: proc {
  1094. vectorTripleProduct_float3,
  1095. vectorTripleProduct_double3,
  1096. vectorTripleProduct_int3,
  1097. }
  1098. vectorTripleProduct_float3 :: proc "c" (a, b, c: float3) -> float3 { return cross(a, cross(b, c)) }
  1099. vectorTripleProduct_double3 :: proc "c" (a, b, c: double3) -> double3 { return cross(a, cross(b, c)) }
  1100. vectorTripleProduct_int3 :: proc "c" (a, b, c: int3) -> int3 { return cross(a, cross(b, c)) }
  1101. // Vector Relational Procedures
  1102. lessThan :: proc{
  1103. lessThan_float,
  1104. lessThan_double,
  1105. lessThan_int,
  1106. lessThan_uint,
  1107. lessThan_float2,
  1108. lessThan_double2,
  1109. lessThan_int2,
  1110. lessThan_uint2,
  1111. lessThan_float3,
  1112. lessThan_double3,
  1113. lessThan_int3,
  1114. lessThan_uint3,
  1115. lessThan_float4,
  1116. lessThan_double4,
  1117. lessThan_int4,
  1118. lessThan_uint4,
  1119. }
  1120. lessThan_float :: proc "c" (a, b: float) -> bool { return a < b }
  1121. lessThan_double :: proc "c" (a, b: double) -> bool { return a < b }
  1122. lessThan_int :: proc "c" (a, b: int) -> bool { return a < b }
  1123. lessThan_uint :: proc "c" (a, b: uint) -> bool { return a < b }
  1124. lessThan_float2 :: proc "c" (a, b: float2) -> bool2 { return {a.x < b.x, a.y < b.y} }
  1125. lessThan_double2 :: proc "c" (a, b: double2) -> bool2 { return {a.x < b.x, a.y < b.y} }
  1126. lessThan_int2 :: proc "c" (a, b: int2) -> bool2 { return {a.x < b.x, a.y < b.y} }
  1127. lessThan_uint2 :: proc "c" (a, b: uint2) -> bool2 { return {a.x < b.x, a.y < b.y} }
  1128. lessThan_float3 :: proc "c" (a, b: float3) -> bool3 { return {a.x < b.x, a.y < b.y, a.z < b.z} }
  1129. lessThan_double3 :: proc "c" (a, b: double3) -> bool3 { return {a.x < b.x, a.y < b.y, a.z < b.z} }
  1130. lessThan_int3 :: proc "c" (a, b: int3) -> bool3 { return {a.x < b.x, a.y < b.y, a.z < b.z} }
  1131. lessThan_uint3 :: proc "c" (a, b: uint3) -> bool3 { return {a.x < b.x, a.y < b.y, a.z < b.z} }
  1132. lessThan_float4 :: proc "c" (a, b: float4) -> bool4 { return {a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w} }
  1133. lessThan_double4 :: proc "c" (a, b: double4) -> bool4 { return {a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w} }
  1134. lessThan_int4 :: proc "c" (a, b: int4) -> bool4 { return {a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w} }
  1135. lessThan_uint4 :: proc "c" (a, b: uint4) -> bool4 { return {a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w} }
  1136. lessThanEqual :: proc{
  1137. lessThanEqual_float,
  1138. lessThanEqual_double,
  1139. lessThanEqual_int,
  1140. lessThanEqual_uint,
  1141. lessThanEqual_float2,
  1142. lessThanEqual_double2,
  1143. lessThanEqual_int2,
  1144. lessThanEqual_uint2,
  1145. lessThanEqual_float3,
  1146. lessThanEqual_double3,
  1147. lessThanEqual_int3,
  1148. lessThanEqual_uint3,
  1149. lessThanEqual_float4,
  1150. lessThanEqual_double4,
  1151. lessThanEqual_int4,
  1152. lessThanEqual_uint4,
  1153. }
  1154. lessThanEqual_float :: proc "c" (a, b: float) -> bool { return a <= b }
  1155. lessThanEqual_double :: proc "c" (a, b: double) -> bool { return a <= b }
  1156. lessThanEqual_int :: proc "c" (a, b: int) -> bool { return a <= b }
  1157. lessThanEqual_uint :: proc "c" (a, b: uint) -> bool { return a <= b }
  1158. lessThanEqual_float2 :: proc "c" (a, b: float2) -> bool2 { return {a.x <= b.x, a.y <= b.y} }
  1159. lessThanEqual_double2 :: proc "c" (a, b: double2) -> bool2 { return {a.x <= b.x, a.y <= b.y} }
  1160. lessThanEqual_int2 :: proc "c" (a, b: int2) -> bool2 { return {a.x <= b.x, a.y <= b.y} }
  1161. lessThanEqual_uint2 :: proc "c" (a, b: uint2) -> bool2 { return {a.x <= b.x, a.y <= b.y} }
  1162. lessThanEqual_float3 :: proc "c" (a, b: float3) -> bool3 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z} }
  1163. lessThanEqual_double3 :: proc "c" (a, b: double3) -> bool3 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z} }
  1164. lessThanEqual_int3 :: proc "c" (a, b: int3) -> bool3 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z} }
  1165. lessThanEqual_uint3 :: proc "c" (a, b: uint3) -> bool3 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z} }
  1166. lessThanEqual_float4 :: proc "c" (a, b: float4) -> bool4 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w} }
  1167. lessThanEqual_double4 :: proc "c" (a, b: double4) -> bool4 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w} }
  1168. lessThanEqual_int4 :: proc "c" (a, b: int4) -> bool4 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w} }
  1169. lessThanEqual_uint4 :: proc "c" (a, b: uint4) -> bool4 { return {a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w} }
  1170. greaterThan :: proc{
  1171. greaterThan_float,
  1172. greaterThan_double,
  1173. greaterThan_int,
  1174. greaterThan_uint,
  1175. greaterThan_float2,
  1176. greaterThan_double2,
  1177. greaterThan_int2,
  1178. greaterThan_uint2,
  1179. greaterThan_float3,
  1180. greaterThan_double3,
  1181. greaterThan_int3,
  1182. greaterThan_uint3,
  1183. greaterThan_float4,
  1184. greaterThan_double4,
  1185. greaterThan_int4,
  1186. greaterThan_uint4,
  1187. }
  1188. greaterThan_float :: proc "c" (a, b: float) -> bool { return a > b }
  1189. greaterThan_double :: proc "c" (a, b: double) -> bool { return a > b }
  1190. greaterThan_int :: proc "c" (a, b: int) -> bool { return a > b }
  1191. greaterThan_uint :: proc "c" (a, b: uint) -> bool { return a > b }
  1192. greaterThan_float2 :: proc "c" (a, b: float2) -> bool2 { return {a.x > b.x, a.y > b.y} }
  1193. greaterThan_double2 :: proc "c" (a, b: double2) -> bool2 { return {a.x > b.x, a.y > b.y} }
  1194. greaterThan_int2 :: proc "c" (a, b: int2) -> bool2 { return {a.x > b.x, a.y > b.y} }
  1195. greaterThan_uint2 :: proc "c" (a, b: uint2) -> bool2 { return {a.x > b.x, a.y > b.y} }
  1196. greaterThan_float3 :: proc "c" (a, b: float3) -> bool3 { return {a.x > b.x, a.y > b.y, a.z > b.z} }
  1197. greaterThan_double3 :: proc "c" (a, b: double3) -> bool3 { return {a.x > b.x, a.y > b.y, a.z > b.z} }
  1198. greaterThan_int3 :: proc "c" (a, b: int3) -> bool3 { return {a.x > b.x, a.y > b.y, a.z > b.z} }
  1199. greaterThan_uint3 :: proc "c" (a, b: uint3) -> bool3 { return {a.x > b.x, a.y > b.y, a.z > b.z} }
  1200. greaterThan_float4 :: proc "c" (a, b: float4) -> bool4 { return {a.x > b.x, a.y > b.y, a.z > b.z, a.w > b.w} }
  1201. greaterThan_double4 :: proc "c" (a, b: double4) -> bool4 { return {a.x > b.x, a.y > b.y, a.z > b.z, a.w > b.w} }
  1202. greaterThan_int4 :: proc "c" (a, b: int4) -> bool4 { return {a.x > b.x, a.y > b.y, a.z > b.z, a.w > b.w} }
  1203. greaterThan_uint4 :: proc "c" (a, b: uint4) -> bool4 { return {a.x > b.x, a.y > b.y, a.z > b.z, a.w > b.w} }
  1204. greaterThanEqual :: proc{
  1205. greaterThanEqual_float,
  1206. greaterThanEqual_double,
  1207. greaterThanEqual_int,
  1208. greaterThanEqual_uint,
  1209. greaterThanEqual_float2,
  1210. greaterThanEqual_double2,
  1211. greaterThanEqual_int2,
  1212. greaterThanEqual_uint2,
  1213. greaterThanEqual_float3,
  1214. greaterThanEqual_double3,
  1215. greaterThanEqual_int3,
  1216. greaterThanEqual_uint3,
  1217. greaterThanEqual_float4,
  1218. greaterThanEqual_double4,
  1219. greaterThanEqual_int4,
  1220. greaterThanEqual_uint4,
  1221. }
  1222. greaterThanEqual_float :: proc "c" (a, b: float) -> bool { return a >= b }
  1223. greaterThanEqual_double :: proc "c" (a, b: double) -> bool { return a >= b }
  1224. greaterThanEqual_int :: proc "c" (a, b: int) -> bool { return a >= b }
  1225. greaterThanEqual_uint :: proc "c" (a, b: uint) -> bool { return a >= b }
  1226. greaterThanEqual_float2 :: proc "c" (a, b: float2) -> bool2 { return {a.x >= b.x, a.y >= b.y} }
  1227. greaterThanEqual_double2 :: proc "c" (a, b: double2) -> bool2 { return {a.x >= b.x, a.y >= b.y} }
  1228. greaterThanEqual_int2 :: proc "c" (a, b: int2) -> bool2 { return {a.x >= b.x, a.y >= b.y} }
  1229. greaterThanEqual_uint2 :: proc "c" (a, b: uint2) -> bool2 { return {a.x >= b.x, a.y >= b.y} }
  1230. greaterThanEqual_float3 :: proc "c" (a, b: float3) -> bool3 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z} }
  1231. greaterThanEqual_double3 :: proc "c" (a, b: double3) -> bool3 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z} }
  1232. greaterThanEqual_int3 :: proc "c" (a, b: int3) -> bool3 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z} }
  1233. greaterThanEqual_uint3 :: proc "c" (a, b: uint3) -> bool3 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z} }
  1234. greaterThanEqual_float4 :: proc "c" (a, b: float4) -> bool4 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w} }
  1235. greaterThanEqual_double4 :: proc "c" (a, b: double4) -> bool4 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w} }
  1236. greaterThanEqual_int4 :: proc "c" (a, b: int4) -> bool4 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w} }
  1237. greaterThanEqual_uint4 :: proc "c" (a, b: uint4) -> bool4 { return {a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w} }
  1238. equal :: proc{
  1239. equal_float,
  1240. equal_double,
  1241. equal_int,
  1242. equal_uint,
  1243. equal_float2,
  1244. equal_double2,
  1245. equal_int2,
  1246. equal_uint2,
  1247. equal_float3,
  1248. equal_double3,
  1249. equal_int3,
  1250. equal_uint3,
  1251. equal_float4,
  1252. equal_double4,
  1253. equal_int4,
  1254. equal_uint4,
  1255. }
  1256. equal_float :: proc "c" (a, b: float) -> bool { return a == b }
  1257. equal_double :: proc "c" (a, b: double) -> bool { return a == b }
  1258. equal_int :: proc "c" (a, b: int) -> bool { return a == b }
  1259. equal_uint :: proc "c" (a, b: uint) -> bool { return a == b }
  1260. equal_float2 :: proc "c" (a, b: float2) -> bool2 { return {a.x == b.x, a.y == b.y} }
  1261. equal_double2 :: proc "c" (a, b: double2) -> bool2 { return {a.x == b.x, a.y == b.y} }
  1262. equal_int2 :: proc "c" (a, b: int2) -> bool2 { return {a.x == b.x, a.y == b.y} }
  1263. equal_uint2 :: proc "c" (a, b: uint2) -> bool2 { return {a.x == b.x, a.y == b.y} }
  1264. equal_float3 :: proc "c" (a, b: float3) -> bool3 { return {a.x == b.x, a.y == b.y, a.z == b.z} }
  1265. equal_double3 :: proc "c" (a, b: double3) -> bool3 { return {a.x == b.x, a.y == b.y, a.z == b.z} }
  1266. equal_int3 :: proc "c" (a, b: int3) -> bool3 { return {a.x == b.x, a.y == b.y, a.z == b.z} }
  1267. equal_uint3 :: proc "c" (a, b: uint3) -> bool3 { return {a.x == b.x, a.y == b.y, a.z == b.z} }
  1268. equal_float4 :: proc "c" (a, b: float4) -> bool4 { return {a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w} }
  1269. equal_double4 :: proc "c" (a, b: double4) -> bool4 { return {a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w} }
  1270. equal_int4 :: proc "c" (a, b: int4) -> bool4 { return {a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w} }
  1271. equal_uint4 :: proc "c" (a, b: uint4) -> bool4 { return {a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w} }
  1272. notEqual :: proc{
  1273. notEqual_float,
  1274. notEqual_double,
  1275. notEqual_int,
  1276. notEqual_uint,
  1277. notEqual_float2,
  1278. notEqual_double2,
  1279. notEqual_int2,
  1280. notEqual_uint2,
  1281. notEqual_float3,
  1282. notEqual_double3,
  1283. notEqual_int3,
  1284. notEqual_uint3,
  1285. notEqual_float4,
  1286. notEqual_double4,
  1287. notEqual_int4,
  1288. notEqual_uint4,
  1289. }
  1290. notEqual_float :: proc "c" (a, b: float) -> bool { return a != b }
  1291. notEqual_double :: proc "c" (a, b: double) -> bool { return a != b }
  1292. notEqual_int :: proc "c" (a, b: int) -> bool { return a != b }
  1293. notEqual_uint :: proc "c" (a, b: uint) -> bool { return a != b }
  1294. notEqual_float2 :: proc "c" (a, b: float2) -> bool2 { return {a.x != b.x, a.y != b.y} }
  1295. notEqual_double2 :: proc "c" (a, b: double2) -> bool2 { return {a.x != b.x, a.y != b.y} }
  1296. notEqual_int2 :: proc "c" (a, b: int2) -> bool2 { return {a.x != b.x, a.y != b.y} }
  1297. notEqual_uint2 :: proc "c" (a, b: uint2) -> bool2 { return {a.x != b.x, a.y != b.y} }
  1298. notEqual_float3 :: proc "c" (a, b: float3) -> bool3 { return {a.x != b.x, a.y != b.y, a.z != b.z} }
  1299. notEqual_double3 :: proc "c" (a, b: double3) -> bool3 { return {a.x != b.x, a.y != b.y, a.z != b.z} }
  1300. notEqual_int3 :: proc "c" (a, b: int3) -> bool3 { return {a.x != b.x, a.y != b.y, a.z != b.z} }
  1301. notEqual_uint3 :: proc "c" (a, b: uint3) -> bool3 { return {a.x != b.x, a.y != b.y, a.z != b.z} }
  1302. notEqual_float4 :: proc "c" (a, b: float4) -> bool4 { return {a.x != b.x, a.y != b.y, a.z != b.z, a.w != b.w} }
  1303. notEqual_double4 :: proc "c" (a, b: double4) -> bool4 { return {a.x != b.x, a.y != b.y, a.z != b.z, a.w != b.w} }
  1304. notEqual_int4 :: proc "c" (a, b: int4) -> bool4 { return {a.x != b.x, a.y != b.y, a.z != b.z, a.w != b.w} }
  1305. notEqual_uint4 :: proc "c" (a, b: uint4) -> bool4 { return {a.x != b.x, a.y != b.y, a.z != b.z, a.w != b.w} }
  1306. any :: proc{
  1307. any_bool,
  1308. any_bool2,
  1309. any_bool3,
  1310. any_bool4,
  1311. }
  1312. any_bool :: proc "c" (v: bool) -> bool { return v }
  1313. any_bool2 :: proc "c" (v: bool2) -> bool { return v.x || v.y }
  1314. any_bool3 :: proc "c" (v: bool3) -> bool { return v.x || v.y || v.z }
  1315. any_bool4 :: proc "c" (v: bool4) -> bool { return v.x || v.y || v.z || v.w }
  1316. all :: proc{
  1317. all_bool,
  1318. all_bool2,
  1319. all_bool3,
  1320. all_bool4,
  1321. }
  1322. all_bool :: proc "c" (v: bool) -> bool { return v }
  1323. all_bool2 :: proc "c" (v: bool2) -> bool { return v.x && v.y }
  1324. all_bool3 :: proc "c" (v: bool3) -> bool { return v.x && v.y && v.z }
  1325. all_bool4 :: proc "c" (v: bool4) -> bool { return v.x && v.y && v.z && v.w }
  1326. not :: proc{
  1327. not_bool,
  1328. not_bool2,
  1329. not_bool3,
  1330. not_bool4,
  1331. }
  1332. not_bool :: proc "c" (v: bool) -> bool { return !v }
  1333. not_bool2 :: proc "c" (v: bool2) -> bool2 { return {!v.x, !v.y} }
  1334. not_bool3 :: proc "c" (v: bool3) -> bool3 { return {!v.x, !v.y, !v.z} }
  1335. not_bool4 :: proc "c" (v: bool4) -> bool4 { return {!v.x, !v.y, !v.z, !v.w} }
  1336. inverse_float1x1 :: proc "c" (m: float1x1) -> float1x1 { return builtin.inverse(m) }
  1337. inverse_float2x2 :: proc "c" (m: float2x2) -> float2x2 { return builtin.inverse(m) }
  1338. inverse_float3x3 :: proc "c" (m: float3x3) -> float3x3 { return builtin.inverse(m) }
  1339. inverse_float4x4 :: proc "c" (m: float4x4) -> float4x4 { return builtin.inverse(m) }
  1340. inverse_double1x1 :: proc "c" (m: double1x1) -> double1x1 { return builtin.inverse(m) }
  1341. inverse_double2x2 :: proc "c" (m: double2x2) -> double2x2 { return builtin.inverse(m) }
  1342. inverse_double3x3 :: proc "c" (m: double3x3) -> double3x3 { return builtin.inverse(m) }
  1343. inverse_double4x4 :: proc "c" (m: double4x4) -> double4x4 { return builtin.inverse(m) }
  1344. inverse :: proc{
  1345. inverse_float1x1,
  1346. inverse_float2x2,
  1347. inverse_float3x3,
  1348. inverse_float4x4,
  1349. inverse_double1x1,
  1350. inverse_double2x2,
  1351. inverse_double3x3,
  1352. inverse_double4x4,
  1353. }
  1354. transpose :: builtin.transpose
  1355. inverse_transpose :: builtin.inverse_transpose
  1356. adjugate :: builtin.adjugate
  1357. hermitian_adjoint :: builtin.hermitian_adjoint
  1358. minor :: builtin.matrix_minor
  1359. determinant :: builtin.determinant
  1360. trace :: builtin.matrix_trace
  1361. asfloat :: proc{
  1362. asfloat_float,
  1363. asfloat_double,
  1364. asfloat_int,
  1365. asfloat_uint,
  1366. asfloat_float1x1,
  1367. asfloat_float2x2,
  1368. asfloat_float3x3,
  1369. asfloat_float4x4,
  1370. asfloat_float1x2,
  1371. asfloat_float1x3,
  1372. asfloat_float1x4,
  1373. asfloat_float2x1,
  1374. asfloat_float2x3,
  1375. asfloat_float2x4,
  1376. asfloat_float3x1,
  1377. asfloat_float3x2,
  1378. asfloat_float3x4,
  1379. asfloat_float4x1,
  1380. asfloat_float4x2,
  1381. asfloat_float4x3,
  1382. asfloat_float2,
  1383. asfloat_float3,
  1384. asfloat_float4,
  1385. asfloat_int2,
  1386. asfloat_int3,
  1387. asfloat_int4,
  1388. asfloat_uint2,
  1389. asfloat_uint3,
  1390. asfloat_uint4,
  1391. asfloat_bool2,
  1392. asfloat_bool3,
  1393. asfloat_bool4,
  1394. asfloat_double1x1,
  1395. asfloat_double2x2,
  1396. asfloat_double3x3,
  1397. asfloat_double4x4,
  1398. asfloat_double1x2,
  1399. asfloat_double1x3,
  1400. asfloat_double1x4,
  1401. asfloat_double2x1,
  1402. asfloat_double2x3,
  1403. asfloat_double2x4,
  1404. asfloat_double3x1,
  1405. asfloat_double3x2,
  1406. asfloat_double3x4,
  1407. asfloat_double4x1,
  1408. asfloat_double4x2,
  1409. asfloat_double4x3,
  1410. asfloat_double2,
  1411. asfloat_double3,
  1412. asfloat_double4,
  1413. }
  1414. asfloat_float :: proc "c" (v: float) -> float { return float(v) }
  1415. asfloat_double :: proc "c" (v: double) -> float { return float(v) }
  1416. asfloat_int :: proc "c" (v: int) -> float { return float(v) }
  1417. asfloat_uint :: proc "c" (v: uint) -> float { return float(v) }
  1418. asfloat_float1x1 :: proc "c" (v: float1x1) -> float1x1 { return float1x1(v) }
  1419. asfloat_float2x2 :: proc "c" (v: float2x2) -> float2x2 { return float2x2(v) }
  1420. asfloat_float3x3 :: proc "c" (v: float3x3) -> float3x3 { return float3x3(v) }
  1421. asfloat_float4x4 :: proc "c" (v: float4x4) -> float4x4 { return float4x4(v) }
  1422. asfloat_float1x2 :: proc "c" (v: float1x2) -> float1x2 { return float1x2(v) }
  1423. asfloat_float1x3 :: proc "c" (v: float1x3) -> float1x3 { return float1x3(v) }
  1424. asfloat_float1x4 :: proc "c" (v: float1x4) -> float1x4 { return float1x4(v) }
  1425. asfloat_float2x1 :: proc "c" (v: float2x1) -> float2x1 { return float2x1(v) }
  1426. asfloat_float2x3 :: proc "c" (v: float2x3) -> float2x3 { return float2x3(v) }
  1427. asfloat_float2x4 :: proc "c" (v: float2x4) -> float2x4 { return float2x4(v) }
  1428. asfloat_float3x1 :: proc "c" (v: float3x1) -> float3x1 { return float3x1(v) }
  1429. asfloat_float3x2 :: proc "c" (v: float3x2) -> float3x2 { return float3x2(v) }
  1430. asfloat_float3x4 :: proc "c" (v: float3x4) -> float3x4 { return float3x4(v) }
  1431. asfloat_float4x1 :: proc "c" (v: float4x1) -> float4x1 { return float4x1(v) }
  1432. asfloat_float4x2 :: proc "c" (v: float4x2) -> float4x2 { return float4x2(v) }
  1433. asfloat_float4x3 :: proc "c" (v: float4x3) -> float4x3 { return float4x3(v) }
  1434. asfloat_float2 :: proc "c" (v: float2) -> float2 { return float2(v) }
  1435. asfloat_float3 :: proc "c" (v: float3) -> float3 { return float3(v) }
  1436. asfloat_float4 :: proc "c" (v: float4) -> float4 { return float4(v) }
  1437. asfloat_int2 :: proc "c" (v: int2) -> float2 { return float2{float(v.x), float(v.y)} }
  1438. asfloat_int3 :: proc "c" (v: int3) -> float3 { return float3{float(v.x), float(v.y), float(v.z)} }
  1439. asfloat_int4 :: proc "c" (v: int4) -> float4 { return float4{float(v.x), float(v.y), float(v.z), float(v.w)} }
  1440. asfloat_uint2 :: proc "c" (v: uint2) -> float2 { return float2{float(v.x), float(v.y)} }
  1441. asfloat_uint3 :: proc "c" (v: uint3) -> float3 { return float3{float(v.x), float(v.y), float(v.z)} }
  1442. asfloat_uint4 :: proc "c" (v: uint4) -> float4 { return float4{float(v.x), float(v.y), float(v.z), float(v.w)} }
  1443. asfloat_bool2 :: proc "c" (v: bool2) -> float2 { return float2{float(int(v.x)), float(int(v.y))} }
  1444. asfloat_bool3 :: proc "c" (v: bool3) -> float3 { return float3{float(int(v.x)), float(int(v.y)), float(int(v.z))} }
  1445. asfloat_bool4 :: proc "c" (v: bool4) -> float4 { return float4{float(int(v.x)), float(int(v.y)), float(int(v.z)), float(int(v.w))} }
  1446. asfloat_double1x1 :: proc "c" (v: double1x1) -> float1x1 { return float1x1(v) }
  1447. asfloat_double2x2 :: proc "c" (v: double2x2) -> float2x2 { return float2x2(v) }
  1448. asfloat_double3x3 :: proc "c" (v: double3x3) -> float3x3 { return float3x3(v) }
  1449. asfloat_double4x4 :: proc "c" (v: double4x4) -> float4x4 { return float4x4(v) }
  1450. asfloat_double1x2 :: proc "c" (v: double1x2) -> float1x2 { return float1x2(v) }
  1451. asfloat_double1x3 :: proc "c" (v: double1x3) -> float1x3 { return float1x3(v) }
  1452. asfloat_double1x4 :: proc "c" (v: double1x4) -> float1x4 { return float1x4(v) }
  1453. asfloat_double2x1 :: proc "c" (v: double2x1) -> float2x1 { return float2x1(v) }
  1454. asfloat_double2x3 :: proc "c" (v: double2x3) -> float2x3 { return float2x3(v) }
  1455. asfloat_double2x4 :: proc "c" (v: double2x4) -> float2x4 { return float2x4(v) }
  1456. asfloat_double3x1 :: proc "c" (v: double3x1) -> float3x1 { return float3x1(v) }
  1457. asfloat_double3x2 :: proc "c" (v: double3x2) -> float3x2 { return float3x2(v) }
  1458. asfloat_double3x4 :: proc "c" (v: double3x4) -> float3x4 { return float3x4(v) }
  1459. asfloat_double4x1 :: proc "c" (v: double4x1) -> float4x1 { return float4x1(v) }
  1460. asfloat_double4x2 :: proc "c" (v: double4x2) -> float4x2 { return float4x2(v) }
  1461. asfloat_double4x3 :: proc "c" (v: double4x3) -> float4x3 { return float4x3(v) }
  1462. asfloat_double2 :: proc "c" (v: double2) -> float2 { return float2{float(v.x), float(v.y)} }
  1463. asfloat_double3 :: proc "c" (v: double3) -> float3 { return float3{float(v.x), float(v.y), float(v.z)} }
  1464. asfloat_double4 :: proc "c" (v: double4) -> float4 { return float4{float(v.x), float(v.y), float(v.z), float(v.w)} }
  1465. asdouble :: proc{
  1466. asdouble_float,
  1467. asdouble_double,
  1468. asdouble_int,
  1469. asdouble_uint,
  1470. asdouble_float1x1,
  1471. asdouble_float2x2,
  1472. asdouble_float3x3,
  1473. asdouble_float4x4,
  1474. asdouble_float1x2,
  1475. asdouble_float1x3,
  1476. asdouble_float1x4,
  1477. asdouble_float2x1,
  1478. asdouble_float2x3,
  1479. asdouble_float2x4,
  1480. asdouble_float3x1,
  1481. asdouble_float3x2,
  1482. asdouble_float3x4,
  1483. asdouble_float4x1,
  1484. asdouble_float4x2,
  1485. asdouble_float4x3,
  1486. asdouble_float2,
  1487. asdouble_float3,
  1488. asdouble_float4,
  1489. asdouble_int2,
  1490. asdouble_int3,
  1491. asdouble_int4,
  1492. asdouble_uint2,
  1493. asdouble_uint3,
  1494. asdouble_uint4,
  1495. asdouble_bool2,
  1496. asdouble_bool3,
  1497. asdouble_bool4,
  1498. asdouble_double1x1,
  1499. asdouble_double2x2,
  1500. asdouble_double3x3,
  1501. asdouble_double4x4,
  1502. asdouble_double1x2,
  1503. asdouble_double1x3,
  1504. asdouble_double1x4,
  1505. asdouble_double2x1,
  1506. asdouble_double2x3,
  1507. asdouble_double2x4,
  1508. asdouble_double3x1,
  1509. asdouble_double3x2,
  1510. asdouble_double3x4,
  1511. asdouble_double4x1,
  1512. asdouble_double4x2,
  1513. asdouble_double4x3,
  1514. asdouble_double2,
  1515. asdouble_double3,
  1516. asdouble_double4,
  1517. }
  1518. asdouble_float :: proc "c" (v: float) -> double { return double(v) }
  1519. asdouble_double :: proc "c" (v: double) -> double { return double(v) }
  1520. asdouble_int :: proc "c" (v: int) -> double { return double(v) }
  1521. asdouble_uint :: proc "c" (v: uint) -> double { return double(v) }
  1522. asdouble_float1x1 :: proc "c" (v: float1x1) -> double1x1 { return double1x1(v) }
  1523. asdouble_float2x2 :: proc "c" (v: float2x2) -> double2x2 { return double2x2(v) }
  1524. asdouble_float3x3 :: proc "c" (v: float3x3) -> double3x3 { return double3x3(v) }
  1525. asdouble_float4x4 :: proc "c" (v: float4x4) -> double4x4 { return double4x4(v) }
  1526. asdouble_float1x2 :: proc "c" (v: float1x2) -> double1x2 { return double1x2(v) }
  1527. asdouble_float1x3 :: proc "c" (v: float1x3) -> double1x3 { return double1x3(v) }
  1528. asdouble_float1x4 :: proc "c" (v: float1x4) -> double1x4 { return double1x4(v) }
  1529. asdouble_float2x1 :: proc "c" (v: float2x1) -> double2x1 { return double2x1(v) }
  1530. asdouble_float2x3 :: proc "c" (v: float2x3) -> double2x3 { return double2x3(v) }
  1531. asdouble_float2x4 :: proc "c" (v: float2x4) -> double2x4 { return double2x4(v) }
  1532. asdouble_float3x1 :: proc "c" (v: float3x1) -> double3x1 { return double3x1(v) }
  1533. asdouble_float3x2 :: proc "c" (v: float3x2) -> double3x2 { return double3x2(v) }
  1534. asdouble_float3x4 :: proc "c" (v: float3x4) -> double3x4 { return double3x4(v) }
  1535. asdouble_float4x1 :: proc "c" (v: float4x1) -> double4x1 { return double4x1(v) }
  1536. asdouble_float4x2 :: proc "c" (v: float4x2) -> double4x2 { return double4x2(v) }
  1537. asdouble_float4x3 :: proc "c" (v: float4x3) -> double4x3 { return double4x3(v) }
  1538. asdouble_float2 :: proc "c" (v: float2) -> double2 { return double2{double(v.x), double(v.y)} }
  1539. asdouble_float3 :: proc "c" (v: float3) -> double3 { return double3{double(v.x), double(v.y), double(v.z)} }
  1540. asdouble_float4 :: proc "c" (v: float4) -> double4 { return double4{double(v.x), double(v.y), double(v.z), double(v.w)} }
  1541. asdouble_int2 :: proc "c" (v: int2) -> double2 { return double2{double(v.x), double(v.y)} }
  1542. asdouble_int3 :: proc "c" (v: int3) -> double3 { return double3{double(v.x), double(v.y), double(v.z)} }
  1543. asdouble_int4 :: proc "c" (v: int4) -> double4 { return double4{double(v.x), double(v.y), double(v.z), double(v.w)} }
  1544. asdouble_uint2 :: proc "c" (v: uint2) -> double2 { return double2{double(v.x), double(v.y)} }
  1545. asdouble_uint3 :: proc "c" (v: uint3) -> double3 { return double3{double(v.x), double(v.y), double(v.z)} }
  1546. asdouble_uint4 :: proc "c" (v: uint4) -> double4 { return double4{double(v.x), double(v.y), double(v.z), double(v.w)} }
  1547. asdouble_bool2 :: proc "c" (v: bool2) -> double2 { return double2{double(int(v.x)), double(int(v.y))} }
  1548. asdouble_bool3 :: proc "c" (v: bool3) -> double3 { return double3{double(int(v.x)), double(int(v.y)), double(int(v.z))} }
  1549. asdouble_bool4 :: proc "c" (v: bool4) -> double4 { return double4{double(int(v.x)), double(int(v.y)), double(int(v.z)), double(int(v.w))} }
  1550. asdouble_double1x1 :: proc "c" (v: double1x1) -> double1x1 { return double1x1(v) }
  1551. asdouble_double2x2 :: proc "c" (v: double2x2) -> double2x2 { return double2x2(v) }
  1552. asdouble_double3x3 :: proc "c" (v: double3x3) -> double3x3 { return double3x3(v) }
  1553. asdouble_double4x4 :: proc "c" (v: double4x4) -> double4x4 { return double4x4(v) }
  1554. asdouble_double1x2 :: proc "c" (v: double1x2) -> double1x2 { return double1x2(v) }
  1555. asdouble_double1x3 :: proc "c" (v: double1x3) -> double1x3 { return double1x3(v) }
  1556. asdouble_double1x4 :: proc "c" (v: double1x4) -> double1x4 { return double1x4(v) }
  1557. asdouble_double2x1 :: proc "c" (v: double2x1) -> double2x1 { return double2x1(v) }
  1558. asdouble_double2x3 :: proc "c" (v: double2x3) -> double2x3 { return double2x3(v) }
  1559. asdouble_double2x4 :: proc "c" (v: double2x4) -> double2x4 { return double2x4(v) }
  1560. asdouble_double3x1 :: proc "c" (v: double3x1) -> double3x1 { return double3x1(v) }
  1561. asdouble_double3x2 :: proc "c" (v: double3x2) -> double3x2 { return double3x2(v) }
  1562. asdouble_double3x4 :: proc "c" (v: double3x4) -> double3x4 { return double3x4(v) }
  1563. asdouble_double4x1 :: proc "c" (v: double4x1) -> double4x1 { return double4x1(v) }
  1564. asdouble_double4x2 :: proc "c" (v: double4x2) -> double4x2 { return double4x2(v) }
  1565. asdouble_double4x3 :: proc "c" (v: double4x3) -> double4x3 { return double4x3(v) }
  1566. asdouble_double2 :: proc "c" (v: double2) -> double2 { return double2{double(v.x), double(v.y)} }
  1567. asdouble_double3 :: proc "c" (v: double3) -> double3 { return double3{double(v.x), double(v.y), double(v.z)} }
  1568. asdouble_double4 :: proc "c" (v: double4) -> double4 { return double4{double(v.x), double(v.y), double(v.z), double(v.w)} }
  1569. asint :: proc{
  1570. asint_float,
  1571. asint_double,
  1572. asint_int,
  1573. asint_uint,
  1574. asint_float1x1,
  1575. asint_float2x2,
  1576. asint_float3x3,
  1577. asint_float4x4,
  1578. asint_float1x2,
  1579. asint_float1x3,
  1580. asint_float1x4,
  1581. asint_float2x1,
  1582. asint_float2x3,
  1583. asint_float2x4,
  1584. asint_float3x1,
  1585. asint_float3x2,
  1586. asint_float3x4,
  1587. asint_float4x1,
  1588. asint_float4x2,
  1589. asint_float4x3,
  1590. asint_float2,
  1591. asint_float3,
  1592. asint_float4,
  1593. asint_int2,
  1594. asint_int3,
  1595. asint_int4,
  1596. asint_uint2,
  1597. asint_uint3,
  1598. asint_uint4,
  1599. asint_bool2,
  1600. asint_bool3,
  1601. asint_bool4,
  1602. asint_double1x1,
  1603. asint_double2x2,
  1604. asint_double3x3,
  1605. asint_double4x4,
  1606. asint_double1x2,
  1607. asint_double1x3,
  1608. asint_double1x4,
  1609. asint_double2x1,
  1610. asint_double2x3,
  1611. asint_double2x4,
  1612. asint_double3x1,
  1613. asint_double3x2,
  1614. asint_double3x4,
  1615. asint_double4x1,
  1616. asint_double4x2,
  1617. asint_double4x3,
  1618. asint_double2,
  1619. asint_double3,
  1620. asint_double4,
  1621. }
  1622. asint_float :: proc "c" (v: float) -> int { return int(v) }
  1623. asint_double :: proc "c" (v: double) -> int { return int(v) }
  1624. asint_int :: proc "c" (v: int) -> int { return int(v) }
  1625. asint_uint :: proc "c" (v: uint) -> int { return int(v) }
  1626. asint_float1x1 :: proc "c" (v: float1x1) -> int1x1 { return int1x1(v) }
  1627. asint_float2x2 :: proc "c" (v: float2x2) -> int2x2 { return int2x2(v) }
  1628. asint_float3x3 :: proc "c" (v: float3x3) -> int3x3 { return int3x3(v) }
  1629. asint_float4x4 :: proc "c" (v: float4x4) -> int4x4 { return int4x4(v) }
  1630. asint_float1x2 :: proc "c" (v: float1x2) -> int1x2 { return int1x2(v) }
  1631. asint_float1x3 :: proc "c" (v: float1x3) -> int1x3 { return int1x3(v) }
  1632. asint_float1x4 :: proc "c" (v: float1x4) -> int1x4 { return int1x4(v) }
  1633. asint_float2x1 :: proc "c" (v: float2x1) -> int2x1 { return int2x1(v) }
  1634. asint_float2x3 :: proc "c" (v: float2x3) -> int2x3 { return int2x3(v) }
  1635. asint_float2x4 :: proc "c" (v: float2x4) -> int2x4 { return int2x4(v) }
  1636. asint_float3x1 :: proc "c" (v: float3x1) -> int3x1 { return int3x1(v) }
  1637. asint_float3x2 :: proc "c" (v: float3x2) -> int3x2 { return int3x2(v) }
  1638. asint_float3x4 :: proc "c" (v: float3x4) -> int3x4 { return int3x4(v) }
  1639. asint_float4x1 :: proc "c" (v: float4x1) -> int4x1 { return int4x1(v) }
  1640. asint_float4x2 :: proc "c" (v: float4x2) -> int4x2 { return int4x2(v) }
  1641. asint_float4x3 :: proc "c" (v: float4x3) -> int4x3 { return int4x3(v) }
  1642. asint_float2 :: proc "c" (v: float2) -> int2 { return int2{int(v.x), int(v.y)} }
  1643. asint_float3 :: proc "c" (v: float3) -> int3 { return int3{int(v.x), int(v.y), int(v.z)} }
  1644. asint_float4 :: proc "c" (v: float4) -> int4 { return int4{int(v.x), int(v.y), int(v.z), int(v.w)} }
  1645. asint_int2 :: proc "c" (v: int2) -> int2 { return int2{int(v.x), int(v.y)} }
  1646. asint_int3 :: proc "c" (v: int3) -> int3 { return int3{int(v.x), int(v.y), int(v.z)} }
  1647. asint_int4 :: proc "c" (v: int4) -> int4 { return int4{int(v.x), int(v.y), int(v.z), int(v.w)} }
  1648. asint_uint2 :: proc "c" (v: uint2) -> int2 { return int2{int(v.x), int(v.y)} }
  1649. asint_uint3 :: proc "c" (v: uint3) -> int3 { return int3{int(v.x), int(v.y), int(v.z)} }
  1650. asint_uint4 :: proc "c" (v: uint4) -> int4 { return int4{int(v.x), int(v.y), int(v.z), int(v.w)} }
  1651. asint_bool2 :: proc "c" (v: bool2) -> int2 { return int2{int(int(v.x)), int(int(v.y))} }
  1652. asint_bool3 :: proc "c" (v: bool3) -> int3 { return int3{int(int(v.x)), int(int(v.y)), int(int(v.z))} }
  1653. asint_bool4 :: proc "c" (v: bool4) -> int4 { return int4{int(int(v.x)), int(int(v.y)), int(int(v.z)), int(int(v.w))} }
  1654. asint_double1x1 :: proc "c" (v: double1x1) -> int1x1 { return int1x1(v) }
  1655. asint_double2x2 :: proc "c" (v: double2x2) -> int2x2 { return int2x2(v) }
  1656. asint_double3x3 :: proc "c" (v: double3x3) -> int3x3 { return int3x3(v) }
  1657. asint_double4x4 :: proc "c" (v: double4x4) -> int4x4 { return int4x4(v) }
  1658. asint_double1x2 :: proc "c" (v: double1x2) -> int1x2 { return int1x2(v) }
  1659. asint_double1x3 :: proc "c" (v: double1x3) -> int1x3 { return int1x3(v) }
  1660. asint_double1x4 :: proc "c" (v: double1x4) -> int1x4 { return int1x4(v) }
  1661. asint_double2x1 :: proc "c" (v: double2x1) -> int2x1 { return int2x1(v) }
  1662. asint_double2x3 :: proc "c" (v: double2x3) -> int2x3 { return int2x3(v) }
  1663. asint_double2x4 :: proc "c" (v: double2x4) -> int2x4 { return int2x4(v) }
  1664. asint_double3x1 :: proc "c" (v: double3x1) -> int3x1 { return int3x1(v) }
  1665. asint_double3x2 :: proc "c" (v: double3x2) -> int3x2 { return int3x2(v) }
  1666. asint_double3x4 :: proc "c" (v: double3x4) -> int3x4 { return int3x4(v) }
  1667. asint_double4x1 :: proc "c" (v: double4x1) -> int4x1 { return int4x1(v) }
  1668. asint_double4x2 :: proc "c" (v: double4x2) -> int4x2 { return int4x2(v) }
  1669. asint_double4x3 :: proc "c" (v: double4x3) -> int4x3 { return int4x3(v) }
  1670. asint_double2 :: proc "c" (v: double2) -> int2 { return int2{int(v.x), int(v.y)} }
  1671. asint_double3 :: proc "c" (v: double3) -> int3 { return int3{int(v.x), int(v.y), int(v.z)} }
  1672. asint_double4 :: proc "c" (v: double4) -> int4 { return int4{int(v.x), int(v.y), int(v.z), int(v.w)} }
  1673. asuint :: proc{
  1674. asuint_float,
  1675. asuint_double,
  1676. asuint_int,
  1677. asuint_uint,
  1678. asuint_float2,
  1679. asuint_float3,
  1680. asuint_float4,
  1681. asuint_int2,
  1682. asuint_int3,
  1683. asuint_int4,
  1684. asuint_uint2,
  1685. asuint_uint3,
  1686. asuint_uint4,
  1687. asuint_bool2,
  1688. asuint_bool3,
  1689. asuint_bool4,
  1690. asuint_double2,
  1691. asuint_double3,
  1692. asuint_double4,
  1693. }
  1694. asuint_float :: proc "c" (v: float) -> uint { return uint(v) }
  1695. asuint_double :: proc "c" (v: double) -> uint { return uint(v) }
  1696. asuint_int :: proc "c" (v: int) -> uint { return uint(v) }
  1697. asuint_uint :: proc "c" (v: uint) -> uint { return uint(v) }
  1698. asuint_float2 :: proc "c" (v: float2) -> uint2 { return uint2{uint(v.x), uint(v.y)} }
  1699. asuint_float3 :: proc "c" (v: float3) -> uint3 { return uint3{uint(v.x), uint(v.y), uint(v.z)} }
  1700. asuint_float4 :: proc "c" (v: float4) -> uint4 { return uint4{uint(v.x), uint(v.y), uint(v.z), uint(v.w)} }
  1701. asuint_int2 :: proc "c" (v: int2) -> uint2 { return uint2{uint(v.x), uint(v.y)} }
  1702. asuint_int3 :: proc "c" (v: int3) -> uint3 { return uint3{uint(v.x), uint(v.y), uint(v.z)} }
  1703. asuint_int4 :: proc "c" (v: int4) -> uint4 { return uint4{uint(v.x), uint(v.y), uint(v.z), uint(v.w)} }
  1704. asuint_uint2 :: proc "c" (v: uint2) -> uint2 { return uint2{uint(v.x), uint(v.y)} }
  1705. asuint_uint3 :: proc "c" (v: uint3) -> uint3 { return uint3{uint(v.x), uint(v.y), uint(v.z)} }
  1706. asuint_uint4 :: proc "c" (v: uint4) -> uint4 { return uint4{uint(v.x), uint(v.y), uint(v.z), uint(v.w)} }
  1707. asuint_bool2 :: proc "c" (v: bool2) -> uint2 { return uint2{uint(uint(v.x)), uint(uint(v.y))} }
  1708. asuint_bool3 :: proc "c" (v: bool3) -> uint3 { return uint3{uint(uint(v.x)), uint(uint(v.y)), uint(uint(v.z))} }
  1709. asuint_bool4 :: proc "c" (v: bool4) -> uint4 { return uint4{uint(uint(v.x)), uint(uint(v.y)), uint(uint(v.z)), uint(uint(v.w))} }
  1710. asuint_double2 :: proc "c" (v: double2) -> uint2 { return uint2{uint(v.x), uint(v.y)} }
  1711. asuint_double3 :: proc "c" (v: double3) -> uint3 { return uint3{uint(v.x), uint(v.y), uint(v.z)} }
  1712. asuint_double4 :: proc "c" (v: double4) -> uint4 { return uint4{uint(v.x), uint(v.y), uint(v.z), uint(v.w)} }
  1713. // TODO(bill): All of the `mul` procedures