Skip to content

light2d pipeline ignoring container rotation for child sprites #6086

@irongaze

Description

@irongaze

Version

  • Phaser Version: 3.55.2
  • Operating system: Windows 10 latest
  • Browser: Firefox latest,

Description

Expected: Adding lit sprites to containers should use the cumulative/world transform during lighting calculations
Actual Behavior: Lit sprites in rotating containers display fixed lighting

Details: Adding a sprite + normal map and setting the sprite to the light2d pipeline works as expected - when rotating/moving the sprite, the angle to the light determines lighting intensity.

However, if you take the same sprite + normal map and add it as the child of a container, the container's rotation is ignored when light calculation occurs, resulting in fixed lighting.

Example Test Code

Codepen here: https://codepen.io/zaphnod/pen/OJzGKZB

Relevant setup:

    function create() {
      // Create ship container
      ship = this.add.container(400, 450);

      // Add ship body to container
      shipBody = this.add.sprite(0, 0, 'ship');
      shipBody.setPipeline('Light2D');
      ship.add(shipBody);

      // Create second ship at scene root
      ship2 = this.add.sprite(1200, 450, 'ship');
      ship2.setPipeline('Light2D');

      this.lights.enable().setAmbientColor(0x333333);

      // Add light at center of scene
      sun = this.lights.addLight(800, 450, 2000, 0xffAA00);
    }

    // Rotate container + ship2
    var timer = 0;
    function update(time, delta) {
      timer += delta;
      ship.setAngle(timer / 20 % 360);
      ship2.setAngle(timer / 20 % 360);
    }

Additional Information

Seems likely that the lighting engine is passing in the object's local rotation to the shader fragment, rather than the full computed transform. I'll try to dig into the internals and get a better theory but I'm new to Phaser so would appreciate any pointers/assistance!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions