reze-engine 0.68.16 → 0.68.18

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/src/engine.ts CHANGED
@@ -294,6 +294,17 @@ const PRESET_NAME_HINTS: Array<[MaterialPreset, (string | RegExp)[]]> = [
294
294
  ],
295
295
  ]
296
296
 
297
+ // The eye parts the game MULTIPLIES over the iris rather than lays over it: an
298
+ // eye shadow, a soft light-grey band at partial alpha whose job is to darken the
299
+ // top of the eye. They stay eye parts — the stencil, the order and the graph are
300
+ // the eye's — and take blend "multiply" per material (blendByMaterial).
301
+ const EYE_SHADOW_HINTS = ["目影", "眼影", "eyeshadow", "eye_shadow", "eye shadow"]
302
+
303
+ function isEyeShadow(materialName: string): boolean {
304
+ const lower = materialName.toLowerCase()
305
+ return EYE_SHADOW_HINTS.some((hint) => lower.includes(hint))
306
+ }
307
+
297
308
  // Whole names that are body parts — skin by another name. Whole, never
298
309
  // substrings: 手 alone is a hand, inside 手套 (gloves) or 手镯 (a bracelet) it is
299
310
  // what the hand wears; 足 is a leg, 足袋 a sock.
@@ -355,6 +366,9 @@ type GroupInstall = {
355
366
  pipelineNoDepthWrite: GPURenderPipeline
356
367
  /** hair render-class only: the stencil-matched IS_OVER_EYES=true variant. */
357
368
  overEyesPipeline?: GPURenderPipeline
369
+ /** The same three for each blend a member keys apart from the group's
370
+ * (StyleGroup.blendByMaterial) — an eye shadow multiplying in the eye group. */
371
+ byBlend: Partial<Record<StyleBlend, Pick<GroupInstall, "pipeline" | "pipelineNoDepthWrite" | "overEyesPipeline">>>
358
372
  uniformBuffer: GPUBuffer
359
373
  /** The group's own image maps, uploaded once per apply and owned here — the
360
374
  * install destroys them when it is replaced, so a re-apply cannot leak. */
@@ -2083,6 +2097,9 @@ export class Engine {
2083
2097
  /** A group blending "premultiplied" — see scene-contract's
2084
2098
  * material-premultiplied. */
2085
2099
  private sceneTargetsPremultiplied!: GPUColorTargetState[]
2100
+ /** A group or member blending "multiply" — see scene-contract's
2101
+ * material-multiply. */
2102
+ private sceneTargetsMultiply!: GPUColorTargetState[]
2086
2103
  /** The scene pass's attachment formats, settled at init once the device has
2087
2104
  * said which HDR format it will blend. Every scene-pass pipeline asks
2088
2105
  * scene-contract for its targets against these. */
@@ -8431,6 +8448,7 @@ export class Engine {
8431
8448
  // blend: "additive". See scene-contract's material-additive.
8432
8449
  this.sceneTargetsAdditive = sceneTargetsFor("material-additive", this.sceneFormats)
8433
8450
  this.sceneTargetsPremultiplied = sceneTargetsFor("material-premultiplied", this.sceneFormats)
8451
+ this.sceneTargetsMultiply = sceneTargetsFor("material-multiply", this.sceneFormats)
8434
8452
  this.fullVertexBufferLayouts = fullVertexBuffers
8435
8453
  // Slot 3 stays empty: the outline hull binds its own stream there between
8436
8454
  // two material draws, and a material reading slot 3 would pick it up.
@@ -18149,6 +18167,7 @@ export class Engine {
18149
18167
  for (const [preset, materials] of buckets) {
18150
18168
  const info = PRESET_GROUP_INFO[preset]
18151
18169
  if (!info) continue
18170
+ const shadows = preset === "eye" ? materials.filter(isEyeShadow) : []
18152
18171
  groups.push({
18153
18172
  id: preset,
18154
18173
  label: info.graph.name,
@@ -18156,6 +18175,7 @@ export class Engine {
18156
18175
  graph: info.graph,
18157
18176
  renderClass: info.renderClass,
18158
18177
  alphaMode: info.alphaMode,
18178
+ ...(shadows.length ? { blendByMaterial: Object.fromEntries(shadows.map((m) => [m, "multiply" as const])) } : {}),
18159
18179
  })
18160
18180
  }
18161
18181
  return this.applyStyleGroups(modelName, groups)
@@ -18239,20 +18259,26 @@ export class Engine {
18239
18259
  groups.map(async (g) => {
18240
18260
  const renderClass = g.renderClass ?? "auto"
18241
18261
  const alphaMode = g.alphaMode ?? "opaque"
18242
- const blend = g.blend ?? "over"
18243
- let result: ReturnType<typeof compileGraph>
18244
- try {
18245
- result = compileGraph(g.graph, { renderClass, alphaMode, blend })
18246
- } catch {
18247
- return
18248
- }
18249
- if (!result.ok) return
18250
- const module = this.cachedShaderModule(result.wgsl, `style group: ${g.id} (${renderClass})`)
18251
- await Promise.all([
18252
- this.createRenderClassPipeline(renderClass, module, false, true, blend),
18253
- this.createRenderClassPipeline(renderClass, module, false, false, blend),
18254
- renderClass === "hair" ? this.createRenderClassPipeline(renderClass, module, true, true, blend) : null,
18255
- ]).catch(() => {})
18262
+ const groupBlend = g.blend ?? "over"
18263
+ // Every blend its members draw with, as the install compiles them.
18264
+ const blends = new Set([groupBlend, ...g.materials.map((m) => g.blendByMaterial?.[m] ?? groupBlend)])
18265
+ await Promise.all(
18266
+ [...blends].map(async (blend) => {
18267
+ let result: ReturnType<typeof compileGraph>
18268
+ try {
18269
+ result = compileGraph(g.graph, { renderClass, alphaMode, blend })
18270
+ } catch {
18271
+ return
18272
+ }
18273
+ if (!result.ok) return
18274
+ const module = this.cachedShaderModule(result.wgsl, `style group: ${g.id} (${renderClass}${blend === groupBlend ? "" : `, ${blend}`})`)
18275
+ await Promise.all([
18276
+ this.createRenderClassPipeline(renderClass, module, false, true, blend),
18277
+ this.createRenderClassPipeline(renderClass, module, false, false, blend),
18278
+ renderClass === "hair" ? this.createRenderClassPipeline(renderClass, module, true, true, blend) : null,
18279
+ ]).catch(() => {})
18280
+ }),
18281
+ )
18256
18282
  }),
18257
18283
  )
18258
18284
  }
@@ -18466,23 +18492,18 @@ export class Engine {
18466
18492
  return true
18467
18493
  }
18468
18494
 
18469
- /** The model at one cast slot — the subject rzSubject(index) reads. */
18470
- private castSubjectName(index: number, subjects: readonly string[] | null = null): string | null {
18495
+ /** The models an effect's rzSubject(i) reads, in its own index order: the
18496
+ * ones it is aimed at, or the whole cast when it is aimed at nobody. */
18497
+ private castSubjectNames(subjects: readonly string[] | null = null): string[] {
18498
+ const names: string[] = []
18471
18499
  let n = 0
18472
- let local = 0
18473
- let found: string | null = null
18474
18500
  this.forEachInstance((inst) => {
18475
- if (found !== null || n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.visible)
18476
- return
18501
+ if (n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.visible) return
18477
18502
  n++
18478
- // The effect's OWN index, which is what its shaders count in: an effect
18479
- // aimed at the third dancer finds her at 0, so a #dissolve on it takes HER
18480
- // apart rather than whoever stands at the head of the cast.
18481
18503
  if (subjects && !subjects.includes(inst.name)) return
18482
- if (local === index) found = inst.name
18483
- local++
18504
+ names.push(inst.name)
18484
18505
  })
18485
- return found
18506
+ return names
18486
18507
  }
18487
18508
 
18488
18509
  /** One effect's four durations: its dials where it declares them, the
@@ -18507,8 +18528,8 @@ export class Engine {
18507
18528
  *
18508
18529
  * Two things ask for one. A cycle set on a model (setModelDissolveCycle) runs
18509
18530
  * on the scene clock and repeats, as it always has. An effect declaring
18510
- * `#dissolve` takes ITS OWN subject 0 apart on its own terms — the first model
18511
- * it is aimed at, the head of the cast when it is aimed at nobody in
18531
+ * `#dissolve` takes every one of ITS subjects apart on its own terms — the
18532
+ * models it is aimed at, the whole cast when it is aimed at nobody in
18512
18533
  * particular: scheduled, the cycle on each clip's clock with her whole between
18513
18534
  * clips; unscheduled, the same repeating cycle as before. Where both ask, the more dissolved wins — two
18514
18535
  * answers about one body, and half a body is not one of them.
@@ -18521,14 +18542,15 @@ export class Engine {
18521
18542
  for (const fx of this.effects) {
18522
18543
  if (!fx.dissolve) continue
18523
18544
  const cycle = dissolveCycleOf(this.dissolveTimingsOf(fx, fx.dissolve))
18524
- const subject = this.castSubjectName(0, fx.subjects)
18525
- if (!cycle || !subject) continue
18545
+ if (!cycle) continue
18546
+ let v: number
18526
18547
  if (fx.window && fx.window.length > 0) {
18527
18548
  transport ??= this.transportTime()
18528
- put(subject, scheduledDissolve(fx.window, cycle, transport))
18549
+ v = scheduledDissolve(fx.window, cycle, transport)
18529
18550
  } else {
18530
- put(subject, sampleDissolveCycle(cycle, this.sceneClock))
18551
+ v = sampleDissolveCycle(cycle, this.sceneClock)
18531
18552
  }
18553
+ for (const subject of this.castSubjectNames(fx.subjects)) put(subject, v)
18532
18554
  }
18533
18555
  for (const name of this.dissolveTouched) if (!want.has(name)) this.setModelDissolve(name, 1)
18534
18556
  this.dissolveTouched = new Set(want.keys())
@@ -18596,14 +18618,23 @@ export class Engine {
18596
18618
  // arrive twice — once as the model lands and again once its sidecar has
18597
18619
  // decoded — and without this the second apply refreshed the definition and
18598
18620
  // silently kept the empty slots from the first.
18621
+ // The blends its members draw with: the group's own first, then any a
18622
+ // member keys for itself (blendByMaterial) — one compile each, the graph and
18623
+ // its slots the same in all of them.
18624
+ const groupBlend = group.blend ?? "over"
18625
+ const blends = [
18626
+ groupBlend,
18627
+ ...new Set(group.materials.map((m) => group.blendByMaterial?.[m] ?? groupBlend).filter((b) => b !== groupBlend)),
18628
+ ]
18599
18629
  const signature = JSON.stringify({
18600
18630
  g: group.graph,
18601
18631
  rc: renderClass,
18602
18632
  am: alphaMode,
18603
- bl: group.blend ?? "over",
18633
+ bl: groupBlend,
18604
18634
  o: opts?.previewNode ?? null,
18605
18635
  im: group.images?.length ?? 0,
18606
18636
  ibm: Object.keys(group.imagesByMaterial ?? {}).sort(),
18637
+ bls: blends,
18607
18638
  })
18608
18639
  const existing = inst.styleGroups.get(group.id)
18609
18640
  if (existing && existing.signature === signature) {
@@ -18611,56 +18642,71 @@ export class Engine {
18611
18642
  return { ok: true, diagnostics: [], slotMap: existing.slotMap }
18612
18643
  }
18613
18644
 
18614
- const result = compileGraph(group.graph, { ...opts, renderClass, alphaMode, blend: group.blend ?? "over" })
18615
- if (!result.ok) return { ok: false, diagnostics: result.diagnostics, slotMap: result.slotMap }
18645
+ const compiled = blends.map((b) => compileGraph(group.graph, { ...opts, renderClass, alphaMode, blend: b }))
18646
+ const result = compiled[0]
18647
+ const failed = compiled.find((r) => !r.ok)
18648
+ if (failed) return { ok: false, diagnostics: failed.diagnostics, slotMap: failed.slotMap }
18616
18649
 
18617
18650
  const generation = (inst.styleGroupGen.get(group.id) ?? 0) + 1
18618
18651
  inst.styleGroupGen.set(group.id, generation)
18619
18652
 
18620
- this.device.pushErrorScope("validation")
18621
- const module = this.cachedShaderModule(result.wgsl, `style group: ${group.id} (${renderClass})`)
18622
- const scopePromise = this.device.popErrorScope()
18623
- // EVERY VARIANT AT ONCE, and the module's diagnostics read beside them
18624
- // rather than first: the compiles run in parallel in the GPU process, and
18625
- // awaiting each in turn (and the diagnostics before any) made a group cost
18626
- // the sum of its pipelines instead of the longest.
18627
- const blend = group.blend ?? "over"
18628
18653
  // The single-sided twins a draw of this group will ask for (sidedPipeline),
18629
18654
  // built with their pipelines rather than synchronously at the first draw.
18630
18655
  const singleSided = inst.drawCalls.some((dc) => !dc.doubleSided && group.materials.includes(dc.materialName))
18631
- const variant = (overEyes: boolean, depthWrite: boolean) =>
18632
- this.createRenderClassPipeline(renderClass, module, overEyes, depthWrite, blend).then(async (p) => {
18633
- if (singleSided) await this.buildSidedTwin(p, false)
18634
- return p
18635
- })
18636
- const variants = Promise.all([
18637
- variant(false, true),
18638
- // The depth-write-off twin: stage transparency draws with it (see
18639
- // pipelineForDrawCall), and a future OIT path would too.
18640
- variant(false, false),
18641
- renderClass === "hair" ? variant(true, true) : undefined,
18642
- ])
18643
- // Handled below either way; this keeps a rejection off the console while
18644
- // the diagnostics are read.
18645
- variants.catch(() => {})
18646
- const [info, scopeError] = await Promise.all([module.getCompilationInfo(), scopePromise])
18656
+ // EVERY VARIANT AT ONCE, and the module's diagnostics read beside them
18657
+ // rather than first: the compiles run in parallel in the GPU process, and
18658
+ // awaiting each in turn (and the diagnostics before any) made a group cost
18659
+ // the sum of its pipelines instead of the longest. One module per blend,
18660
+ // each with its variants.
18661
+ const builds = compiled.map((r, i) => {
18662
+ const blend = blends[i]
18663
+ this.device.pushErrorScope("validation")
18664
+ const module = this.cachedShaderModule(r.wgsl, `style group: ${group.id} (${renderClass}${blend === blends[0] ? "" : `, ${blend}`})`)
18665
+ const scopePromise = this.device.popErrorScope()
18666
+ const variant = (overEyes: boolean, depthWrite: boolean) =>
18667
+ this.createRenderClassPipeline(renderClass, module, overEyes, depthWrite, blend).then(async (p) => {
18668
+ if (singleSided) await this.buildSidedTwin(p, false)
18669
+ return p
18670
+ })
18671
+ const variants = Promise.all([
18672
+ variant(false, true),
18673
+ // The depth-write-off twin: stage transparency draws with it (see
18674
+ // pipelineForDrawCall), and a future OIT path would too.
18675
+ variant(false, false),
18676
+ renderClass === "hair" ? variant(true, true) : undefined,
18677
+ ])
18678
+ // Handled below either way; this keeps a rejection off the console while
18679
+ // the diagnostics are read.
18680
+ variants.catch(() => {})
18681
+ return { wgsl: r.wgsl, module, scopePromise, variants }
18682
+ })
18647
18683
  const diagnostics = [...result.diagnostics]
18648
- for (const msg of info.messages) {
18649
- if (msg.type !== "error") continue
18650
- diagnostics.push({ severity: "error", nodeId: nodeIdForWgslLine(result.wgsl, msg.lineNum), message: `WGSL: ${msg.message}` })
18684
+ let scopeError: GPUError | null = null
18685
+ for (const build of builds) {
18686
+ const [info, error] = await Promise.all([build.module.getCompilationInfo(), build.scopePromise])
18687
+ scopeError ??= error
18688
+ for (const msg of info.messages) {
18689
+ if (msg.type !== "error") continue
18690
+ diagnostics.push({ severity: "error", nodeId: nodeIdForWgslLine(build.wgsl, msg.lineNum), message: `WGSL: ${msg.message}` })
18691
+ }
18651
18692
  }
18652
18693
  if (diagnostics.some((d) => d.severity === "error") || scopeError) {
18653
18694
  if (scopeError && !diagnostics.some((d) => d.severity === "error"))
18654
18695
  diagnostics.push({ severity: "error", message: `WGSL: ${scopeError.message}` })
18655
- this.forgetShaderModule(result.wgsl)
18696
+ for (const build of builds) this.forgetShaderModule(build.wgsl)
18656
18697
  return { ok: false, diagnostics, slotMap: result.slotMap }
18657
18698
  }
18658
18699
 
18659
18700
  let pipeline: GPURenderPipeline
18660
18701
  let pipelineNoDepthWrite: GPURenderPipeline
18661
18702
  let overEyesPipeline: GPURenderPipeline | undefined
18703
+ const byBlend: GroupInstall["byBlend"] = {}
18662
18704
  try {
18663
- ;[pipeline, pipelineNoDepthWrite, overEyesPipeline] = await variants
18705
+ const sets = await Promise.all(builds.map((build) => build.variants))
18706
+ ;[pipeline, pipelineNoDepthWrite, overEyesPipeline] = sets[0]
18707
+ sets.slice(1).forEach(([p, noDepth, overEyes], i) => {
18708
+ byBlend[blends[i + 1]] = { pipeline: p, pipelineNoDepthWrite: noDepth, overEyesPipeline: overEyes }
18709
+ })
18664
18710
  } catch (e) {
18665
18711
  diagnostics.push({ severity: "error", message: `pipeline creation failed: ${(e as Error).message}` })
18666
18712
  return { ok: false, diagnostics, slotMap: result.slotMap }
@@ -18690,6 +18736,7 @@ export class Engine {
18690
18736
  pipeline,
18691
18737
  pipelineNoDepthWrite,
18692
18738
  overEyesPipeline,
18739
+ byBlend,
18693
18740
  uniformBuffer,
18694
18741
  images: this.uploadGroupImages(group),
18695
18742
  imagesByMaterial: group.imagesByMaterial
@@ -18942,7 +18989,9 @@ export class Engine {
18942
18989
  ? this.sceneTargetsAdditive
18943
18990
  : blend === "premultiplied"
18944
18991
  ? this.sceneTargetsPremultiplied
18945
- : this.sceneTargets,
18992
+ : blend === "multiply"
18993
+ ? this.sceneTargetsMultiply
18994
+ : this.sceneTargets,
18946
18995
  },
18947
18996
  depthStencil,
18948
18997
  }
@@ -19177,7 +19226,8 @@ export class Engine {
19177
19226
  if (dc.groupId) {
19178
19227
  const install = inst.styleGroups.get(dc.groupId)
19179
19228
  if (install) {
19180
- return stageGlass ? install.pipelineNoDepthWrite : install.pipeline
19229
+ const own = this.memberPipelines(install, dc)
19230
+ return stageGlass ? own.pipelineNoDepthWrite : own.pipeline
19181
19231
  }
19182
19232
  }
19183
19233
  return stageGlass ? this.neutralPipelineNoDepthWrite : this.neutralPipeline
@@ -19604,7 +19654,14 @@ export class Engine {
19604
19654
  private overEyesPipelineFor(inst: ModelInstance, dc: DrawCall): GPURenderPipeline | null {
19605
19655
  if (!dc.groupId) return null
19606
19656
  const install = inst.styleGroups.get(dc.groupId)
19607
- return install?.renderClass === "hair" ? (install.overEyesPipeline ?? null) : null
19657
+ return install?.renderClass === "hair" ? (this.memberPipelines(install, dc).overEyesPipeline ?? null) : null
19658
+ }
19659
+
19660
+ /** A member's pipelines: those of the blend it keys for itself, else the
19661
+ * group's (StyleGroup.blendByMaterial). */
19662
+ private memberPipelines(install: GroupInstall, dc: DrawCall): Pick<GroupInstall, "pipeline" | "pipelineNoDepthWrite" | "overEyesPipeline"> {
19663
+ const blend = install.group.blendByMaterial?.[dc.materialName]
19664
+ return (blend && install.byBlend[blend]) || install
19608
19665
  }
19609
19666
 
19610
19667
  private updateCameraUniforms() {
@@ -14,9 +14,11 @@ export type AlphaMode = "opaque" | "hashed"
14
14
  /** How a group's colour meets the frame. "over" is the ordinary alpha blend;
15
15
  * "additive" adds its light and never reads alpha; "premultiplied" takes a
16
16
  * colour already weighted by its own coverage (One, OneMinusSrcAlpha) — a
17
- * game's glass, whose reflection must not fade with its transparency. See
18
- * StyleGroup.blend. */
19
- export type StyleBlend = "over" | "additive" | "premultiplied"
17
+ * game's glass, whose reflection must not fade with its transparency;
18
+ * "multiply" filters what is already there by the surface's colour
19
+ * (DstColor Zero) — a game's eye shadow, a tint over the iris that can only
20
+ * darken it. See StyleGroup.blend. */
21
+ export type StyleBlend = "over" | "additive" | "premultiplied" | "multiply"
20
22
 
21
23
  /** Descriptive manifest for hosts (reze-design) so the render-class picker is data-driven
22
24
  * instead of hardcoding strings. The effect implementations stay engine-side; this only
@@ -221,6 +221,23 @@ function epilogue(renderClass: RenderClass, alphaMode: AlphaMode, hasOpacity: bo
221
221
  const FOG = takesLight
222
222
  ? ` 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`
223
223
  : ""
224
+ // MULTIPLY WRITES A FILTER, NOT A COLOUR. What it darkens was lit already —
225
+ // the iris under an eye shadow took the sun and its own glow — so the shade
226
+ // takes no light of its own: lit, a light-grey shadow came out brighter than
227
+ // the eye and multiplied it WHITER. The multiplier is the surface's own
228
+ // colour, its texture times the PMX diffuse as every look's base is, or what
229
+ // an emission-only graph paints, which is already a colour no light reaches.
230
+ // Faded by coverage here (the blend reads no alpha), capped at 1 so it can
231
+ // only darken, and with no lamps, burn or fog — all three are light. The aux
232
+ // is kept by the blend, so the mask written is never stored.
233
+ if (blend === "multiply") {
234
+ const filter = takesLight ? "tex_color * material.diffuseColor" : "final_color"
235
+ return ` var out: FSOut;
236
+ out.color = vec4f(mix(vec3f(1.0), saturate(${filter}), ${alphaBase}), ${alphaBase});
237
+ out.mask = vec4f(0.0);
238
+ ${ID_WRITE} return out;
239
+ `
240
+ }
224
241
  if (renderClass === "hair") {
225
242
  return `${ALBEDO} var outAlpha = ${alphaBase};
226
243
  if (IS_OVER_EYES) { outAlpha = ${alphaBase} * 0.25; }
@@ -30,8 +30,26 @@ export type StyleGroup = {
30
30
  * nebula and a starfield on cylinders round the scene, their alpha 0 across
31
31
  * the whole image because additive blending does not look at it. Laid over,
32
32
  * they are invisible.
33
+ *
34
+ * "multiply" is a FILTER: the frame behind is scaled by the surface's own
35
+ * colour, faded by its alpha, and nothing is added — see `blendByMaterial`
36
+ * for the eye shadow it exists for.
33
37
  */
34
38
  blend?: StyleBlend
39
+ /**
40
+ * `blend`, but PER MATERIAL — for a member that meets the frame unlike the
41
+ * rest of its group.
42
+ *
43
+ * An eye shadow (目影) is an EYE part: it sits on the iris, stamps the same
44
+ * stencil the see-through hair reads, and draws in the eye's order. What sets
45
+ * it apart is only how it lands — the game multiplies it, a soft grey band
46
+ * that darkens the top of the iris, where laid over it veils the eye white.
47
+ * Keyed here it stays in the eye's group, shading on the eye's graph, and
48
+ * draws through a pipeline of its own blend.
49
+ *
50
+ * A material with no entry takes `blend`.
51
+ */
52
+ blendByMaterial?: Record<string, StyleBlend>
35
53
  /**
36
54
  * Extra image maps for this group's shading, up to four.
37
55
  *
@@ -104,6 +104,14 @@ type SceneRenderClass =
104
104
  * express. Out of WRITES_ID for the mirror's reason: a window is not what a
105
105
  * click on the figure behind it means. */
106
106
  | "material-premultiplied"
107
+ /** A material that FILTERS what is behind it — a game's eye shadow (Blend
108
+ * DstColor Zero): a soft band over the top of the iris whose colour is a
109
+ * multiplier, so the eye under it darkens and never lightens. Laid over, its
110
+ * light grey at partial alpha veils the iris white instead. The aux and the
111
+ * coverage are left as they were — a shade is not a surface, and the eye
112
+ * under it keeps its bloom — and out of WRITES_ID for the mirror's reason:
113
+ * a click there means the eye. */
114
+ | "material-multiply"
107
115
  /** Particles and ribbons in their default, non-additive mode. */
108
116
  | "particle"
109
117
  /** Particles declaring `#blend additive` — LIGHT rather than matter, so
@@ -163,6 +171,20 @@ const PREMULTIPLIED_OVER: GPUBlendState = {
163
171
  alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" },
164
172
  }
165
173
 
174
+ /** The destination scaled by the source colour; alpha is not touched. The
175
+ * fragment writes its multiplier already faded by its own coverage
176
+ * (mix(1, colour, alpha)), so the blend reads no alpha. */
177
+ const MULTIPLY_KEEP_ALPHA: GPUBlendState = {
178
+ color: { srcFactor: "dst", dstFactor: "zero", operation: "add" },
179
+ alpha: { srcFactor: "zero", dstFactor: "one", operation: "add" },
180
+ }
181
+
182
+ /** Leaves the attachment exactly as it was. */
183
+ const KEEP: GPUBlendState = {
184
+ color: { srcFactor: "zero", dstFactor: "one", operation: "add" },
185
+ alpha: { srcFactor: "zero", dstFactor: "one", operation: "add" },
186
+ }
187
+
166
188
  /** Additive, premultiplied by the fragment's alpha as it writes. */
167
189
  const ADD_PREMULTIPLIED: GPUBlendState = {
168
190
  color: { srcFactor: "src-alpha", dstFactor: "one", operation: "add" },
@@ -199,6 +221,8 @@ const BLENDS: Record<Exclude<SceneRenderClass, "depth-prepass">, [GPUBlendState,
199
221
  // The colour premultiplied by the graph (game_pbr's glass); the aux is
200
222
  // written straight, as every material's is.
201
223
  "material-premultiplied": [PREMULTIPLIED_OVER, ALPHA_OVER],
224
+ // A shade over what is drawn: the colour filtered, the aux untouched.
225
+ "material-multiply": [MULTIPLY_KEEP_ALPHA, KEEP],
202
226
  // PREMULTIPLIED, like the ground and for the same reason: what a mirror
203
227
  // writes is a sample of the HDR target, and that target already holds colour
204
228
  // premultiplied by its own alpha. Handed to the src-alpha blend it would be