Cocos AIR materials and effects triggers
Source annotations refer to the AIR checkout.
When to use what
- "Paint a 3D object, no lighting" ->
initialize({ effectName: 'builtin-unlit' })+mainColor. - "Physically shaded object" ->
effectName: 'builtin-standard'+metallic/roughness/emissive; table in property-types.md. - "Show a texture" -> the map macro FIRST in
initialize({ defines }), thensetProperty;USE_TEXTUREfor unlit and sprite,USE_ALBEDO_MAPfor standard (defines.md). - "Two objects, same recipe, different colors" -> two
new Material();Material.copy(src, overrides?), never a shared builtin write. - "Change one renderer without touching its material" ->
renderer.getMaterialInstance(i)/ therenderer.materialgetter; semantics in builtin-effects.md. - "Change a macro or blend state after initialization" ->
MaterialInstance.recompileShaders/MaterialInstance.overridePipelineStates; a plainMaterialonly warns. - "Write my own GLSL" -> compiled-shape effect JSON +
glsl3variant +effect.onLoaded(); custom-glsl.md. - "Per-frame uniform" -> cache
pass.getHandle(name)and callPass.setUniform(handle, value). - "Fog on an unlit object" ->
createAirUnlitFogEffect(). - "Mask a Sprite" ->
attachAirSpriteMask(sprite, texture, options?). - "What state does this material really have" ->
inspectAirMaterial(material), orinspectAirMeshMaterial(mesh, material)for define-versus-attribute checks.