@woosh/meep-engine 3.78.1 → 3.78.3

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 (47) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/package.json +1 -1
  3. package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -1
  4. package/src/engine/asset/loaders/GroomAssetLoader.js +2 -1
  5. package/src/engine/graphics/hair/Groom.d.ts +30 -0
  6. package/src/engine/graphics/hair/Groom.d.ts.map +1 -1
  7. package/src/engine/graphics/hair/Groom.js +35 -0
  8. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +18 -2
  9. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -1
  10. package/src/engine/graphics/hair/GroomSerializationAdapter.js +36 -6
  11. package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts +8 -0
  12. package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts.map +1 -0
  13. package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.js +44 -0
  14. package/src/engine/graphics/hair/groom_bake_shelter.d.ts +33 -0
  15. package/src/engine/graphics/hair/groom_bake_shelter.d.ts.map +1 -0
  16. package/src/engine/graphics/hair/groom_bake_shelter.js +288 -0
  17. package/src/engine/graphics/hair/groom_build_group.d.ts +10 -2
  18. package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -1
  19. package/src/engine/graphics/hair/groom_build_group.js +8 -2
  20. package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts +119 -0
  21. package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts.map +1 -0
  22. package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.js +563 -0
  23. package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.d.ts +11 -0
  24. package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.d.ts.map +1 -0
  25. package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.js +10 -0
  26. package/src/generation/wfc/GridWFCCompiledTileSet.d.ts +123 -0
  27. package/src/generation/wfc/GridWFCCompiledTileSet.d.ts.map +1 -0
  28. package/src/generation/wfc/GridWFCCompiledTileSet.js +355 -0
  29. package/src/generation/wfc/GridWFCEdge.d.ts +13 -0
  30. package/src/generation/wfc/GridWFCEdge.d.ts.map +1 -0
  31. package/src/generation/wfc/GridWFCEdge.js +14 -0
  32. package/src/generation/wfc/GridWFCTileSet.d.ts +120 -0
  33. package/src/generation/wfc/GridWFCTileSet.d.ts.map +1 -0
  34. package/src/generation/wfc/GridWFCTileSet.js +275 -0
  35. package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
  36. package/src/shade/renderer/hair/GPUHairSystem.js +55 -11
  37. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -1
  38. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +4 -0
  39. package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts +77 -15
  40. package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts.map +1 -1
  41. package/src/shade/renderer/hair/HAIR_SIMULATION.js +104 -17
  42. package/src/shade/renderer/hair/chunk_hair_guide.d.ts +9 -2
  43. package/src/shade/renderer/hair/chunk_hair_guide.d.ts.map +1 -1
  44. package/src/shade/renderer/hair/chunk_hair_guide.js +30 -2
  45. package/src/shade/renderer/hair/shader_hair_simulate.d.ts +27 -18
  46. package/src/shade/renderer/hair/shader_hair_simulate.d.ts.map +1 -1
  47. package/src/shade/renderer/hair/shader_hair_simulate.js +174 -83
