Jump to content

Light2D, rotating normal map issue


fazz
 Share

Recommended Posts

Hi,

I think I've found an issue with the normal map spot light. Either that or I've done something daft in my code.

I believe the spot light system correctly selects which pixels to illuminate, but it doesn't consider the sprite's rotation, only the pixel normal value, when calculating per pixel lightness. This only becomes apparent when a sprite is rotated, and it is difficult to demonstrate when using very flat normal maps, like in this spot light demo http://labs.phaser.io/view.html?src=src\game objects\lights\spotlight.js

You can see my below code snippet running here https://madcarrot.itch.io/phaser3-demo?secret=70SZ1Whbm3Wsf9onEXXdRM2deQ

If you position the spot light (attached to pointer) behind the insect to highlight the abdomen, when the insect is facing downward, the light angle is correct, when the insect is facing upward, the light angle is 180 degs off.

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var game = new Phaser.Game(config);

var insect;

function preload () {

    this.load.image('insect', [
        'assets/images/bug-99x103.png',
        'assets/images/bug-nm-99x103.png'
    ]);
}

function create () {
    
    this.lights.enable().setAmbientColor(0x333333);
    
    insect = this.add.image(400, 300, 'insect').setOrigin(0.5).setScale(3);
    insect.setPipeline('Light2D');
    
    var light = this.lights.addLight(180, 80, 200).setColor(0xffffff).setIntensity(2);
    
    this.input.on('pointermove', function (pointer) {
        light.x = pointer.x;
        light.y = pointer.y;
    });
}

function update() {
    
    insect.angle += 0.5;
}

Can anyone see if I've done anything daft here? Or whether this is worth raising as a bug?

Thanks in advance

 

bug-99x103.png

bug-nm-99x103.png

Link to comment
Share on other sites

  • 1 year later...

I found the issue in my case:

Because of the uInverseRotationMatrix uniform, the Lighting is not compatible with the sprite batching.

So I've added `            this.flush();` in the batchSprite function if a normalTexture is found.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...