reze-engine 0.68.32 → 0.69.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/dist/_dbg-loader.mjs +1100 -0
- package/dist/engine.d.ts +15 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +15 -5
- package/dist/shaders/passes/ground.d.ts.map +1 -1
- package/dist/shaders/passes/ground.js +55 -27
- package/package.json +1 -1
- package/src/engine.ts +29 -4
- package/src/shaders/passes/ground.ts +55 -27
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
|
|
@@ -11890,6 +11900,11 @@ export class Engine {
|
|
|
11890
11900
|
/** Mirror softness, 0–1: 0 a polished mirror, 1 the softest blur level,
|
|
11891
11901
|
* scaled by how far the reflected geometry sits behind the surface. */
|
|
11892
11902
|
mirrorBlur?: number
|
|
11903
|
+
/** How much the mirror reflects looking straight down, 0–1 (Schlick's F0);
|
|
11904
|
+
* Fresnel takes it toward 1 as the view grazes. 1 (default) is a true
|
|
11905
|
+
* mirror. Independent of `opacity`, which is only how see-through the
|
|
11906
|
+
* floor is: the reflection lies OVER the floor's colour. */
|
|
11907
|
+
mirrorReflectivity?: number
|
|
11893
11908
|
/** How soft the received shadow's edge is, 0–1. 0 (default) is the sharp
|
|
11894
11909
|
* kernel this has always used, to the bit; 1 spreads the taps fourteen
|
|
11895
11910
|
* times as wide, which is the edge an overcast sky throws.
|
|
@@ -11920,10 +11935,12 @@ export class Engine {
|
|
|
11920
11935
|
gridLineWidth: 0.012,
|
|
11921
11936
|
gridLineOpacity: 0.4,
|
|
11922
11937
|
gridLineColor: new Vec3(0.85, 0.85, 0.85),
|
|
11938
|
+
gridPattern: "lines" as "lines" | "dots",
|
|
11923
11939
|
noiseStrength: 0.05,
|
|
11924
11940
|
opacity: 1.0,
|
|
11925
11941
|
mirror: false,
|
|
11926
11942
|
mirrorBlur: 0,
|
|
11943
|
+
mirrorReflectivity: 1,
|
|
11927
11944
|
shadowSoftness: 0,
|
|
11928
11945
|
...options,
|
|
11929
11946
|
}
|
|
@@ -15866,10 +15883,12 @@ export class Engine {
|
|
|
15866
15883
|
gridLineWidth: number
|
|
15867
15884
|
gridLineOpacity: number
|
|
15868
15885
|
gridLineColor: Vec3
|
|
15886
|
+
gridPattern: "lines" | "dots"
|
|
15869
15887
|
noiseStrength: number
|
|
15870
15888
|
opacity: number
|
|
15871
15889
|
mirror: boolean
|
|
15872
15890
|
mirrorBlur: number
|
|
15891
|
+
mirrorReflectivity: number
|
|
15873
15892
|
shadowSoftness: number
|
|
15874
15893
|
}) {
|
|
15875
15894
|
const {
|
|
@@ -15882,10 +15901,12 @@ export class Engine {
|
|
|
15882
15901
|
gridLineWidth,
|
|
15883
15902
|
gridLineOpacity,
|
|
15884
15903
|
gridLineColor,
|
|
15904
|
+
gridPattern,
|
|
15885
15905
|
noiseStrength,
|
|
15886
15906
|
opacity,
|
|
15887
15907
|
mirror,
|
|
15888
15908
|
mirrorBlur,
|
|
15909
|
+
mirrorReflectivity,
|
|
15889
15910
|
shadowSoftness,
|
|
15890
15911
|
} = opts
|
|
15891
15912
|
// Shadow map is already created in setupPipelines()
|
|
@@ -15901,6 +15922,8 @@ export class Engine {
|
|
|
15901
15922
|
gb[3] = fadeStart
|
|
15902
15923
|
gb[4] = fadeEnd
|
|
15903
15924
|
gb[5] = shadowStrength
|
|
15925
|
+
// gb[6] — the grid's pattern, 0 lines and 1 dots. Was padding.
|
|
15926
|
+
gb[6] = gridPattern === "dots" ? 1 : 0
|
|
15904
15927
|
gb[7] = gridSpacing
|
|
15905
15928
|
gb[8] = gridLineWidth
|
|
15906
15929
|
gb[9] = gridLineOpacity
|
|
@@ -15913,6 +15936,8 @@ export class Engine {
|
|
|
15913
15936
|
this.groundMirror = gb[15]
|
|
15914
15937
|
gb[16] = Math.min(Math.max(mirrorBlur, 0), 1)
|
|
15915
15938
|
this.groundMirrorBlur = gb[16]
|
|
15939
|
+
// gb[17] — reflectivity, the mirror's F0. Was padding.
|
|
15940
|
+
gb[17] = Math.min(Math.max(mirrorReflectivity, 0), 1)
|
|
15916
15941
|
// gb[18] — shadow edge softness. Was padding; the shader reads it as the
|
|
15917
15942
|
// Vogel disk's radius, and 0 takes the sharp nine-tap path unchanged.
|
|
15918
15943
|
gb[18] = Math.min(Math.max(shadowSoftness, 0), 1)
|
|
@@ -93,10 +93,10 @@ 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
|
-
mirrorBlur: f32,
|
|
99
|
+
mirrorBlur: f32, mirrorReflectivity: f32, shadowSoftness: f32, groundY: f32,
|
|
100
100
|
// Every shadow caster in one sphere, refreshed per frame. w = radius; 0 means
|
|
101
101
|
// nothing casts, negative means "do not use this" (a rigid caster has no
|
|
102
102
|
// sphere, so a scene with a stage keeps the taps). See rzShadowPossible.
|
|
@@ -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,34 +390,46 @@ ${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.
|
|
393
|
+
// REFLECTION IS NOT TRANSPARENCY. A solid glossy floor reflects: its colour
|
|
394
|
+
// and its reflection ADD, in a share set by the material and the angle, and
|
|
395
|
+
// how see-through the floor is has nothing to do with it. So the two are two
|
|
396
|
+
// dials. Opacity is the surface's coverage, for compositing over a photo or a
|
|
397
|
+
// key. Reflectivity is Schlick's F0, the share reflected looking straight
|
|
398
|
+
// down; Fresnel takes it toward 1 as the view grazes, (1 - cos)^5. 1 is a true
|
|
399
|
+
// mirror at every angle.
|
|
400
|
+
let viewCos = clamp(dot(n, normalize(camera.viewPos - i.worldPos)), 0.0, 1.0);
|
|
401
|
+
let f0 = clamp(material.mirrorReflectivity, 0.0, 1.0);
|
|
402
|
+
let fresnel = f0 + (1.0 - f0) * pow(1.0 - viewCos, 5.0);
|
|
377
403
|
let surfA = edgeFade * material.opacity;
|
|
378
404
|
let gridA = gridLine * material.gridLineOpacity * edgeFade;
|
|
379
|
-
// The mirror covers only what it actually REFLECTS. The backdrop
|
|
380
|
-
//
|
|
381
|
-
// its own colour everywhere the cast is not standing
|
|
382
|
-
//
|
|
383
|
-
let mirrA = material.mirror * edgeFade * reflA;
|
|
405
|
+
// The mirror covers only what it actually REFLECTS. The backdrop does not
|
|
406
|
+
// ride in the reflection target (it clears transparent), so the floor keeps
|
|
407
|
+
// its own colour everywhere the cast is not standing: an MMD stage floor,
|
|
408
|
+
// not a mirror of the sky.
|
|
409
|
+
let mirrA = material.mirror * edgeFade * reflA * fresnel;
|
|
384
410
|
// As opacity drops the received shadow becomes a translucent dark layer
|
|
385
411
|
// (Blender's Shadow Catcher), so models still feel grounded on a photo or a
|
|
386
|
-
// 360 backdrop. Colourless by construction: it darkens by covering.
|
|
387
|
-
//
|
|
388
|
-
|
|
389
|
-
let catchA = dark * 0.65 * edgeFade * (1.0 - material.opacity) * (1.0 - mirrA);
|
|
412
|
+
// 360 backdrop. Colourless by construction: it darkens by covering. Where the
|
|
413
|
+
// reflection lies over it, the reflection's own shadow shows instead.
|
|
414
|
+
let catchA = dark * 0.65 * edgeFade * (1.0 - material.opacity);
|
|
390
415
|
|
|
391
|
-
// FOUR LAYERS, premultiplied, bottom to top:
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
//
|
|
395
|
-
|
|
396
|
-
var
|
|
397
|
-
|
|
398
|
-
pm = pm * (1.0 - catchA);
|
|
399
|
-
cov = catchA + cov * (1.0 - catchA);
|
|
416
|
+
// FOUR LAYERS, premultiplied, bottom to top: received shadow, ground
|
|
417
|
+
// surface, reflection, grid. The reflection over the surface is the energy
|
|
418
|
+
// split itself: what the floor reflects it does not diffuse, so the surface
|
|
419
|
+
// under it keeps (1 - F) of itself, and a floor at opacity 0 still mirrors,
|
|
420
|
+
// the way glass does.
|
|
421
|
+
var pm = vec3f(0.0);
|
|
422
|
+
var cov = catchA;
|
|
400
423
|
// Surface over shadow.
|
|
401
424
|
pm = baseColor * surfA + pm * (1.0 - surfA);
|
|
402
425
|
cov = surfA + cov * (1.0 - surfA);
|
|
403
|
-
//
|
|
404
|
-
//
|
|
426
|
+
// Reflection over the surface. reflShadowed is ALREADY premultiplied by its
|
|
427
|
+
// coverage (reflA): the HDR target stores colour weighted by its own alpha,
|
|
428
|
+
// so it takes the switch, the fade and Fresnel, never reflA a second time.
|
|
429
|
+
pm = reflShadowed * (material.mirror * edgeFade * fresnel) + pm * (1.0 - mirrA);
|
|
430
|
+
cov = mirrA + cov * (1.0 - mirrA);
|
|
431
|
+
// Grid over everything. Unshadowed, as it has always been: a painted line
|
|
432
|
+
// reads as paint.
|
|
405
433
|
pm = material.gridLineColor * gridA + pm * (1.0 - gridA);
|
|
406
434
|
cov = gridA + cov * (1.0 - gridA);
|
|
407
435
|
|