reze-engine 0.68.17 → 0.68.19

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/engine.js CHANGED
@@ -149,6 +149,15 @@ const PRESET_NAME_HINTS = [
149
149
  ],
150
150
  ],
151
151
  ];
152
+ // The eye parts the game MULTIPLIES over the iris rather than lays over it: an
153
+ // eye shadow, a soft light-grey band at partial alpha whose job is to darken the
154
+ // top of the eye. They stay eye parts — the stencil, the order and the graph are
155
+ // the eye's — and take blend "multiply" per material (blendByMaterial).
156
+ const EYE_SHADOW_HINTS = ["目影", "眼影", "eyeshadow", "eye_shadow", "eye shadow"];
157
+ function isEyeShadow(materialName) {
158
+ const lower = materialName.toLowerCase();
159
+ return EYE_SHADOW_HINTS.some((hint) => lower.includes(hint));
160
+ }
152
161
  // Whole names that are body parts — skin by another name. Whole, never
153
162
  // substrings: 手 alone is a hand, inside 手套 (gloves) or 手镯 (a bracelet) it is
154
163
  // what the hand wears; 足 is a leg, 足袋 a sock.
@@ -6744,6 +6753,7 @@ export class Engine {
6744
6753
  // blend: "additive". See scene-contract's material-additive.
6745
6754
  this.sceneTargetsAdditive = sceneTargetsFor("material-additive", this.sceneFormats);
6746
6755
  this.sceneTargetsPremultiplied = sceneTargetsFor("material-premultiplied", this.sceneFormats);
6756
+ this.sceneTargetsMultiply = sceneTargetsFor("material-multiply", this.sceneFormats);
6747
6757
  this.fullVertexBufferLayouts = fullVertexBuffers;
6748
6758
  // Slot 3 stays empty: the outline hull binds its own stream there between
6749
6759
  // two material draws, and a material reading slot 3 would pick it up.
@@ -9764,15 +9774,15 @@ export class Engine {
9764
9774
  this.updateLightBuffer();
9765
9775
  }
9766
9776
  /**
9767
- * The cast's shadow on a stage, as a game on SimPipeline lays its ground
9768
- * shadow: the characters drawn into a map of their own from `direction` (the
9769
- * way TO the light, this engine's axes), and every Unity-mode stage surface
9770
- * multiplied toward `color` (linear) by amount × how much of the cast stands
9771
- * in the way. Its darkness is independent of the sun's — X340's is dim
9772
- * moonlight, which left a kneeling figure no shadow at all — and without a
9773
- * `direction` it falls along the sun, so it agrees with every other shadow on
9774
- * the stage. Only stage materials read it; a scene
9775
- * without a stage is untouched. Null turns it off.
9777
+ * The cast's shadow on a stage the sun cannot reach: the characters drawn
9778
+ * into a map of their own from `direction` (the way TO the light, this
9779
+ * engine's axes), and every graph-drawn stage surface multiplied toward
9780
+ * `color` (linear) by amount × how much of the cast stands in the way —
9781
+ * where the stage roofs her from the sun (rzRoofedCastShadow). Under open
9782
+ * sky the sun's own map lays her shadow and this adds nothing; under a
9783
+ * ceiling, where the lamps cast none, it is the only shadow she has. Without
9784
+ * a `direction` it falls along the sun. A scene without a stage is
9785
+ * untouched. Null turns it off.
9776
9786
  */
9777
9787
  setStageCastShadow(opts) {
9778
9788
  this.castShadow = opts;
@@ -13207,11 +13217,14 @@ export class Engine {
13207
13217
  }
13208
13218
  // Its ObjectLight: the world's ambient, and the layers its kind draws on —
13209
13219
  // the cast on the character layer as well as the default one. Words:
13210
- // layers [0..3], ambient flag [4..7], SH [8..43], fill [44..47], jelly
13211
- // eyes [48..71] — see materials/common.ts.
13220
+ // layers [0..3] (y: a stage, which takes the cast's shadow —
13221
+ // rzRoofedCastShadow), ambient flag [4..7], SH [8..43], fill [44..47],
13222
+ // jelly eyes [48..71] — see materials/common.ts.
13212
13223
  const objectLight = new Float32Array(96);
13213
- new Uint32Array(objectLight.buffer)[0] =
13224
+ const objectLayers = new Uint32Array(objectLight.buffer);
13225
+ objectLayers[0] =
13214
13226
  isStage || isPlane || isProp ? RENDERING_LAYER_DEFAULT : (RENDERING_LAYER_DEFAULT | RENDERING_LAYER_CHARACTER) >>> 0;
13227
+ objectLayers[1] = isStage ? 1 : 0;
13215
13228
  const lightBuffer = this.device.createBuffer({
13216
13229
  label: `${name}: object light`,
13217
13230
  size: objectLight.byteLength,
@@ -15549,6 +15562,7 @@ export class Engine {
15549
15562
  const info = PRESET_GROUP_INFO[preset];
15550
15563
  if (!info)
15551
15564
  continue;
15565
+ const shadows = preset === "eye" ? materials.filter(isEyeShadow) : [];
15552
15566
  groups.push({
15553
15567
  id: preset,
15554
15568
  label: info.graph.name,
@@ -15556,6 +15570,7 @@ export class Engine {
15556
15570
  graph: info.graph,
15557
15571
  renderClass: info.renderClass,
15558
15572
  alphaMode: info.alphaMode,
15573
+ ...(shadows.length ? { blendByMaterial: Object.fromEntries(shadows.map((m) => [m, "multiply"])) } : {}),
15559
15574
  });
15560
15575
  }
15561
15576
  return this.applyStyleGroups(modelName, groups);
@@ -15634,22 +15649,26 @@ export class Engine {
15634
15649
  await Promise.all(groups.map(async (g) => {
15635
15650
  const renderClass = g.renderClass ?? "auto";
15636
15651
  const alphaMode = g.alphaMode ?? "opaque";
15637
- const blend = g.blend ?? "over";
15638
- let result;
15639
- try {
15640
- result = compileGraph(g.graph, { renderClass, alphaMode, blend });
15641
- }
15642
- catch {
15643
- return;
15644
- }
15645
- if (!result.ok)
15646
- return;
15647
- const module = this.cachedShaderModule(result.wgsl, `style group: ${g.id} (${renderClass})`);
15648
- await Promise.all([
15649
- this.createRenderClassPipeline(renderClass, module, false, true, blend),
15650
- this.createRenderClassPipeline(renderClass, module, false, false, blend),
15651
- renderClass === "hair" ? this.createRenderClassPipeline(renderClass, module, true, true, blend) : null,
15652
- ]).catch(() => { });
15652
+ const groupBlend = g.blend ?? "over";
15653
+ // Every blend its members draw with, as the install compiles them.
15654
+ const blends = new Set([groupBlend, ...g.materials.map((m) => g.blendByMaterial?.[m] ?? groupBlend)]);
15655
+ await Promise.all([...blends].map(async (blend) => {
15656
+ let result;
15657
+ try {
15658
+ result = compileGraph(g.graph, { renderClass, alphaMode, blend });
15659
+ }
15660
+ catch {
15661
+ return;
15662
+ }
15663
+ if (!result.ok)
15664
+ return;
15665
+ const module = this.cachedShaderModule(result.wgsl, `style group: ${g.id} (${renderClass}${blend === groupBlend ? "" : `, ${blend}`})`);
15666
+ await Promise.all([
15667
+ this.createRenderClassPipeline(renderClass, module, false, true, blend),
15668
+ this.createRenderClassPipeline(renderClass, module, false, false, blend),
15669
+ renderClass === "hair" ? this.createRenderClassPipeline(renderClass, module, true, true, blend) : null,
15670
+ ]).catch(() => { });
15671
+ }));
15653
15672
  }));
15654
15673
  }
15655
15674
  /** Add or replace a single style group by id. `opts` may carry a `previewNode` for the
@@ -15980,70 +15999,94 @@ export class Engine {
15980
15999
  // arrive twice — once as the model lands and again once its sidecar has
15981
16000
  // decoded — and without this the second apply refreshed the definition and
15982
16001
  // silently kept the empty slots from the first.
16002
+ // The blends its members draw with: the group's own first, then any a
16003
+ // member keys for itself (blendByMaterial) — one compile each, the graph and
16004
+ // its slots the same in all of them.
16005
+ const groupBlend = group.blend ?? "over";
16006
+ const blends = [
16007
+ groupBlend,
16008
+ ...new Set(group.materials.map((m) => group.blendByMaterial?.[m] ?? groupBlend).filter((b) => b !== groupBlend)),
16009
+ ];
15983
16010
  const signature = JSON.stringify({
15984
16011
  g: group.graph,
15985
16012
  rc: renderClass,
15986
16013
  am: alphaMode,
15987
- bl: group.blend ?? "over",
16014
+ bl: groupBlend,
15988
16015
  o: opts?.previewNode ?? null,
15989
16016
  im: group.images?.length ?? 0,
15990
16017
  ibm: Object.keys(group.imagesByMaterial ?? {}).sort(),
16018
+ bls: blends,
15991
16019
  });
15992
16020
  const existing = inst.styleGroups.get(group.id);
15993
16021
  if (existing && existing.signature === signature) {
15994
16022
  existing.group = group; // refresh def (label/materials) without recompiling
15995
16023
  return { ok: true, diagnostics: [], slotMap: existing.slotMap };
15996
16024
  }
15997
- const result = compileGraph(group.graph, { ...opts, renderClass, alphaMode, blend: group.blend ?? "over" });
15998
- if (!result.ok)
15999
- return { ok: false, diagnostics: result.diagnostics, slotMap: result.slotMap };
16025
+ const compiled = blends.map((b) => compileGraph(group.graph, { ...opts, renderClass, alphaMode, blend: b }));
16026
+ const result = compiled[0];
16027
+ const failed = compiled.find((r) => !r.ok);
16028
+ if (failed)
16029
+ return { ok: false, diagnostics: failed.diagnostics, slotMap: failed.slotMap };
16000
16030
  const generation = (inst.styleGroupGen.get(group.id) ?? 0) + 1;
16001
16031
  inst.styleGroupGen.set(group.id, generation);
16002
- this.device.pushErrorScope("validation");
16003
- const module = this.cachedShaderModule(result.wgsl, `style group: ${group.id} (${renderClass})`);
16004
- const scopePromise = this.device.popErrorScope();
16005
- // EVERY VARIANT AT ONCE, and the module's diagnostics read beside them
16006
- // rather than first: the compiles run in parallel in the GPU process, and
16007
- // awaiting each in turn (and the diagnostics before any) made a group cost
16008
- // the sum of its pipelines instead of the longest.
16009
- const blend = group.blend ?? "over";
16010
16032
  // The single-sided twins a draw of this group will ask for (sidedPipeline),
16011
16033
  // built with their pipelines rather than synchronously at the first draw.
16012
16034
  const singleSided = inst.drawCalls.some((dc) => !dc.doubleSided && group.materials.includes(dc.materialName));
16013
- const variant = (overEyes, depthWrite) => this.createRenderClassPipeline(renderClass, module, overEyes, depthWrite, blend).then(async (p) => {
16014
- if (singleSided)
16015
- await this.buildSidedTwin(p, false);
16016
- return p;
16035
+ // EVERY VARIANT AT ONCE, and the module's diagnostics read beside them
16036
+ // rather than first: the compiles run in parallel in the GPU process, and
16037
+ // awaiting each in turn (and the diagnostics before any) made a group cost
16038
+ // the sum of its pipelines instead of the longest. One module per blend,
16039
+ // each with its variants.
16040
+ const builds = compiled.map((r, i) => {
16041
+ const blend = blends[i];
16042
+ this.device.pushErrorScope("validation");
16043
+ const module = this.cachedShaderModule(r.wgsl, `style group: ${group.id} (${renderClass}${blend === blends[0] ? "" : `, ${blend}`})`);
16044
+ const scopePromise = this.device.popErrorScope();
16045
+ const variant = (overEyes, depthWrite) => this.createRenderClassPipeline(renderClass, module, overEyes, depthWrite, blend).then(async (p) => {
16046
+ if (singleSided)
16047
+ await this.buildSidedTwin(p, false);
16048
+ return p;
16049
+ });
16050
+ const variants = Promise.all([
16051
+ variant(false, true),
16052
+ // The depth-write-off twin: stage transparency draws with it (see
16053
+ // pipelineForDrawCall), and a future OIT path would too.
16054
+ variant(false, false),
16055
+ renderClass === "hair" ? variant(true, true) : undefined,
16056
+ ]);
16057
+ // Handled below either way; this keeps a rejection off the console while
16058
+ // the diagnostics are read.
16059
+ variants.catch(() => { });
16060
+ return { wgsl: r.wgsl, module, scopePromise, variants };
16017
16061
  });
16018
- const variants = Promise.all([
16019
- variant(false, true),
16020
- // The depth-write-off twin: stage transparency draws with it (see
16021
- // pipelineForDrawCall), and a future OIT path would too.
16022
- variant(false, false),
16023
- renderClass === "hair" ? variant(true, true) : undefined,
16024
- ]);
16025
- // Handled below either way; this keeps a rejection off the console while
16026
- // the diagnostics are read.
16027
- variants.catch(() => { });
16028
- const [info, scopeError] = await Promise.all([module.getCompilationInfo(), scopePromise]);
16029
16062
  const diagnostics = [...result.diagnostics];
16030
- for (const msg of info.messages) {
16031
- if (msg.type !== "error")
16032
- continue;
16033
- diagnostics.push({ severity: "error", nodeId: nodeIdForWgslLine(result.wgsl, msg.lineNum), message: `WGSL: ${msg.message}` });
16063
+ let scopeError = null;
16064
+ for (const build of builds) {
16065
+ const [info, error] = await Promise.all([build.module.getCompilationInfo(), build.scopePromise]);
16066
+ scopeError ?? (scopeError = error);
16067
+ for (const msg of info.messages) {
16068
+ if (msg.type !== "error")
16069
+ continue;
16070
+ diagnostics.push({ severity: "error", nodeId: nodeIdForWgslLine(build.wgsl, msg.lineNum), message: `WGSL: ${msg.message}` });
16071
+ }
16034
16072
  }
16035
16073
  if (diagnostics.some((d) => d.severity === "error") || scopeError) {
16036
16074
  if (scopeError && !diagnostics.some((d) => d.severity === "error"))
16037
16075
  diagnostics.push({ severity: "error", message: `WGSL: ${scopeError.message}` });
16038
- this.forgetShaderModule(result.wgsl);
16076
+ for (const build of builds)
16077
+ this.forgetShaderModule(build.wgsl);
16039
16078
  return { ok: false, diagnostics, slotMap: result.slotMap };
16040
16079
  }
16041
16080
  let pipeline;
16042
16081
  let pipelineNoDepthWrite;
16043
16082
  let overEyesPipeline;
16083
+ const byBlend = {};
16044
16084
  try {
16045
- ;
16046
- [pipeline, pipelineNoDepthWrite, overEyesPipeline] = await variants;
16085
+ const sets = await Promise.all(builds.map((build) => build.variants));
16086
+ [pipeline, pipelineNoDepthWrite, overEyesPipeline] = sets[0];
16087
+ sets.slice(1).forEach(([p, noDepth, overEyes], i) => {
16088
+ byBlend[blends[i + 1]] = { pipeline: p, pipelineNoDepthWrite: noDepth, overEyesPipeline: overEyes };
16089
+ });
16047
16090
  }
16048
16091
  catch (e) {
16049
16092
  diagnostics.push({ severity: "error", message: `pipeline creation failed: ${e.message}` });
@@ -16070,6 +16113,7 @@ export class Engine {
16070
16113
  pipeline,
16071
16114
  pipelineNoDepthWrite,
16072
16115
  overEyesPipeline,
16116
+ byBlend,
16073
16117
  uniformBuffer,
16074
16118
  images: this.uploadGroupImages(group),
16075
16119
  imagesByMaterial: group.imagesByMaterial
@@ -16307,7 +16351,9 @@ export class Engine {
16307
16351
  ? this.sceneTargetsAdditive
16308
16352
  : blend === "premultiplied"
16309
16353
  ? this.sceneTargetsPremultiplied
16310
- : this.sceneTargets,
16354
+ : blend === "multiply"
16355
+ ? this.sceneTargetsMultiply
16356
+ : this.sceneTargets,
16311
16357
  },
16312
16358
  depthStencil,
16313
16359
  };
@@ -16513,7 +16559,8 @@ export class Engine {
16513
16559
  if (dc.groupId) {
16514
16560
  const install = inst.styleGroups.get(dc.groupId);
16515
16561
  if (install) {
16516
- return stageGlass ? install.pipelineNoDepthWrite : install.pipeline;
16562
+ const own = this.memberPipelines(install, dc);
16563
+ return stageGlass ? own.pipelineNoDepthWrite : own.pipeline;
16517
16564
  }
16518
16565
  }
16519
16566
  return stageGlass ? this.neutralPipelineNoDepthWrite : this.neutralPipeline;
@@ -16904,7 +16951,13 @@ export class Engine {
16904
16951
  if (!dc.groupId)
16905
16952
  return null;
16906
16953
  const install = inst.styleGroups.get(dc.groupId);
16907
- return install?.renderClass === "hair" ? (install.overEyesPipeline ?? null) : null;
16954
+ return install?.renderClass === "hair" ? (this.memberPipelines(install, dc).overEyesPipeline ?? null) : null;
16955
+ }
16956
+ /** A member's pipelines: those of the blend it keys for itself, else the
16957
+ * group's (StyleGroup.blendByMaterial). */
16958
+ memberPipelines(install, dc) {
16959
+ const blend = install.group.blendByMaterial?.[dc.materialName];
16960
+ return (blend && install.byBlend[blend]) || install;
16908
16961
  }
16909
16962
  updateCameraUniforms() {
16910
16963
  const viewMatrix = this.camera.getViewMatrix();
@@ -6,9 +6,11 @@ export type AlphaMode = "opaque" | "hashed";
6
6
  /** How a group's colour meets the frame. "over" is the ordinary alpha blend;
7
7
  * "additive" adds its light and never reads alpha; "premultiplied" takes a
8
8
  * colour already weighted by its own coverage (One, OneMinusSrcAlpha) — a
9
- * game's glass, whose reflection must not fade with its transparency. See
10
- * StyleGroup.blend. */
11
- export type StyleBlend = "over" | "additive" | "premultiplied";
9
+ * game's glass, whose reflection must not fade with its transparency;
10
+ * "multiply" filters what is already there by the surface's colour
11
+ * (DstColor Zero) — a game's eye shadow, a tint over the iris that can only
12
+ * darken it. See StyleGroup.blend. */
13
+ export type StyleBlend = "over" | "additive" | "premultiplied" | "multiply";
12
14
  /** Descriptive manifest for hosts (reze-design) so the render-class picker is data-driven
13
15
  * instead of hardcoding strings. The effect implementations stay engine-side; this only
14
16
  * describes them. `pairsWith` = the effect needs a counterpart class present to show. */
@@ -1 +1 @@
1
- {"version":3,"file":"render-class.d.ts","sourceRoot":"","sources":["../../src/graph/render-class.ts"],"names":[],"mappings":"AAMA,wEAAwE;AACxE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;AAEjD;0FAC0F;AAC1F,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE3C;;;;wBAIwB;AACxB,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,eAAe,CAAA;AAE9D;;0FAE0F;AAC1F,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,WAAW,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,WAAW,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EASpD,CAAA"}
1
+ {"version":3,"file":"render-class.d.ts","sourceRoot":"","sources":["../../src/graph/render-class.ts"],"names":[],"mappings":"AAMA,wEAAwE;AACxE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;AAEjD;0FAC0F;AAC1F,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE3C;;;;;;uCAMuC;AACvC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,eAAe,GAAG,UAAU,CAAA;AAE3E;;0FAE0F;AAC1F,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,WAAW,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,WAAW,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EASpD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../../src/graph/slots.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAoOxE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,oBAAoB,EAAE,OAAO,EAC7B,UAAU,UAAQ,EAClB,KAAK,GAAE,UAAmB,EAC1B,UAAU,UAAO,GAChB,MAAM,CAgBR"}
1
+ {"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../../src/graph/slots.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AA2PxE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,oBAAoB,EAAE,OAAO,EAC7B,UAAU,UAAQ,EAClB,KAAK,GAAE,UAAmB,EAC1B,UAAU,UAAO,GAChB,MAAM,CAgBR"}
@@ -189,6 +189,12 @@ function epilogue(renderClass, alphaMode, hasOpacity, blend, takesLight) {
189
189
  // shadows, and under a hard step flip whole regions at once. After the graph
190
190
  // it lifts her evenly and leaves every shadow where it is.
191
191
  const LIT = takesLight ? ` + (rzLightsDiffuseOnce(input.worldPos, n) + objectLight.fill.rgb) * albedo` : "";
192
+ // The cast's shadow on a stage the sun cannot reach under its roof
193
+ // (rzRoofedCastShadow), over everything the surface took — the lamps
194
+ // included, since they are what light a closed room. Zero off a stage.
195
+ const CAST = takesLight
196
+ ? ` out.color = vec4f(out.color.rgb * mix(vec3f(1.0), light.castShadow.rgb, rzRoofedCastShadow(input.worldPos) * light.castShadow.w), out.color.a);\n`
197
+ : "";
192
198
  const ALBEDO = ` let albedo = tex_color;
193
199
  `;
194
200
  // The dissolve's burning edge, ADDED after the graph and after the lights —
@@ -205,19 +211,36 @@ function epilogue(renderClass, alphaMode, hasOpacity, blend, takesLight) {
205
211
  const FOG = takesLight
206
212
  ? ` out.color = vec4f(mix(mix(out.color.rgb, light.fog[0].rgb${fogOver}, input.fog.x), light.fog[2].rgb${fogOver}, input.fog.y), out.color.a);\n`
207
213
  : "";
214
+ // MULTIPLY WRITES A FILTER, NOT A COLOUR. What it darkens was lit already —
215
+ // the iris under an eye shadow took the sun and its own glow — so the shade
216
+ // takes no light of its own: lit, a light-grey shadow came out brighter than
217
+ // the eye and multiplied it WHITER. The multiplier is the surface's own
218
+ // colour, its texture times the PMX diffuse as every look's base is, or what
219
+ // an emission-only graph paints, which is already a colour no light reaches.
220
+ // Faded by coverage here (the blend reads no alpha), capped at 1 so it can
221
+ // only darken, and with no lamps, burn or fog — all three are light. The aux
222
+ // is kept by the blend, so the mask written is never stored.
223
+ if (blend === "multiply") {
224
+ const filter = takesLight ? "tex_color * material.diffuseColor" : "final_color";
225
+ return ` var out: FSOut;
226
+ out.color = vec4f(mix(vec3f(1.0), saturate(${filter}), ${alphaBase}), ${alphaBase});
227
+ out.mask = vec4f(0.0);
228
+ ${ID_WRITE} return out;
229
+ `;
230
+ }
208
231
  if (renderClass === "hair") {
209
232
  return `${ALBEDO} var outAlpha = ${alphaBase};
210
233
  if (IS_OVER_EYES) { outAlpha = ${alphaBase} * 0.25; }
211
234
 
212
235
  var out: FSOut;
213
236
  out.color = vec4f(final_color${LIT}${BURN}, outAlpha);
214
- ${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
237
+ ${CAST}${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
215
238
  ${ID_WRITE} return out;
216
239
  `;
217
240
  }
218
241
  return `${ALBEDO} var out: FSOut;
219
242
  out.color = vec4f(final_color${LIT}${BURN}, ${alphaBase});
220
- ${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
243
+ ${CAST}${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
221
244
  ${ID_WRITE} return out;
222
245
  `;
223
246
  }
@@ -23,8 +23,26 @@ export type StyleGroup = {
23
23
  * nebula and a starfield on cylinders round the scene, their alpha 0 across
24
24
  * the whole image because additive blending does not look at it. Laid over,
25
25
  * they are invisible.
26
+ *
27
+ * "multiply" is a FILTER: the frame behind is scaled by the surface's own
28
+ * colour, faded by its alpha, and nothing is added — see `blendByMaterial`
29
+ * for the eye shadow it exists for.
26
30
  */
27
31
  blend?: StyleBlend;
32
+ /**
33
+ * `blend`, but PER MATERIAL — for a member that meets the frame unlike the
34
+ * rest of its group.
35
+ *
36
+ * An eye shadow (目影) is an EYE part: it sits on the iris, stamps the same
37
+ * stencil the see-through hair reads, and draws in the eye's order. What sets
38
+ * it apart is only how it lands — the game multiplies it, a soft grey band
39
+ * that darkens the top of the iris, where laid over it veils the eye white.
40
+ * Keyed here it stays in the eye's group, shading on the eye's graph, and
41
+ * draws through a pipeline of its own blend.
42
+ *
43
+ * A material with no entry takes `blend`.
44
+ */
45
+ blendByMaterial?: Record<string, StyleBlend>;
28
46
  /**
29
47
  * Extra image maps for this group's shading, up to four.
30
48
  *
@@ -1 +1 @@
1
- {"version":3,"file":"style-group.d.ts","sourceRoot":"","sources":["../../src/graph/style-group.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,MAAM,UAAU,GAAG;IACvB,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAA;IACV;2CACuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2EAA2E;IAC3E,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,sFAAsF;IACtF,KAAK,EAAE,WAAW,CAAA;IAClB,uEAAuE;IACvE,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,wEAAwE;IACxE,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,CAAC,UAAU,GAAG,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAA;IACjD;;;;;;;;;;;;OAYG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,UAAU,GAAG,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;CAC5E,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,WAAW,GA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CAAA;CACpB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,SAAS,EAAE,CAAA;CAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/common.ts"],"names":[],"mappings":"AA4BA;;;;uBAIuB;AACvB,eAAO,MAAM,iBAAiB,8iFA4D7B,CAAA;AAED,eAAO,MAAM,oBAAoB,QAiQhC,CAAC;AAwHF,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,orMAgHzB,CAAA;AAQD,eAAO,MAAM,4BAA4B,QAC6H,CAAA"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/common.ts"],"names":[],"mappings":"AA4BA;;;;uBAIuB;AACvB,eAAO,MAAM,iBAAiB,8iFA4D7B,CAAA;AAED,eAAO,MAAM,oBAAoB,QAiQhC,CAAC;AA4JF,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,orMAgHzB,CAAA;AAQD,eAAO,MAAM,4BAA4B,QAC6H,CAAA"}
@@ -384,6 +384,42 @@ fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
384
384
  return mix(1.0, _rzSunTaps(a), castAmt);
385
385
  }
386
386
 
387
+ /**
388
+ * The cast's shadow on a stage surface where the stage ROOFS the cast from the
389
+ * sun, 0–1 — setStageCastShadow on a graph-drawn stage (a GLB's). Under open
390
+ * sky the sun's own map already lays the cast's shadow, and laying this one too
391
+ * doubled it; under a ceiling the sun reaches neither the floor nor her, the
392
+ * lamps cast nothing, and she stood on the floor with no shadow at all. So
393
+ * per pixel: find the point of the cast that throws this shadow (the cast
394
+ * map's nearest depth, walked back toward the light along the map's z row),
395
+ * step off her toward the light, and ask the sun's map whether it reaches
396
+ * there. Lit: the sun shadow has it, answer 0. Shadowed: this is the only
397
+ * shadow she gets. Zero on everything that is not a stage (objectLight
398
+ * layers.y).
399
+ */
400
+ fn rzRoofedCastShadow(wp: vec3f) -> f32 {
401
+ if (light.castShadow.w <= 0.0 || objectLight.layers.y == 0u) { return 0.0; }
402
+ let cover = _rzCastShadow(wp);
403
+ if (cover <= 0.0) { return 0.0; }
404
+ let ndc = (light.castVP * vec4f(wp, 1.0)).xyz;
405
+ let size = vec2i(textureDimensions(castShadowMap));
406
+ let px = vec2i(vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5) * vec2f(size));
407
+ // The nearest of her over the filter's footprint: a penumbra texel's own
408
+ // depth may be the cleared 1.
409
+ var occ = 1.0;
410
+ for (var y = -2; y <= 2; y += 2) {
411
+ for (var x = -2; x <= 2; x += 2) {
412
+ occ = min(occ, textureLoad(castShadowMap, clamp(px + vec2i(x, y), vec2i(0), size - 1), 0));
413
+ }
414
+ }
415
+ if (occ >= ndc.z) { return 0.0; }
416
+ // Orthographic: depth grows away from the light at |g| per unit.
417
+ let g = vec3f(light.castVP[0].z, light.castVP[1].z, light.castVP[2].z);
418
+ let k = length(g);
419
+ let q = wp - (g / k) * ((ndc.z - occ) / k + 0.5);
420
+ return cover * (1.0 - rzSunOcclusion(q, vec3f(0.0)));
421
+ }
422
+
387
423
  `;
388
424
  // ─── Skinning vertex shader ─────────────────────────────────────────
389
425
  // Four-bone linear blend skinning. Renormalizes weights when they don't sum to 1