reze-engine 0.68.31 → 0.69.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/dist/_dbg-loader.mjs +1100 -0
- package/dist/engine.d.ts +10 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +12 -5
- package/dist/jelly-eyes.d.ts.map +1 -1
- package/dist/jelly-eyes.js +27 -4
- package/dist/shaders/passes/ground.d.ts.map +1 -1
- package/dist/shaders/passes/ground.js +37 -8
- package/package.json +1 -1
- package/src/engine.ts +19 -4
- package/src/jelly-eyes.ts +32 -4
- package/src/shaders/passes/ground.ts +37 -8
package/src/engine.ts
CHANGED
|
@@ -709,6 +709,9 @@ export type DepthOfFieldOptions = {
|
|
|
709
709
|
* dancer stays sharp without anyone touching a slider. "manual" uses
|
|
710
710
|
* focusDistance/focusRange as given. */
|
|
711
711
|
focusMode: "auto" | "manual"
|
|
712
|
+
/** The character auto focus tracks, by model name. Null, or a name that is
|
|
713
|
+
* not a visible character, falls back to the first visible character. */
|
|
714
|
+
focusModel: string | null
|
|
712
715
|
/** Camera-space distance to the focus plane (MMD units). */
|
|
713
716
|
focusDistance: number
|
|
714
717
|
/** Depth band that stays perfectly sharp, centered on focusDistance. In auto
|
|
@@ -727,6 +730,7 @@ export type DepthOfFieldOptions = {
|
|
|
727
730
|
export const DEFAULT_DEPTH_OF_FIELD_OPTIONS: DepthOfFieldOptions = {
|
|
728
731
|
enabled: false,
|
|
729
732
|
focusMode: "auto",
|
|
733
|
+
focusModel: null,
|
|
730
734
|
focusDistance: 25,
|
|
731
735
|
focusRange: 2,
|
|
732
736
|
aperture: 1,
|
|
@@ -7711,13 +7715,16 @@ export class Engine {
|
|
|
7711
7715
|
return { ...this.depthOfField }
|
|
7712
7716
|
}
|
|
7713
7717
|
|
|
7714
|
-
/** Auto-focus target: the camera-space depth span of the
|
|
7715
|
-
*
|
|
7716
|
-
* span plus a margin for what bones
|
|
7718
|
+
/** Auto-focus target: the camera-space depth span of the chosen character's
|
|
7719
|
+
* bones (focusModel), else the first visible character's. Focus sits at the
|
|
7720
|
+
* span's midpoint; the range covers the span plus a margin for what bones
|
|
7721
|
+
* don't reach (shoes, hair, cloth). */
|
|
7717
7722
|
private getModelBodyFocus(): { distance: number; range: number } | null {
|
|
7718
7723
|
if (!this.camera) return null
|
|
7719
7724
|
const view = this.camera.getViewMatrix().values
|
|
7720
|
-
|
|
7725
|
+
const chosen = this.depthOfField.focusModel ? this.modelInstances.get(this.depthOfField.focusModel) : undefined
|
|
7726
|
+
const order = chosen ? [chosen, ...this.modelInstances.values()] : this.modelInstances.values()
|
|
7727
|
+
for (const inst of order) {
|
|
7721
7728
|
// Neither a stage nor a plane is a performer, so neither is a subject an
|
|
7722
7729
|
// effect can follow.
|
|
7723
7730
|
if (!inst.model.drawn || inst.isStage || inst.isPlane || inst.isProp) continue
|
|
@@ -11880,6 +11887,9 @@ export class Engine {
|
|
|
11880
11887
|
gridLineWidth?: number
|
|
11881
11888
|
gridLineOpacity?: number
|
|
11882
11889
|
gridLineColor?: Vec3
|
|
11890
|
+
/** What the grid draws: "lines" (default), or "dots", one on every
|
|
11891
|
+
* crossing the lines would draw. Same spacing, colour and opacity. */
|
|
11892
|
+
gridPattern?: "lines" | "dots"
|
|
11883
11893
|
noiseStrength?: number
|
|
11884
11894
|
/** Whole-ground opacity, 0–1 (multiplies the radial edge fade). Default 1. */
|
|
11885
11895
|
opacity?: number
|
|
@@ -11920,6 +11930,7 @@ export class Engine {
|
|
|
11920
11930
|
gridLineWidth: 0.012,
|
|
11921
11931
|
gridLineOpacity: 0.4,
|
|
11922
11932
|
gridLineColor: new Vec3(0.85, 0.85, 0.85),
|
|
11933
|
+
gridPattern: "lines" as "lines" | "dots",
|
|
11923
11934
|
noiseStrength: 0.05,
|
|
11924
11935
|
opacity: 1.0,
|
|
11925
11936
|
mirror: false,
|
|
@@ -15866,6 +15877,7 @@ export class Engine {
|
|
|
15866
15877
|
gridLineWidth: number
|
|
15867
15878
|
gridLineOpacity: number
|
|
15868
15879
|
gridLineColor: Vec3
|
|
15880
|
+
gridPattern: "lines" | "dots"
|
|
15869
15881
|
noiseStrength: number
|
|
15870
15882
|
opacity: number
|
|
15871
15883
|
mirror: boolean
|
|
@@ -15882,6 +15894,7 @@ export class Engine {
|
|
|
15882
15894
|
gridLineWidth,
|
|
15883
15895
|
gridLineOpacity,
|
|
15884
15896
|
gridLineColor,
|
|
15897
|
+
gridPattern,
|
|
15885
15898
|
noiseStrength,
|
|
15886
15899
|
opacity,
|
|
15887
15900
|
mirror,
|
|
@@ -15901,6 +15914,8 @@ export class Engine {
|
|
|
15901
15914
|
gb[3] = fadeStart
|
|
15902
15915
|
gb[4] = fadeEnd
|
|
15903
15916
|
gb[5] = shadowStrength
|
|
15917
|
+
// gb[6] — the grid's pattern, 0 lines and 1 dots. Was padding.
|
|
15918
|
+
gb[6] = gridPattern === "dots" ? 1 : 0
|
|
15904
15919
|
gb[7] = gridSpacing
|
|
15905
15920
|
gb[8] = gridLineWidth
|
|
15906
15921
|
gb[9] = gridLineOpacity
|
package/src/jelly-eyes.ts
CHANGED
|
@@ -110,6 +110,15 @@ const ROLL_ZETA = Math.LN2 / HALF_LIFE / (2 * Math.PI * ROLL_HZ)
|
|
|
110
110
|
// How much of the spring's swing about the expression angle shows: a
|
|
111
111
|
// twenty-fifth of an iris radius past centre after a blink.
|
|
112
112
|
const ROLL_SWING = 0.25
|
|
113
|
+
// How long a held expression takes to stop pressing and rolling the iris, in
|
|
114
|
+
// seconds: the press and the roll answer the CHANGE of the lids, as the MME's
|
|
115
|
+
// spring does, never where they sit. A smile or a はぅ held through a chorus
|
|
116
|
+
// once kept the iris a fifth shorter and rolled down for as long as it held —
|
|
117
|
+
// on a squint that leaves the eyes open, the irises sank to the bottom of the
|
|
118
|
+
// eyes — and leftover weights of a few hundredths, summed, kept a neutral face
|
|
119
|
+
// pressed for good. A blink's own close is far quicker than this, so it still
|
|
120
|
+
// presses and rolls in full.
|
|
121
|
+
const HOLD_S = 0.3
|
|
113
122
|
const PUSH_ELASTIC = 0.04
|
|
114
123
|
// A highlight sheet by name, for rigs that keep it on its own material.
|
|
115
124
|
const HIGHLIGHT = /ハイライト|ハイライト|高光|highlight|hilight|(^|[^a-z])hl([^a-z]|$)/i
|
|
@@ -199,6 +208,10 @@ interface EyeState {
|
|
|
199
208
|
// The roll (degrees) and its velocity, chasing the expressions' angle.
|
|
200
209
|
roll: number
|
|
201
210
|
rollV: number
|
|
211
|
+
// Where the lids and the expressions' angle have been HELD: followers HOLD_S
|
|
212
|
+
// behind them. The press and the roll are what is left past them.
|
|
213
|
+
closureHeld: number
|
|
214
|
+
rollHeld: number
|
|
202
215
|
pulseV: number
|
|
203
216
|
}
|
|
204
217
|
|
|
@@ -237,6 +250,8 @@ interface MorphShift {
|
|
|
237
250
|
|
|
238
251
|
const newState = (): EyeState => ({
|
|
239
252
|
closure: 0,
|
|
253
|
+
closureHeld: 0,
|
|
254
|
+
rollHeld: 0,
|
|
240
255
|
prev: 0,
|
|
241
256
|
speed: 0,
|
|
242
257
|
trend: 0,
|
|
@@ -373,11 +388,18 @@ export class JellyEyes {
|
|
|
373
388
|
s.lag[1] = s.look[1]
|
|
374
389
|
s.lagV[0] = s.lagV[1] = 0
|
|
375
390
|
s.pulse = s.pulseV = 0
|
|
376
|
-
s.
|
|
391
|
+
s.closureHeld = s.closure
|
|
392
|
+
s.rollHeld = this.roll[e]
|
|
393
|
+
s.roll = 0
|
|
377
394
|
s.rollV = 0
|
|
378
395
|
continue
|
|
379
396
|
}
|
|
380
397
|
blink(s, dt)
|
|
398
|
+
if (dt > 0) {
|
|
399
|
+
const k = 1 - Math.exp(-dt / HOLD_S)
|
|
400
|
+
s.closureHeld += (s.closure - s.closureHeld) * k
|
|
401
|
+
s.rollHeld += (this.roll[e] - s.rollHeld) * k
|
|
402
|
+
}
|
|
381
403
|
const steps = Math.ceil(dt / SUBSTEP)
|
|
382
404
|
const h = steps > 0 ? dt / steps : 0
|
|
383
405
|
const pulseTarget = PULSE_MAX * knock
|
|
@@ -386,7 +408,7 @@ export class JellyEyes {
|
|
|
386
408
|
s.pulse += h * s.pulseV
|
|
387
409
|
s.squashV += h * spring(s.squash - squashTarget, s.squashV, SQUASH_HZ, SQUASH_ZETA)
|
|
388
410
|
s.squash += h * s.squashV
|
|
389
|
-
s.rollV += h * spring(s.roll - this.roll[e], s.rollV, ROLL_HZ, ROLL_ZETA)
|
|
411
|
+
s.rollV += h * spring(s.roll - pressedRoll(this.roll[e], s.rollHeld), s.rollV, ROLL_HZ, ROLL_ZETA)
|
|
390
412
|
s.roll += h * s.rollV
|
|
391
413
|
for (let k = 0; k < 2; k++) {
|
|
392
414
|
s.lagV[k] += h * spring(s.lag[k] - s.look[k], s.lagV[k], LAG_HZ, LAG_ZETA)
|
|
@@ -420,7 +442,7 @@ export class JellyEyes {
|
|
|
420
442
|
const vn = s.v / omega
|
|
421
443
|
const gain = (k: 0 | 1) => SCALE_GAIN[k] * (x >= 0 ? 1 : REBOUND[k])
|
|
422
444
|
const kx = (1 + x * gain(0)) * (1 - 0.8 * s.squash + pulse)
|
|
423
|
-
const ky = (1 + x * gain(1)) * (1 - SQUEEZE_Y * s.closure) * (1 - s.squash + pulse)
|
|
445
|
+
const ky = (1 + x * gain(1)) * (1 - SQUEEZE_Y * Math.max(0, s.closure - s.closureHeld)) * (1 - s.squash + pulse)
|
|
424
446
|
o.set([rest.radius[0], rest.radius[1], s.closure, this.eyeBones[e]], 56 + e * 4)
|
|
425
447
|
// [4]/[5]: scale across and down, the iris's twist, the highlight's turn.
|
|
426
448
|
o.set([by(kx, 0.78, 1.25), by(ky, 0.7, 1.08), (x * TWIST_POS + vn * TWIST_VEL) * DEG * g, vn * HL_TURN * DEG * g], 64 + e * 4)
|
|
@@ -440,7 +462,7 @@ export class JellyEyes {
|
|
|
440
462
|
// [8]/[9]: the roll's pivot and angle; [10]/[11]: the highlight's own
|
|
441
463
|
// scale, and how far the iris comes forward (bind units).
|
|
442
464
|
const pivot = rest.pivot
|
|
443
|
-
o.set(pivot ? [pivot[0], pivot[1], pivot[2], (this.roll[e] + (s.roll - this.roll[e]) * ROLL_SWING) * DEG * g] : [0, 0, 0, 0], 80 + e * 4)
|
|
465
|
+
o.set(pivot ? [pivot[0], pivot[1], pivot[2], (pressedRoll(this.roll[e], s.rollHeld) + (s.roll - pressedRoll(this.roll[e], s.rollHeld)) * ROLL_SWING) * DEG * g] : [0, 0, 0, 0], 80 + e * 4)
|
|
444
466
|
const hs = (k: 0 | 1) => Math.max(HL_SCALE_MIN, Math.min(HL_SCALE_MAX, 1 + x * HL_SCALE[k] * g))
|
|
445
467
|
o.set([hs(0), hs(1), Math.min(Math.abs(x), SPRING_LIMIT) * PUSH_ELASTIC * r * g, 0], 88 + e * 4)
|
|
446
468
|
}
|
|
@@ -499,6 +521,12 @@ export class JellyEyes {
|
|
|
499
521
|
}
|
|
500
522
|
}
|
|
501
523
|
|
|
524
|
+
/** The part of an expression's roll past where it has been held: the full
|
|
525
|
+
* angle while it arrives, nothing once it stays, nothing as it leaves. */
|
|
526
|
+
function pressedRoll(angle: number, held: number): number {
|
|
527
|
+
return Math.sign(angle) * Math.max(0, Math.abs(angle) - Math.abs(held))
|
|
528
|
+
}
|
|
529
|
+
|
|
502
530
|
/** Zero jelly[0..11] — strength 0 is what the shader reads as off. */
|
|
503
531
|
export function clearJellyEyes(o: Float32Array): void {
|
|
504
532
|
o.fill(0, 48, 96)
|
|
@@ -93,7 +93,7 @@ struct Light { direction: vec4f, color: vec4f, };
|
|
|
93
93
|
struct LightUniforms { ambientColor: vec4f, lights: array<Light, 4>, sh: array<vec4f, 9>, };
|
|
94
94
|
struct GroundShadowMat {
|
|
95
95
|
diffuseColor: vec3f, fadeStart: f32,
|
|
96
|
-
fadeEnd: f32, shadowStrength: f32,
|
|
96
|
+
fadeEnd: f32, shadowStrength: f32, gridPattern: f32, gridSpacing: f32,
|
|
97
97
|
gridLineWidth: f32, gridLineOpacity: f32, noiseStrength: f32, opacity: f32,
|
|
98
98
|
gridLineColor: vec3f, mirror: f32,
|
|
99
99
|
mirrorBlur: f32, _pad17: f32, shadowSoftness: f32, groundY: f32,
|
|
@@ -293,10 +293,18 @@ ${pcfWgsl("shadowAtlas", "suv", `${1 / SHADOW_ATLAS_SIZE}`, "compareZ", "acc", "
|
|
|
293
293
|
// Grid lines — anti-aliased via screen-space derivatives
|
|
294
294
|
let gridFrac = abs(fract(gp - 0.5) - 0.5);
|
|
295
295
|
let halfLine = material.gridLineWidth * 0.5;
|
|
296
|
-
let
|
|
296
|
+
let lines = 1.0 - min(
|
|
297
297
|
smoothstep(halfLine - gridDeriv.x, halfLine + gridDeriv.x, gridFrac.x),
|
|
298
298
|
smoothstep(halfLine - gridDeriv.y, halfLine + gridDeriv.y, gridFrac.y)
|
|
299
299
|
);
|
|
300
|
+
// Dots: one round dot on every crossing the lines would draw, its radius
|
|
301
|
+
// four line widths so the two patterns weigh about the same on the floor.
|
|
302
|
+
// Anti-aliased by the same derivative, so a far dot fades rather than
|
|
303
|
+
// shimmers.
|
|
304
|
+
let dotR = material.gridLineWidth * 4.0;
|
|
305
|
+
let dotAa = max(gridDeriv.x, gridDeriv.y);
|
|
306
|
+
let dots = 1.0 - smoothstep(dotR - dotAa, dotR + dotAa, length(gridFrac));
|
|
307
|
+
let gridLine = select(lines, dots, material.gridPattern > 0.5);
|
|
300
308
|
let sun = rzWorldAmbient(n) + light.lights[0].color.xyz * light.lights[0].color.w * max(dot(n, -light.lights[0].direction.xyz), 0.0);
|
|
301
309
|
// The positional layer reaches the floor too. A stage light that lit the
|
|
302
310
|
// cast and not the ground under her would read as a sticker, which is the
|
|
@@ -341,8 +349,12 @@ ${pcfWgsl("shadowAtlas", "suv", `${1 / SHADOW_ATLAS_SIZE}`, "compareZ", "acc", "
|
|
|
341
349
|
// reconstruct the reflected image point along the ray from the MIRRORED
|
|
342
350
|
// eye through this fragment. Mirroring across the floor's own plane is a
|
|
343
351
|
// sign flip on y about that height (the forward vector is a direction, so
|
|
344
|
-
// it flips alone)
|
|
345
|
-
//
|
|
352
|
+
// it flips alone). From the MIRRORED eye that ray lands on the object
|
|
353
|
+
// itself, ABOVE the plane — the pass drew view × R, which is the real
|
|
354
|
+
// object seen from the mirrored camera — so its height is y − floor.
|
|
355
|
+
// (It read floor − y, the image point's depth below the plane, which is
|
|
356
|
+
// never positive from this eye: every texel took level 0 and the dial
|
|
357
|
+
// did nothing.)
|
|
346
358
|
let dims = vec2f(textureDimensions(mirrorDepth));
|
|
347
359
|
let texel = clamp(vec2i(muv * dims), vec2i(0), vec2i(dims) - vec2i(1));
|
|
348
360
|
let z = textureLoad(mirrorDepth, texel, 0);
|
|
@@ -353,7 +365,7 @@ ${pcfWgsl("shadowAtlas", "suv", `${1 / SHADOW_ATLAS_SIZE}`, "compareZ", "acc", "
|
|
|
353
365
|
let toFrag = i.worldPos - eyeM;
|
|
354
366
|
let dir = toFrag * inverseSqrt(max(dot(toFrag, toFrag), 1e-8));
|
|
355
367
|
let t = viewZ / max(dot(dir, fwdM), 1e-4);
|
|
356
|
-
let height = max(
|
|
368
|
+
let height = max((eyeM.y + dir.y * t) - material.groundY, 0.0);
|
|
357
369
|
// Full softness by BLUR_SPAN units above the floor — about a character's
|
|
358
370
|
// height. The hardware clamps the level, so the nominal 5.0 needs no
|
|
359
371
|
// knowledge of the real chain length, and blur 0 reads exactly level 0.
|
|
@@ -364,7 +376,11 @@ ${pcfWgsl("shadowAtlas", "suv", `${1 / SHADOW_ATLAS_SIZE}`, "compareZ", "acc", "
|
|
|
364
376
|
// Still under the received shadow: a polished floor in shade shows a dim
|
|
365
377
|
// reflection, and a mirror that ignored the shadow would glow in it.
|
|
366
378
|
reflShadowed = refl.rgb * (1.0 - dark * 0.65);
|
|
367
|
-
|
|
379
|
+
// THE SAME LEVEL as the colour (the placed mirror's rule, mirror.ts): the
|
|
380
|
+
// colour is premultiplied by this coverage, so the two are one quantity in
|
|
381
|
+
// two textures. Coverage read sharp under a blurred colour is a reflection
|
|
382
|
+
// that darkens as the dial comes up, from the first level that spreads.
|
|
383
|
+
reflA = textureSampleLevel(mirrorMask, linearSampler, muv, lod).g;
|
|
368
384
|
}
|
|
369
385
|
// THREE LAYERS, composited premultiplied, bottom to top: the shadow the
|
|
370
386
|
// catcher receives, the ground surface, and the grid.
|
|
@@ -374,7 +390,16 @@ ${pcfWgsl("shadowAtlas", "suv", `${1 / SHADOW_ATLAS_SIZE}`, "compareZ", "acc", "
|
|
|
374
390
|
// with it — you could not have a bare grid over a photo, which is most of
|
|
375
391
|
// what a grid is for. It is its own layer now: the ground plane keeps an
|
|
376
392
|
// alpha, and the grid is simply on or off.
|
|
377
|
-
|
|
393
|
+
// FRESNEL over the reflection. A real polished floor is mostly its own
|
|
394
|
+
// colour looking straight down and nearly a mirror toward the horizon
|
|
395
|
+
// (Schlick's falloff, (1 - cos)^5), so where the mirror has something to
|
|
396
|
+
// show, the surface thins as the view grazes. Opacity is therefore the
|
|
397
|
+
// floor's coverage LOOKING STRAIGHT DOWN. Where nothing reflected, and with
|
|
398
|
+
// the mirror off, the surface is untouched: the far floor does not dissolve
|
|
399
|
+
// into an empty target.
|
|
400
|
+
let viewCos = clamp(dot(n, normalize(camera.viewPos - i.worldPos)), 0.0, 1.0);
|
|
401
|
+
let fresnel = pow(1.0 - viewCos, 5.0);
|
|
402
|
+
let surfA = edgeFade * material.opacity * (1.0 - fresnel * material.mirror * reflA);
|
|
378
403
|
let gridA = gridLine * material.gridLineOpacity * edgeFade;
|
|
379
404
|
// The mirror covers only what it actually REFLECTS. The backdrop no longer
|
|
380
405
|
// rides in the reflection target — it clears transparent — so the floor keeps
|
|
@@ -392,7 +417,11 @@ ${pcfWgsl("shadowAtlas", "suv", `${1 / SHADOW_ATLAS_SIZE}`, "compareZ", "acc", "
|
|
|
392
417
|
// ground surface, grid. Each with its own coverage, none scaling another —
|
|
393
418
|
// ground opacity REVEALS the mirror rather than the mirror carrying a
|
|
394
419
|
// strength of its own.
|
|
395
|
-
|
|
420
|
+
// reflShadowed is ALREADY premultiplied by its coverage (reflA): the HDR
|
|
421
|
+
// target stores colour weighted by its own alpha. So the layer's colour takes
|
|
422
|
+
// the mirror's switch and the fade, not reflA a second time — that squared
|
|
423
|
+
// coverage dimmed every edge, and every pixel once the blur spread it.
|
|
424
|
+
var pm = reflShadowed * material.mirror * edgeFade;
|
|
396
425
|
var cov = mirrA;
|
|
397
426
|
// Shadow catcher over the reflection-or-nothing: black, it covers.
|
|
398
427
|
pm = pm * (1.0 - catchA);
|