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/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.
@@ -11691,15 +11709,15 @@ export class Engine {
11691
11709
  }
11692
11710
 
11693
11711
  /**
11694
- * The cast's shadow on a stage, as a game on SimPipeline lays its ground
11695
- * shadow: the characters drawn into a map of their own from `direction` (the
11696
- * way TO the light, this engine's axes), and every Unity-mode stage surface
11697
- * multiplied toward `color` (linear) by amount × how much of the cast stands
11698
- * in the way. Its darkness is independent of the sun's — X340's is dim
11699
- * moonlight, which left a kneeling figure no shadow at all — and without a
11700
- * `direction` it falls along the sun, so it agrees with every other shadow on
11701
- * the stage. Only stage materials read it; a scene
11702
- * without a stage is untouched. Null turns it off.
11712
+ * The cast's shadow on a stage the sun cannot reach: the characters drawn
11713
+ * into a map of their own from `direction` (the way TO the light, this
11714
+ * engine's axes), and every graph-drawn stage surface multiplied toward
11715
+ * `color` (linear) by amount × how much of the cast stands in the way —
11716
+ * where the stage roofs her from the sun (rzRoofedCastShadow). Under open
11717
+ * sky the sun's own map lays her shadow and this adds nothing; under a
11718
+ * ceiling, where the lamps cast none, it is the only shadow she has. Without
11719
+ * a `direction` it falls along the sun. A scene without a stage is
11720
+ * untouched. Null turns it off.
11703
11721
  */