@@ -25,6 +25,7 @@ import {
25
25
  HAIR_BINDING_NONE,
26
26
  HAIR_COLLIDER_LIMIT,
27
27
  HAIR_COLLIDER_WORDS,
28
+ HAIR_EXPOSED_DRAG_SHARE,
28
29
  HAIR_FIBRE_DENSITY,
29
30
  HAIR_FOLLOW_THE_LEADER_DAMPING,
30
31
  HAIR_GUIDE_BOUNDS_WORDS,
@@ -33,6 +34,10 @@ import {
33
34
  HAIR_STATE_LAST_POSITION,
34
35
  HAIR_STATE_NONE,
35
36
  HAIR_STATE_POSITION,
37
+ HAIR_STATE_PREVIOUS_POSITION,
38
+ HAIR_STATE_PREVIOUS_ROTATION,
39
+ HAIR_STATE_SOLVED_POSITION,
40
+ HAIR_STATE_SOLVED_ROTATION,
36
41
  HAIR_STATE_VELOCITY
37
42
  } from "./HAIR_SIMULATION.js";
38
43
  import { HAIR_LOD_WORKGROUP_SIZE } from "./shader_hair_lod.js";
@@ -140,9 +145,9 @@ pose_resources.createGroup()
140
145
  .addStorageBuffer("hair_colliders", WebGPUArray.u32, true);
141
146
 
142
147
  /**
143
- * Writes each collider of the frame's list the way from the world into its own frame (`HAIR_COLLIDER_WORDS`), a
144
- * thread a collider, from its entity's world matrix as the scene holds it: a rigid motion and a uniform scale, whose
145
- * largest axis is taken.
148
+ * Writes each collider of the frame's list the way from the world into its own frame (`HAIR_COLLIDER_WORDS`), now
149
+ * and a frame ago, a thread a collider, from its entity's world matrices as the scene holds them: a rigid motion and
150
+ * a uniform scale, whose largest axis is taken.
146
151
  *
147
152
  * @type {ComputeShader}
148
153
  */
@@ -152,6 +157,22 @@ export const shader_hair_collider_poses = ComputeShader.from({
152
157
  body: CodeChunk.from(
153
158
  //language=WGSL
154
159
  `
160
+ // the way from the world into the frame of a matrix, eight words from a word of the collider list
161
+ fn hair_collider_write_pose(at: u32, m: mat4x4<f32>) {
162
+ let scale = max(length(m[0].xyz), max(length(m[1].xyz), length(m[2].xyz)));
163
+ let rotation = quat_from_m3(mat3x3<f32>(m[0].xyz, m[1].xyz, m[2].xyz) * (1.0 / max(scale, 1e-30)));
164
+ let inverse = quat_conjugate(rotation);
165
+
166
+ hair_colliders[at] = bitcast<u32>(inverse.x);
167
+ hair_colliders[at + 1u] = bitcast<u32>(inverse.y);
168
+ hair_colliders[at + 2u] = bitcast<u32>(inverse.z);
169
+ hair_colliders[at + 3u] = bitcast<u32>(inverse.w);
170
+ hair_colliders[at + 4u] = bitcast<u32>(m[3].x);
171
+ hair_colliders[at + 5u] = bitcast<u32>(m[3].y);
172
+ hair_colliders[at + 6u] = bitcast<u32>(m[3].z);
173
+ hair_colliders[at + 7u] = bitcast<u32>(scale);
174
+ }
175
+
155
176
  @compute @workgroup_size(${COMPUTE_SHADER_DEFAULT_GROUP_SIZE})
156
177
  fn main(@builtin(global_invocation_id) id: vec3<u32>) {
157
178
  if (id.x >= settings.count) {
@@ -159,20 +180,10 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
159
180
  }
160
181
 
161
182
  let at = settings.first + id.x * ${HAIR_COLLIDER_WORDS}u;
162
- let m = scene_read_node(&scene_database, hair_colliders[at + 1u]).global;
163
-
164
- let scale = max(length(m[0].xyz), max(length(m[1].xyz), length(m[2].xyz)));
165
- let rotation = quat_from_m3(mat3x3<f32>(m[0].xyz, m[1].xyz, m[2].xyz) * (1.0 / max(scale, 1e-30)));
166
- let inverse = quat_conjugate(rotation);
183
+ let node = scene_read_node(&scene_database, hair_colliders[at + 1u]);
167
184
 
168
- hair_colliders[at + 8u] = bitcast<u32>(inverse.x);
169
- hair_colliders[at + 9u] = bitcast<u32>(inverse.y);
170
- hair_colliders[at + 10u] = bitcast<u32>(inverse.z);
171
- hair_colliders[at + 11u] = bitcast<u32>(inverse.w);
172
- hair_colliders[at + 12u] = bitcast<u32>(m[3].x);
173
- hair_colliders[at + 13u] = bitcast<u32>(m[3].y);
174
- hair_colliders[at + 14u] = bitcast<u32>(m[3].z);
175
- hair_colliders[at + 15u] = bitcast<u32>(scale);
185
+ hair_collider_write_pose(at + 8u, node.global);
186
+ hair_collider_write_pose(at + 16u, node.prev_global);
176
187
  }
177
188
  `, [chunk_scene_database_access, chunk_quat_from_m3, chunk_quat_conjugate]),
178
189
  });
@@ -180,10 +191,18 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
180
191
  export const HAIR_SIMULATE_SETTINGS = WebGPUStruct.from({
181
192
  /** the world's gravity, metres a second squared */
182
193
  gravity: vec3f,
183
- /** a substep, seconds */
194
+ /** a step, seconds */
184
195
  step: f32,
185
- /** substeps this frame */
186
- substeps: u32,
196
+ /** steps this frame */
197
+ steps: u32,
198
+ /** the share of the frame's motion the first step falls at, a frame ago at 0 and now at 1 */
199
+ first: f32,
200
+ /** the share of the frame's motion from a step to the next */
201
+ stride: f32,
202
+ /** how far what is drawn is from the step before the last, 0, to the last, 1 */
203
+ blend: f32,
204
+ /** the scene's clock moved this frame, seconds */
205
+ seconds: f32,
187
206
  }, "HairSimulateSettings");
188
207
 
189
208
  const simulate_resources = new ShaderResourceSetDescriptor();
@@ -216,8 +235,9 @@ fn hair_ordered(v: f32) -> u32 {
216
235
  return bits ^ select(0x80000000u, 0xFFFFFFFFu, (bits & 0x80000000u) != 0u);
217
236
  }
218
237
 
219
- // pushes a node out of the instance's colliders, by its wisp's radius, and takes away part of its sliding along them
220
- fn hair_collide(row: u32, anchor: vec3<f32>, start: vec3<f32>, position: vec3<f32>, radius: f32) -> vec3<f32> {
238
+ // pushes a node out of the instance's colliders, by its wisp's radius, and takes away part of its sliding along them;
239
+ // the colliders where they are at a share of the frame's motion, a frame ago at 0 and now at 1
240
+ fn hair_collide(row: u32, anchor: vec3<f32>, start: vec3<f32>, position: vec3<f32>, radius: f32, share: f32) -> vec3<f32> {
221
241
  var p = position;
222
242
 
223
243
  let first = hair_colliders[row * 2u];
@@ -234,9 +254,16 @@ fn hair_collide(row: u32, anchor: vec3<f32>, start: vec3<f32>, position: vec3<f3
234
254
  let friction = bitcast<f32>(hair_colliders[at + 2u]);
235
255
  let inflation = bitcast<f32>(hair_colliders[at + 3u]);
236
256
  let parameters = bitcast<vec4<f32>>(vec4<u32>(hair_colliders[at + 4u], hair_colliders[at + 5u], hair_colliders[at + 6u], hair_colliders[at + 7u]));
237
- let inverse = bitcast<vec4<f32>>(vec4<u32>(hair_colliders[at + 8u], hair_colliders[at + 9u], hair_colliders[at + 10u], hair_colliders[at + 11u]));
238
- let origin = bitcast<vec3<f32>>(vec3<u32>(hair_colliders[at + 12u], hair_colliders[at + 13u], hair_colliders[at + 14u]));
239
- let scale = bitcast<f32>(hair_colliders[at + 15u]);
257
+ let inverse_now = bitcast<vec4<f32>>(vec4<u32>(hair_colliders[at + 8u], hair_colliders[at + 9u], hair_colliders[at + 10u], hair_colliders[at + 11u]));
258
+ let origin_now = bitcast<vec3<f32>>(vec3<u32>(hair_colliders[at + 12u], hair_colliders[at + 13u], hair_colliders[at + 14u]));
259
+ let scale_now = bitcast<f32>(hair_colliders[at + 15u]);
260
+ let inverse_before = bitcast<vec4<f32>>(vec4<u32>(hair_colliders[at + 16u], hair_colliders[at + 17u], hair_colliders[at + 18u], hair_colliders[at + 19u]));
261
+ let origin_before = bitcast<vec3<f32>>(vec3<u32>(hair_colliders[at + 20u], hair_colliders[at + 21u], hair_colliders[at + 22u]));
262
+ let scale_before = bitcast<f32>(hair_colliders[at + 23u]);
263
+
264
+ let inverse = hair_quat_nlerp(inverse_before, inverse_now, share);
265
+ let origin = mix(origin_before, origin_now, share);
266
+ let scale = mix(scale_before, scale_now, share);
240
267
 
241
268
  let local = quat_rotate_v3(inverse, anchor + p - origin) / scale;
242
269
  let field = shape_record_signed_distance_gradient(kind, parameters, local);
@@ -247,7 +274,7 @@ fn hair_collide(row: u32, anchor: vec3<f32>, start: vec3<f32>, position: vec3<f3
247
274
 
248
275
  p -= normal * depth;
249
276
 
250
- // positional friction: of the sliding this substep, as much is taken away as the push out was deep
277
+ // positional friction: of the sliding this step, as much is taken away as the push out was deep
251
278
  let travel = p - start;
252
279
  let sliding = travel - normal * dot(travel, normal);
253
280
  let length_ = length(sliding);
@@ -315,11 +342,19 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
315
342
  let scale = max(length(now[0]), max(length(now[1]), length(now[2])));
316
343
  let diameter = bitcast<f32>(record.z) * scale;
317
344
  let width = instance.width_mean * scale;
318
- let mass = f32(record.y) * ${HAIR_FIBRE_DENSITY}.0 * 0.78539816 * width * width;
345
+ // a fibre's mass a unit length; and the group as one body in the wind's way, as the entity scales it
346
+ let fibre_mass = ${HAIR_FIBRE_DENSITY}.0 * 0.78539816 * width * width;
347
+ let body_diameter = instance.body_diameter * scale;
348
+ let body_mass = instance.body_mass * scale * scale;
319
349
  let radius = 0.5 * diameter + instance.thickness;
320
350
 
321
351
  const IDENTITY = vec4<f32>(0.0, 0.0, 0.0, 1.0);
322
352
 
353
+ // the root's frame now: its rotation, and where the root is
354
+ let turn_now = normalize(quat_from_m3(now * (1.0 / max(scale, 1e-30))));
355
+ let rest_0 = hair_rest_point(instance, strand, 0u).xyz;
356
+ let root_now = now * rest_0 + now_origin;
357
+
323
358
  if (reset) {
324
359
  // at rest in the entity's frame, still
325
360
  for (var i = 0u; i < nodes; i++) {
@@ -330,34 +365,42 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
330
365
  hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i, guide)] = IDENTITY;
331
366
  hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_POSITION}u, i, guide)] = vec4<f32>(x, 0.0);
332
367
  hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_FRAME}u, i, guide)] = IDENTITY;
