Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-materials-effects

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Configure materials, effects, uniforms, defines and GLSL. Diagnose black/invisible effects, missing textures, setProperty, AIR_E_MATERIAL_NOT_READY or AIR_E_MATERIAL_TYPE.

  • 12 files
  • 116 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-materials-effects

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescontracts.md

≈1.9k tokens on demand. Your agent reads this file only when SKILL.md points to it.

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(...) before Material.initialize. _createPasses reads cclegacy.director.root.device and throws AIR_E_MATERIAL_NOT_READY when it is missing, naming await 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 to Game.EVENT_RENDERER_INITED while deviceManager.gfxDevice is 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).
  • initialize is one-shot per object. When _passes is already populated it emits warnID(12005) and returns, keeping the old effect, technique and defines (material.ts:206-217). Re-configuration goes through reset(info) (same body, :225-227), copy(mat, overrides?) (:382-399) or a fresh Material. destroy() is terminal - "cannot re-initialize after destroy" (:229-244).
  • setProperty(name, value, passIdx?) writes the SAME property to every pass when passIdx is 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-range passIdx is NOT a soft failure: it emits warnID(16372, passIdx) without returning, then still indexes this._passes[passIdx] and uploads into it, so Pass.getHandle dereferences undefined and the call throws TypeError: Cannot read properties of undefined (reading 'getHandle') (:328-333, :524). The if (!pass) { continue; } guard covers only the preparation loop (:308); the one warn-and-return path is getProperty, which answers null (:366-369). Pass an in-range index or omit passIdx (doc :299).
  • Value types are enforced by a THROW. validateUniformValue raises AIR_E_MATERIAL_TYPE (TypeError carrying .code/.property/.expected/.example) for a wrong instance class, a non-finite or fround-unrepresentable component, or an array longer than the declared count (src/cocos/render-scene/core/pass-utils.ts:110-129, src/cocos/core/platform/property-validation.ts:2-11). The accepted class per gfx.Type is the type2validator matrix (pass-utils.ts:76-87); FLOAT4 accepts Vec4, Color or Quat, FLOAT3 accepts only Vec3. The full table is in property-types.md.
  • An unknown property NAME never throws: Pass.getHandle returns 0 for it (src/cocos/render-scene/core/pass.ts:263-264), _uploadProperty returns false (material.ts:524-525), and the only signal is warnID(16373, name) when no pass accepted the write (:337-339). Names are case sensitive and effects alias them - mainColor writes albedo and mainTexture writes albedoMap on builtin-standard (src/air/builtin/builtin-effects.ts:601).
  • Color carries 0-255 bytes but its x/y/z/w getters return byte / 255 (src/cocos/core/math/color.ts:36, :390-397) and the UBO writer reads v.x..v.w (src/cocos/core/math/vec4.ts:505-511), so a Color arrives as fractions and a Vec4 arrives verbatim. Both validate, so an out-of-range Vec4 renders wrong with no diagnostic.
  • Properties declared "linear": true are sRGB-to-linear converted, but only for a non-array scalar; w is copied back from the input and arrays are never converted (material.ts:503-517; SRGBToLinear imported at :34). mainColor and emissive on standard, mainColor and color on unlit carry it (src/air/builtin/builtin-effects.ts:601, :861).
  • Passing null resets instead of clearing to zero: null on a uniform calls Pass.resetUniform(name), which restores the effect-declared default value and falls back to getDefaultFromType (material.ts:528-529, src/cocos/render-scene/core/pass.ts:433-446); null on a sampler calls pass.resetTexture(name) (material.ts:541-542). A TextureBase whose gfx texture has zero width or height is skipped silently, with the warning commented out (material.ts:555-560).
  • Material.recompileShaders and Material.overridePipelineStates are warn stubs that do nothing (warnID(16370), warnID(16371), material.ts:252-264), and the base Pass.overridePipelineStates is a warn stub too (warnID(12102), src/cocos/render-scene/core/pass.ts:377-379). Only MaterialInstance implements them (src/cocos/render-scene/core/material-instance.ts:64-90) via PassInstance (src/cocos/render-scene/core/pass-instance.ts:81-100). PassOverrides is RecursivePartial<EffectAsset.IPassStates> (src/cocos/render-scene/core/pass.ts:52) over priority, 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-119 records the discipline: give complete defines at initialize.
  • Shared versus instanced semantics: renderer.setSharedMaterial(m, 0) stores the reference, so m.setProperty drives the pixels directly, and passing a MaterialInstance there raises errorID(12012) (src/cocos/misc/renderer.ts:175-189). The renderer.material GETTER is not symmetric with the setter - it returns getMaterialInstance(0), which constructs a MaterialInstance copy on first read (:100-102, :196-207) and from then on that instance is what renders. MaterialInstance.destroy() returns true unconditionally and its passes are PassInstances that force USE_INSTANCING = false (material-instance.ts:92-95, pass-instance.ts:118-121).
  • Builtin effects and materials are registered by registerBuiltinAirAssets() on Game.EVENT_POST_SUBSYSTEM_INIT (src/air/builtin/register.ts:100-132, wired at src/air/bootstrap.ts:145), which is part of the createAirApp path; 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 getDeviceShaderVersion selects the glsl3 variant (src/cocos/render-scene/core/program-lib.ts:592-600); glsl1 is 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, attachAirSpriteMask and createAirRenderTarget resolve by name in the main entry - the first five also resolve by symbol name in build/cocosair.module.d.ts; registerBuiltinAirAssets, Pass, PassInstance and MaterialInstance are NOT in the 626-name export { ... } block of build/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.json records material-* and shader-* Gallery runs against its own recorded candidate fingerprint, which is evidence for that candidate and not for today's bytes.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "setProperty changes nothing",
  "texture missing after setProperty",
  "different colors for each renderer",
  "change blend or depth state",
  "custom GLSL shader fails"
]
owns
[
  "material",
  "effect",
  "uniform-types",
  "shader-defines",
  "custom-glsl",
  "material-instance"
]
not_for
[
  "lighting, shadows or post-process -> cocosair-rendering",
  "glTF material import -> cocosair-gltf",
  "mesh geometry and sub-models -> cocosair-primitives-mesh"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "配置材质、效果、属性类型、宏和自定义 GLSL。用于 USE_TEXTURE、uniform 类型、效果初始化或材质诊断问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-materials-effects