@xort/cga 0.0.93 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (384) hide show
  1. package/THIRD_PARTY_NOTICES.md +76 -0
  2. package/build/@xort_cga.js +20213 -12091
  3. package/build/cga.d.ts +3151 -2032
  4. package/build/cga.esm.js +20175 -0
  5. package/{src/shader → build/shaders}/cga.glsl +204 -202
  6. package/build/shaders/common.glsl +36 -0
  7. package/{src/shader → build/shaders}/noise/GLSL-Noise.md +1108 -1108
  8. package/build/shaders/noise/LICENSE +20 -0
  9. package/build/shaders/noise/cellular2D.glsl +69 -0
  10. package/{src/shader → build/shaders}/noise/cellular2x2.glsl +64 -64
  11. package/build/shaders/noise/cellular2x2x2.glsl +88 -0
  12. package/build/shaders/noise/cellular3D.glsl +187 -0
  13. package/{src/shader → build/shaders}/noise/classicnoise2D.glsl +113 -113
  14. package/{src/shader → build/shaders}/noise/classicnoise3D.glsl +177 -177
  15. package/{src/shader → build/shaders}/noise/classicnoise4D.glsl +302 -302
  16. package/{src/shader → build/shaders}/noise/noise2D.glsl +71 -71
  17. package/{src/shader → build/shaders}/noise/noise3D.glsl +103 -103
  18. package/{src/shader → build/shaders}/noise/noise3Dgrad.glsl +111 -111
  19. package/{src/shader → build/shaders}/noise/noise4D.glsl +129 -129
  20. package/{src/shader → build/shaders}/noise/psrdnoise2D.glsl +463 -462
  21. package/dist/THIRD_PARTY_NOTICES.md +76 -0
  22. package/dist/index.cjs +20352 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +3176 -0
  25. package/dist/index.d.ts +3176 -38
  26. package/dist/index.js +20177 -56
  27. package/dist/index.js.map +1 -0
  28. package/dist/shaders.cjs +21 -0
  29. package/dist/shaders.d.cts +20 -0
  30. package/dist/shaders.d.ts +20 -0
  31. package/dist/shaders.js +20 -0
  32. package/dist/three.cjs +3034 -0
  33. package/dist/three.cjs.map +1 -0
  34. package/dist/three.d.cts +308 -0
  35. package/dist/three.d.ts +308 -0
  36. package/dist/three.js +3007 -0
  37. package/dist/three.js.map +1 -0
  38. package/package.json +96 -47
  39. package/readme.md +111 -247
  40. package/.github/FUNDING.yml +0 -12
  41. package/cga/1./347/202/271/344/270/216/347/272/277/346/200/247/345/205/203/347/264/240/347/232/204/350/267/235/347/246/273.html +0 -601
  42. package/cga/1./347/202/271/344/270/216/347/272/277/346/200/247/345/205/203/347/264/240/347/232/204/350/267/235/347/246/273.md +0 -111
  43. package/cga/2./347/202/271/344/270/216/351/235/242/346/200/247/345/205/203/347/264/240.md +0 -4
  44. package/cga/img//347/202/271/344/270/216/345/260/204/347/272/277.png +0 -0
  45. package/cga/img//347/202/271/344/270/216/347/233/264/347/272/277.png +0 -0
  46. package/cga/img//347/202/271/344/270/216/347/272/277/346/256/265.png +0 -0
  47. package/cga/img//347/233/264/347/272/277/347/232/204/350/241/250/350/276/276/345/274/217.png +0 -0
  48. package/deploy.sh +0 -39
  49. package/dist/IKanimation/Bone.d.ts +0 -7
  50. package/dist/IKanimation/Bone.js +0 -20
  51. package/dist/IKanimation/CCDSolver.d.ts +0 -37
  52. package/dist/IKanimation/CCDSolver.js +0 -93
  53. package/dist/IKanimation/Joint.d.ts +0 -3
  54. package/dist/IKanimation/Joint.js +0 -17
  55. package/dist/IKanimation/constaint/constraint.d.ts +0 -10
  56. package/dist/IKanimation/constaint/constraint.js +0 -25
  57. package/dist/IKanimation/constaint/hinge.d.ts +0 -12
  58. package/dist/IKanimation/constaint/hinge.js +0 -46
  59. package/dist/IKanimation/constaint/slider.d.ts +0 -12
  60. package/dist/IKanimation/constaint/slider.js +0 -44
  61. package/dist/IKanimation/index.d.ts +0 -0
  62. package/dist/IKanimation/index.js +0 -9
  63. package/dist/IKanimation/isolver.d.ts +0 -4
  64. package/dist/IKanimation/isolver.js +0 -10
  65. package/dist/IKanimation/skeleton.d.ts +0 -13
  66. package/dist/IKanimation/skeleton.js +0 -31
  67. package/dist/alg/common.d.ts +0 -114
  68. package/dist/alg/common.js +0 -302
  69. package/dist/alg/curve.d.ts +0 -4
  70. package/dist/alg/curve.js +0 -11
  71. package/dist/alg/delaunator.d.ts +0 -29
  72. package/dist/alg/delaunator.js +0 -442
  73. package/dist/alg/delaunay.d.ts +0 -20
  74. package/dist/alg/delaunay.js +0 -199
  75. package/dist/alg/delaunayslow.d.ts +0 -18
  76. package/dist/alg/delaunayslow.js +0 -140
  77. package/dist/alg/extrude/extrude.d.ts +0 -3
  78. package/dist/alg/extrude/extrude.js +0 -17
  79. package/dist/alg/extrude.d.ts +0 -199
  80. package/dist/alg/extrude.js +0 -728
  81. package/dist/alg/offset/index.d.ts +0 -0
  82. package/dist/alg/offset/index.js +0 -9
  83. package/dist/alg/offset.d.ts +0 -0
  84. package/dist/alg/offset.js +0 -472
  85. package/dist/alg/pointset.d.ts +0 -94
  86. package/dist/alg/pointset.js +0 -223
  87. package/dist/alg/recognition.d.ts +0 -14
  88. package/dist/alg/recognition.js +0 -37
  89. package/dist/alg/result.d.ts +0 -22
  90. package/dist/alg/result.js +0 -2
  91. package/dist/alg/segmentset.d.ts +0 -11
  92. package/dist/alg/segmentset.js +0 -45
  93. package/dist/alg/sort.d.ts +0 -2
  94. package/dist/alg/sort.js +0 -14
  95. package/dist/alg/split.d.ts +0 -8
  96. package/dist/alg/split.js +0 -10
  97. package/dist/alg/trianglution.d.ts +0 -15
  98. package/dist/alg/trianglution.js +0 -70
  99. package/dist/alg/vol.d.ts +0 -6
  100. package/dist/alg/vol.js +0 -18
  101. package/dist/alg/voronoi.d.ts +0 -31
  102. package/dist/alg/voronoi.js +0 -418
  103. package/dist/app.d.ts +0 -1
  104. package/dist/app.js +0 -248
  105. package/dist/basic/distance.d.ts +0 -12
  106. package/dist/basic/distance.js +0 -39
  107. package/dist/csg/bsp.d.ts +0 -9
  108. package/dist/csg/bsp.js +0 -22
  109. package/dist/csg/node.d.ts +0 -12
  110. package/dist/csg/node.js +0 -75
  111. package/dist/csg/polygon.d.ts +0 -43
  112. package/dist/csg/polygon.js +0 -161
  113. package/dist/diamondMaterialShader.d.ts +0 -92
  114. package/dist/diamondMaterialShader.js +0 -118
  115. package/dist/effect/breath-light.d.ts +0 -4
  116. package/dist/effect/breath-light.js +0 -39
  117. package/dist/extends/geometryaid.d.ts +0 -28
  118. package/dist/extends/geometryaid.js +0 -71
  119. package/dist/extends/split.d.ts +0 -3
  120. package/dist/extends/split.js +0 -13
  121. package/dist/glview.d.ts +0 -112
  122. package/dist/glview.js +0 -564
  123. package/dist/math/Color.d.ts +0 -33
  124. package/dist/math/Color.js +0 -235
  125. package/dist/math/Euler.d.ts +0 -46
  126. package/dist/math/Euler.js +0 -225
  127. package/dist/math/HVec3.d.ts +0 -43
  128. package/dist/math/HVec3.js +0 -176
  129. package/dist/math/Mat3.d.ts +0 -29
  130. package/dist/math/Mat3.js +0 -244
  131. package/dist/math/Mat4.d.ts +0 -85
  132. package/dist/math/Mat4.js +0 -791
  133. package/dist/math/Math.d.ts +0 -130
  134. package/dist/math/Math.js +0 -198
  135. package/dist/math/Quat.d.ts +0 -82
  136. package/dist/math/Quat.js +0 -418
  137. package/dist/math/Vec2.d.ts +0 -68
  138. package/dist/math/Vec2.js +0 -328
  139. package/dist/math/Vec3.d.ts +0 -240
  140. package/dist/math/Vec3.js +0 -1082
  141. package/dist/math/Vec4.d.ts +0 -81
  142. package/dist/math/Vec4.js +0 -475
  143. package/dist/math/vecs.d.ts +0 -134
  144. package/dist/math/vecs.js +0 -464
  145. package/dist/render/bufferAttribute.d.ts +0 -104
  146. package/dist/render/bufferAttribute.js +0 -344
  147. package/dist/render/geometry.d.ts +0 -87
  148. package/dist/render/geometry.js +0 -769
  149. package/dist/render/mesh.d.ts +0 -30
  150. package/dist/render/mesh.js +0 -87
  151. package/dist/render/types.d.ts +0 -3
  152. package/dist/render/types.js +0 -8
  153. package/dist/robust/plane.d.ts +0 -7
  154. package/dist/robust/plane.js +0 -17
  155. package/dist/robust/vec.d.ts +0 -15
  156. package/dist/robust/vec.js +0 -71
  157. package/dist/struct/3d/Box.d.ts +0 -23
  158. package/dist/struct/3d/Box.js +0 -109
  159. package/dist/struct/3d/Capsule.d.ts +0 -12
  160. package/dist/struct/3d/Capsule.js +0 -36
  161. package/dist/struct/3d/Circle.d.ts +0 -52
  162. package/dist/struct/3d/Circle.js +0 -138
  163. package/dist/struct/3d/Disk.d.ts +0 -10
  164. package/dist/struct/3d/Disk.js +0 -22
  165. package/dist/struct/3d/Frustum.d.ts +0 -35
  166. package/dist/struct/3d/Frustum.js +0 -159
  167. package/dist/struct/3d/Line.d.ts +0 -40
  168. package/dist/struct/3d/Line.js +0 -340
  169. package/dist/struct/3d/Path.d.ts +0 -75
  170. package/dist/struct/3d/Path.js +0 -308
  171. package/dist/struct/3d/Plane.d.ts +0 -74
  172. package/dist/struct/3d/Plane.js +0 -298
  173. package/dist/struct/3d/Point.d.ts +0 -4
  174. package/dist/struct/3d/Point.js +0 -30
  175. package/dist/struct/3d/Polygon.d.ts +0 -8
  176. package/dist/struct/3d/Polygon.js +0 -55
  177. package/dist/struct/3d/Polyline.d.ts +0 -34
  178. package/dist/struct/3d/Polyline.js +0 -130
  179. package/dist/struct/3d/Ray.d.ts +0 -21
  180. package/dist/struct/3d/Ray.js +0 -262
  181. package/dist/struct/3d/Rectangle.d.ts +0 -7
  182. package/dist/struct/3d/Rectangle.js +0 -35
  183. package/dist/struct/3d/Segment.d.ts +0 -32
  184. package/dist/struct/3d/Segment.js +0 -334
  185. package/dist/struct/3d/Shape.d.ts +0 -4
  186. package/dist/struct/3d/Shape.js +0 -27
  187. package/dist/struct/3d/Sphere.d.ts +0 -11
  188. package/dist/struct/3d/Sphere.js +0 -30
  189. package/dist/struct/3d/Triangle.d.ts +0 -8
  190. package/dist/struct/3d/Triangle.js +0 -53
  191. package/dist/struct/bsp.d.ts +0 -9
  192. package/dist/struct/bsp.js +0 -44
  193. package/dist/struct/btree.d.ts +0 -0
  194. package/dist/struct/btree.js +0 -1
  195. package/dist/struct/data/ArrayList.d.ts +0 -42
  196. package/dist/struct/data/ArrayList.js +0 -172
  197. package/dist/struct/data/ArrayObject.d.ts +0 -30
  198. package/dist/struct/data/ArrayObject.js +0 -131
  199. package/dist/struct/data/type.d.ts +0 -13
  200. package/dist/struct/data/type.js +0 -18
  201. package/dist/struct/kdtree.d.ts +0 -0
  202. package/dist/struct/kdtree.js +0 -1
  203. package/dist/struct/polyTree.d.ts +0 -4
  204. package/dist/struct/polyTree.js +0 -27
  205. package/dist/struct/quatTree.d.ts +0 -0
  206. package/dist/struct/quatTree.js +0 -1
  207. package/dist/struct/tree.d.ts +0 -11
  208. package/dist/struct/tree.js +0 -26
  209. package/dist/utils/array.d.ts +0 -24
  210. package/dist/utils/array.js +0 -89
  211. package/dist/utils/types.d.ts +0 -24
  212. package/dist/utils/types.js +0 -20
  213. package/docs/.vuepress/components/distance.vue +0 -125
  214. package/docs/.vuepress/components/intersect.vue +0 -0
  215. package/docs/.vuepress/components/trianglution.vue +0 -121
  216. package/docs/.vuepress/components/utils.js +0 -314
  217. package/docs/.vuepress/config.js +0 -99
  218. package/docs/.vuepress/enhanceApp.js +0 -13
  219. package/docs/.vuepress/public/delaunay.png +0 -0
  220. package/docs/.vuepress/public/logo.png +0 -0
  221. package/docs/.vuepress/public/plane-set-convex.png +0 -0
  222. package/docs/.vuepress/public/sponsor/alipay.jpg +0 -0
  223. package/docs/.vuepress/public/sponsor/wechat.png +0 -0
  224. package/docs/README.md +0 -14
  225. package/docs/demo/README.md +0 -9
  226. package/docs/guide/README.md +0 -94
  227. package/docs/guide/array.md +0 -10
  228. package/docs/guide/cy/trianglution.html +0 -2
  229. package/docs/guide/distLineAll.md +0 -85
  230. package/docs/guide/distPointAll.md +0 -137
  231. package/docs/guide/distRayAll.md +0 -69
  232. package/docs/guide/distSegmentAll.md +0 -19
  233. package/docs/guide/point.vue +0 -12
  234. package/docs/guide/vector.md +0 -10
  235. package/docs/guide//345/270/270/347/224/250.md +0 -156
  236. package/docs/sponsor/README.md +0 -15
  237. package/docs//345/274/200/345/217/221/346/227/245/345/277/227/2020/345/271/2643/346/234/21013/346/227/245.md +0 -6
  238. package/effect/common.glsl +0 -34
  239. package/effect/drawing.glsl +0 -36
  240. package/effect/shape.arc.glsl +0 -13
  241. package/effect/shape.circle.glsl +0 -13
  242. package/effect/shape.grid.glsl +0 -42
  243. package/effect/shape.line.glsl +0 -18
  244. package/effect/shape.pie.glsl +0 -18
  245. package/effect/shape.plot.glsl +0 -10
  246. package/effect/shape.poly.glsl +0 -15
  247. package/effect/shape.rect.glsl +0 -14
  248. package/effect/shape.rectround.glsl +0 -15
  249. package/effect/shape.segment.glsl +0 -10
  250. package/effect/shape.spiral.glsl +0 -12
  251. package/effect/shape.star.glsl +0 -16
  252. package/examples/index.html +0 -31
  253. package/git.sh +0 -12
  254. package/gitproxy.sh +0 -6
  255. package/image/readme/1640758500266.png +0 -0
  256. package/image/readme/1640758513361.png +0 -0
  257. package/index.html +0 -14
  258. package/linear algorithm//346/225/260/345/255/246/350/241/250/350/276/276/345/274/217.md" +0 -122
  259. package/linear algorithm//347/237/251/351/230/265.md" +0 -91
  260. package/rollup.config.js +0 -82
  261. package/scripttest.html +0 -23
  262. package/src/IKanimation/Bone.ts +0 -20
  263. package/src/IKanimation/CCDSolver.ts +0 -114
  264. package/src/IKanimation/Joint.ts +0 -13
  265. package/src/IKanimation/constaint/constraint.ts +0 -23
  266. package/src/IKanimation/constaint/hinge.ts +0 -29
  267. package/src/IKanimation/constaint/slider.ts +0 -25
  268. package/src/IKanimation/index.ts +0 -8
  269. package/src/IKanimation/isolver.ts +0 -13
  270. package/src/IKanimation/skeleton.ts +0 -30
  271. package/src/alg/common.ts +0 -304
  272. package/src/alg/curve.ts +0 -9
  273. package/src/alg/delaunator.ts +0 -519
  274. package/src/alg/delaunay.ts +0 -163
  275. package/src/alg/delaunayslow.ts +0 -183
  276. package/src/alg/extrude/extrude.ts +0 -19
  277. package/src/alg/extrude.ts +0 -941
  278. package/src/alg/offset/index.ts +0 -8
  279. package/src/alg/offset.ts +0 -501
  280. package/src/alg/pointset.ts +0 -219
  281. package/src/alg/recognition.ts +0 -43
  282. package/src/alg/result.ts +0 -24
  283. package/src/alg/segmentset.ts +0 -44
  284. package/src/alg/sort.ts +0 -11
  285. package/src/alg/split.ts +0 -15
  286. package/src/alg/trianglution.ts +0 -53
  287. package/src/alg/vol.ts +0 -18
  288. package/src/alg/voronoi.ts +0 -303
  289. package/src/app.css +0 -12
  290. package/src/app.ts +0 -285
  291. package/src/assets/color.jpg +0 -0
  292. package/src/basic/distance.ts +0 -40
  293. package/src/clipper/clipper.d.ts +0 -323
  294. package/src/clipper/clipper.js +0 -7626
  295. package/src/clipper/clipper_float.js +0 -185
  296. package/src/clipper/clipper_float_unminified.js +0 -5639
  297. package/src/clipper/clipperint.js +0 -7626
  298. package/src/csg/bsp.ts +0 -24
  299. package/src/csg/csg.js +0 -583
  300. package/src/csg/node.ts +0 -91
  301. package/src/csg/polygon.ts +0 -177
  302. package/src/diamondMaterialShader.ts +0 -93
  303. package/src/effect/breath-light.ts +0 -24
  304. package/src/extends/geometryaid.ts +0 -86
  305. package/src/extends/split.ts +0 -15
  306. package/src/glview.ts +0 -570
  307. package/src/index.ts +0 -47
  308. package/src/math/Color.ts +0 -225
  309. package/src/math/Euler.ts +0 -238
  310. package/src/math/HVec3.ts +0 -1144
  311. package/src/math/Mat3.ts +0 -365
  312. package/src/math/Mat4.ts +0 -1134
  313. package/src/math/Math.ts +0 -213
  314. package/src/math/Quat.ts +0 -536
  315. package/src/math/Vec2.ts +0 -408
  316. package/src/math/Vec3.ts +0 -1307
  317. package/src/math/Vec4.ts +0 -587
  318. package/src/math/vecs.ts +0 -486
  319. package/src/render/bufferAttribute.ts +0 -491
  320. package/src/render/geometry.ts +0 -1329
  321. package/src/render/mesh.ts +0 -82
  322. package/src/render/types.ts +0 -17
  323. package/src/robust/plane.ts +0 -12
  324. package/src/robust/readme.md +0 -1
  325. package/src/robust/vec.ts +0 -61
  326. package/src/shader/common.glsl +0 -87
  327. package/src/shader/noise/cellular2D.glsl +0 -69
  328. package/src/shader/noise/cellular2x2x2.glsl +0 -88
  329. package/src/shader/noise/cellular3D.glsl +0 -187
  330. package/src/struct/3d/Box.ts +0 -124
  331. package/src/struct/3d/Capsule.ts +0 -18
  332. package/src/struct/3d/Circle.ts +0 -149
  333. package/src/struct/3d/Disk.ts +0 -22
  334. package/src/struct/3d/Frustum.ts +0 -189
  335. package/src/struct/3d/Line.ts +0 -378
  336. package/src/struct/3d/Path.ts +0 -314
  337. package/src/struct/3d/Plane.ts +0 -341
  338. package/src/struct/3d/Point.ts +0 -7
  339. package/src/struct/3d/PolyLine.ts +0 -115
  340. package/src/struct/3d/Polygon.ts +0 -46
  341. package/src/struct/3d/Ray.ts +0 -285
  342. package/src/struct/3d/Rectangle.ts +0 -18
  343. package/src/struct/3d/Segment.ts +0 -330
  344. package/src/struct/3d/Shape.ts +0 -7
  345. package/src/struct/3d/Sphere.ts +0 -31
  346. package/src/struct/3d/Triangle.ts +0 -28
  347. package/src/struct/bsp.ts +0 -18
  348. package/src/struct/btree.ts +0 -0
  349. package/src/struct/data/ArrayList.ts +0 -144
  350. package/src/struct/data/ArrayObject.ts +0 -105
  351. package/src/struct/data/type.ts +0 -14
  352. package/src/struct/kdtree.ts +0 -0
  353. package/src/struct/polyTree.ts +0 -8
  354. package/src/struct/quatTree.ts +0 -0
  355. package/src/struct/tree.ts +0 -30
  356. package/src/utils/array.ts +0 -106
  357. package/src/utils/types.ts +0 -42
  358. package/src-gis/app.ts +0 -7
  359. package/src-gis/core/Cartographic.ts +0 -48
  360. package/src-gis/core/EllipsoidGeodesic.ts +0 -56
  361. package/src-gis/core/EllipsoidTerrainProvider.ts +0 -35
  362. package/src-gis/core/HeightmapTerrainData.ts +0 -5
  363. package/src-gis/core/Rectangle.ts +0 -112
  364. package/src-gis/core/TaskProcessor.ts +0 -222
  365. package/src-gis/gis.ts +0 -25
  366. package/src-gis/globe.ts +0 -54
  367. package/src-gis/math/Cartographic.ts +0 -24
  368. package/src-gis/math/GVec3.ts +0 -55
  369. package/src-gis/math/ellipsoid.ts +0 -13
  370. package/src-gis/provider/DcTerrainProvider.ts +0 -36
  371. package/src-gis/provider/TerrainProvider.ts +0 -12
  372. package/src-gis/scene/DcImageryProvider.ts +0 -36
  373. package/src-gis/scene/GeographicTilingScheme.ts +0 -65
  374. package/src-gis/scene/Globe.ts +0 -76
  375. package/src-gis/scene/GlobeSurfaceShaderSet.ts +0 -9
  376. package/src-gis/scene/GlobeSurfaceTileProvider.ts +0 -25
  377. package/src-gis/scene/ImageryLayerCollection.ts +0 -75
  378. package/src-gis/scene/ImageryProvider.ts +0 -28
  379. package/src-gis/scene/QuadtreeTile.ts +0 -162
  380. package/src-gis/scene/UrlTemplateImageryProvider.ts +0 -32
  381. package/src-gis/scene/quadtree_primitive.ts +0 -58
  382. package/tsconfig.json +0 -77
  383. package/webpack.config.js +0 -112
  384. package//350/256/241/347/256/227/345/207/240/344/275/225/351/227/256/351/242/230.md +0 -26
