@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.
- package/CHANGELOG.md +13 -0
- package/package.json +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.js +2 -1
- package/src/engine/graphics/hair/Groom.d.ts +30 -0
- package/src/engine/graphics/hair/Groom.d.ts.map +1 -1
- package/src/engine/graphics/hair/Groom.js +35 -0
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +18 -2
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -1
- package/src/engine/graphics/hair/GroomSerializationAdapter.js +36 -6
- package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts +8 -0
- package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts.map +1 -0
- package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.js +44 -0
- package/src/engine/graphics/hair/groom_bake_shelter.d.ts +33 -0
- package/src/engine/graphics/hair/groom_bake_shelter.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_bake_shelter.js +288 -0
- package/src/engine/graphics/hair/groom_build_group.d.ts +10 -2
- package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -1
- package/src/engine/graphics/hair/groom_build_group.js +8 -2
- package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts +119 -0
- package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts.map +1 -0
- package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.js +563 -0
- package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.d.ts +11 -0
- package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.d.ts.map +1 -0
- package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.js +10 -0
- package/src/generation/wfc/GridWFCCompiledTileSet.d.ts +123 -0
- package/src/generation/wfc/GridWFCCompiledTileSet.d.ts.map +1 -0
- package/src/generation/wfc/GridWFCCompiledTileSet.js +355 -0
- package/src/generation/wfc/GridWFCEdge.d.ts +13 -0
- package/src/generation/wfc/GridWFCEdge.d.ts.map +1 -0
- package/src/generation/wfc/GridWFCEdge.js +14 -0
- package/src/generation/wfc/GridWFCTileSet.d.ts +120 -0
- package/src/generation/wfc/GridWFCTileSet.d.ts.map +1 -0
- package/src/generation/wfc/GridWFCTileSet.js +275 -0
- package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
- package/src/shade/renderer/hair/GPUHairSystem.js +55 -11
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +4 -0
- package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts +77 -15
- package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR_SIMULATION.js +104 -17
- package/src/shade/renderer/hair/chunk_hair_guide.d.ts +9 -2
- package/src/shade/renderer/hair/chunk_hair_guide.d.ts.map +1 -1
- package/src/shade/renderer/hair/chunk_hair_guide.js +30 -2
- package/src/shade/renderer/hair/shader_hair_simulate.d.ts +27 -18
- package/src/shade/renderer/hair/shader_hair_simulate.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_simulate.js +174 -83
|
@@ -11,19 +11,31 @@
|
|
|
11
11
|
* for `P` nodes a guide and `G` guides, so the threads of neighbouring guides read neighbouring vectors.
|
|
12
12
|
*
|
|
13
13
|
* Positions are metres from the instance's **anchor**, its entity's translation this frame, along the world's axes:
|
|
14
|
-
* near zero wherever the entity is, so a
|
|
14
|
+
* near zero wherever the entity is, so a step's small moves keep their precision far from the world's origin.
|
|
15
|
+
*
|
|
16
|
+
* The guides are solved in steps of {@link HAIR_STEP}, whatever the frames' lengths ({@link hair_frame_steps}), and
|
|
17
|
+
* drawn between the last two steps: what the strands read is the **drawn** state, the solver's own is the **solved**
|
|
18
|
+
* one. The drawn state is blended in the frame of the guide's root (the entity's, or its strand's root frame on a bound
|
|
19
|
+
* mesh), from the step before the last to the last by the share of a step the frames have run past the last, and
|
|
20
|
+
* carried by the root's frame now: a guide's drawn root is its root this frame, and a root that turns or moves between
|
|
21
|
+
* steps carries its guide rigidly.
|
|
15
22
|
*
|
|
16
23
|
* ```
|
|
17
24
|
* header 0 the anchor, world metres; w: the epoch the state was made for, u32 bits
|
|
18
|
-
* 1 the anchor's move since the
|
|
25
|
+
* 1 the anchor's move since the frame before; w: 1 when the state is to be laid at rest
|
|
19
26
|
* 2..4 the entity's world matrix now, its columns' x, y and z, translation dropped
|
|
20
27
|
* 5..7 the same a frame ago
|
|
21
28
|
* 8 where the entity's origin was a frame ago, from the anchor
|
|
22
|
-
* plane 0 a node's position
|
|
23
|
-
* 1 its velocity, metres a second
|
|
24
|
-
* 2 its frame: the rotation, a unit quaternion, from its rest frame carried by the entity to where it is
|
|
25
|
-
* 3 its position a frame ago, from this frame's anchor
|
|
26
|
-
* 4 its frame a frame ago
|
|
29
|
+
* plane 0 a node's drawn position
|
|
30
|
+
* 1 its solved velocity, metres a second, at the last step
|
|
31
|
+
* 2 its drawn frame: the rotation, a unit quaternion, from its rest frame carried by the entity to where it is
|
|
32
|
+
* 3 its drawn position a frame ago, from this frame's anchor
|
|
33
|
+
* 4 its drawn frame a frame ago
|
|
34
|
+
* 5 its solved position at the last step
|
|
35
|
+
* 6 its solved rotation at the last step, a unit quaternion: from the groom's rest space to the world, scale
|
|
36
|
+
* left out. The root node's is its root frame's.
|
|
37
|
+
* 7 its solved position a step before the last: from its guide's root, along the root frame's axes
|
|
38
|
+
* 8 its solved rotation a step before the last, in the root frame's axes
|
|
27
39
|
* ```
|
|
28
40
|
*/
|
|
29
41
|
|
|
@@ -56,26 +68,75 @@ export const HAIR_STATE_HEADER = 9;
|
|
|
56
68
|
* Planes of a guide state, a vector a node each.
|
|
57
69
|
* @type {number}
|
|
58
70
|
*/
|
|
59
|
-
export const HAIR_STATE_PLANES =
|
|
71
|
+
export const HAIR_STATE_PLANES = 9;
|
|
60
72
|
|
|
61
73
|
export const HAIR_STATE_POSITION = 0;
|
|
62
74
|
export const HAIR_STATE_VELOCITY = 1;
|
|
63
75
|
export const HAIR_STATE_FRAME = 2;
|
|
64
76
|
export const HAIR_STATE_LAST_POSITION = 3;
|
|
65
77
|
export const HAIR_STATE_LAST_FRAME = 4;
|
|
78
|
+
export const HAIR_STATE_SOLVED_POSITION = 5;
|
|
79
|
+
export const HAIR_STATE_SOLVED_ROTATION = 6;
|
|
80
|
+
export const HAIR_STATE_PREVIOUS_POSITION = 7;
|
|
81
|
+
export const HAIR_STATE_PREVIOUS_ROTATION = 8;
|
|
66
82
|
|
|
67
83
|
/**
|
|
68
84
|
* Words of a guide's record in the groom pool: its strand's rank, its wisp's strand count, its wisp's diameter and
|
|
69
|
-
* its length (f32 bits each, groom metres).
|
|
85
|
+
* its length (f32 bits each, groom metres). A group's guide records are followed by its guides' shelter
|
|
86
|
+
* (`GroomGroup#guide_shelter`): `GROOM_SHELTER_WORDS` depths a node (f32 bits), a guide's nodes in turn, guide after
|
|
87
|
+
* guide.
|
|
70
88
|
* @type {number}
|
|
71
89
|
*/
|
|
72
90
|
export const HAIR_GUIDE_RECORD_WORDS = 4;
|
|
73
91
|
|
|
74
92
|
/**
|
|
75
|
-
* The
|
|
93
|
+
* The solver's step, seconds: every step is this long, whatever the frames' lengths, so the hair's pose and its
|
|
94
|
+
* stability do not follow the frame rate.
|
|
76
95
|
* @type {number}
|
|
77
96
|
*/
|
|
78
|
-
export const
|
|
97
|
+
export const HAIR_STEP = 1 / 60;
|
|
98
|
+
|
|
99
|
+
/** Steps the solver takes this frame, in {@link hair_frame_steps}' result. */
|
|
100
|
+
export const HAIR_FRAME_STEPS_COUNT = 0;
|
|
101
|
+
|
|
102
|
+
/** Seconds the frames have run past the last step, less than {@link HAIR_STEP}, in {@link hair_frame_steps}' result. */
|
|
103
|
+
export const HAIR_FRAME_STEPS_OWED = 1;
|
|
104
|
+
|
|
105
|
+
/** The share of the frame's motion the first step falls at, in {@link hair_frame_steps}' result. */
|
|
106
|
+
export const HAIR_FRAME_STEPS_FIRST = 2;
|
|
107
|
+
|
|
108
|
+
/** The share of the frame's motion from a step to the next, in {@link hair_frame_steps}' result. */
|
|
109
|
+
export const HAIR_FRAME_STEPS_STRIDE = 3;
|
|
110
|
+
|
|
111
|
+
/** How far the drawn state is from the step before the last, 0, to the last, 1, in {@link hair_frame_steps}' result. */
|
|
112
|
+
export const HAIR_FRAME_STEPS_BLEND = 4;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* How a frame's time is cut into the solver's steps. The time not yet stepped through, `owed` from the frames
|
|
116
|
+
* before and this frame's `seconds` (at most {@link HAIR_FRAME_STEP_MAX} of them), is stepped through in whole
|
|
117
|
+
* steps of {@link HAIR_STEP}; what is left is owed to the next frame. A step falls at a time within the frame, and
|
|
118
|
+
* reads the world there: the share of the frame's motion, from a frame ago at 0 to now at 1, is `first` for the
|
|
119
|
+
* frame's first step and `stride` more for each after it. The drawn state is `blend` of the way from the step
|
|
120
|
+
* before the last to the last: a step behind the scene's clock, always.
|
|
121
|
+
*
|
|
122
|
+
* @param {Float64Array|number[]} result written: the `HAIR_FRAME_STEPS_*` words
|
|
123
|
+
* @param {number} owed seconds the frames before ran past their last step, in `[0, HAIR_STEP)`
|
|
124
|
+
* @param {number} seconds the scene's clock moved this frame
|
|
125
|
+
*/
|
|
126
|
+
export function hair_frame_steps(result, owed, seconds) {
|
|
127
|
+
const frame = Math.min(seconds, HAIR_FRAME_STEP_MAX);
|
|
128
|
+
const time = owed + frame;
|
|
129
|
+
const count = Math.floor(time / HAIR_STEP);
|
|
130
|
+
|
|
131
|
+
// never negative, and never a whole step: the count is what the division's rounding made it
|
|
132
|
+
const left = Math.min(Math.max(time - count * HAIR_STEP, 0), HAIR_STEP * (1 - Number.EPSILON));
|
|
133
|
+
|
|
134
|
+
result[HAIR_FRAME_STEPS_COUNT] = count;
|
|
135
|
+
result[HAIR_FRAME_STEPS_OWED] = left;
|
|
136
|
+
result[HAIR_FRAME_STEPS_FIRST] = count > 0 ? Math.min((HAIR_STEP - owed) / frame, 1) : 0;
|
|
137
|
+
result[HAIR_FRAME_STEPS_STRIDE] = count > 0 ? HAIR_STEP / frame : 0;
|
|
138
|
+
result[HAIR_FRAME_STEPS_BLEND] = left / HAIR_STEP;
|
|
139
|
+
}
|
|
79
140
|
|
|
80
141
|
/**
|
|
81
142
|
* The longest frame the simulation steps, seconds, as the animation clamps its own: a stall slows the hair rather
|
|
@@ -102,6 +163,13 @@ export const HAIR_AIR_VISCOSITY = 1.81e-5;
|
|
|
102
163
|
*/
|
|
103
164
|
export const HAIR_FIBRE_DENSITY = 1300;
|
|
104
165
|
|
|
166
|
+
/**
|
|
167
|
+
* The most of its own drag in open air a fibre of a groom takes, where nothing stands between it and the wind: the
|
|
168
|
+
* hair about it still shares its load. A chosen value, not a derived one.
|
|
169
|
+
* @type {number}
|
|
170
|
+
*/
|
|
171
|
+
export const HAIR_EXPOSED_DRAG_SHARE = 0.3;
|
|
172
|
+
|
|
105
173
|
/**
|
|
106
174
|
* The share of a node's follow-the-leader correction taken back out of its parent's velocity (Müller et al. 2012's
|
|
107
175
|
* `s`), which keeps the correction from feeding the velocity it was made to undo.
|
|
@@ -126,11 +194,12 @@ export const HAIR_COLLIDER_LIMIT = 32;
|
|
|
126
194
|
* 8 .. 11 from the world to its own frame, as the pose pass writes it: the rotation, a unit quaternion
|
|
127
195
|
* 12 .. 14 the translation after it
|
|
128
196
|
* 15 the scale after that: distances in its frame are the world's times it
|
|
197
|
+
* 16 .. 23 the same a frame ago
|
|
129
198
|
* ```
|
|
130
199
|
*
|
|
131
200
|
* @type {number}
|
|
132
201
|
*/
|
|
133
|
-
export const HAIR_COLLIDER_WORDS =
|
|
202
|
+
export const HAIR_COLLIDER_WORDS = 24;
|
|
134
203
|
|
|
135
204
|
/**
|
|
136
205
|
* Words of an instance's guide bounds a row: the largest of each coordinate over its nodes, then the smallest, as
|
|
@@ -141,11 +210,29 @@ export const HAIR_COLLIDER_WORDS = 16;
|
|
|
141
210
|
export const HAIR_GUIDE_BOUNDS_WORDS = 8;
|
|
142
211
|
|
|
143
212
|
/**
|
|
144
|
-
* The
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
213
|
+
* The drag coefficient of a cylinder of diameter `diameter` across a flow of speed `speed`: White's correlation,
|
|
214
|
+
* `C_d = 1 + 10 Re^(-2/3)`, good to ±10% for `1 < Re < 2·10⁵`, and held under `Re = 1` at its value there, so that
|
|
215
|
+
* still air's is a number. The WGSL `hair_drag_coefficient` is its twin.
|
|
216
|
+
*
|
|
217
|
+
* @param {number} speed metres a second
|
|
218
|
+
* @param {number} diameter metres
|
|
219
|
+
* @returns {number}
|
|
220
|
+
*/
|
|
221
|
+
export function hair_drag_coefficient(speed, diameter) {
|
|
222
|
+
const reynolds = HAIR_AIR_DENSITY * speed * diameter / HAIR_AIR_VISCOSITY;
|
|
223
|
+
|
|
224
|
+
return 1 + 10 * Math.pow(Math.max(reynolds, 1), -2 / 3);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The rate a body's velocity relaxes toward the air's by drag, per second: the drag of a cylinder of diameter
|
|
229
|
+
* `diameter` across the flow at relative speed `speed`, over its mass a unit length, `k = ½ ρ C_d(Re) D |w| / m`.
|
|
230
|
+
* The cylinder's drag coefficient is White's correlation, `C_d = 1 + 10 Re^(-2/3)` (good to ±10% for
|
|
231
|
+
* `1 < Re < 2·10⁵`), so `k = (½ ρ D / m)(|w| + 10 |w|^(1/3) (ρ D / μ_air)^(-2/3))`, which goes to zero with the
|
|
232
|
+
* speed. The WGSL `hair_drag_rate` is its twin.
|
|
233
|
+
*
|
|
234
|
+
* A guide's node takes it twice (`shader_hair_simulate.js`): for a fibre of its group alone in open air, and for the
|
|
235
|
+
* group as one body in the wind's way, a cylinder across the disc of its silhouette with the mass of all its fibres.
|
|
149
236
|
*
|
|
150
237
|
* @param {number} speed metres a second
|
|
151
238
|
* @param {number} diameter metres
|
|
@@ -18,7 +18,9 @@ export const HAIR_GUIDE_STATE_RESOURCE: ShaderResourceDescriptor;
|
|
|
18
18
|
* fn hair_state_index(instance: HairInstance, plane: u32, node: u32, guide: u32) -> u32
|
|
19
19
|
* fn hair_guide_record(instance: HairInstance, guide: u32) -> vec4<u32>
|
|
20
20
|
* fn hair_quat_nlerp(a: vec4<f32>, b: vec4<f32>, t: f32) -> vec4<f32>
|
|
21
|
+
* fn hair_drag_coefficient(speed: f32, diameter: f32) -> f32
|
|
21
22
|
* fn hair_drag_rate(speed: f32, diameter: f32, mass_per_length: f32) -> f32
|
|
23
|
+
* fn hair_guide_reach(instance: HairInstance, node: u32, guide: u32, upwind: vec3<f32>, half_drag: f32) -> f32
|
|
22
24
|
* ```
|
|
23
25
|
*
|
|
24
26
|
* `hair_strand_frame` is what carries a strand's rest points into the world: its root frame (`shader_hair_roots.js`)
|
|
@@ -27,8 +29,13 @@ export const HAIR_GUIDE_STATE_RESOURCE: ShaderResourceDescriptor;
|
|
|
27
29
|
* frame's step holds another tenant's nodes, or none, and its strands ride the entity until the next step lays it.
|
|
28
30
|
* Reads the state's header. `hair_state_index` is a vector of the state pool, node-interleaved. `hair_guide_record` is a guide's four words in
|
|
29
31
|
* the groom pool: its strand's rank, its wisp's strand count, its wisp's diameter and its length (f32 bits).
|
|
30
|
-
* `hair_quat_nlerp` blends two unit quaternions along the shorter arc. `
|
|
31
|
-
* (`HAIR_SIMULATION.js`):
|
|
32
|
+
* `hair_quat_nlerp` blends two unit quaternions along the shorter arc. `hair_drag_coefficient` and `hair_drag_rate`
|
|
33
|
+
* are their namesakes' twins (`HAIR_SIMULATION.js`): a cylinder's drag coefficient, and the rate its velocity relaxes
|
|
34
|
+
* toward the air's. `hair_guide_reach` is the share of a wind that reaches a guide's node through the hair of its
|
|
35
|
+
* group, from the node's shelter (`GroomGroup#guide_shelter`): `upwind` is where the wind comes from, a unit vector
|
|
36
|
+
* in the groom's rest space, and `half_drag` half a fibre's drag coefficient at the wind's speed. Each axis gives
|
|
37
|
+
* `e^(−half_drag · depth)` for the depth on the side the wind comes from, and the three are weighed by the squares of
|
|
38
|
+
* `upwind`'s parts; an `upwind` of no length gives none.
|
|
32
39
|
*
|
|
33
40
|
* @type {CodeChunk}
|
|
34
41
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk_hair_guide.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/chunk_hair_guide.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chunk_hair_guide.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/chunk_hair_guide.js"],"names":[],"mappings":"AAsBA;;;GAGG;AACH,8BAFU,MAAM,CAEwB;AAExC;;;;GAIG;AACH,wCAFU,wBAAwB,CAE2F;AAE7H;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,+BAFU,SAAS,CA4EhB;AAKH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,sCAFU,SAAS,CAyChB;yCAxMsC,gDAAgD;0BAD/D,iCAAiC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GROOM_SHELTER_WORDS } from "../../../engine/graphics/hair/Groom.js";
|
|
1
2
|
import { chunk_quat_rotate_v3 } from "../shader/chunk/geometry/quaternion/chunk_v3_apply_quat.js";
|
|
2
3
|
import { CodeChunk } from "../shader/compiler/CodeChunk.js";
|
|
3
4
|
import { ShaderResourceDescriptor } from "../shader/resource/ShaderResourceDescriptor.js";
|
|
@@ -41,7 +42,9 @@ export const HAIR_GUIDE_STATE_RESOURCE = ShaderResourceDescriptor.storageBuffer(
|
|
|
41
42
|
* fn hair_state_index(instance: HairInstance, plane: u32, node: u32, guide: u32) -> u32
|
|
42
43
|
* fn hair_guide_record(instance: HairInstance, guide: u32) -> vec4<u32>
|
|
43
44
|
* fn hair_quat_nlerp(a: vec4<f32>, b: vec4<f32>, t: f32) -> vec4<f32>
|
|
45
|
+
* fn hair_drag_coefficient(speed: f32, diameter: f32) -> f32
|
|
44
46
|
* fn hair_drag_rate(speed: f32, diameter: f32, mass_per_length: f32) -> f32
|
|
47
|
+
* fn hair_guide_reach(instance: HairInstance, node: u32, guide: u32, upwind: vec3<f32>, half_drag: f32) -> f32
|
|
45
48
|
* ```
|
|
46
49
|
*
|
|
47
50
|
* `hair_strand_frame` is what carries a strand's rest points into the world: its root frame (`shader_hair_roots.js`)
|
|
@@ -50,8 +53,13 @@ export const HAIR_GUIDE_STATE_RESOURCE = ShaderResourceDescriptor.storageBuffer(
|
|
|
50
53
|
* frame's step holds another tenant's nodes, or none, and its strands ride the entity until the next step lays it.
|
|
51
54
|
* Reads the state's header. `hair_state_index` is a vector of the state pool, node-interleaved. `hair_guide_record` is a guide's four words in
|
|
52
55
|
* the groom pool: its strand's rank, its wisp's strand count, its wisp's diameter and its length (f32 bits).
|
|
53
|
-
* `hair_quat_nlerp` blends two unit quaternions along the shorter arc. `
|
|
54
|
-
* (`HAIR_SIMULATION.js`):
|
|
56
|
+
* `hair_quat_nlerp` blends two unit quaternions along the shorter arc. `hair_drag_coefficient` and `hair_drag_rate`
|
|
57
|
+
* are their namesakes' twins (`HAIR_SIMULATION.js`): a cylinder's drag coefficient, and the rate its velocity relaxes
|
|
58
|
+
* toward the air's. `hair_guide_reach` is the share of a wind that reaches a guide's node through the hair of its
|
|
59
|
+
* group, from the node's shelter (`GroomGroup#guide_shelter`): `upwind` is where the wind comes from, a unit vector
|
|
60
|
+
* in the groom's rest space, and `half_drag` half a fibre's drag coefficient at the wind's speed. Each axis gives
|
|
61
|
+
* `e^(−half_drag · depth)` for the depth on the side the wind comes from, and the three are weighed by the squares of
|
|
62
|
+
* `upwind`'s parts; an `upwind` of no length gives none.
|
|
55
63
|
*
|
|
56
64
|
* @type {CodeChunk}
|
|
57
65
|
*/
|
|
@@ -101,6 +109,26 @@ fn hair_quat_nlerp(a: vec4<f32>, b: vec4<f32>, t: f32) -> vec4<f32> {
|
|
|
101
109
|
return normalize(mix(a, b * side, t));
|
|
102
110
|
}
|
|
103
111
|
|
|
112
|
+
fn hair_drag_coefficient(speed: f32, diameter: f32) -> f32 {
|
|
113
|
+
let reynolds = ${HAIR_AIR_DENSITY} * speed * diameter / ${HAIR_AIR_VISCOSITY};
|
|
114
|
+
|
|
115
|
+
return 1.0 + 10.0 * pow(max(reynolds, 1.0), -2.0 / 3.0);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fn hair_guide_reach(instance: ${HAIR_INSTANCE_STRUCT.wgsl_ref}, node: u32, guide: u32, upwind: vec3<f32>, half_drag: f32) -> f32 {
|
|
119
|
+
let at = instance.guides + instance.guide_count * ${HAIR_GUIDE_RECORD_WORDS}u
|
|
120
|
+
+ (guide * instance.guide_point_count + node) * ${GROOM_SHELTER_WORDS}u;
|
|
121
|
+
|
|
122
|
+
// each axis's depth on the side the wind comes from
|
|
123
|
+
let depth = vec3<f32>(
|
|
124
|
+
bitcast<f32>(hair_grooms[at + select(0u, 1u, upwind.x < 0.0)]),
|
|
125
|
+
bitcast<f32>(hair_grooms[at + select(2u, 3u, upwind.y < 0.0)]),
|
|
126
|
+
bitcast<f32>(hair_grooms[at + select(4u, 5u, upwind.z < 0.0)]),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return dot(upwind * upwind, exp(-half_drag * depth));
|
|
130
|
+
}
|
|
131
|
+
|
|
104
132
|
fn hair_drag_rate(speed: f32, diameter: f32, mass_per_length: f32) -> f32 {
|
|
105
133
|
let reynolds_per_speed = ${HAIR_AIR_DENSITY} * diameter / ${HAIR_AIR_VISCOSITY};
|
|
106
134
|
|
|
@@ -11,41 +11,50 @@ export { HAIR_EPOCH_MASK } from "./chunk_hair_guide.js";
|
|
|
11
11
|
export const shader_hair_simulate_begin: ComputeShader;
|
|
12
12
|
export const HAIR_COLLIDER_POSE_SETTINGS: WebGPUStruct;
|
|
13
13
|
/**
|
|
14
|
-
* Writes each collider of the frame's list the way from the world into its own frame (`HAIR_COLLIDER_WORDS`),
|
|
15
|
-
* thread a collider, from its entity's world
|
|
16
|
-
* largest axis is taken.
|
|
14
|
+
* Writes each collider of the frame's list the way from the world into its own frame (`HAIR_COLLIDER_WORDS`), now
|
|
15
|
+
* and a frame ago, a thread a collider, from its entity's world matrices as the scene holds them: a rigid motion and
|
|
16
|
+
* a uniform scale, whose largest axis is taken.
|
|
17
17
|
*
|
|
18
18
|
* @type {ComputeShader}
|
|
19
19
|
*/
|
|
20
20
|
export const shader_hair_collider_poses: ComputeShader;
|
|
21
21
|
export const HAIR_SIMULATE_SETTINGS: WebGPUStruct;
|
|
22
22
|
/**
|
|
23
|
-
* Steps every simulated instance's guides through the frame
|
|
24
|
-
* of a row found from the inclusive sums of the rows' guide counts.
|
|
23
|
+
* Steps every simulated instance's guides through the frame's steps and writes what is drawn of them, a thread a
|
|
24
|
+
* guide (`HAIR_SIMULATION.js`), the threads of a row found from the inclusive sums of the rows' guide counts.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* Every step is `settings.step` long; a frame takes `settings.steps` of them, none when its time has not reached the
|
|
27
|
+
* next (`hair_frame_steps`). A step reads the world at its own time within the frame: a guide's root rides the
|
|
28
|
+
* entity, or its strand's root frame where the instance is bound to a mesh, the frame taken linearly from a frame
|
|
29
|
+
* ago to now at the step's share of the frame's motion, and the colliders are where they were at that share. The
|
|
30
|
+
* first segment's rest direction is held, as every other's, by the local shape from the entity's frame. A frame of
|
|
31
|
+
* no time carries the solved state rigidly from the entity's frame a frame ago to now, as its own geometry is
|
|
32
|
+
* carried. Each step, from the node after the root to the tip, a node:
|
|
31
33
|
*
|
|
32
34
|
* - **predicts**: its velocity loses `1 − e^(−damping·h)`, gains gravity, and relaxes toward the air's
|
|
33
|
-
* (`wind_field_sample` at the node) as `v ← u + (v − u) e^(−k h)
|
|
34
|
-
* (`hair_drag_rate`)
|
|
35
|
+
* (`wind_field_sample` at the node) as `v ← u + (v − u) e^(−k h)`; it moves by the velocity. The drag rate `k`
|
|
36
|
+
* lies between two (`hair_drag_rate`): at the least the node's even share of the drag of its group as one body in
|
|
37
|
+
* 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
|
|
38
|
+
* that reaches the node through the hair upwind of it (`hair_guide_reach`, from the groom's baked shelter); never
|
|
39
|
+
* more than the fibre's own;
|
|
35
40
|
* - is pulled toward its rest place in the entity's frame (**global shape**) at a rate that falls from
|
|
36
41
|
* `global_shape_rate` at the root to nothing at `global_shape_range` of the length, and toward its rest
|
|
37
42
|
* direction turned by its parent's frame (**local shape**) at `local_shape_rate`, each a share
|
|
38
|
-
* `1 − e^(−rate·h)
|
|
43
|
+
* `1 − e^(−rate·h)` a step;
|
|
39
44
|
* - is pushed out of each of its instance's colliders by its wisp's radius plus the instance's thickness and the
|
|
40
45
|
* collider's inflation, and loses `friction` of its sliding along it per push out as deep as the sliding;
|
|
41
46
|
* - is put back onto the sphere of its rest segment's length about its parent (**follow the leader**), and never
|
|
42
|
-
* farther from the root than its length along the guide; its velocity is its move over the
|
|
43
|
-
* parent's loses `HAIR_FOLLOW_THE_LEADER_DAMPING` of this node's correction over the
|
|
47
|
+
* farther from the root than its length along the guide; its velocity is its move over the step, and its
|
|
48
|
+
* parent's loses `HAIR_FOLLOW_THE_LEADER_DAMPING` of this node's correction over the step (Müller's DFTL).
|
|
44
49
|
*
|
|
45
50
|
* A segment's frame is its parent's, turned the least that takes the rest direction it predicts to the direction
|
|
46
|
-
* the segment has; a node's frame
|
|
47
|
-
*
|
|
48
|
-
*
|
|
51
|
+
* 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
|
|
52
|
+
* pose, still. Colliders and the wind are read in the world: the anchor plus a node's position.
|
|
53
|
+
*
|
|
54
|
+
* **What is drawn**, every frame, stepped or not: each node between where the last two steps solved it, in the frame
|
|
55
|
+
* of its guide's root at each, `settings.blend` of the way from the step before the last to the last, carried by the
|
|
56
|
+
* 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
|
|
57
|
+
* nodes' bounds, from the anchor, are gathered into the row's guide bounds.
|
|
49
58
|
*
|
|
50
59
|
* @type {ComputeShader}
|
|
51
60
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader_hair_simulate.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/shader_hair_simulate.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"shader_hair_simulate.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/shader_hair_simulate.js"],"names":[],"mappings":";AAwDA;;;;;;;;GAQG;AACH,yCAFU,aAAa,CAkEpB;AAEH,uDAK+B;AAU/B;;;;;;GAMG;AACH,yCAFU,aAAa,CAqCpB;AAEH,kDAe2B;AAqZ3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,mCAFU,aAAa,CAMpB;8BAjoB2B,4BAA4B;6BAK7B,gCAAgC"}
|