368
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)] = vec4<f32>(x, 0.0);
369
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, i, guide)] = turn_now;
370
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_POSITION}u, i, guide)] = vec4<f32>(quat_rotate_v3(quat_conjugate(turn_now), x - root_now), 0.0);
371
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_ROTATION}u, i, guide)] = IDENTITY;
333
372
  }
334
- } else if (settings.substeps == 0u) {
335
- // no time this frame: the guides are carried with the entity from where it was to where it is, the way its
336
- // own geometry is, and what was becomes a frame ago
337
- let before_scale = max(length(before[0]), max(length(before[1]), length(before[2])));
338
- let carry = now * (transpose(before) * (1.0 / max(before_scale * before_scale, 1e-30)));
339
- let turn = quat_from_m3(carry * (before_scale / max(scale, 1e-30)));
340
-
373
+ } else {
374
+ // the frame begins: what was drawn becomes a frame ago, and the solved positions follow the anchor
341
375
  for (var i = 0u; i < nodes; i++) {
342
- let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)].xyz - moved;
343
- let v = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, i, guide)].xyz;
344
- let q = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i, guide)];
376
+ let drawn = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)].xyz - moved;
377
+ let drawn_frame = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i, guide)];
378
+ let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)].xyz - moved;
345
379
 
346
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_POSITION}u, i, guide)] = vec4<f32>(x, 0.0);
347
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_FRAME}u, i, guide)] = q;
348
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)] = vec4<f32>(carry * (x - before_origin) + now_origin, 0.0);
349
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, i, guide)] = vec4<f32>(quat_rotate_v3(turn, v), 0.0);
350
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i, guide)] = quat_multiply(quat_multiply(turn, q), quat_conjugate(turn));
380
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_POSITION}u, i, guide)] = vec4<f32>(drawn, 0.0);
381
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_FRAME}u, i, guide)] = drawn_frame;
382
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)] = vec4<f32>(x, 0.0);
351
383
  }
