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

/cocosair-rendering

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Configure lighting, shadows, render targets, MSAA and sRGB. Use for offscreen pixels, post-processing, AIR_E_RENDER_TARGET_SAMPLES or AIR_E_TEXTURE_COLOR.

  • 11 files
  • 159.1 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-rendering

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencescontracts.md

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

Derived from the cocosair-rendering 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

  • Ordinary directional lights share ONE scene.renderScene.mainLight (there is no Scene.mainLight accessor; the engine warn text below says scene.mainLight loosely): _attachToScene calls addDirectionalLight then setMainLight for every directional it activates (src/cocos/3d/lights/light-component.ts:291, :292), so the LAST activated directional wins and the earlier one stops contributing; the legacy forward camera UBO shades mainLight only (src/cocos/render-scene/core/render-scene.ts:100). Registration emits a single warn when the list reaches two (:338), text [AIR_W_DIRECTIONAL_LIGHT_LIMIT] ordinary directionals share one legacy mainLight; extra registered lights do not add illumination. Inspect scene.mainLight.. inspectAirDirectionalLights(scene) reports identity and nothing else - status: 'unavailable' with lights: [] while the scene has no native render scene (src/air/rendering/engine-contracts.ts:106), then scope: 'legacy-forward-main-directional', ordinaryDirectionalCapacity: 1, selection: 'native-mainLight' (:107-108) and one entry per registered light with effective: light === native.mainLight (:110); it applies no brightness threshold.
  • Shadows need four independent switches and no path warns when one is missing: scene.globals.shadows.enabled (default false, src/cocos/scene-graph/scene-globals.ts:987), scene.globals.shadows.type = ShadowMap (the field default is Planar, :989), the light's own shadowEnabled (default false, src/cocos/3d/lights/directional-light-component.ts:55), and renderer.shadowCastingMode = MeshRenderer.ShadowCastingMode.ON (component default OFF, src/cocos/3d/framework/mesh-renderer.ts:339, static enum at :318). ShadowFlow.render returns at its guard unless enabled && type === ShadowMap (src/cocos/rendering/shadow/shadow-flow.ts:116), the map pass then serves only camera.scene.mainLight (:140), and culling drops any model whose castShadow is false (src/cocos/rendering/scene-culling.ts:193) or whose world bounds are missing (:132).
  • The scene-global object mirrors into the pipeline object on a defined schedule: SceneGlobals.activate binds sceneData.shadows when the scene activates (src/cocos/scene-graph/scene-globals.ts:1709, driven from src/cocos/scene-graph/scene.ts:204) and ShadowsInfo.activate then calls resource.initialize(this) and activate() (:1022-:1025), which copies enabled and forces the internal SHADOW_TYPE_NONE while disabled (src/cocos/render-scene/scene/shadows.ts:367, :368); after activation the enabled/type setters push straight through (src/cocos/scene-graph/scene-globals.ts:867, :886; pipeline-side setters src/cocos/render-scene/scene/shadows.ts:217, :230). ShadowType, PCFType, CSMLevel and Shadows are not export names on the default bundle face, so Code First callers pass the ordinals 0 Planar and 1 ShadowMap (src/cocos/render-scene/scene/shadows.ts:80, :88) and read docs/manual/shadow-support-matrix.md for which light types cast at all.
  • A render target negotiates with the driver and you only learn the outcome from info: AirTargetColorFormat is exactly 'rgba8' | 'rgba16f' | 'rgba32f' | 'srgb8-alpha8' (src/air/rendering/render-target.ts:14), samples is exactly the literal set 1 | 2 | 4 | 8 (:23, validated :105) intersected with the device's color and depth SAMPLES support (:114-:117), and sampleFallback defaults to 'error' (:100) - an unsupported count then throws AIR_E_RENDER_TARGET_SAMPLES listing the supported set (:120), while 'lower' silently selects the largest supported value at or below the request (:119). Even a negotiated value is provisional: a mismatched driver SAMPLES reading after allocation throws AIR_E_RENDER_TARGET_SAMPLES (:179). The frozen info getter (:138-:142) is the only readout, separating requested from effective and exposing samples, resolveRequired (true only above 1 effective sample, :141), supportedSamples, glSamples, generation and disposed.
  • The target owns the native object and its identity changes on resize: attachCamera stores the camera's prior targetTexture, assigns its own and registers RENDER_CAMERA_BEGIN/RENDER_CAMERA_END listeners - the end listener calling resolve() so the next camera samples in the same frame - then returns the detach() closure (src/air/rendering/render-target.ts:200, :203, :204, :213). resolve() is a no-op at 1 sample (:218). A successful resize builds a new native RenderTexture and rebinds attached cameras by reassigning camera.targetTexture (:192); code assigning camera.targetTexture by hand must follow the new object itself (docs/manual/rendering-contracts.md:32). texture/depthTexture are borrowed views and dispose() unbinds, detaches and repeats safely (:280, :281).
  • AirTransmissionCapture allows exactly one capture per scene and says so loudly: onEnable scans the module-level active set and throws when another enabled capture shares node.scene (src/air/rendering/transmission-capture.ts:103-:105), because a material instance carries one scene-color binding. Assigning mainCamera re-arms an already-enabled capture so node-activation ordering cannot strand it (:81-:86), the capability is armed only while enabled on a WebGL2 device (:112, :65), and onDisable/onDestroy release bindings and restore main-camera visibility before the RenderTexture dies (:120, :130).
  • Color decisions are preflight only and the accepted pairing set is closed: decode is none | shader-srgb | hardware-srgb (src/air/rendering/color-contract.ts:35), and hardware-srgb is accepted exactly when the resolved format is in the sRGB set - every other pairing throws at :45 with hardware-srgb requires an sRGB GPU format; an sRGB format already decodes RGB and must not be software-decoded again, a non-color usage carrying an sRGB format or any decode other than none throws at :44 with normal/roughness/metallic/depth data must remain linear, with no sRGB decode, and usage disagreeing with isAirDepthFormat throws at :43. An explicitly undefined format throws AIR_E_TEXTURE_FORMAT instead of taking the default (:24); every rejection is an AirColorContractError extends TypeError formatted [code] property: message (:6-:9). Nothing is repaired: the module never changes texture bytes, standard material decode or framebuffer output (:37).
  • Post-process reachability is three different layers, and the custom pipeline is compiled but inert by default. custom-pipeline IS element 10 of the default AIR_FEATURES list (tools/build/build.cjs:27) and rendering IS a name in the built bundle's export block (src/exports/custom-pipeline.ts:4), but the aggregate source file the air unit builds from never re-exports ./custom-pipeline (src/exports/air.ts:6-:42), so import { rendering } resolves against the built ESM artifact while the aggregate source face does not surface it at all. At runtime game reads the rendering.customPipeline setting and, being falsy for AIR because bootstrap passes only rendering.renderMode (src/air/bootstrap.ts:152), assigns cclegacy.rendering = undefined (src/cocos/game/game.ts:804); Root.setRenderPipeline(false) takes the legacy branch and clears usesCustomPipeline (src/cocos/root.ts:385, :392), and the director wires a custom builder only while that flag and cclegacy.rendering are both live (src/cocos/game/director.ts:857). The single reader of camera.usePostProcess is the custom-pipeline PostProcessBuilder (src/cocos/rendering/post-process/post-process-builder.ts:201), registered under 'Forward' and 'Custom' (src/cocos/rendering/post-process/index.ts:9), so the postProcess namespace the aggregate does export (src/exports/air.ts:39) compiles and never runs unless a variant build plus a truthy setting take over; docs/reference/owner-decisions.md:42 records those gates and the variant-evidence resolution.
  • Capability layers stay separate. createAirRenderTarget, AirRenderTarget, AirTransmissionCapture, TRANSMISSION_LAYER, isTransmissionMaterial, inspectAirDirectionalLights, the color-contract functions, the five light components, rendering and postProcess all resolve by symbol name in the single export block of build/cocosair.module.js (626 names parsed) - a build lookup, not browser verification. ShadowType, PCFType, CSMLevel, Shadows, LightType, ModelShadowCastingMode, legacy_rendering, Format and PixelFormat are not export names there: the GFX enums arrive only as the namespace gfx (src/exports/base.ts:34, :46), so a format is written gfx.Format.RGBA8 (ordinal 35) or gfx.Format.SRGB8_A8 (37), and AirTargetColorFormat, AirRenderTargetOptions, AirRenderTargetInfo, AirTextureColorContract are declarations only. No recorded browser evidence in this repository covers the default bundle's rendering face, and docs/evidence/examples-verified.json proves only the candidate fingerprint it records, not 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
[
  "scene brightness looks wrong",
  "no shadows from lights",
  "render mirror or refraction into a texture",
  "texture looks washed out after load",
  "can bloom or post-processing run"
]
owns
[
  "lighting",
  "shadows",
  "render-target",
  "msaa",
  "srgb",
  "post-process"
]
not_for
[
  "material property types -> cocosair-materials-effects",
  "camera framing or projection -> cocosair-camera",
  "DOM offscreen textures -> cocosair-graphics-and-dom"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "配置灯光、阴影、渲染目标、MSAA、颜色契约和管线可达性。用于光照、阴影、离屏渲染、读回或后处理问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-rendering