moeru-ai/airi · warning

[AIRI] Failed to patch built-in MToon outline shader: expect

Error message

[AIRI] Failed to patch built-in MToon outline shader: expected shader anchors were not found.

What it means

AIRI patches the built-in MToon outline pass by string-anchored replacements on the vertex shader source (patchOutlineVertexShader). If the expected anchor substrings are not present in material.vertexShader — i.e. @pixiv/three-vrm changed its GLSL — the patch is abandoned with this warn and the material is left unpatched (returns false). It is cosmetic robustness: outlines render with stock behavior instead of AIRI's.

Source

Thrown at packages/stage-ui-three/src/composables/vrm/outline.ts:369

  if (!hasCommonAnchor || !hasBeginNormalAnchor || !hasOutlineBlockAnchor)
    return undefined

  return replaceOutlineExtrusionBlock(
    replaceOutlineNormalSource(
      injectOutlineNormalAttribute(vertexShader),
    ),
  )
}

function patchBuiltInOutlineMaterial(material: MToonMaterial) {
  if (!material.isOutline || isOutlineMaterialPatched(material))
    return false

  const originalCustomProgramCacheKey = material.customProgramCacheKey.bind(material)
  const patchedVertexShader = patchOutlineVertexShader(material.vertexShader)

  if (!patchedVertexShader) {
    console.warn(
      '[AIRI] Failed to patch built-in MToon outline shader: expected shader anchors were not found.',
      material.name,
    )
    return false
  }

  // NOTICE: Three's WebGL program cache includes material.customProgramCacheKey().
  // We patch the outline vertex shader below, so the patched outline pass needs a distinct cache key.
  material.customProgramCacheKey = () => {
    const baseKey = originalCustomProgramCacheKey()

    return baseKey
      ? `${baseKey},${AIRI_OUTLINE_SHADER_PATCH_CACHE_KEY}`
      : AIRI_OUTLINE_SHADER_PATCH_CACHE_KEY
  }

  // NOTICE: @pixiv/three-vrm-materials-mtoon@3.5.1 hardcodes the MToon shader strings in
  // `lib/three-vrm-materials-mtoon.module.js`. The current patch depends on three stable anchors:

View on GitHub (pinned to 677329427f)

Solutions

  1. Pin @pixiv/three-vrm / @pixiv/three-vrm-core to the version the anchors were written against (check package.json).
  2. Update the anchor strings in patchOutlineVertexShader to match the new MToon vertex shader source of your three-vrm version.
  3. Accept the fallback: unpatched outline rendering is intentional degradation, not a crash.

Example fix

// before
// anchors target three-vrm v2.x MToon vertex shader
const patched = patchOutlineVertexShader(material.vertexShader)

// after
// update anchor literals to the new shader, e.g.
// '#include <beginnormal_vertex>' -> '#include <defaultnormal_vertex>'
// after inspecting node_modules/@pixiv/three-vrm*/types/shaders/MToonVertexShader.gsl
Defensive patterns

Strategy: fallback

Validate before calling

if (!patchOutlineVertexShader(material.vertexShader)) { /* stock outline rendering; acceptable */ }

Prevention

When it happens

Trigger: Upgrading @pixiv/three-vrm (or three) to a release whose MToon vertex shader was refactored; using a custom MToonMaterial subclass whose shader differs; shader caches serving a stale variant.

Common situations: Dependency bump without re-checking anchor strings in outline.ts; three-vrm nightly/beta versions; forks that override MToon shaders.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/026a21c1aac548ee. Report an issue: GitHub.