352
- } else {
353
- // the frame begins: positions follow the anchor, and what is now becomes a frame ago
354
- for (var i = 0u; i < nodes; i++) {
355
- let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)].xyz - moved;
356
- let q = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i, guide)];
357
384
 
358
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)] = vec4<f32>(x, 0.0);
359
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_POSITION}u, i, guide)] = vec4<f32>(x, 0.0);
360
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_LAST_FRAME}u, i, guide)] = q;
385
+ if (settings.seconds == 0.0) {
386
+ // no time this frame: the solved state is carried with the entity from where it was to where it is, the
387
+ // way its own geometry is
388
+ let before_scale = max(length(before[0]), max(length(before[1]), length(before[2])));
389
+ let carry = now * (transpose(before) * (1.0 / max(before_scale * before_scale, 1e-30)));
390
+ let turn = normalize(quat_from_m3(carry * (before_scale / max(scale, 1e-30))));
391
+ let grown = scale / max(before_scale, 1e-30);
392
+
393
+ for (var i = 0u; i < nodes; i++) {
394
+ let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)].xyz;
395
+ let v = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, i, guide)].xyz;
396
+ let q = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, i, guide)];
397
+ let u = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_POSITION}u, i, guide)].xyz;
398
+
399
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)] = vec4<f32>(carry * (x - before_origin) + now_origin, 0.0);
400
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, i, guide)] = vec4<f32>(quat_rotate_v3(turn, v), 0.0);
401
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, i, guide)] = normalize(quat_multiply(turn, q));
402
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_POSITION}u, i, guide)] = vec4<f32>(u * grown, 0.0);
403
+ }
361
404
  }