@@ -1,462 +1,463 @@
1
- //
2
- // vec3 psrdnoise(vec2 pos, vec2 per, float rot)
3
- // vec3 psdnoise(vec2 pos, vec2 per)
4
- // float psrnoise(vec2 pos, vec2 per, float rot)
5
- // float psnoise(vec2 pos, vec2 per)
6
- // vec3 srdnoise(vec2 pos, float rot)
7
- // vec3 sdnoise(vec2 pos)
8
- // float srnoise(vec2 pos, float rot)
9
- // float snoise(vec2 pos)
10
- //
11
- // Periodic (tiling) 2-D simplex noise (hexagonal lattice gradient noise)
12
- // with rotating gradients and analytic derivatives.
13
- // Variants also without the derivative (no "d" in the name), without
14
- // the tiling property (no "p" in the name) and without the rotating
15
- // gradients (no "r" in the name).
16
- //
17
- // This is (yet) another variation on simplex noise. It's similar to the
18
- // version presented by Ken Perlin, but the grid is axis-aligned and
19
- // slightly stretched in the y direction to permit rectangular tiling.
20
- //
21
- // The noise can be made to tile seamlessly to any integer period in x and
22
- // any even integer period in y. Odd periods may be specified for y, but
23
- // then the actual tiling period will be twice that number.
24
- //
25
- // The rotating gradients give the appearance of a swirling motion, and can
26
- // serve a similar purpose for animation as motion along z in 3-D noise.
27
- // The rotating gradients in conjunction with the analytic derivatives
28
- // can make "flow noise" effects as presented by Perlin and Neyret.
29
- //
30
- // vec3 {p}s{r}dnoise(vec2 pos {, vec2 per} {, float rot})
31
- // "pos" is the input (x,y) coordinate
32
- // "per" is the x and y period, where per.x is a positive integer
33
- // and per.y is a positive even integer
34
- // "rot" is the angle to rotate the gradients (any float value,
35
- // where 0.0 is no rotation and 1.0 is one full turn)
36
- // The first component of the 3-element return vector is the noise value.
37
- // The second and third components are the x and y partial derivatives.
38
- //
39
- // float {p}s{r}noise(vec2 pos {, vec2 per} {, float rot})
40
- // "pos" is the input (x,y) coordinate
41
- // "per" is the x and y period, where per.x is a positive integer
42
- // and per.y is a positive even integer
43
- // "rot" is the angle to rotate the gradients (any float value,
44
- // where 0.0 is no rotation and 1.0 is one full turn)
45
- // The return value is the noise value.
46
- // Partial derivatives are not computed, making these functions faster.
47
- //
48
- // Author: Stefan Gustavson (stefan.gustavson@gmail.com)
49
- // Version 2016-05-10.
50
- //
51
- // Many thanks to Ian McEwan of Ashima Arts for the
52
- // idea of using a permutation polynomial.
53
- //
54
- // Copyright (c) 2016 Stefan Gustavson. All rights reserved.
55
- // Distributed under the MIT license. See LICENSE file.
56
- // https://github.com/stegu/webgl-noise
57
- //
58
-
59
- //
60
- // TODO: One-pixel wide artefacts used to occur due to precision issues with
61
- // the gradient indexing. This is specific to this variant of noise, because
62
- // one axis of the simplex grid is perfectly aligned with the input x axis.
63
- // The errors were rare, and they are now very unlikely to ever be visible
64
- // after a quick fix was introduced: a small offset is added to the y coordinate.
65
- // A proper fix would involve using round() instead of floor() in selected
66
- // places, but the quick fix works fine.
67
- // (If you run into problems with this, please let me know.)
68
- //
69
-
70
- // Modulo 289, optimizes to code without divisions
71
- vec3 mod289(vec3 x) {
72
- return x - floor(x * (1.0 / 289.0)) * 289.0;
73
- }
74
-
75
- // Permutation polynomial (ring size 289 = 17*17)
76
- vec3 permute(vec3 x) {
77
- return mod289(((x*34.0)+1.0)*x);
78
- }
79
-
80
- // Hashed 2-D gradients with an extra rotation.
81
- // (The constant 0.0243902439 is 1/41)
82
- vec2 rgrad2(vec2 p, float rot) {
83
- #if 0
84
- // Map from a line to a diamond such that a shift maps to a rotation.
85
- float u = permute(permute(p.x) + p.y) * 0.0243902439 + rot; // Rotate by shift
86
- u = 4.0 * fract(u) - 2.0;
87
- // (This vector could be normalized, exactly or approximately.)
88
- return vec2(abs(u)-1.0, abs(abs(u+1.0)-2.0)-1.0);
89
- #else
90
- // For more isotropic gradients, sin/cos can be used instead.
91
- float u = permute(permute(p.x) + p.y) * 0.0243902439 + rot; // Rotate by shift
92
- u = fract(u) * 6.28318530718; // 2*pi
93
- return vec2(cos(u), sin(u));
94
- #endif
95
- }
96
-
97
- //
98
- // 2-D tiling simplex noise with rotating gradients and analytical derivative.
99
- // The first component of the 3-element return vector is the noise value,
100
- // and the second and third components are the x and y partial derivatives.
101
- //
102
- vec3 psrdnoise(vec2 pos, vec2 per, float rot) {
103
- // Hack: offset y slightly to hide some rare artifacts
104
- pos.y += 0.01;
105
- // Skew to hexagonal grid
106
- vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
107
-
108
- vec2 i0 = floor(uv);
109
- vec2 f0 = fract(uv);
110
- // Traversal order
111
- vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
112
-
113
- // Unskewed grid points in (x,y) space
114
- vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
115
- vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
116
- vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
117
-
118
- // Integer grid point indices in (u,v) space
119
- i1 = i0 + i1;
120
- vec2 i2 = i0 + vec2(1.0, 1.0);
121
-
122
- // Vectors in unskewed (x,y) coordinates from
123
- // each of the simplex corners to the evaluation point
124
- vec2 d0 = pos - p0;
125
- vec2 d1 = pos - p1;
126
- vec2 d2 = pos - p2;
127
-
128
- // Wrap i0, i1 and i2 to the desired period before gradient hashing:
129
- // wrap points in (x,y), map to (u,v)
130
- vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);
131
- vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);
132
- vec3 iuw = xw + 0.5 * yw;
133
- vec3 ivw = yw;
134
-
135
- // Create gradients from indices
136
- vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
137
- vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
138
- vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
139
-
140
- // Gradients dot vectors to corresponding corners
141
- // (The derivatives of this are simply the gradients)
142
- vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
143
-
144
- // Radial weights from corners
145
- // 0.8 is the square of 2/sqrt(5), the distance from
146
- // a grid point to the nearest simplex boundary
147
- vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
148
-
149
- // Partial derivatives for analytical gradient computation
150
- vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);
151
- vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);
152
-
153
- // Set influence of each surflet to zero outside radius sqrt(0.8)
154
- if (t.x < 0.0) {
155
- dtdx.x = 0.0;
156
- dtdy.x = 0.0;
157
- t.x = 0.0;
158
- }
159
- if (t.y < 0.0) {
160
- dtdx.y = 0.0;
161
- dtdy.y = 0.0;
162
- t.y = 0.0;
163
- }
164
- if (t.z < 0.0) {
165
- dtdx.z = 0.0;
166
- dtdy.z = 0.0;
167
- t.z = 0.0;
168
- }
169
-
170
- // Fourth power of t (and third power for derivative)
171
- vec3 t2 = t * t;
172
- vec3 t4 = t2 * t2;
173
- vec3 t3 = t2 * t;
174
-
175
- // Final noise value is:
176
- // sum of ((radial weights) times (gradient dot vector from corner))
177
- float n = dot(t4, w);
178
-
179
- // Final analytical derivative (gradient of a sum of scalar products)
180
- vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;
181
- vec2 dn0 = t4.x * g0 + dt0 * w.x;
182
- vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;
183
- vec2 dn1 = t4.y * g1 + dt1 * w.y;
184
- vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;
185
- vec2 dn2 = t4.z * g2 + dt2 * w.z;
186
-
187
- return 11.0*vec3(n, dn0 + dn1 + dn2);
188
- }
189
-
190
- //
191
- // 2-D tiling simplex noise with fixed gradients
192
- // and analytical derivative.
193
- // This function is implemented as a wrapper to "psrdnoise",
194
- // at the minimal cost of three extra additions.
195
- //
196
- vec3 psdnoise(vec2 pos, vec2 per) {
197
- return psrdnoise(pos, per, 0.0);
198
- }
199
-
200
- //
201
- // 2-D tiling simplex noise with rotating gradients,
202
- // but without the analytical derivative.
203
- //
204
- float psrnoise(vec2 pos, vec2 per, float rot) {
205
- // Offset y slightly to hide some rare artifacts
206
- pos.y += 0.001;
207
- // Skew to hexagonal grid
208
- vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
209
-
210
- vec2 i0 = floor(uv);
211
- vec2 f0 = fract(uv);
212
- // Traversal order
213
- vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
214
-
215
- // Unskewed grid points in (x,y) space
216
- vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
217
- vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
218
- vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
219
-
220
- // Integer grid point indices in (u,v) space
221
- i1 = i0 + i1;
222
- vec2 i2 = i0 + vec2(1.0, 1.0);
223
-
224
- // Vectors in unskewed (x,y) coordinates from
225
- // each of the simplex corners to the evaluation point
226
- vec2 d0 = pos - p0;
227
- vec2 d1 = pos - p1;
228
- vec2 d2 = pos - p2;
229
-
230
- // Wrap i0, i1 and i2 to the desired period before gradient hashing:
231
- // wrap points in (x,y), map to (u,v)
232
- vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);
233
- vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);
234
- vec3 iuw = xw + 0.5 * yw;
235
- vec3 ivw = yw;
236
-
237
- // Create gradients from indices
238
- vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
239
- vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
240
- vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
241
-
242
- // Gradients dot vectors to corresponding corners
243
- // (The derivatives of this are simply the gradients)
244
- vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
245
-
246
- // Radial weights from corners
247
- // 0.8 is the square of 2/sqrt(5), the distance from
248
- // a grid point to the nearest simplex boundary
249
- vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
250
-
251
- // Set influence of each surflet to zero outside radius sqrt(0.8)
252
- t = max(t, 0.0);
253
-
254
- // Fourth power of t
255
- vec3 t2 = t * t;
256
- vec3 t4 = t2 * t2;
257
-
258
- // Final noise value is:
259
- // sum of ((radial weights) times (gradient dot vector from corner))
260
- float n = dot(t4, w);
261
-
262
- // Rescale to cover the range [-1,1] reasonably well
263
- return 11.0*n;
264
- }
265
-
266
- //
267
- // 2-D tiling simplex noise with fixed gradients,
268
- // without the analytical derivative.
269
- // This function is implemented as a wrapper to "psrnoise",
270
- // at the minimal cost of three extra additions.
271
- //
272
- float psnoise(vec2 pos, vec2 per) {
273
- return psrnoise(pos, per, 0.0);
274
- }
275
-
276
- //
277
- // 2-D non-tiling simplex noise with rotating gradients and analytical derivative.
278
- // The first component of the 3-element return vector is the noise value,
279
- // and the second and third components are the x and y partial derivatives.
280
- //
281
- vec3 srdnoise(vec2 pos, float rot) {
282
- // Offset y slightly to hide some rare artifacts
283
- pos.y += 0.001;
284
- // Skew to hexagonal grid
285
- vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
286
-
287
- vec2 i0 = floor(uv);
288
- vec2 f0 = fract(uv);
289
- // Traversal order
290
- vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
291
-
292
- // Unskewed grid points in (x,y) space
293
- vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
294
- vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
295
- vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
296
-
297
- // Integer grid point indices in (u,v) space
298
- i1 = i0 + i1;
299
- vec2 i2 = i0 + vec2(1.0, 1.0);
300
-
301
- // Vectors in unskewed (x,y) coordinates from
302
- // each of the simplex corners to the evaluation point
303
- vec2 d0 = pos - p0;
304
- vec2 d1 = pos - p1;
305
- vec2 d2 = pos - p2;
306
-
307
- vec3 x = vec3(p0.x, p1.x, p2.x);
308
- vec3 y = vec3(p0.y, p1.y, p2.y);
309
- vec3 iuw = x + 0.5 * y;
310
- vec3 ivw = y;
311
-
312
- // Avoid precision issues in permutation
313
- iuw = mod289(iuw);
314
- ivw = mod289(ivw);
315
-
316
- // Create gradients from indices
317
- vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
318
- vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
319
- vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
320
-
321
- // Gradients dot vectors to corresponding corners
322
- // (The derivatives of this are simply the gradients)
323
- vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
324
-
325
- // Radial weights from corners
326
- // 0.8 is the square of 2/sqrt(5), the distance from
327
- // a grid point to the nearest simplex boundary
328
- vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
329
-
330
- // Partial derivatives for analytical gradient computation
331
- vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);
332
- vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);
333
-
334
- // Set influence of each surflet to zero outside radius sqrt(0.8)
335
- if (t.x < 0.0) {
336
- dtdx.x = 0.0;
337
- dtdy.x = 0.0;
338
- t.x = 0.0;
339
- }
340
- if (t.y < 0.0) {
341
- dtdx.y = 0.0;
342
- dtdy.y = 0.0;
343
- t.y = 0.0;
344
- }
345
- if (t.z < 0.0) {
346
- dtdx.z = 0.0;
347
- dtdy.z = 0.0;
348
- t.z = 0.0;
349
- }
350
-
351
- // Fourth power of t (and third power for derivative)
352
- vec3 t2 = t * t;
353
- vec3 t4 = t2 * t2;
354
- vec3 t3 = t2 * t;
355
-
356
- // Final noise value is:
357
- // sum of ((radial weights) times (gradient dot vector from corner))
358
- float n = dot(t4, w);
359
-
360
- // Final analytical derivative (gradient of a sum of scalar products)
361
- vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;
362
- vec2 dn0 = t4.x * g0 + dt0 * w.x;
363
- vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;
364
- vec2 dn1 = t4.y * g1 + dt1 * w.y;
365
- vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;
366
- vec2 dn2 = t4.z * g2 + dt2 * w.z;
367
-
368
- return 11.0*vec3(n, dn0 + dn1 + dn2);
369
- }
370
-
371
- //
372
- // 2-D non-tiling simplex noise with fixed gradients and analytical derivative.
373
- // This function is implemented as a wrapper to "srdnoise",
374
- // at the minimal cost of three extra additions.
375
- //
376
- vec3 sdnoise(vec2 pos) {
377
- return srdnoise(pos, 0.0);
378
- }
379
-
380
- //
381
- // 2-D non-tiling simplex noise with rotating gradients,
382
- // without the analytical derivative.
383
- //
384
- float srnoise(vec2 pos, float rot) {
385
- // Offset y slightly to hide some rare artifacts
386
- pos.y += 0.001;
387
- // Skew to hexagonal grid
388
- vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
389
-
390
- vec2 i0 = floor(uv);
391
- vec2 f0 = fract(uv);
392
- // Traversal order
393
- vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
394
-
395
- // Unskewed grid points in (x,y) space
396
- vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
397
- vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
398
- vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
399
-
400
- // Integer grid point indices in (u,v) space
401
- i1 = i0 + i1;
402
- vec2 i2 = i0 + vec2(1.0, 1.0);
403
-
404
- // Vectors in unskewed (x,y) coordinates from
405
- // each of the simplex corners to the evaluation point
406
- vec2 d0 = pos - p0;
407
- vec2 d1 = pos - p1;
408
- vec2 d2 = pos - p2;
409
-
410
- // Wrap i0, i1 and i2 to the desired period before gradient hashing:
411
- // wrap points in (x,y), map to (u,v)
412
- vec3 x = vec3(p0.x, p1.x, p2.x);
413
- vec3 y = vec3(p0.y, p1.y, p2.y);
414
- vec3 iuw = x + 0.5 * y;
415
- vec3 ivw = y;
416
-
417
- // Avoid precision issues in permutation
418
- iuw = mod289(iuw);
419
- ivw = mod289(ivw);
420
-
421
- // Create gradients from indices
422
- vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
423
- vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
424
- vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
425
-
426
- // Gradients dot vectors to corresponding corners
427
- // (The derivatives of this are simply the gradients)
428
- vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
429
-
430
- // Radial weights from corners
431
- // 0.8 is the square of 2/sqrt(5), the distance from
432
- // a grid point to the nearest simplex boundary
433
- vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
434
-
435
- // Set influence of each surflet to zero outside radius sqrt(0.8)
436
- t = max(t, 0.0);
437
-
438
- // Fourth power of t
439
- vec3 t2 = t * t;
440
- vec3 t4 = t2 * t2;
441
-
442
- // Final noise value is:
443
- // sum of ((radial weights) times (gradient dot vector from corner))
444
- float n = dot(t4, w);
445
-
446
- // Rescale to cover the range [-1,1] reasonably well
447
- return 11.0*n;
448
- }
449
-
450
- //
451
- // 2-D non-tiling simplex noise with fixed gradients,
452
- // without the analytical derivative.
453
- // This function is implemented as a wrapper to "srnoise",
454
- // at the minimal cost of three extra additions.
455
- // Note: if this kind of noise is all you want, there are faster
456
- // GLSL implementations of non-tiling simplex noise out there.
457
- // This one is included mainly for completeness and compatibility
458
- // with the other functions in the file.
459
- //
460
- float snoise(vec2 pos) {
461
- return srnoise(pos, 0.0);
462
- }
1
+ //
2
+ // vec3 psrdnoise(vec2 pos, vec2 per, float rot)
3
+ // vec3 psdnoise(vec2 pos, vec2 per)
4
+ // float psrnoise(vec2 pos, vec2 per, float rot)
5
+ // float psnoise(vec2 pos, vec2 per)
6
+ // vec3 srdnoise(vec2 pos, float rot)
7
+ // vec3 sdnoise(vec2 pos)
8
+ // float srnoise(vec2 pos, float rot)
9
+ // float snoise(vec2 pos)
10
+ //
11
+ // Periodic (tiling) 2-D simplex noise (hexagonal lattice gradient noise)
12
+ // with rotating gradients and analytic derivatives.
13
+ // Variants also without the derivative (no "d" in the name), without
14
+ // the tiling property (no "p" in the name) and without the rotating
15
+ // gradients (no "r" in the name).
16
+ //
17
+ // This is (yet) another variation on simplex noise. It's similar to the
18
+ // version presented by Ken Perlin, but the grid is axis-aligned and
19
+ // slightly stretched in the y direction to permit rectangular tiling.
20
+ //
21
+ // The noise can be made to tile seamlessly to any integer period in x and
22
+ // any even integer period in y. Odd periods may be specified for y, but
23
+ // then the actual tiling period will be twice that number.
24
+ //
25
+ // The rotating gradients give the appearance of a swirling motion, and can
26
+ // serve a similar purpose for animation as motion along z in 3-D noise.
27
+ // The rotating gradients in conjunction with the analytic derivatives
28
+ // can make "flow noise" effects as presented by Perlin and Neyret.
29
+ //
30
+ // vec3 {p}s{r}dnoise(vec2 pos {, vec2 per} {, float rot})
31
+ // "pos" is the input (x,y) coordinate
32
+ // "per" is the x and y period, where per.x is a positive integer
33
+ // and per.y is a positive even integer
34
+ // "rot" is the angle to rotate the gradients (any float value,
35
+ // where 0.0 is no rotation and 1.0 is one full turn)
36
+ // The first component of the 3-element return vector is the noise value.
37
+ // The second and third components are the x and y partial derivatives.
38
+ //
39
+ // float {p}s{r}noise(vec2 pos {, vec2 per} {, float rot})
40
+ // "pos" is the input (x,y) coordinate
41
+ // "per" is the x and y period, where per.x is a positive integer
42
+ // and per.y is a positive even integer
43
+ // "rot" is the angle to rotate the gradients (any float value,
44
+ // where 0.0 is no rotation and 1.0 is one full turn)
45
+ // The return value is the noise value.
46
+ // Partial derivatives are not computed, making these functions faster.
47
+ //
48
+ // Author: Stefan Gustavson (stefan.gustavson@gmail.com)
49
+ // Version 2016-05-10.
50
+ //
51
+ // Many thanks to Ian McEwan of Ashima Arts for the
52
+ // idea of using a permutation polynomial.
53
+ //
54
+ // Copyright (c) 2016 Stefan Gustavson. All rights reserved.
55
+ // Distributed under the MIT license. See LICENSE file.
56
+ // https://github.com/stegu/webgl-noise
57
+ //
58
+
59
+ //
60
+ // TODO: One-pixel wide artefacts used to occur due to precision issues with
61
+ // the gradient indexing. This is specific to this variant of noise, because
62
+ // one axis of the simplex grid is perfectly aligned with the input x axis.
63
+ // The errors were rare, and they are now very unlikely to ever be visible
64
+ // after a quick fix was introduced: a small offset is added to the y coordinate.
65
+ // A proper fix would involve using round() instead of floor() in selected
66
+ // places, but the quick fix works fine.
67
+ // (If you run into problems with this, please let me know.)
68
+ //
69
+
70
+ // Modulo 289, optimizes to code without divisions
71
+ vec3 mod289(vec3 x) {
72
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
73
+ }
74
+
75
+ // Permutation polynomial (ring size 289 = 17*17)
76
+ float permute(float x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
77
+ vec3 permute(vec3 x) {
78
+ return mod289(((x*34.0)+1.0)*x);
79
+ }
80
+
81
+ // Hashed 2-D gradients with an extra rotation.
82
+ // (The constant 0.0243902439 is 1/41)
83
+ vec2 rgrad2(vec2 p, float rot) {
84
+ #if 0
85
+ // Map from a line to a diamond such that a shift maps to a rotation.
86
+ float u = permute(permute(p.x) + p.y) * 0.0243902439 + rot; // Rotate by shift
87
+ u = 4.0 * fract(u) - 2.0;
88
+ // (This vector could be normalized, exactly or approximately.)
89
+ return vec2(abs(u)-1.0, abs(abs(u+1.0)-2.0)-1.0);
90
+ #else
91
+ // For more isotropic gradients, sin/cos can be used instead.
92
+ float u = permute(permute(p.x) + p.y) * 0.0243902439 + rot; // Rotate by shift
93
+ u = fract(u) * 6.28318530718; // 2*pi
94
+ return vec2(cos(u), sin(u));
95
+ #endif
96
+ }
97
+
98
+ //
99
+ // 2-D tiling simplex noise with rotating gradients and analytical derivative.
100
+ // The first component of the 3-element return vector is the noise value,
101
+ // and the second and third components are the x and y partial derivatives.
102
+ //
103
+ vec3 psrdnoise(vec2 pos, vec2 per, float rot) {
104
+ // Hack: offset y slightly to hide some rare artifacts
105
+ pos.y += 0.01;
106
+ // Skew to hexagonal grid
107
+ vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
108
+
109
+ vec2 i0 = floor(uv);
110
+ vec2 f0 = fract(uv);
111
+ // Traversal order
112
+ vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
113
+
114
+ // Unskewed grid points in (x,y) space
115
+ vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
116
+ vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
117
+ vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
118
+
119
+ // Integer grid point indices in (u,v) space
120
+ i1 = i0 + i1;
121
+ vec2 i2 = i0 + vec2(1.0, 1.0);
122
+
123
+ // Vectors in unskewed (x,y) coordinates from
124
+ // each of the simplex corners to the evaluation point
125
+ vec2 d0 = pos - p0;
126
+ vec2 d1 = pos - p1;
127
+ vec2 d2 = pos - p2;
128
+
129
+ // Wrap i0, i1 and i2 to the desired period before gradient hashing:
130
+ // wrap points in (x,y), map to (u,v)
131
+ vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);
132
+ vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);
133
+ vec3 iuw = xw + 0.5 * yw;
134
+ vec3 ivw = yw;
135
+
136
+ // Create gradients from indices
137
+ vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
138
+ vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
139
+ vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
140
+
141
+ // Gradients dot vectors to corresponding corners
142
+ // (The derivatives of this are simply the gradients)
143
+ vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
144
+
145
+ // Radial weights from corners
146
+ // 0.8 is the square of 2/sqrt(5), the distance from
147
+ // a grid point to the nearest simplex boundary
148
+ vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
149
+
150
+ // Partial derivatives for analytical gradient computation
151
+ vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);
152
+ vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);
153
+
154
+ // Set influence of each surflet to zero outside radius sqrt(0.8)
155
+ if (t.x < 0.0) {
156
+ dtdx.x = 0.0;
157
+ dtdy.x = 0.0;
158
+ t.x = 0.0;
159
+ }
160
+ if (t.y < 0.0) {
161
+ dtdx.y = 0.0;
162
+ dtdy.y = 0.0;
163
+ t.y = 0.0;
164
+ }
165
+ if (t.z < 0.0) {
166
+ dtdx.z = 0.0;
167
+ dtdy.z = 0.0;
168
+ t.z = 0.0;
169
+ }
170
+
171
+ // Fourth power of t (and third power for derivative)
172
+ vec3 t2 = t * t;
173
+ vec3 t4 = t2 * t2;
174
+ vec3 t3 = t2 * t;
175
+
176
+ // Final noise value is:
177
+ // sum of ((radial weights) times (gradient dot vector from corner))
178
+ float n = dot(t4, w);
179
+
180
+ // Final analytical derivative (gradient of a sum of scalar products)
181
+ vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;
182
+ vec2 dn0 = t4.x * g0 + dt0 * w.x;
183
+ vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;
184
+ vec2 dn1 = t4.y * g1 + dt1 * w.y;
185
+ vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;
186
+ vec2 dn2 = t4.z * g2 + dt2 * w.z;
187
+
188
+ return 11.0*vec3(n, dn0 + dn1 + dn2);
189
+ }
190
+
191
+ //
192
+ // 2-D tiling simplex noise with fixed gradients
193
+ // and analytical derivative.
194
+ // This function is implemented as a wrapper to "psrdnoise",
195
+ // at the minimal cost of three extra additions.
196
+ //
197
+ vec3 psdnoise(vec2 pos, vec2 per) {
198
+ return psrdnoise(pos, per, 0.0);
199
+ }
200
+
201
+ //
202
+ // 2-D tiling simplex noise with rotating gradients,
203
+ // but without the analytical derivative.
204
+ //
205
+ float psrnoise(vec2 pos, vec2 per, float rot) {
206
+ // Offset y slightly to hide some rare artifacts
207
+ pos.y += 0.001;
208
+ // Skew to hexagonal grid
209
+ vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
210
+
211
+ vec2 i0 = floor(uv);
212
+ vec2 f0 = fract(uv);
213
+ // Traversal order
214
+ vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
215
+
216
+ // Unskewed grid points in (x,y) space
217
+ vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
218
+ vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
219
+ vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
220
+
221
+ // Integer grid point indices in (u,v) space
222
+ i1 = i0 + i1;
223
+ vec2 i2 = i0 + vec2(1.0, 1.0);
224
+
225
+ // Vectors in unskewed (x,y) coordinates from
226
+ // each of the simplex corners to the evaluation point
227
+ vec2 d0 = pos - p0;
228
+ vec2 d1 = pos - p1;
229
+ vec2 d2 = pos - p2;
230
+
231
+ // Wrap i0, i1 and i2 to the desired period before gradient hashing:
232
+ // wrap points in (x,y), map to (u,v)
233
+ vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);
234
+ vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);
235
+ vec3 iuw = xw + 0.5 * yw;
236
+ vec3 ivw = yw;
237
+
238
+ // Create gradients from indices
239
+ vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
240
+ vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
241
+ vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
242
+
243
+ // Gradients dot vectors to corresponding corners
244
+ // (The derivatives of this are simply the gradients)
245
+ vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
246
+
247
+ // Radial weights from corners
248
+ // 0.8 is the square of 2/sqrt(5), the distance from
249
+ // a grid point to the nearest simplex boundary
250
+ vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
251
+
252
+ // Set influence of each surflet to zero outside radius sqrt(0.8)
253
+ t = max(t, 0.0);
254
+
255
+ // Fourth power of t
256
+ vec3 t2 = t * t;
257
+ vec3 t4 = t2 * t2;
258
+
259
+ // Final noise value is:
260
+ // sum of ((radial weights) times (gradient dot vector from corner))
261
+ float n = dot(t4, w);
262
+
263
+ // Rescale to cover the range [-1,1] reasonably well
264
+ return 11.0*n;
265
+ }
266
+
267
+ //
268
+ // 2-D tiling simplex noise with fixed gradients,
269
+ // without the analytical derivative.
270
+ // This function is implemented as a wrapper to "psrnoise",
271
+ // at the minimal cost of three extra additions.
272
+ //
273
+ float psnoise(vec2 pos, vec2 per) {
274
+ return psrnoise(pos, per, 0.0);
275
+ }
276
+
277
+ //
278
+ // 2-D non-tiling simplex noise with rotating gradients and analytical derivative.
279
+ // The first component of the 3-element return vector is the noise value,
280
+ // and the second and third components are the x and y partial derivatives.
281
+ //
282
+ vec3 srdnoise(vec2 pos, float rot) {
283
+ // Offset y slightly to hide some rare artifacts
284
+ pos.y += 0.001;
285
+ // Skew to hexagonal grid
286
+ vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
287
+
288
+ vec2 i0 = floor(uv);
289
+ vec2 f0 = fract(uv);
290
+ // Traversal order
291
+ vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
292
+
293
+ // Unskewed grid points in (x,y) space
294
+ vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
295
+ vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
296
+ vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
297
+
298
+ // Integer grid point indices in (u,v) space
299
+ i1 = i0 + i1;
300
+ vec2 i2 = i0 + vec2(1.0, 1.0);
301
+
302
+ // Vectors in unskewed (x,y) coordinates from
303
+ // each of the simplex corners to the evaluation point
304
+ vec2 d0 = pos - p0;
305
+ vec2 d1 = pos - p1;
306
+ vec2 d2 = pos - p2;
307
+
308
+ vec3 x = vec3(p0.x, p1.x, p2.x);
309
+ vec3 y = vec3(p0.y, p1.y, p2.y);
310
+ vec3 iuw = x + 0.5 * y;
311
+ vec3 ivw = y;
312
+
313
+ // Avoid precision issues in permutation
314
+ iuw = mod289(iuw);
315
+ ivw = mod289(ivw);
316
+
317
+ // Create gradients from indices
318
+ vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
319
+ vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
320
+ vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
321
+
322
+ // Gradients dot vectors to corresponding corners
323
+ // (The derivatives of this are simply the gradients)
324
+ vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
325
+
326
+ // Radial weights from corners
327
+ // 0.8 is the square of 2/sqrt(5), the distance from
328
+ // a grid point to the nearest simplex boundary
329
+ vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
330
+
331
+ // Partial derivatives for analytical gradient computation
332
+ vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);
333
+ vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);
334
+
335
+ // Set influence of each surflet to zero outside radius sqrt(0.8)
336
+ if (t.x < 0.0) {
337
+ dtdx.x = 0.0;
338
+ dtdy.x = 0.0;
339
+ t.x = 0.0;
340
+ }
341
+ if (t.y < 0.0) {
342
+ dtdx.y = 0.0;
343
+ dtdy.y = 0.0;
344
+ t.y = 0.0;
345
+ }
346
+ if (t.z < 0.0) {
347
+ dtdx.z = 0.0;
348
+ dtdy.z = 0.0;
349
+ t.z = 0.0;
350
+ }
351
+
352
+ // Fourth power of t (and third power for derivative)
353
+ vec3 t2 = t * t;
354
+ vec3 t4 = t2 * t2;
355
+ vec3 t3 = t2 * t;
356
+
357
+ // Final noise value is:
358
+ // sum of ((radial weights) times (gradient dot vector from corner))
359
+ float n = dot(t4, w);
360
+
361
+ // Final analytical derivative (gradient of a sum of scalar products)
362
+ vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;
363
+ vec2 dn0 = t4.x * g0 + dt0 * w.x;
364
+ vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;
365
+ vec2 dn1 = t4.y * g1 + dt1 * w.y;
366
+ vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;
367
+ vec2 dn2 = t4.z * g2 + dt2 * w.z;
368
+
369
+ return 11.0*vec3(n, dn0 + dn1 + dn2);
370
+ }
371
+
372
+ //
373
+ // 2-D non-tiling simplex noise with fixed gradients and analytical derivative.
374
+ // This function is implemented as a wrapper to "srdnoise",
375
+ // at the minimal cost of three extra additions.
376
+ //
377
+ vec3 sdnoise(vec2 pos) {
378
+ return srdnoise(pos, 0.0);
379
+ }
380
+
381
+ //
382
+ // 2-D non-tiling simplex noise with rotating gradients,
383
+ // without the analytical derivative.
384
+ //
385
+ float srnoise(vec2 pos, float rot) {
386
+ // Offset y slightly to hide some rare artifacts
387
+ pos.y += 0.001;
388
+ // Skew to hexagonal grid
389
+ vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);
390
+
391
+ vec2 i0 = floor(uv);
392
+ vec2 f0 = fract(uv);
393
+ // Traversal order
394
+ vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
395
+
396
+ // Unskewed grid points in (x,y) space
397
+ vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);
398
+ vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);
399
+ vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);
400
+
401
+ // Integer grid point indices in (u,v) space
402
+ i1 = i0 + i1;
403
+ vec2 i2 = i0 + vec2(1.0, 1.0);
404
+
405
+ // Vectors in unskewed (x,y) coordinates from
406
+ // each of the simplex corners to the evaluation point
407
+ vec2 d0 = pos - p0;
408
+ vec2 d1 = pos - p1;
409
+ vec2 d2 = pos - p2;
410
+
411
+ // Wrap i0, i1 and i2 to the desired period before gradient hashing:
412
+ // wrap points in (x,y), map to (u,v)
413
+ vec3 x = vec3(p0.x, p1.x, p2.x);
414
+ vec3 y = vec3(p0.y, p1.y, p2.y);
415
+ vec3 iuw = x + 0.5 * y;
416
+ vec3 ivw = y;
417
+
418
+ // Avoid precision issues in permutation
419
+ iuw = mod289(iuw);
420
+ ivw = mod289(ivw);
421
+
422
+ // Create gradients from indices
423
+ vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);
424
+ vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);
425
+ vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);
426
+
427
+ // Gradients dot vectors to corresponding corners
428
+ // (The derivatives of this are simply the gradients)
429
+ vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));
430
+
431
+ // Radial weights from corners
432
+ // 0.8 is the square of 2/sqrt(5), the distance from
433
+ // a grid point to the nearest simplex boundary
434
+ vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));
435
+
436
+ // Set influence of each surflet to zero outside radius sqrt(0.8)
437
+ t = max(t, 0.0);
438
+
439
+ // Fourth power of t
440
+ vec3 t2 = t * t;
441
+ vec3 t4 = t2 * t2;
442
+
443
+ // Final noise value is:
444
+ // sum of ((radial weights) times (gradient dot vector from corner))
445
+ float n = dot(t4, w);
446
+
447
+ // Rescale to cover the range [-1,1] reasonably well
448
+ return 11.0*n;
449
+ }
450
+
451
+ //
452
+ // 2-D non-tiling simplex noise with fixed gradients,
453
+ // without the analytical derivative.
454
+ // This function is implemented as a wrapper to "srnoise",
455
+ // at the minimal cost of three extra additions.
456
+ // Note: if this kind of noise is all you want, there are faster
457
+ // GLSL implementations of non-tiling simplex noise out there.
458
+ // This one is included mainly for completeness and compatibility
459
+ // with the other functions in the file.
460
+ //
461
+ float snoise(vec2 pos) {
462
+ return srnoise(pos, 0.0);
463
+ }