glre 0.40.0 → 0.42.0

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 (150) hide show
  1. package/dist/addons.cjs +1 -1
  2. package/dist/addons.cjs.map +1 -1
  3. package/dist/addons.d.ts +382 -10
  4. package/dist/addons.js +1 -1
  5. package/dist/addons.js.map +1 -1
  6. package/dist/index.cjs +6 -6
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +9 -8
  9. package/dist/index.js +5 -5
  10. package/dist/index.js.map +1 -1
  11. package/dist/native.d.ts +12 -11
  12. package/dist/node.cjs +16 -16
  13. package/dist/node.cjs.map +1 -1
  14. package/dist/node.d.ts +6 -5
  15. package/dist/node.js +15 -15
  16. package/dist/node.js.map +1 -1
  17. package/dist/react.d.ts +9 -8
  18. package/dist/solid.d.ts +9 -8
  19. package/package.json +1 -1
  20. package/src/addons/color/blend/add.ts +35 -0
  21. package/src/addons/color/blend/average.ts +35 -0
  22. package/src/addons/color/blend/color.ts +28 -0
  23. package/src/addons/color/blend/colorBurn.ts +35 -0
  24. package/src/addons/color/blend/colorDodge.ts +39 -0
  25. package/src/addons/color/blend/darken.ts +35 -0
  26. package/src/addons/color/blend/difference.ts +35 -0
  27. package/src/addons/color/blend/exclusion.ts +35 -0
  28. package/src/addons/color/blend/glow.ts +36 -0
  29. package/src/addons/color/blend/hardLight.ts +36 -0
  30. package/src/addons/color/blend/hardMix.ts +39 -0
  31. package/src/addons/color/blend/hue.ts +29 -0
  32. package/src/addons/color/blend/index.ts +28 -0
  33. package/src/addons/color/blend/lighten.ts +35 -0
  34. package/src/addons/color/blend/linearBurn.ts +39 -0
  35. package/src/addons/color/blend/linearDodge.ts +39 -0
  36. package/src/addons/color/blend/linearLight.ts +44 -0
  37. package/src/addons/color/blend/luminosity.ts +28 -0
  38. package/src/addons/color/blend/multiply.ts +35 -0
  39. package/src/addons/color/blend/negation.ts +35 -0
  40. package/src/addons/color/blend/overlay.ts +38 -0
  41. package/src/addons/color/blend/phoenix.ts +35 -0
  42. package/src/addons/color/blend/pinLight.ts +40 -0
  43. package/src/addons/color/blend/reflect.ts +35 -0
  44. package/src/addons/color/blend/saturation.ts +28 -0
  45. package/src/addons/color/blend/screen.ts +39 -0
  46. package/src/addons/color/blend/softLight.ts +63 -0
  47. package/src/addons/color/blend/subtract.ts +37 -0
  48. package/src/addons/color/blend/vividLight.ts +44 -0
  49. package/src/addons/color/composite/compositeXor.ts +40 -0
  50. package/src/addons/color/composite/destinationAtop.ts +42 -0
  51. package/src/addons/color/composite/destinationIn.ts +42 -0
  52. package/src/addons/color/composite/destinationOut.ts +42 -0
  53. package/src/addons/color/composite/destinationOver.ts +42 -0
  54. package/src/addons/color/composite/index.ts +9 -0
  55. package/src/addons/color/composite/sourceAtop.ts +42 -0
  56. package/src/addons/color/composite/sourceIn.ts +40 -0
  57. package/src/addons/color/composite/sourceOut.ts +40 -0
  58. package/src/addons/color/composite/sourceOver.ts +40 -0
  59. package/src/addons/color/palette/macbeth.ts +31 -33
  60. package/src/addons/draw/arrows.ts +34 -48
  61. package/src/addons/draw/axis.ts +24 -42
  62. package/src/addons/draw/bridge.ts +4 -4
  63. package/src/addons/draw/char.ts +235 -18
  64. package/src/addons/draw/circle.ts +22 -1
  65. package/src/addons/draw/colorChecker.ts +42 -0
  66. package/src/addons/draw/colorPicker.ts +66 -0
  67. package/src/addons/draw/digits.ts +334 -0
  68. package/src/addons/draw/index.ts +4 -0
  69. package/src/addons/draw/matrix.ts +26 -0
  70. package/src/addons/draw/point.ts +24 -11
  71. package/src/addons/geometry/triangle/closestPoint.ts +7 -7
  72. package/src/addons/index.ts +3 -0
  73. package/src/addons/math/const.ts +4 -4
  74. package/src/addons/math/mod289.ts +1 -6
  75. package/src/addons/math/powFast.ts +4 -10
  76. package/src/addons/math/quartic.ts +6 -11
  77. package/src/addons/math/quat/quatLerp.ts +3 -3
  78. package/src/addons/math/quintic.ts +7 -12
  79. package/src/addons/math/rotate2d.ts +1 -6
  80. package/src/addons/math/rotate3d.ts +4 -10
  81. package/src/addons/math/rotate3dX.ts +3 -12
  82. package/src/addons/math/rotate3dY.ts +3 -12
  83. package/src/addons/math/rotate3dZ.ts +3 -12
  84. package/src/addons/math/rotate4d.ts +4 -10
  85. package/src/addons/math/rotate4dX.ts +3 -13
  86. package/src/addons/math/rotate4dY.ts +1 -6
  87. package/src/addons/math/rotate4dZ.ts +3 -13
  88. package/src/addons/math/scale2d.ts +16 -32
  89. package/src/addons/math/toMat3.ts +1 -6
  90. package/src/addons/math/toMat4.ts +1 -6
  91. package/src/addons/sdf/arrowSDF.ts +61 -0
  92. package/src/addons/sdf/boxFrameSDF.ts +31 -0
  93. package/src/addons/sdf/boxSDF.ts +4 -6
  94. package/src/addons/sdf/capsuleSDF.ts +17 -0
  95. package/src/addons/sdf/coneSDF.ts +60 -0
  96. package/src/addons/sdf/crossSDF.ts +4 -7
  97. package/src/addons/sdf/cubeSDF.ts +13 -0
  98. package/src/addons/sdf/cylinderSDF.ts +65 -0
  99. package/src/addons/sdf/dodecahedronSDF.ts +32 -0
  100. package/src/addons/sdf/ellipsoidSDF.ts +14 -0
  101. package/src/addons/sdf/flowerSDF.ts +16 -0
  102. package/src/addons/sdf/gearSDF.ts +22 -0
  103. package/src/addons/sdf/heartSDF.ts +17 -0
  104. package/src/addons/sdf/hexPrismSDF.ts +15 -0
  105. package/src/addons/sdf/hexSDF.ts +8 -15
  106. package/src/addons/sdf/icosahedronSDF.ts +23 -0
  107. package/src/addons/sdf/index.ts +41 -0
  108. package/src/addons/sdf/juliaSDF.ts +39 -0
  109. package/src/addons/sdf/kochSDF.ts +49 -0
  110. package/src/addons/sdf/linkSDF.ts +15 -0
  111. package/src/addons/sdf/mandelbulbSDF.ts +41 -0
  112. package/src/addons/sdf/octahedronSDF.ts +30 -0
  113. package/src/addons/sdf/octogonPrismSDF.ts +19 -0
  114. package/src/addons/sdf/opElongate.ts +35 -0
  115. package/src/addons/sdf/opExtrude.ts +14 -0
  116. package/src/addons/sdf/opIntersection.ts +25 -0
  117. package/src/addons/sdf/opOnion.ts +12 -0
  118. package/src/addons/sdf/opRepeat.ts +49 -0
  119. package/src/addons/sdf/opRevolve.ts +12 -0
  120. package/src/addons/sdf/opRound.ts +12 -0
  121. package/src/addons/sdf/opSubtraction.ts +50 -0
  122. package/src/addons/sdf/opUnion.ts +39 -0
  123. package/src/addons/sdf/planeSDF.ts +21 -0
  124. package/src/addons/sdf/polySDF.ts +32 -0
  125. package/src/addons/sdf/pyramidSDF.ts +29 -0
  126. package/src/addons/sdf/raysSDF.ts +14 -0
  127. package/src/addons/sdf/rhombSDF.ts +10 -0
  128. package/src/addons/sdf/spiralSDF.ts +15 -0
  129. package/src/addons/sdf/starSDF.ts +47 -0
  130. package/src/addons/sdf/superShapeSDF.ts +73 -0
  131. package/src/addons/sdf/tetrahedronSDF.ts +21 -0
  132. package/src/addons/sdf/torusSDF.ts +27 -0
  133. package/src/addons/sdf/triPrismSDF.ts +13 -0
  134. package/src/addons/sdf/triSDF.ts +19 -11
  135. package/src/addons/sdf/vesicaSDF.ts +23 -0
  136. package/src/addons/space/bracketing.ts +1 -2
  137. package/src/addons/space/kaleidoscope.ts +1 -2
  138. package/src/addons/space/scale.ts +42 -7
  139. package/src/addons/space/windmillTile.ts +2 -1
  140. package/src/node/create.ts +2 -3
  141. package/src/node/scope.ts +3 -2
  142. package/src/node/types.ts +1 -1
  143. package/src/node/utils/index.ts +2 -1
  144. package/src/node/utils/infer.ts +2 -1
  145. package/src/node/utils/utils.ts +6 -11
  146. package/src/types.ts +4 -3
  147. package/src/utils/helpers.ts +25 -8
  148. package/src/utils/program.ts +11 -4
  149. package/src/utils/webgl.ts +9 -3
  150. package/src/utils/webgpu.ts +12 -4
