q5 2.4.10 → 2.5.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.
package/src/readme.md CHANGED
@@ -54,6 +54,11 @@ WebGPU rendering modules are in development:
54
54
  - [webgpu-drawing](#webgpu-drawing)
55
55
  - [webgpu-image](#webgpu-image)
56
56
  - [webgpu-text](#webgpu-text)
57
+ - [Default Font](#default-font)
58
+ - [Loading Custom Fonts](#loading-custom-fonts)
59
+ - [Displaying Emojis](#displaying-emojis)
60
+ - [Lightweight Use](#lightweight-use)
61
+ - [Implemented functions](#implemented-functions)
57
62
  - [math](#math)
58
63
  - [noisier](#noisier)
59
64
 
@@ -179,13 +184,83 @@ Implemented functions:
179
184
 
180
185
  ## webgpu-text
181
186
 
182
- > Use `textFill` and `textStroke` to set text colors.
187
+ The q5 WebGPU text renderer uses the multi-channel signed distance fields (MSDF) technique for high performance and high quality real-time text rendering. Text can be rapidly recolored, rotated, and scaled without any loss in quality or performance.
183
188
 
184
- Internally, q5's WebGPU renderer uses a q5 graphics object to draw text to a Canvas2D canvas via `createTextImage`, then converts that canvas to a WebGPU texture. Each texture is cached, so it doesn't have to be recreated every frame that users want to display the same text.
189
+ MSDF, introduced by Chlumsky Viktor in his master's thesis ["Shape Decomposition for Multi-channel Distance Fields" (2015)](https://dspace.cvut.cz/bitstream/handle/10467/62770/F8-DP-2015-Chlumsky-Viktor-thesis.pdf), improves upon the signed distance field (SDF) technique, popularized by Chris Green and [Valve Software](https://www.valvesoftware.com/en/) in ["Improved Alpha-Tested Magnification for Vector Textures and Special Effects" (2007)](https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf).
185
190
 
186
- Implemented functions:
191
+ | SDF | MSDF |
192
+ | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
193
+ | ![demo-sdf16](https://user-images.githubusercontent.com/18639794/106391905-e679af00-63ef-11eb-96c3-993176330911.png) | ![demo-msdf16](https://user-images.githubusercontent.com/18639794/106391899-e37ebe80-63ef-11eb-988b-4764004bb196.png) |
194
+
195
+ ### Default Font
196
+
197
+ For convenience, if no font is loaded before `text` is run, then q5's default MSDF font is loaded: https://q5js.org/fonts/YaHei-msdf.json
198
+
199
+ ![YaHei msdf texture](https://q5js.org/fonts/YaHei.png)
200
+
201
+ This 512x512 msdf texture (207kb) was made with the [Microsoft YaHei](https://learn.microsoft.com/en-us/typography/font-list/microsoft-yahei) font and stores every character visible on a standard English keyboard, letters with diacritics (accents) used in European languages, and mathematical symbols.
202
+
203
+ ```
204
+ !"#$%&'()\*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^\_`abcdefghijklmnopqrstuvwxyz{|}~€¡¢£¥©®°²³´·¹º¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ‘’“”π
205
+ ```
206
+
207
+ > Do you think any other characters ought to be included in the default set? Let us know! https://github.com/q5js/q5.js/issues
208
+
209
+ ### Loading Custom Fonts
210
+
211
+ You can choose a custom set of characters and convert fonts to MSDF format by using the [msdf-bmfont-xml](https://msdf-bmfont.donmccurdy.com/) website, created by Don McCurdy.
212
+
213
+ Here's how to load an MSDF font:
214
+
215
+ ```js
216
+ function preload() {
217
+ loadFont('arial-msdf.json');
218
+ }
219
+
220
+ function setup() {
221
+ createCanvas(200, 200);
222
+ }
223
+
224
+ function draw() {
225
+ fill(0.71, 0.92, 1);
226
+ text('Hello, World!', mouseX, mouseY);
227
+ }
228
+
229
+ Q5.webgpu();
230
+ ```
231
+
232
+ ### Displaying Emojis
233
+
234
+ Full color emoji characters can't be rendered using the MSDF technique, so use `createTextImage` and display them with `textImage`:
235
+
236
+ ```js
237
+ let puppy;
238
+
239
+ function setup() {
240
+ createCanvas(200, 200);
241
+ textSize(100);
242
+ puppy = createTextImage('🐶');
243
+ }
244
+
245
+ function draw() {
246
+ textAlign(CENTER, CENTER);
247
+ textImage(puppy, 0, 0);
248
+ }
249
+
250
+ Q5.webgpu();
251
+ ```
252
+
253
+ ### Lightweight Use
254
+
255
+ For super lightweight use load <https://q5js.org/fonts/YaHei-256-msdf.json>, which has a limited character set of english letters and some common punctuation symbols that completely fill in a 256x256 texture (73kb).
256
+
257
+ ```
258
+ !@'",-.0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
259
+ ```
260
+
261
+ ### Implemented functions
187
262
 
188
- `loadFont`,`textFont`, `textSize`, `textLeading`, `textStyle`, `textAlign`, `textWidth`, `textAscent`, `textDescent`, `textFill`, `textStroke`, `text`
263
+ `loadFont`, `text`, `textSize`, `textAlign`, `textWidth`, `createTextImage`, `textImage`
189
264
 
190
265
  ## math
191
266