q5 2.4.10 → 2.5.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.
package/src/readme.md CHANGED
@@ -54,6 +54,12 @@ 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
+ - [Create a MSDF Font](#create-a-msdf-font)
59
+ - [Load a MSDF font](#load-a-msdf-font)
60
+ - [Displaying Emojis](#displaying-emojis)
61
+ - [Lightweight Use](#lightweight-use)
62
+ - [Implemented functions](#implemented-functions)
57
63
  - [math](#math)
58
64
  - [noisier](#noisier)
59
65
 
@@ -179,13 +185,84 @@ Implemented functions:
179
185
 
180
186
  ## webgpu-text
181
187
 
182
- > Use `textFill` and `textStroke` to set text colors.
188
+ The q5 WebGPU text renderer uses multi-channel signed distance fields (MSDF) 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
189
 
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.
190
+ 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
191
 
186
- Implemented functions:
192
+ | SDF | MSDF |
193
+ | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
194
+ | ![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) |
195
+
196
+ ### Default Font
197
+
198
+ 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
199
+
200
+ ![YaHei msdf texture](https://q5js.org/fonts/YaHei.png)
201
+
202
+ 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.
203
+
204
+ ```
205
+ !"#$%&'()\*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^\_`abcdefghijklmnopqrstuvwxyz{|}~€¡¢£¥©®°²³´·¹º¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ‘’“”π
206
+ ```
207
+
208
+ > Do you think any other characters ought to be included in the default set? Let us know! https://github.com/q5js/q5.js/issues
209
+
210
+ ### Create a MSDF Font
211
+
212
+ 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.
213
+
214
+ ### Load a MSDF font
215
+
216
+ Fonts must be in MSDF format with the file ending "-msdf.json".
217
+
218
+ ```js
219
+ function preload() {
220
+ loadFont('arial-msdf.json');
221
+ }
222
+
223
+ function setup() {
224
+ createCanvas(200, 200);
225
+ }
226
+
227
+ function draw() {
228
+ fill(0.71, 0.92, 1);
229
+ text('Hello, World!', mouseX, mouseY);
230
+ }
231
+
232
+ Q5.webgpu();
233
+ ```
234
+
235
+ ### Displaying Emojis
236
+
237
+ Full color emoji characters can't be rendered using the MSDF technique, so draw them using `textImage`.
238
+
239
+ ```js
240
+ function setup() {
241
+ createCanvas(200, 200);
242
+ textSize(100);
243
+ }
244
+
245
+ function draw() {
246
+ textAlign(CENTER, CENTER);
247
+ textImage('🐶', 0, 0);
248
+ }
249
+
250
+ Q5.webgpu();
251
+ ```
252
+
253
+ You can also use `createTextImage` and display it with `textImage`.
254
+
255
+ ### Lightweight Use
256
+
257
+ 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).
258
+
259
+ ```
260
+ !@'",-.0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
261
+ ```
262
+
263
+ ### Implemented functions
187
264
 
188
- `loadFont`,`textFont`, `textSize`, `textLeading`, `textStyle`, `textAlign`, `textWidth`, `textAscent`, `textDescent`, `textFill`, `textStroke`, `text`
265
+ `loadFont`, `text`, `textFont`, `textSize`, `textAlign`, `textWidth`, `createTextImage`, `textImage`
189
266
 
190
267
  ## math
191
268