11704
11722
  setStageCastShadow(opts: StageCastShadow | null): void {
11705
11723
  this.castShadow = opts
@@ -15400,11 +15418,14 @@ export class Engine {
15400
15418
 
15401
15419
  // Its ObjectLight: the world's ambient, and the layers its kind draws on —
15402
15420
  // the cast on the character layer as well as the default one. Words:
15403
- // layers [0..3], ambient flag [4..7], SH [8..43], fill [44..47], jelly
15404
- // eyes [48..71] — see materials/common.ts.
15421
+ // layers [0..3] (y: a stage, which takes the cast's shadow —
15422
+ // rzRoofedCastShadow), ambient flag [4..7], SH [8..43], fill [44..47],
15423
+ // jelly eyes [48..71] — see materials/common.ts.
15405
15424
  const objectLight = new Float32Array(96)
15406
- new Uint32Array(objectLight.buffer)[0] =
15425
+ const objectLayers = new Uint32Array(objectLight.buffer)
15426
+ objectLayers[0] =
15407
15427
  isStage || isPlane || isProp ? RENDERING_LAYER_DEFAULT : (RENDERING_LAYER_DEFAULT | RENDERING_LAYER_CHARACTER) >>> 0
15428
+ objectLayers[1] = isStage ? 1 : 0
15408
15429
  const lightBuffer = this.device.createBuffer({
15409
15430
  label: `${name}: object light`,
15410
15431
  size: objectLight.byteLength,
@@ -18149,6 +18170,7 @@ export class Engine {
18149
18170
  for (const [preset, materials] of buckets) {
18150
18171
  const info = PRESET_GROUP_INFO[preset]
18151
18172
  if (!info) continue
18173
+ const shadows = preset === "eye" ? materials.filter(isEyeShadow) : []
18152
18174
  groups.push({
18153
18175
  id: preset,
18154
18176
  label: info.graph.name,
@@ -18156,6 +18178,7 @@ export class Engine {
18156
18178
  graph: info.graph,
18157
18179
  renderClass: info.renderClass,
18158
18180
  alphaMode: info.alphaMode,
18181
+ ...(shadows.length ? { blendByMaterial: Object.fromEntries(shadows.map((m) => [m, "multiply" as const])) } : {}),
18159
18182
  })
18160
18183
  }
18161
18184
  return this.applyStyleGroups(modelName, groups)
@@ -18239,20 +18262,26 @@ export class Engine {
18239
18262
  groups.map(async (g) => {
18240
18263
  const renderClass = g.renderClass ?? "auto"
18241
18264
  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(() => {})
18265
+ const groupBlend = g.blend ?? "over"
18266
+ // Every blend its members draw with, as the install compiles them.
18267
+ const blends = new Set([groupBlend, ...g.materials.map((m) => g.blendByMaterial?.[m] ?? groupBlend)])
18268
+ await Promise.all(
18269
+ [...blends].map(async (blend) => {
18270
+ let result: ReturnType<typeof compileGraph>
18271
+ try {
18272
+ result = compileGraph(g.graph, { renderClass, alphaMode, blend })
18273
+ } catch {
18274
+ return
18275
+ }
18276
+ if (!result.ok) return
18277
+ const module = this.cachedShaderModule(result.wgsl, `style group: ${g.id} (${renderClass}${blend === groupBlend ? "" : `, ${blend}`})`)
18278
+ await Promise.all([
18279
+ this.createRenderClassPipeline(renderClass, module, false, true, blend),
18280
+ this.createRenderClassPipeline(renderClass, module, false, false, blend),
18281
+ renderClass === "hair" ? this.createRenderClassPipeline(renderClass, module, true, true, blend) : null,
18282
+ ]).catch(() => {})
18283
+ }),
18284
+ )
18256
18285
  }),
18257
18286
  )
18258
18287
  }
@@ -18592,14 +18621,23 @@ export class Engine {
18592
18621
  // arrive twice — once as the model lands and again once its sidecar has
18593
18622
  // decoded — and without this the second apply refreshed the definition and
18594
18623
  // silently kept the empty slots from the first.
18624
+ // The blends its members draw with: the group's own first, then any a
18625
+ // member keys for itself (blendByMaterial) — one compile each, the graph and
18626
+ // its slots the same in all of them.
18627
+ const groupBlend = group.blend ?? "over"
18628
+ const blends = [
18629
+ groupBlend,
18630
+ ...new Set(group.materials.map((m) => group.blendByMaterial?.[m] ?? groupBlend).filter((b) => b !== groupBlend)),
18631
+ ]
18595
18632
  const signature = JSON.stringify({
18596
18633
  g: group.graph,
18597
18634
  rc: renderClass,
18598
18635
  am: alphaMode,
18599
- bl: group.blend ?? "over",
18636
+ bl: groupBlend,
18600
18637
  o: opts?.previewNode ?? null,
18601
18638
  im: group.images?.length ?? 0,
18602
18639
  ibm: Object.keys(group.imagesByMaterial ?? {}).sort(),
18640
+ bls: blends,
18603
18641
  })
18604
18642
  const existing = inst.styleGroups.get(group.id)
18605
18643
  if (existing && existing.signature === signature) {
@@ -18607,56 +18645,71 @@ export class Engine {
18607
18645
  return { ok: true, diagnostics: [], slotMap: existing.slotMap }
18608
18646
  }
18609
18647
 
18610
- const result = compileGraph(group.graph, { ...opts, renderClass, alphaMode, blend: group.blend ?? "over" })
18611
- if (!result.ok) return { ok: false, diagnostics: result.diagnostics, slotMap: result.slotMap }
18648
+ const compiled = blends.map((b) => compileGraph(group.graph, { ...opts, renderClass, alphaMode, blend: b }))
18649
+ const result = compiled[0]
18650
+ const failed = compiled.find((r) => !r.ok)
18651
+ if (failed) return { ok: false, diagnostics: failed.diagnostics, slotMap: failed.slotMap }
18612
18652
 
18613
18653
  const generation = (inst.styleGroupGen.get(group.id) ?? 0) + 1
18614
18654
  inst.styleGroupGen.set(group.id, generation)
18615
18655
 
18616
- this.device.pushErrorScope("validation")
18617
- const module = this.cachedShaderModule(result.wgsl, `style group: ${group.id} (${renderClass})`)
18618
- const scopePromise = this.device.popErrorScope()
18619
- // EVERY VARIANT AT ONCE, and the module's diagnostics read beside them
18620
- // rather than first: the compiles run in parallel in the GPU process, and
18621
- // awaiting each in turn (and the diagnostics before any) made a group cost
18622
- // the sum of its pipelines instead of the longest.
18623
- const blend = group.blend ?? "over"
18624
18656
  // The single-sided twins a draw of this group will ask for (sidedPipeline),
18625
18657
  // built with their pipelines rather than synchronously at the first draw.
18626
18658
  const singleSided = inst.drawCalls.some((dc) => !dc.doubleSided && group.materials.includes(dc.materialName))
18627
- const variant = (overEyes: boolean, depthWrite: boolean) =>
18628
- this.createRenderClassPipeline(renderClass, module, overEyes, depthWrite, blend).then(async (p) => {
18629
- if (singleSided) await this.buildSidedTwin(p, false)
18630
- return p
18631
- })
18632
- const variants = Promise.all([
18633
- variant(false, true),
18634
- // The depth-write-off twin: stage transparency draws with it (see
18635
- // pipelineForDrawCall), and a future OIT path would too.
18636
- variant(false, false),
18637
- renderClass === "hair" ? variant(true, true) : undefined,
18638
- ])
18639
- // Handled below either way; this keeps a rejection off the console while
18640
- // the diagnostics are read.
18641
- variants.catch(() => {})
18642
- const [info, scopeError] = await Promise.all([module.getCompilationInfo(), scopePromise])
18659
+ // EVERY VARIANT AT ONCE, and the module's diagnostics read beside them
18660
+ // rather than first: the compiles run in parallel in the GPU process, and
18661
+ // awaiting each in turn (and the diagnostics before any) made a group cost
18662
+ // the sum of its pipelines instead of the longest. One module per blend,
18663
+ // each with its variants.
18664
+ const builds = compiled.map((r, i) => {
18665
+ const blend = blends[i]
18666
+ this.device.pushErrorScope("validation")
18667
+ const module = this.cachedShaderModule(r.wgsl, `style group: ${group.id} (${renderClass}${blend === blends[0] ? "" : `, ${blend}`})`)
18668
+ const scopePromise = this.device.popErrorScope()
18669
+ const variant = (overEyes: boolean, depthWrite: boolean) =>
18670
+ this.createRenderClassPipeline(renderClass, module, overEyes, depthWrite, blend).then(async (p) => {
18671
+ if (singleSided) await this.buildSidedTwin(p, false)
18672
+ return p
18673
+ })
18674
+ const variants = Promise.all([
18675
+ variant(false, true),
18676
+ // The depth-write-off twin: stage transparency draws with it (see
18677
+ // pipelineForDrawCall), and a future OIT path would too.
18678
+ variant(false, false),
18679
+ renderClass === "hair" ? variant(true, true) : undefined,
18680
+ ])
18681
+ // Handled below either way; this keeps a rejection off the console while
18682
+ // the diagnostics are read.
18683
+ variants.catch(() => {})
18684
+ return { wgsl: r.wgsl, module, scopePromise, variants }
18685
+ })
18643
18686
  const diagnostics = [...result.diagnostics]
18644
- for (const msg of info.messages) {
18645
- if (msg.type !== "error") continue
18646
- diagnostics.push({ severity: "error", nodeId: nodeIdForWgslLine(result.wgsl, msg.lineNum), message: `WGSL: ${msg.message}` })
18687
+ let scopeError: GPUError | null = null
18688
+ for (const build of builds) {
18689
+ const [info, error] = await Promise.all([build.module.getCompilationInfo(), build.scopePromise])
18690
+ scopeError ??= error
18691
+ for (const msg of info.messages) {
18692
+ if (msg.type !== "error") continue
18693
+ diagnostics.push({ severity: "error", nodeId: nodeIdForWgslLine(build.wgsl, msg.lineNum), message: `WGSL: ${msg.message}` })
18694
+ }
18647
18695
  }
18648
18696
  if (diagnostics.some((d) => d.severity === "error") || scopeError) {
18649
18697
  if (scopeError && !diagnostics.some((d) => d.severity === "error"))
18650
18698
  diagnostics.push({ severity: "error", message: `WGSL: ${scopeError.message}` })
18651
- this.forgetShaderModule(result.wgsl)
18699
+ for (const build of builds) this.forgetShaderModule(build.wgsl)
18652
18700
  return { ok: false, diagnostics, slotMap: result.slotMap }
18653
18701
  }
18654
18702
 
18655
18703
  let pipeline: GPURenderPipeline
18656
18704
  let pipelineNoDepthWrite: GPURenderPipeline
18657
18705
  let overEyesPipeline: GPURenderPipeline | undefined
18706
+ const byBlend: GroupInstall["byBlend"] = {}
18658
18707
  try {
18659
- ;[pipeline, pipelineNoDepthWrite, overEyesPipeline] = await variants
18708
+ const sets = await Promise.all(builds.map((build) => build.variants))
18709
+ ;[pipeline, pipelineNoDepthWrite, overEyesPipeline] = sets[0]
18710
+ sets.slice(1).forEach(([p, noDepth, overEyes], i) => {
18711
+ byBlend[blends[i + 1]] = { pipeline: p, pipelineNoDepthWrite: noDepth, overEyesPipeline: overEyes }
18712
+ })
18660
18713
  } catch (e) {
18661
18714
  diagnostics.push({ severity: "error", message: `pipeline creation failed: ${(e as Error).message}` })
18662
18715
  return { ok: false, diagnostics, slotMap: result.slotMap }
@@ -18686,6 +18739,7 @@ export class Engine {
18686
18739
  pipeline,
18687
18740
  pipelineNoDepthWrite,
18688
18741
  overEyesPipeline,
18742
+ byBlend,
18689
18743
  uniformBuffer,
18690
18744
  images: this.uploadGroupImages(group),
18691
18745
  imagesByMaterial: group.imagesByMaterial
@@ -18938,7 +18992,9 @@ export class Engine {
18938
18992
  ? this.sceneTargetsAdditive
18939
18993
  : blend === "premultiplied"
18940
18994
  ? this.sceneTargetsPremultiplied
18941
- : this.sceneTargets,
18995
+ : blend === "multiply"
18996
+ ? this.sceneTargetsMultiply
18997
+ : this.sceneTargets,
18942
18998
  },
18943
18999
  depthStencil,
18944
19000
  }
@@ -19173,7 +19229,8 @@ export class Engine {
19173
19229
  if (dc.groupId) {
19174
19230
  const install = inst.styleGroups.get(dc.groupId)
19175
19231
  if (install) {
19176
- return stageGlass ? install.pipelineNoDepthWrite : install.pipeline
19232
+ const own = this.memberPipelines(install, dc)
19233
+ return stageGlass ? own.pipelineNoDepthWrite : own.pipeline
19177
19234
  }
19178
19235
  }
19179
19236
  return stageGlass ? this.neutralPipelineNoDepthWrite : this.neutralPipeline
@@ -19600,7 +19657,14 @@ export class Engine {
19600
19657
  private overEyesPipelineFor(inst: ModelInstance, dc: DrawCall): GPURenderPipeline | null {
19601
19658
  if (!dc.groupId) return null
19602
19659
  const install = inst.styleGroups.get(dc.groupId)
19603
- return install?.renderClass === "hair" ? (install.overEyesPipeline ?? null) : null
19660
+ return install?.renderClass === "hair" ? (this.memberPipelines(install, dc).overEyesPipeline ?? null) : null
19661
+ }
19662
+
19663
+ /** A member's pipelines: those of the blend it keys for itself, else the
19664
+ * group's (StyleGroup.blendByMaterial). */
19665
+ private memberPipelines(install: GroupInstall, dc: DrawCall): Pick<GroupInstall, "pipeline" | "pipelineNoDepthWrite" | "overEyesPipeline"> {
19666
+ const blend = install.group.blendByMaterial?.[dc.materialName]
19667
+ return (blend && install.byBlend[blend]) || install
19604
19668
  }
19605
19669
 
19606
19670
  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
@@ -204,6 +204,12 @@ function epilogue(renderClass: RenderClass, alphaMode: AlphaMode, hasOpacity: bo
204
204
  // shadows, and under a hard step flip whole regions at once. After the graph
205
205
  // it lifts her evenly and leaves every shadow where it is.
206
206
  const LIT = takesLight ? ` + (rzLightsDiffuseOnce(input.worldPos, n) + objectLight.fill.rgb) * albedo` : ""
207
+ // The cast's shadow on a stage the sun cannot reach under its roof
208
+ // (rzRoofedCastShadow), over everything the surface took — the lamps
209
+ // included, since they are what light a closed room. Zero off a stage.
210
+ const CAST = takesLight
211
+ ? ` out.color = vec4f(out.color.rgb * mix(vec3f(1.0), light.castShadow.rgb, rzRoofedCastShadow(input.worldPos) * light.castShadow.w), out.color.a);\n`
212
+ : ""
207
213
 
208
214
  const ALBEDO = ` let albedo = tex_color;
209
215
  `
@@ -221,19 +227,36 @@ function epilogue(renderClass: RenderClass, alphaMode: AlphaMode, hasOpacity: bo
221
227
  const FOG = takesLight
222
228
  ? ` 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
229
  : ""
230
+ // MULTIPLY WRITES A FILTER, NOT A COLOUR. What it darkens was lit already —
231
+ // the iris under an eye shadow took the sun and its own glow — so the shade
232
+ // takes no light of its own: lit, a light-grey shadow came out brighter than
233
+ // the eye and multiplied it WHITER. The multiplier is the surface's own
234
+ // colour, its texture times the PMX diffuse as every look's base is, or what
235
+ // an emission-only graph paints, which is already a colour no light reaches.
236
+ // Faded by coverage here (the blend reads no alpha), capped at 1 so it can
237
+ // only darken, and with no lamps, burn or fog — all three are light. The aux
238
+ // is kept by the blend, so the mask written is never stored.
239
+ if (blend === "multiply") {
240
+ const filter = takesLight ? "tex_color * material.diffuseColor" : "final_color"
241
+ return ` var out: FSOut;
242
+ out.color = vec4f(mix(vec3f(1.0), saturate(${filter}), ${alphaBase}), ${alphaBase});
243
+ out.mask = vec4f(0.0);
244
+ ${ID_WRITE} return out;
245
+ `
246
+ }
224
247
  if (renderClass === "hair") {
225
248
  return `${ALBEDO} var outAlpha = ${alphaBase};
226
249
  if (IS_OVER_EYES) { outAlpha = ${alphaBase} * 0.25; }
227
250
 
228
251
  var out: FSOut;
229
252
  out.color = vec4f(final_color${LIT}${BURN}, outAlpha);
230
- ${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
253
+ ${CAST}${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
231
254
  ${ID_WRITE} return out;
232
255
  `
233
256
  }
234
257
  return `${ALBEDO} var out: FSOut;
235
258
  out.color = vec4f(final_color${LIT}${BURN}, ${alphaBase});
236
- ${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
259
+ ${CAST}${FOG} out.mask = vec4f(1.0, 1.0, _rzSubsurface, out.color.a);
237
260
  ${ID_WRITE} return out;
238
261
  `
239
262
  }
@@ -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
  *
@@ -390,6 +390,42 @@ fn sampleShadow(worldPos: vec3f, n: vec3f) -> f32 {
390
390
  return mix(1.0, _rzSunTaps(a), castAmt);
391
391
  }
392
392
 
393
+ /**
394
+ * The cast's shadow on a stage surface where the stage ROOFS the cast from the
395
+ * sun, 0–1 — setStageCastShadow on a graph-drawn stage (a GLB's). Under open
396
+ * sky the sun's own map already lays the cast's shadow, and laying this one too
397
+ * doubled it; under a ceiling the sun reaches neither the floor nor her, the
398
+ * lamps cast nothing, and she stood on the floor with no shadow at all. So
399
+ * per pixel: find the point of the cast that throws this shadow (the cast
400
+ * map's nearest depth, walked back toward the light along the map's z row),
401
+ * step off her toward the light, and ask the sun's map whether it reaches
402
+ * there. Lit: the sun shadow has it, answer 0. Shadowed: this is the only
403
+ * shadow she gets. Zero on everything that is not a stage (objectLight
404
+ * layers.y).
405
+ */
406
+ fn rzRoofedCastShadow(wp: vec3f) -> f32 {
407
+ if (light.castShadow.w <= 0.0 || objectLight.layers.y == 0u) { return 0.0; }
408
+ let cover = _rzCastShadow(wp);
409
+ if (cover <= 0.0) { return 0.0; }
410
+ let ndc = (light.castVP * vec4f(wp, 1.0)).xyz;
411
+ let size = vec2i(textureDimensions(castShadowMap));
412
+ let px = vec2i(vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5) * vec2f(size));
413
+ // The nearest of her over the filter's footprint: a penumbra texel's own
414
+ // depth may be the cleared 1.
415
+ var occ = 1.0;
416
+ for (var y = -2; y <= 2; y += 2) {
417
+ for (var x = -2; x <= 2; x += 2) {
418
+ occ = min(occ, textureLoad(castShadowMap, clamp(px + vec2i(x, y), vec2i(0), size - 1), 0));
419
+ }
420
+ }
421
+ if (occ >= ndc.z) { return 0.0; }
422
+ // Orthographic: depth grows away from the light at |g| per unit.
423
+ let g = vec3f(light.castVP[0].z, light.castVP[1].z, light.castVP[2].z);
424
+ let k = length(g);
425
+ let q = wp - (g / k) * ((ndc.z - occ) / k + 0.5);
426
+ return cover * (1.0 - rzSunOcclusion(q, vec3f(0.0)));
427
+ }
428
+
393
429
  `;
394
430
 
395
431
  // ─── Skinning vertex shader ─────────────────────────────────────────
@@ -1703,8 +1703,7 @@ fn urp_lit(base: vec3f, metallic: f32, smoothness: f32, spec: f32, occlusion: f3
1703
1703
  let direct = diffuse * (sun_rgb * (NL * shadow) + lampDiff) + directSpec;
1704
1704
  let indirect = diffuse * amb_rgb * ao
1705
1705
  + rzProbeSpecular(reflect(-V, N), wp, r) * ao * urp_env_brdf(specular, r, sm, reflectivity, NV);
1706
- var lit = direct + indirect;
1707
- lit = lit * mix(vec3f(1.0), light.castShadow.rgb, _rzCastShadow(wp) * light.castShadow.w);
1706
+ let lit = direct + indirect;
1708
1707
  return vec4f(lit + max(emission, vec3f(0.0)), a * oneMinusReflectivity + reflectivity);
1709
1708
  }
1710
1709
 
@@ -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