phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.15k stars 7.1k forks source link

SpriteSheet File doesn't complete Normal Map loading #3995

Closed inmylo closed 4 years ago

inmylo commented 6 years ago

Version

Description

I've noticed problems with tilemap dynamic layer and sprites when I enable light:

  1. Sprite becomes invisible
  2. Dynamic layer shows JS errors in a console

Example Test Code

Here is an example code, which you can copy to the labs.phaser.io and run:

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    parent: 'phaser-example',
    backgroundColor: '#333333',
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var light;
var player;
var layer;

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('tiles', [ 'assets/tilemaps/tiles/drawtiles1.png', 'assets/tilemaps/tiles/drawtiles1_n.png' ]);
    this.load.spritesheet('dude', ['src/games/firstgame/assets/dude.png', 'src/games/firstgame/assets/dude.png'], { frameWidth: 32, frameHeight: 48 });

    this.load.tilemapCSV('map', 'assets/tilemaps/csv/grid.csv');
}

function create ()
{
    var map = this.make.tilemap({ key: 'map', tileWidth: 32, tileHeight: 32 });

    var tileset = map.addTilesetImage('tiles', null, 32, 32, 1, 2);
    layer = map.createDynamicLayer(0, tileset, 0, 0);
    player = this.add.sprite(48, 40, 'dude');

    player.setPipeline('Light2D');
    layer.setPipeline('Light2D');

    this.lights.enable().setAmbientColor(0xffffff);
    this.lights.addLight(48, 40, 100).setColor(0xff0000).setIntensity(3.0);
}

function update (){}

Javascript error in the console:

WebGLPipeline.js:345 WebGL: INVALID_VALUE: disableVertexAttribArray: index out of range

In Firefox ESR (v52.9) error's description is a little more informative:

Error: WebGL warning: disableVertexAttribArray: -1 is not a valid `index`. This value probably comes from a getAttribLocation() call, where this return value -1 means that the passed name didn't correspond to an active attribute in the specified program.

In Firefox 61 sprite is visible, but no light. No related errors in the console.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/62861551-spritesheet-file-doesn-t-complete-normal-map-loading?utm_campaign=plugin&utm_content=tracker%2F283654&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F283654&utm_medium=issues&utm_source=github).
photonstorm commented 6 years ago

Having looked at this, the error is nothing to do with the tilemap, it's just to do with the fact that load.spritesheet doesn't support normal maps. If you swap it for an image or an atlas it'll work fine.

FrancescoNegri commented 6 years ago

Sorry to bother you. Will load.spritesheet support normal maps in the future or it is not expected to?

photonstorm commented 6 years ago

Yes, but not in 3.16.

photonstorm commented 4 years ago

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

photonstorm commented 4 years ago

This issue has been mentioned on Phaser. There might be relevant details there:

https://phaser.discourse.group/t/normal-maps-with-spritesheets-and-phaser-3-5/7503/1