logo
Shadow

rendering

Shadow

Free

Install with the CLI:

bjs download Shadow

Shadow

Marks an entity's mesh as a shadow caster and/or receiver, wired to a DirectionalLight through the renderer adapter.

What it does

ShadowSystem listens for meshprimitive.created to cache each entity's mesh handle, then for any entity carrying a Shadow it finds the first DirectionalLight's handle in the world and registers the mesh: attachShadowCaster(light, mesh) when castShadow is set, and setMeshReceiveShadows(mesh, true) when receiveShadow is set. Each entity is wired once — an initialized guard makes repeated apply calls cheap no-ops. It emits shadow.caster.added and shadow.enabled when wired, and on entity removal it detaches the caster and emits shadow.disabled. Only opaque handles cross between systems; the System never reads the light or mesh components' data.

Use it in a scene

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Fastest path

bjs download scene Shadow

Pulls this exact scene into your project and runs it — no copy-paste. Add --all to grab the components and assets it needs too.

Or build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add Shadow
    bjs download Shadow

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "Crate": {
    "components": {
      "MeshPrimitive": {
        "primitive": "box", "size": 2, "position": [0, 1, 0],
        "material": { "diffuseColor": [0.85, 0.3, 0.25] }
      },
      "Shadow": { "castShadow": true, "receiveShadow": false }
    }
  },
  "Floor": {
    "components": {
      "MeshPrimitive": {
        "primitive": "box", "width": 20, "height": 0.2, "depth": 20, "position": [0, -0.1, 0],
        "material": { "diffuseColor": [0.4, 0.42, 0.45] }
      },
      "Shadow": { "castShadow": false, "receiveShadow": true }
    }
  }
}

Props

  • castShadow (boolean, default true) — register the mesh as a shadow caster on the directional light. Set false on flat receivers like a floor.
  • receiveShadow (boolean, default true) — let other casters' shadows draw onto this mesh. Set false on small props where self-received shadow noise isn't wanted.

Events

  • Emits shadow.caster.added (ShadowEvents.SHADOW_CASTER_ADDED) — { entityId }, once the caster is attached.
  • Emits shadow.enabled (ShadowEvents.SHADOW_ENABLED) — { entityId, castShadow, receiveShadow }, once the entity is wired.
  • Emits shadow.disabled (ShadowEvents.SHADOW_DISABLED) — { entityId }, on entity removal when it detaches the caster.
  • Consumes meshprimitive.created{ entityId, handle }, to cache the mesh handle that gets registered.

Dependencies

DirectionalLight — shadows need a directional light to register against; ShadowSystem searches the world for the first one and silently skips casting if none exists (a HemisphericLight alone casts nothing). MeshPrimitive — supplies the mesh handle, delivered through meshprimitive.created, that gets marked as caster/receiver.

Notes

  • MeshPrimitive creates its meshes during addSystem, which can fire meshprimitive.created before ShadowSystem subscribes. On initialize the System also pulls handles straight off each MeshPrimitiveComponent, so a mesh built that early still gets wired.
  • Casting is keyed off the first DirectionalLight found in the world; one directional light drives every caster in the scene.
  • A receiver-only floor still carries a Shadow (with castShadow: false) — receiveShadow is what lets a caster's shadow land on it.

More like this

DirectionalLight
Mesh
MeshPrimitive
AiPilot
Animation
ArcCamera
Asteroid
Bullet
CameraFollow
EnemySpawner
EnvironmentTexture
Flash
FreighterCar
FreighterChain
FreighterHead
GameConfig
Health
HemisphericLight
Jump
KeyboardInput
KeyboardMover
LensFlare
Lifetime
LineOfSight
MachineGun
Missile
MissileLauncher
MissionDirector
MouseInput
Movement
NebulaSky
Obstacle
ObstacleField
OilBlob
Parts
Physics
PlayerInput
PlayerWalkAnimator
Renderable
RespawnTimer
RoadTreadmill
RoundReset
Score
ShipDamageFX
ShipLoadout
SkeletonAnimator
Skybox
SmokeScreen
SpaceDust
SpaceShooterBullet
SpaceShooterFX
SpaceShooterHealth
SpaceShooterScore
ToneMapping
TwinStickEnemy
WaveDirector
Waypoint
WaypointTrack

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search