362
405
 
363
406
  let h = settings.step;
@@ -366,22 +409,36 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
366
409
  let keep_velocity = exp(-instance.damping * h);
367
410
  let local_pull = 1.0 - exp(-instance.local_shape_rate * h);
368
411
 
369
- let rest_0 = hair_rest_point(instance, strand, 0u).xyz;
412
+ for (var k = 0u; k < settings.steps; k++) {
413
+ if (k + 1u == settings.steps) {
414
+ // what the last step starts from is what the drawn state is blended from: in its root's frame
415
+ let from_root = quat_conjugate(hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, 0u, guide)]);
416
+ let root_before = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, 0u, guide)].xyz;
417
+
418
+ for (var i = 0u; i < nodes; i++) {
419
+ let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)].xyz;
420
+ let q = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, i, guide)];
370
421
 
371
- for (var k = 0u; k < settings.substeps; k++) {
372
- let last_substep = k + 1u == settings.substeps;
422
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_POSITION}u, i, guide)] = vec4<f32>(quat_rotate_v3(from_root, x - root_before), 0.0);
423
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_ROTATION}u, i, guide)] = quat_multiply(from_root, q);
424
+ }
425
+ }
373
426
 
374
- // the entity's frame through the frame, the anchor being where it ends
375
- let f = f32(k + 1u) / f32(settings.substeps);
427
+ // the world at the step's time: the entity's frame, the anchor being where the frame ends
428
+ let f = settings.first + f32(k) * settings.stride;
376
429
  let linear = mat3x3<f32>(mix(before[0], now[0], f), mix(before[1], now[1], f), mix(before[2], now[2], f));
377
430
  let origin = mix(before_origin, now_origin, f);
378
431
 
432
+ let linear_scale = max(length(linear[0]), max(length(linear[1]), length(linear[2])));
433
+ let turn = normalize(quat_from_m3(linear * (1.0 / max(linear_scale, 1e-30))));
434
+
379
435
  // the root rides the entity; the first segment's rest direction is held by the local shape, from the
380
436
  // entity's frame
381
437
  let root = origin + linear * rest_0;
382
438
  var parent = root;
383
439
 
384
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, 0u, guide)] = vec4<f32>(root, 0.0);
440
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, 0u, guide)] = vec4<f32>(root, 0.0);
441
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, 0u, guide)] = turn;
385
442
 
386
443
  var rest_parent = rest_0;
387
444
  var arc = 0.0;
@@ -395,16 +452,27 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
395
452
  for (var i = 1u; i < nodes; i++) {
396
453
  let rest = hair_rest_point(instance, strand, i * step).xyz;
397
454
 
398
- let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)].xyz;
455
+ let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)].xyz;
399
456
  var v = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, i, guide)].xyz;
400
457
 
401
- // predict: damping and gravity, then the drag of the wisp relaxing the velocity toward the air's
458
+ // predict: damping and gravity, then drag relaxing the velocity toward the air's
402
459
  v = v * keep_velocity + gravity * h;
403
460
 
404
461
  let air = wind_field_sample(anchor + x);
405
462
  let relative = v - air;
463
+ let speed = length(relative);
464
+
465
+ // a fibre's own drag in open air, and its even share of the group's as one body: never more than its own
466
+ let own = hair_drag_rate(speed, width, fibre_mass);
467
+ let even = min(own, hair_drag_rate(speed, body_diameter, body_mass));
468
+
469
+ // what of the wind reaches the node through the hair upwind of it, in the groom's rest space
470
+ let upwind = quat_rotate_v3(quat_conjugate(turn), relative / max(speed, 1e-30));
471
+ let exposed = hair_guide_reach(instance, i, guide, upwind, 0.5 * hair_drag_coefficient(speed, width));
472
+
473
+ let drag = mix(even, max(even, ${HAIR_EXPOSED_DRAG_SHARE} * own), exposed);
406
474
 
