layers: pixi-display + pixi-light Crash

Hi ivan I have a small crash experimenting with pixi light and the layer system. I do not know if these my group system would cause this? I separated the process in 2 steps for easy debug.

Step1, the loader will inject resource in a global variable. at this step are all fine.

// ┌------------------------------------------------------------------------------┐
// PIXI LOADER for light ressources (testing)
//└------------------------------------------------------------------------------┘
_SLL.prototype.load_pixiLight = function() {
    const loader_light = new PIXI.loaders.Loader();
    loader_light.add('bg_diffuse', 'lightIMG/BGTextureTest.jpg')
        .add('bg_normal', 'lightIMG/BGTextureNORM.jpg')
        .add('block_diffuse', 'lightIMG/block.png')
        .add('block_normal', 'lightIMG/blockNormalMap.png');
    loader_light.load(onAssetsLoaded);

    function onAssetsLoaded(loader, res) {
        $SLL.resourceLight = { // add reference to $SLL global (debug only)
             bg:[res.bg_diffuse.texture, res.bg_normal.texture],
             block:[res.block_diffuse.texture, res.block_normal.texture],
             block1:[res.block_diffuse.texture, res.block_normal.texture],
             block2:[res.block_diffuse.texture, res.block_normal.texture]
        }
    };

    loader_light.onComplete.add(() => {$SLL.setLightLoaded()}); // tell the light loader are finish
};

step2 i initialise my layers system (original) and after inject light feature in the stage. the stage “this” are initialise before in other module. stage

Stage.prototype = Object.create(PIXI.display.Stage.prototype);
Stage.prototype.constructor = Stage;
Stage.prototype.initialize = function() {
    PIXI.display.Stage.call(this);
    this.interactive = false; // The interactive flag causes a memory leak.
};

step2 look at end on // PIXI LIGHT TEST IMPLEMENTATION

// LAYER ASIGNATION TO MAP STAGE
Spriteset_Map.prototype.createLowerLayer = function() {
    Spriteset_Base.prototype.createLowerLayer.call(this);
    // TODO: create global display.Group for avoid init each time new map loaded
    this.displayGroup = [
        new PIXI.display.Group(0, false), // backgroud Map. BG tile elements will no update and no interaction
        new PIXI.display.Group(1, true), // map elements default player, chara and all basic sprite update z and interaction
        new PIXI.display.Group(2, true), // map elements 2er
        new PIXI.display.Group(3, true), // map elements 3er
        new PIXI.display.Group(4, false), //levelGui: GUI Elements over maps
        new PIXI.display.Group(5, false), //levelMenu: MENU Elements over maps
        new PIXI.display.Group(6, false), //levelTxt: txt bubble, or SFX over all
    ];
    this.displayLayers = [];
    for (let l = 0, len = this.displayGroup.length; l < len; l++) {
        const DG = this.displayGroup[l];
        const DL = new PIXI.display.Layer(DG);
        this.displayLayers.push(DL);//(debugOnly) reference acces ref
        this.addChild(DL); // add to Stage PIXI.display
    };

    // PIXI LIGHT TEST IMPLEMENTATION
    var light = new PIXI.lights.PointLight(0xffffff, 1);
    this.addChild(new PIXI.display.Layer(PIXI.lights.diffuseGroup));
    this.addChild(new PIXI.display.Layer(PIXI.lights.normalGroup));
    this.addChild(new PIXI.display.Layer(PIXI.lights.lightGroup));
    // create ligth and normal
    function createPair(diffuseTex, normalTex) {
        var container = new PIXI.Container();
        var diffuseSprite = new PIXI.Sprite(diffuseTex);
        diffuseSprite.parentGroup = PIXI.lights.diffuseGroup;
        var normalSprite = new PIXI.Sprite(normalTex);
        normalSprite.parentGroup = PIXI.lights.normalGroup;
        container.addChild(diffuseSprite);
        container.addChild(normalSprite);
        return container;
    }

    let PAIR = {};
    for (const key in $SLL.resourceLight) {
        const res = $SLL.resourceLight[key];
        PAIR[key] = createPair(res[0], res[1]);
    }
    console.log('PAIR: ', PAIR); // add to stage
    this.addChild(PAIR.bg);
    this.addChild(PAIR.block);
    this.addChild(PAIR.block1);
    this.addChild(PAIR.block2);


    this.addChild(new PIXI.lights.AmbientLight(null, 0.4)); // GET ERROR !!!


    //... other stuff
};

at the line this.addChild(new PIXI.lights.AmbientLight(null, 0.4)); i get a error texLayer.getRenderTexture is not a function

image

if i remove this line, i can see all the element normal seem loaded. image

did you know what i’m doing wrong in my context ? i think it where and how i add light with new PIXI.display.Group? thank

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 52 (28 by maintainers)

Most upvoted comments

Here we go: http://pixijs.io/examples/#/layers/normals-drag.js

Now you can just set 'sortPriority=1` for your sorting group.

Nice! Ok, tomorrow ill have something for you.

because i dont have automatic build for that. And im lazy to add it.

you can make lighted spine, you have to make your own Spine class based on heaven or pixi-spine Spine class, override createSprite property - create two sprites, one diffuse and one normal.

To make normal texture, you can just create PIXI.Texture with different baseTexture but same frame/crop/orig combo.

I can make lighted spine example in weekend.

Does it produce JSON output that can be read without RMMV?

I want to help you releasing this as a independend pixi scene editor

you can add light wherever you want - it has PIXI.lights.lightGroup as a parentGroup by default.

I understand that for every old layer that you want to light you need two layers now, and they will sort independently. Unfortunately, there’re no shortcuts in pixi-layers for that. It will use z-index and z-order from the normal/diffuse instead their parent, you might want to change either sorting function either pass z-index z-order inside.

Try more, then i’ll help you if you become stuck.

Again, im telling you that im proud that you are doing it. you are proving that its possible to make custom rendering pipeline with pixi-layers.

You can put several layers INSIDE diffuseLayer and normalLayer as a children. inner layers will sort things for you, and outer layer will render it to textures that are needed for lights.

I hope you dont have any non-lighted layers between, but even in that case, i have some crazy ideas 😉 Your case is a best one for testing my pixi-layers idea.