Derived from the cocosair-materials-effects skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.
Contracts
- Order is fixed:
await createAirApp(...)beforeMaterial.initialize._createPassesreadscclegacy.director.root.deviceand throwsAIR_E_MATERIAL_NOT_READYwhen it is missing, namingawait createAirApp({ canvas })as the fix (src/cocos/asset/assets/material.ts:452-456).EffectAsset.onLoaded()has no such requirement: it registers metadata immediately and defers GPU program registration toGame.EVENT_RENDERER_INITEDwhiledeviceManager.gfxDeviceis absent (src/cocos/asset/assets/effect-asset.ts:339-351), so an effect can be registered before the app while a pass-bearing material cannot (docs/manual/materials.md:10). initializeis one-shot per object. When_passesis already populated it emitswarnID(12005)and returns, keeping the old effect, technique and defines (material.ts:206-217). Re-configuration goes throughreset(info)(same body,:225-227),copy(mat, overrides?)(:382-399) or a freshMaterial.destroy()is terminal - "cannot re-initialize after destroy" (:229-244).setProperty(name, value, passIdx?)writes the SAME property to every pass whenpassIdxis omitted, and all passes are prepared before any is written so a rejected value cannot leave earlier passes half-updated (material.ts:302-340, intent comment:303-304). An out-of-rangepassIdxis NOT a soft failure: it emitswarnID(16372, passIdx)without returning, then still indexesthis._passes[passIdx]and uploads into it, soPass.getHandledereferencesundefinedand the call throwsTypeError: Cannot read properties of undefined (reading 'getHandle')(:328-333,:524). Theif (!pass) { continue; }guard covers only the preparation loop (:308); the one warn-and-return path isgetProperty, which answersnull(:366-369). Pass an in-range index or omitpassIdx(doc:299).- Value types are enforced by a THROW.
validateUniformValueraisesAIR_E_MATERIAL_TYPE(TypeErrorcarrying.code/.property/.expected/.example) for a wrong instance class, a non-finite orfround-unrepresentable component, or an array longer than the declaredcount(src/cocos/render-scene/core/pass-utils.ts:110-129,src/cocos/core/platform/property-validation.ts:2-11). The accepted class pergfx.Typeis thetype2validatormatrix (pass-utils.ts:76-87);FLOAT4acceptsVec4,ColororQuat,FLOAT3accepts onlyVec3. The full table is in property-types.md. - An unknown property NAME never throws:
Pass.getHandlereturns0for it (src/cocos/render-scene/core/pass.ts:263-264),_uploadPropertyreturnsfalse(material.ts:524-525), and the only signal iswarnID(16373, name)when no pass accepted the write (:337-339). Names are case sensitive and effects alias them -mainColorwritesalbedoandmainTexturewritesalbedoMaponbuiltin-standard(src/air/builtin/builtin-effects.ts:601). Colorcarries 0-255 bytes but itsx/y/z/wgetters returnbyte / 255(src/cocos/core/math/color.ts:36,:390-397) and the UBO writer readsv.x..v.w(src/cocos/core/math/vec4.ts:505-511), so aColorarrives as fractions and aVec4arrives verbatim. Both validate, so an out-of-rangeVec4renders wrong with no diagnostic.- Properties declared
"linear": trueare sRGB-to-linear converted, but only for a non-array scalar;wis copied back from the input and arrays are never converted (material.ts:503-517;SRGBToLinearimported at:34).mainColorandemissiveon standard,mainColorandcoloron unlit carry it (src/air/builtin/builtin-effects.ts:601,:861). - Passing
nullresets instead of clearing to zero:nullon a uniform callsPass.resetUniform(name), which restores the effect-declared default value and falls back togetDefaultFromType(material.ts:528-529,src/cocos/render-scene/core/pass.ts:433-446);nullon a sampler callspass.resetTexture(name)(material.ts:541-542). ATextureBasewhose gfx texture has zero width or height is skipped silently, with the warning commented out (material.ts:555-560). Material.recompileShadersandMaterial.overridePipelineStatesare warn stubs that do nothing (warnID(16370),warnID(16371),material.ts:252-264), and the basePass.overridePipelineStatesis a warn stub too (warnID(12102),src/cocos/render-scene/core/pass.ts:377-379). OnlyMaterialInstanceimplements them (src/cocos/render-scene/core/material-instance.ts:64-90) viaPassInstance(src/cocos/render-scene/core/pass-instance.ts:81-100).PassOverridesisRecursivePartial<EffectAsset.IPassStates>(src/cocos/render-scene/core/pass.ts:52) overpriority,primitive,stage,rasterizerState,depthStencilState,blendState,dynamicStates,phase(src/cocos/asset/assets/effect-asset.ts:49-60), and an override rebuilds from the effect's own pass info first, so it replaces rather than patches (pass-instance.ts:82-88).docs/manual/custom-shaders.md:118-119records the discipline: give completedefinesatinitialize.- Shared versus instanced semantics:
renderer.setSharedMaterial(m, 0)stores the reference, som.setPropertydrives the pixels directly, and passing aMaterialInstancethere raiseserrorID(12012)(src/cocos/misc/renderer.ts:175-189). Therenderer.materialGETTER is not symmetric with the setter - it returnsgetMaterialInstance(0), which constructs aMaterialInstancecopy on first read (:100-102,:196-207) and from then on that instance is what renders.MaterialInstance.destroy()returnstrueunconditionally and its passes arePassInstances that forceUSE_INSTANCING = false(material-instance.ts:92-95,pass-instance.ts:118-121). - Builtin effects and materials are registered by
registerBuiltinAirAssets()onGame.EVENT_POST_SUBSYSTEM_INIT(src/air/builtin/register.ts:100-132, wired atsrc/air/bootstrap.ts:145), which is part of thecreateAirApppath; the function is exported from its own module only and is not a name in the main bundle export list, so a hand-rolled engine bootstrap gets neither the 21 effects nor the 17 materials. - WebGL 2 is the only browser target, so
getDeviceShaderVersionselects theglsl3variant (src/cocos/render-scene/core/program-lib.ts:592-600);glsl1is retained upstream shape that the runtime does not consume, and every shader variant must be self-contained because there is no chunk include system (docs/manual/custom-shaders.md:75-78,:13-16). - Capability layers, stated separately (source export / default-bundle reachable / browser-verified):
Material,EffectAsset,builtinResMgr,createAirUnlitFogEffect,inspectAirMaterial,inspectAirMeshMaterial,attachAirSpriteMaskandcreateAirRenderTargetresolve by name in the main entry - the first five also resolve by symbol name inbuild/cocosair.module.d.ts;registerBuiltinAirAssets,Pass,PassInstanceandMaterialInstanceare NOT in the 626-nameexport { ... }block ofbuild/cocosair.module.js(parse that block programmatically rather than grepping it), so treat them as objects you receive, not names you import.docs/evidence/examples-verified.jsonrecordsmaterial-*andshader-*Gallery runs against its own recorded candidate fingerprint, which is evidence for that candidate and not for today's bytes.