@@ -1,30 +1,247 @@
1
- import { Fn, Vec2, Int, Float, float, vec2, floor, ivec2 } from '../../node'
1
+ import { Fn, Vec2, Float, Int, int, vec2, ivec2, ivec4, floor, pow, If } from '../../node'
2
+ import { modi } from '../math/modi'
2
3
 
3
- export const charLookupSimple = Fn(([index]: [Int]): Float => {
4
- const isValidChar = index.greaterThan(31).and(index.lessThan(127))
5
- return float(0).select(float(1), isValidChar)
4
+ // Character constants
5
+ export const CHAR_SIZE = vec2(0.02)
6
+ export const CHAR_TOTAL = 96
7
+
8
+ // Character codes
9
+ export const CHAR = {
10
+ SPACE: 0,
11
+ EXCLAMATION: 1,
12
+ QUOTE: 2,
13
+ NUMBER: 3,
14
+ DOLLAR: 4,
15
+ PERCENT: 5,
16
+ AMPERSAND: 6,
17
+ APOSTROPHE: 7,
18
+ PAREN_LEFT: 8,
19
+ PAREN_RIGHT: 9,
20
+ ASTERISK: 10,
21
+ PLUS: 11,
22
+ COMMA: 12,
23
+ MINUS: 13,
24
+ PERIOD: 14,
25
+ SLASH: 15,
26
+ 0: 16,
27
+ 1: 17,
28
+ 2: 18,
29
+ 3: 19,
30
+ 4: 20,
31
+ 5: 21,
32
+ 6: 22,
33
+ 7: 23,
34
+ 8: 24,
35
+ 9: 25,
36
+ COLON: 26,
37
+ SEMICOLON: 27,
38
+ LESS: 28,
39
+ EQUAL: 29,
40
+ GREATER: 30,
41
+ QUESTION: 31,
42
+ AT: 32,
43
+ A: 33,
44
+ B: 34,
45
+ C: 35,
46
+ D: 36,
47
+ E: 37,
48
+ F: 38,
49
+ G: 39,
50
+ H: 40,
51
+ I: 41,
52
+ J: 42,
53
+ K: 43,
54
+ L: 44,
55
+ M: 45,
56
+ N: 46,
57
+ O: 47,
58
+ P: 48,
59
+ Q: 49,
60
+ R: 50,
61
+ S: 51,
62
+ T: 52,
63
+ U: 53,
64
+ V: 54,
65
+ W: 55,
66
+ X: 56,
67
+ Y: 57,
68
+ Z: 58,
69
+ BRACKET_LEFT: 59,
70
+ BACKSLASH: 60,
71
+ BRACKET_RIGHT: 61,
72
+ CARET: 62,
73
+ UNDERSCORE: 63,
74
+ GRAVE: 64,
75
+ a: 65,
76
+ b: 66,
77
+ c: 67,
78
+ d: 68,
79
+ e: 69,
80
+ f: 70,
81
+ g: 71,
82
+ h: 72,
83
+ i: 73,
84
+ j: 74,
85
+ k: 75,
86
+ l: 76,
87
+ m: 77,
88
+ n: 78,
89
+ o: 79,
90
+ p: 80,
91
+ q: 81,
92
+ r: 82,
93
+ s: 83,
94
+ t: 84,
95
+ u: 85,
96
+ v: 86,
97
+ w: 87,
98
+ x: 88,
99
+ y: 89,
100
+ z: 90,
101
+ BRACE_LEFT: 91,
102
+ BAR: 92,
103
+ BRACE_RIGHT: 93,
104
+ TILDE: 94,
105
+ }
106
+
107
+ // Character bitmap data (compressed)
108
+ const CHAR_DATA: [number, number, number, number][] = [
109
+ [0x0, 0x0, 0x0, 0x0],
110
+ [0x1010, 0x10101010, 0x1010, 0x0],
111
+ [0x242424, 0x24000000, 0x0, 0x0],
112
+ [0x24, 0x247e2424, 0x247e2424, 0x0],
113
+ [0x808, 0x1e20201c, 0x2023c08, 0x8000000],
114
+ [0x30, 0x494a3408, 0x16294906, 0x0],
115
+ [0x3048, 0x48483031, 0x49464639, 0x0],
116
+ [0x101010, 0x10000000, 0x0, 0x0],
117
+ [0x408, 0x8101010, 0x10101008, 0x8040000],
118
+ [0x2010, 0x10080808, 0x8080810, 0x10200000],
119
+ [0x0, 0x24187e, 0x18240000, 0x0],
120
+ [0x0, 0x808087f, 0x8080800, 0x0],
121
+ [0x0, 0x0, 0x1818, 0x8081000],
122
+ [0x0, 0x7e, 0x0, 0x0],
123
+ [0x0, 0x0, 0x1818, 0x0],
124
+ [0x202, 0x4040808, 0x10102020, 0x40400000],
125
+ [0x3c, 0x42464a52, 0x6242423c, 0x0],
126
+ [0x8, 0x18280808, 0x808083e, 0x0],
127
+ [0x3c, 0x42020204, 0x810207e, 0x0],
128
+ [0x7e, 0x4081c02, 0x202423c, 0x0],
129
+ [0x4, 0xc142444, 0x7e040404, 0x0],
130
+ [0x7e, 0x40407c02, 0x202423c, 0x0],
131
+ [0x1c, 0x2040407c, 0x4242423c, 0x0],
132
+ [0x7e, 0x2040408, 0x8101010, 0x0],
133
+ [0x3c, 0x4242423c, 0x4242423c, 0x0],
134
+ [0x3c, 0x4242423e, 0x2020438, 0x0],
135
+ [0x0, 0x181800, 0x1818, 0x0],
136
+ [0x0, 0x181800, 0x1818, 0x8081000],
137
+ [0x4, 0x8102040, 0x20100804, 0x0],
138
+ [0x0, 0x7e00, 0x7e0000, 0x0],
139
+ [0x20, 0x10080402, 0x4081020, 0x0],
140
+ [0x3c42, 0x2040810, 0x1010, 0x0],
141
+ [0x1c22, 0x414f5151, 0x51534d40, 0x201f0000],
142
+ [0x18, 0x24424242, 0x7e424242, 0x0],
143
+ [0x7c, 0x4242427c, 0x4242427c, 0x0],
144
+ [0x1e, 0x20404040, 0x4040201e, 0x0],
145
+ [0x78, 0x44424242, 0x42424478, 0x0],
146
+ [0x7e, 0x4040407c, 0x4040407e, 0x0],
147
+ [0x7e, 0x4040407c, 0x40404040, 0x0],
148
+ [0x1e, 0x20404046, 0x4242221e, 0x0],
149
+ [0x42, 0x4242427e, 0x42424242, 0x0],
150
+ [0x3e, 0x8080808, 0x808083e, 0x0],
151
+ [0x2, 0x2020202, 0x242423c, 0x0],
152
+ [0x42, 0x44485060, 0x50484442, 0x0],
153
+ [0x40, 0x40404040, 0x4040407e, 0x0],
154
+ [0x41, 0x63554949, 0x41414141, 0x0],
155
+ [0x42, 0x62524a46, 0x42424242, 0x0],
156
+ [0x3c, 0x42424242, 0x4242423c, 0x0],
157
+ [0x7c, 0x4242427c, 0x40404040, 0x0],
158
+ [0x3c, 0x42424242, 0x4242423c, 0x4020000],
159
+ [0x7c, 0x4242427c, 0x48444242, 0x0],
160
+ [0x3e, 0x40402018, 0x402027c, 0x0],
161
+ [0x7f, 0x8080808, 0x8080808, 0x0],
162
+ [0x42, 0x42424242, 0x4242423c, 0x0],
163
+ [0x42, 0x42424242, 0x24241818, 0x0],
164
+ [0x41, 0x41414149, 0x49495563, 0x0],
165
+ [0x41, 0x41221408, 0x14224141, 0x0],
166
+ [0x41, 0x41221408, 0x8080808, 0x0],
167
+ [0x7e, 0x4080810, 0x1020207e, 0x0],
168
+ [0x1e10, 0x10101010, 0x10101010, 0x101e0000],
169
+ [0x4040, 0x20201010, 0x8080404, 0x2020000],
170
+ [0x7808, 0x8080808, 0x8080808, 0x8780000],
171
+ [0x1028, 0x44000000, 0x0, 0x0],
172
+ [0x0, 0x0, 0x0, 0xff0000],
173
+ [0x201008, 0x4000000, 0x0, 0x0],
174
+ [0x0, 0x3c0202, 0x3e42423e, 0x0],
175
+ [0x4040, 0x407c4242, 0x4242427c, 0x0],
176
+ [0x0, 0x3c4240, 0x4040423c, 0x0],
177
+ [0x202, 0x23e4242, 0x4242423e, 0x0],
178
+ [0x0, 0x3c4242, 0x7e40403e, 0x0],
179
+ [0xe10, 0x107e1010, 0x10101010, 0x0],
180
+ [0x0, 0x3e4242, 0x4242423e, 0x2023c00],
181
+ [0x4040, 0x407c4242, 0x42424242, 0x0],
182
+ [0x808, 0x380808, 0x808083e, 0x0],
183
+ [0x404, 0x1c0404, 0x4040404, 0x4043800],
184
+ [0x4040, 0x40444850, 0x70484442, 0x0],
185
+ [0x3808, 0x8080808, 0x808083e, 0x0],
186
+ [0x0, 0x774949, 0x49494949, 0x0],
187
+ [0x0, 0x7c4242, 0x42424242, 0x0],
188
+ [0x0, 0x3c4242, 0x4242423c, 0x0],
189
+ [0x0, 0x7c4242, 0x4242427c, 0x40404000],
190
+ [0x0, 0x3e4242, 0x4242423e, 0x2020200],
191
+ [0x0, 0x2e3020, 0x20202020, 0x0],
192
+ [0x0, 0x3e4020, 0x1804027c, 0x0],
193
+ [0x10, 0x107e1010, 0x1010100e, 0x0],
194
+ [0x0, 0x424242, 0x4242423e, 0x0],
195
+ [0x0, 0x424242, 0x24241818, 0x0],
196
+ [0x0, 0x414141, 0x49495563, 0x0],
197
+ [0x0, 0x412214, 0x8142241, 0x0],
198
+ [0x0, 0x424242, 0x4242423e, 0x2023c00],
199
+ [0x0, 0x7e0408, 0x1020407e, 0x0],
200
+ [0xe1010, 0x101010e0, 0x10101010, 0x100e0000],
201
+ [0x80808, 0x8080808, 0x8080808, 0x8080000],
202
+ [0x700808, 0x8080807, 0x8080808, 0x8700000],
203
+ [0x3149, 0x46000000, 0x0, 0x0],
204
+ ]
205
+
206
+ const charLUT = Fn(([index]: [Int]) => {
207
+ const result = ivec4(0).toVar('result')
208
+ let ifChain = If(index.equal(int(0)), () => void result.assign(ivec4(...CHAR_DATA[0])))
209
+ for (let i = 1; i < CHAR_DATA.length; i++)
210
+ ifChain = ifChain.ElseIf(index.equal(int(i)), () => void result.assign(ivec4(...CHAR_DATA[i])))
211
+ return result
6
212
  }).setLayout({
7
- name: 'charLookupSimple',
8
- type: 'float',
213
+ name: 'charLUT',
214
+ type: 'ivec4',
9
215
  inputs: [{ name: 'index', type: 'int' }],
10
216
  })
11
217
 
12
- export const charSimple = Fn(([uv, charCode]: [Vec2, Int]): Float => {
13
- const charCoord = ivec2(floor(uv.mul(vec2(8, 16)))).toVar()
14
- charCoord.x.assign(charCoord.x.clamp(0, 7))
15
- charCoord.y.assign(charCoord.y.clamp(0, 15))
16
- const centerX = charCoord.x.sub(4).abs()
17
- const centerY = charCoord.y.sub(8).abs()
18
- const pattern = centerX.add(centerY).lessThan(charCode.mod(8) as any)
19
- return float(0).select(float(1), pattern)
218
+ export const char = Fn(([uv, charCode]: [Vec2, Int]): Float => {
219
+ const charCoord = ivec2(7, 15)
220
+ .sub(floor(uv.mul(vec2(8, 16))).toIVec2())
221
+ .toVar('charCoord')
222
+ const col = charLUT(charCode).toVar('col')
223
+ const fourLines = int(0).toVar('fourLines')
224
+ const index = charCoord.y.toFloat().div(4).floor().toInt().toVar('index')
225
+
226
+ If(index.equal(int(0)), () => void fourLines.assign(col.x))
227
+ .ElseIf(index.equal(int(1)), () => void fourLines.assign(col.y))
228
+ .ElseIf(index.equal(int(2)), () => void fourLines.assign(col.z))
229
+ .Else(() => void fourLines.assign(col.w))
230
+
231
+ const yMod4 = modi(charCoord.y as unknown as Int, int(4)).toVar('yMod4')
232
+ const exponent = int(3).sub(yMod4).toVar('exponent')
233
+ const divisor = pow(int(256).toFloat(), exponent.toFloat()).toInt().toVar('divisor')
234
+ const currentLine = modi(fourLines.div(divisor), int(256)).toVar('currentLine')
235
+
236
+ const pixelDivisor = pow(int(2).toFloat(), charCoord.x.toFloat()).toInt().toVar('pixelDivisor')
237
+ const currentPixel = modi(currentLine.div(pixelDivisor), int(2)).toVar('currentPixel')
238
+
239
+ return currentPixel.toFloat()
20
240
  }).setLayout({
21
- name: 'charSimple',
241
+ name: 'char',
22
242
  type: 'float',
23
243
  inputs: [
24
244
  { name: 'uv', type: 'vec2' },
25
245
  { name: 'charCode', type: 'int' },
26
246
  ],
27
247
  })
28
-
29
- // Default char function using simplified implementation
30
- export const char = charSimple
@@ -26,4 +26,25 @@ export const circleStroke = Fn(([st, size, strokeWidth]: [Vec2, Float, Float]):
26
26
  ],
27
27
  })
28
28
 
29
- export const circle = circleFill
29
+ export const circle = Fn(([st, size]: [Vec2, Float]): Float => {
30
+ return fill(circleSDFBasic(st), size)
31
+ }).setLayout({
32
+ name: 'circle',
33
+ type: 'float',
34
+ inputs: [
35
+ { name: 'st', type: 'vec2' },
36
+ { name: 'size', type: 'float' },
37
+ ],
38
+ })
39
+
40
+ export const circleWithStroke = Fn(([st, size, strokeWidth]: [Vec2, Float, Float]): Float => {
41
+ return stroke(circleSDFBasic(st), size, strokeWidth)
42
+ }).setLayout({
43
+ name: 'circleWithStroke',
44
+ type: 'float',
45
+ inputs: [
46
+ { name: 'st', type: 'vec2' },
47
+ { name: 'size', type: 'float' },
48
+ { name: 'strokeWidth', type: 'float' },
49
+ ],
50
+ })
@@ -0,0 +1,42 @@
1
+ import { Fn, Vec2, Vec4, Int, vec2, vec4, floor, float } from '../../node'
2
+ import { scale2dVec } from '../space/scale'
3
+ import { macbeth } from '../color/palette/macbeth'
4
+ import { crossSDF } from '../sdf/crossSDF'
5
+ import { rectSDF } from '../sdf/rectSDF'
6
+ import { rectFill } from './rect'
7
+ import { fill } from './fill'
8
+ import { stroke } from './stroke'
9
+
10
+ export const colorCheckerTile = Fn(([uv]: [Vec2]): Vec4 => {
11
+ const st = scale2dVec(uv, vec2(1, 1.5)).mul(vec2(6, 4)).toVar('st')
12
+ return vec4(st.fract(), st.floor())
13
+ }).setLayout({
14
+ name: 'colorCheckerTile',
15
+ type: 'vec4',
16
+ inputs: [{ name: 'uv', type: 'vec2' }],
17
+ })
18
+
19
+ export const colorCheckerMacbeth = Fn(([uv]: [Vec2]): Vec4 => {
20
+ const t = colorCheckerTile(vec2(uv.x, uv.y.oneMinus())).toVar('t')
21
+ const index = t.w.mul(6).add(t.z).floor().toInt().toVar('index')
22
+
23
+ const color = macbeth(index)
24
+ .mul(rectFill(t.xy, vec2(0.8)))
25
+ .add(fill(crossSDF(uv, float(2)), float(0.015)))
26
+ .add(
27
+ stroke(rectSDF(uv, vec2(1.015, 0.68)), float(1), float(0.01))
28
+ .sub(rectFill(uv, vec2(0.966, 1)))
29
+ .sub(rectFill(uv, vec2(1.1, 0.63)))
30
+ .saturate()
31
+ )
32
+ .toVar('color')
33
+
34
+ const alpha = rectFill(uv, vec2(1.03, 0.69)).toVar('alpha')
35
+ return vec4(color.saturate().mul(alpha), alpha)
36
+ }).setLayout({
37
+ name: 'colorCheckerMacbeth',
38
+ type: 'vec4',
39
+ inputs: [{ name: 'uv', type: 'vec2' }],
40
+ })
41
+
42
+ export const colorChecker = colorCheckerMacbeth
@@ -0,0 +1,66 @@
1
+ import { Fn, Vec2, Vec4, vec2, vec4, texture, step, float, vec3 } from '../../node'
2
+ import { nearest } from '../space/nearest'
3
+
4
+ const pickerSize = vec2(0.05)
5
+ const crosshairSize = float(0.003)
6
+
7
+ export const colorPickerSample = Fn(([tex, pos, texResolution]: [any, Vec2, Vec2]): Vec4 => {
8
+ const nearestPos = nearest(pos, texResolution)
9
+ return texture(tex, nearestPos)
10
+ }).setLayout({
11
+ name: 'colorPickerSample',
12
+ type: 'vec4',
13
+ inputs: [
14
+ { name: 'tex', type: 'sampler2D' },
15
+ { name: 'pos', type: 'vec2' },
16
+ { name: 'texResolution', type: 'vec2' },
17
+ ],
18
+ })
19
+
20
+ export const colorPickerDisplay = Fn(([st, pickerPos, pickedColor]: [Vec2, Vec2, Vec4]): Vec4 => {
21
+ const displayPos = pickerPos.add(vec2(0.08, 0.08)).toVar('displayPos')
22
+ const distToDisplay = st.sub(displayPos).abs().toVar('distToDisplay')
23
+ const inPatch = step(distToDisplay.x, pickerSize.x).mul(step(distToDisplay.y, pickerSize.y)).toVar('inPatch')
24
+ const crosshair = step(st.sub(pickerPos).abs().x, crosshairSize)
25
+ .mul(step(st.sub(pickerPos).abs().y, crosshairSize.mul(5)))
26
+ .add(
27
+ step(st.sub(pickerPos).abs().y, crosshairSize).mul(
28
+ step(st.sub(pickerPos).abs().x, crosshairSize.mul(5))
29
+ )
30
+ )
31
+ .toVar('crosshair')
32
+ const borderWidth = float(0.002).toVar('borderWidth')
33
+ const inBorder = step(distToDisplay.x, pickerSize.x.add(borderWidth))
34
+ .mul(step(distToDisplay.y, pickerSize.y.add(borderWidth)))
35
+ .sub(inPatch)
36
+ .toVar('inBorder')
37
+ const result = vec4(0, 0, 0, 0).toVar('result')
38
+ result.rgb.assign(pickedColor.rgb.mul(inPatch))
39
+ result.a.assign(inPatch)
40
+ result.rgb.assign(result.rgb.add(vec3(1, 1, 1).mul(crosshair)))
41
+ result.a.assign(result.a.add(crosshair))
42
+ result.a.assign(result.a.add(inBorder))
43
+ return result
44
+ }).setLayout({
45
+ name: 'colorPickerDisplay',
46
+ type: 'vec4',
47
+ inputs: [
48
+ { name: 'st', type: 'vec2' },
49
+ { name: 'pickerPos', type: 'vec2' },
50
+ { name: 'pickedColor', type: 'vec4' },
51
+ ],
52
+ })
53
+
54
+ export const colorPicker = Fn(([st, tex, pickerPos, texResolution]: [Vec2, any, Vec2, Vec2]): Vec4 => {
55
+ const pickedColor = colorPickerSample(tex, pickerPos, texResolution)
56
+ return colorPickerDisplay(st, pickerPos, pickedColor)
57
+ }).setLayout({
58
+ name: 'colorPicker',
59
+ type: 'vec4',
60
+ inputs: [
61
+ { name: 'st', type: 'vec2' },
62
+ { name: 'tex', type: 'sampler2D' },
63
+ { name: 'pickerPos', type: 'vec2' },
64
+ { name: 'texResolution', type: 'vec2' },
65
+ ],
66
+ })