407
- v = air + relative * exp(-hair_drag_rate(length(relative), diameter, mass) * h);
475
+ v = air + relative * exp(-drag * h);
408
476
 
409
477
  var p = x + v * h;
410
478
 
@@ -420,7 +488,7 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
420
488
 
421
489
  p += local_pull * (parent + quat_rotate_v3(frame, segment) - p);
422
490
 
423
- p = hair_collide(row, anchor, x, p, radius);
491
+ p = hair_collide(row, anchor, x, p, radius, f);
424
492
 
425
493
  // follow the leader: back onto the sphere of the segment's length about the parent
426
494
  let reach = p - parent;
@@ -461,13 +529,11 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
461
529
  if (pending) {
462
530
  pending_velocity -= correction * (${HAIR_FOLLOW_THE_LEADER_DAMPING} / h);
463
531
 
464
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i - 1u, guide)] = vec4<f32>(pending_position, 0.0);
532
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i - 1u, guide)] = vec4<f32>(pending_position, 0.0);
465
533
  hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, i - 1u, guide)] = vec4<f32>(pending_velocity, 0.0);
466
- }
467
534
 
468
- if (last_substep && i >= 2u) {
469
535
  // a node's frame blends the segments either side of it; the root's is the entity's
470
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i - 1u, guide)] = hair_quat_nlerp(frame, next_frame, 0.5);
536
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, i - 1u, guide)] = quat_multiply(hair_quat_nlerp(frame, next_frame, 0.5), turn);
471
537
  }
472
538
 
473
539
  pending_position = p;
@@ -480,14 +546,30 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
480
546
  }
481
547
 
482
548
  if (pending) {
483
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, nodes - 1u, guide)] = vec4<f32>(pending_position, 0.0);
549
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, nodes - 1u, guide)] = vec4<f32>(pending_position, 0.0);
484
550
  hair_guide_state[hair_state_index(instance, ${HAIR_STATE_VELOCITY}u, nodes - 1u, guide)] = vec4<f32>(pending_velocity, 0.0);
551
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, nodes - 1u, guide)] = quat_multiply(frame, turn);
485
552
  }
553
+ }
486
554
 
487
- if (last_substep) {
488
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, 0u, guide)] = IDENTITY;
489
- hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, nodes - 1u, guide)] = frame;
490
- }
555
+ // what is drawn: between the last two steps in the root's frame, carried by the root's frame now
556
+ let solved_turn = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, 0u, guide)];
557
+ let solved_root = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, 0u, guide)].xyz;
558
+ let from_solved = quat_conjugate(solved_turn);
559
+ let carry_solved = quat_multiply(turn_now, from_solved);
560
+ let from_now = quat_conjugate(turn_now);
561
+
562
+ for (var i = 0u; i < nodes; i++) {
563
+ let x = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_POSITION}u, i, guide)].xyz;
564
+ let q = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_SOLVED_ROTATION}u, i, guide)];
565
+ let u = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_POSITION}u, i, guide)].xyz;
566
+ let w = hair_guide_state[hair_state_index(instance, ${HAIR_STATE_PREVIOUS_ROTATION}u, i, guide)];
567
+
568
+ let place = mix(quat_rotate_v3(turn_now, u), quat_rotate_v3(carry_solved, x - solved_root), settings.blend);
569
+ let turned = hair_quat_nlerp(w, quat_multiply(from_solved, q), settings.blend);
570
+
571
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_POSITION}u, i, guide)] = vec4<f32>(root_now + place, 0.0);
572
+ hair_guide_state[hair_state_index(instance, ${HAIR_STATE_FRAME}u, i, guide)] = quat_multiply(quat_multiply(turn_now, turned), from_now);
491
573
  }
492
574
  }
493
575
 
@@ -527,32 +609,41 @@ fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocatio
527
609
  ]);
528
610
 
529
611
  /**
530
- * Steps every simulated instance's guides through the frame, a thread a guide (`HAIR_SIMULATION.js`), the threads
531
- * of a row found from the inclusive sums of the rows' guide counts.
612
+ * Steps every simulated instance's guides through the frame's steps and writes what is drawn of them, a thread a
613
+ * guide (`HAIR_SIMULATION.js`), the threads of a row found from the inclusive sums of the rows' guide counts.
532
614
  *
533
- * A guide's root rides the entity, or its strand's root frame where the instance is bound to a mesh, the frame taken
534
- * linearly from a frame ago to now across the substeps; the first
535
- * segment's rest direction is held, as every other's, by the local shape from the entity's frame. A frame of no time
536
- * carries the guides rigidly from the entity's frame a frame ago to now, as its own geometry is carried. Each substep,
537
- * from the node after the root to the tip, a node:
615
+ * Every step is `settings.step` long; a frame takes `settings.steps` of them, none when its time has not reached the
616
+ * next (`hair_frame_steps`). A step reads the world at its own time within the frame: a guide's root rides the
617
+ * entity, or its strand's root frame where the instance is bound to a mesh, the frame taken linearly from a frame
618
+ * ago to now at the step's share of the frame's motion, and the colliders are where they were at that share. The
619
+ * first segment's rest direction is held, as every other's, by the local shape from the entity's frame. A frame of
620
+ * no time carries the solved state rigidly from the entity's frame a frame ago to now, as its own geometry is
621
+ * carried. Each step, from the node after the root to the tip, a node:
538
622
  *
539
623
  * - **predicts**: its velocity loses `1 − e^(−damping·h)`, gains gravity, and relaxes toward the air's
540
- * (`wind_field_sample` at the node) as `v ← u + (v − u) e^(−k h)`, `k` the wisp's drag rate
541
- * (`hair_drag_rate`); it moves by the velocity;
624
+ * (`wind_field_sample` at the node) as `v ← u + (v − u) e^(−k h)`; it moves by the velocity. The drag rate `k`
625
+ * lies between two (`hair_drag_rate`): at the least the node's even share of the drag of its group as one body in
626
+ * the wind's way, and at the most `HAIR_EXPOSED_DRAG_SHARE` of a fibre's own in open air, by the share of the wind
627
+ * that reaches the node through the hair upwind of it (`hair_guide_reach`, from the groom's baked shelter); never
628
+ * more than the fibre's own;
542
629
  * - is pulled toward its rest place in the entity's frame (**global shape**) at a rate that falls from
543
630
  * `global_shape_rate` at the root to nothing at `global_shape_range` of the length, and toward its rest
544
631
  * direction turned by its parent's frame (**local shape**) at `local_shape_rate`, each a share
545
- * `1 − e^(−rate·h)`, so the hair behaves alike at any frame rate;
632
+ * `1 − e^(−rate·h)` a step;
546
633
  * - is pushed out of each of its instance's colliders by its wisp's radius plus the instance's thickness and the
547
634
  * collider's inflation, and loses `friction` of its sliding along it per push out as deep as the sliding;
548
635
  * - is put back onto the sphere of its rest segment's length about its parent (**follow the leader**), and never
549
- * farther from the root than its length along the guide; its velocity is its move over the substep, and its
550
- * parent's loses `HAIR_FOLLOW_THE_LEADER_DAMPING` of this node's correction over the substep (Müller's DFTL).
636
+ * farther from the root than its length along the guide; its velocity is its move over the step, and its
637
+ * parent's loses `HAIR_FOLLOW_THE_LEADER_DAMPING` of this node's correction over the step (Müller's DFTL).
551
638
  *
552
639
  * A segment's frame is its parent's, turned the least that takes the rest direction it predicts to the direction
553
- * the segment has; a node's frame, written on the last substep, blends the two segments either side of it. A state
554
- * to be laid at rest is the rest pose, still. The nodes' bounds, from the anchor, are gathered into the row's guide
555
- * bounds. Colliders and the wind are read in the world: the anchor plus a node's position.
640
+ * the segment has; a node's frame blends the two segments either side of it. A state to be laid at rest is the rest
641
+ * pose, still. Colliders and the wind are read in the world: the anchor plus a node's position.
642
+ *
643
+ * **What is drawn**, every frame, stepped or not: each node between where the last two steps solved it, in the frame
644
+ * of its guide's root at each, `settings.blend` of the way from the step before the last to the last, carried by the
645
+ * root's frame now. The drawn root is the root now; what was drawn the frame before is kept as a frame ago. The drawn
646
+ * nodes' bounds, from the anchor, are gathered into the row's guide bounds.
556
647
  *
557
648
  * @type {ComputeShader}
558
649
  */