import {Group, Layer} from '@pixi/layers'; import * as Lights from '@pixi/lights'; class LightLayer extends Layer { $$diffuseTexture; $$normalTexture; constructor(group, diffuseLayer, normalLayer) { super(group); this.$$diffuseLayer = diffuseLayer; this.$$diffuseTexture = diffuseLayer.getRenderTexture(); this.$$normalTexture = normalLayer.getRenderTexture(); } get diffuseTexture() { return this.$$diffuseTexture; } get normalTexture() { return this.$$normalTexture; } } class DeferredLighting { diffuseGroup = new Group(0, false); lightGroup = new Group(0, false); normalGroup = new Group(0, false); constructor() { this.diffuseGroup.useRenderTexture = true; this.diffuseLayer = new Layer(this.diffuseGroup); this.normalGroup.useRenderTexture = true; this.normalLayer = new Layer(this.normalGroup); this.lightLayer = new LightLayer( this.lightGroup, this.diffuseLayer, this.normalLayer, ); this.lightLayer.alpha = 0.5; } addToStage(stage) { stage.addChild(this.diffuseLayer); stage.addChild(this.normalLayer); stage.addChild(this.lightLayer); } } export const deferredLighting = new DeferredLighting(); export class AmbientLight extends Lights.AmbientLight { constructor(...args) { super(...args); this.parentGroup = deferredLighting.lightGroup; } } export class PointLight extends Lights.PointLight { constructor(...args) { super(...args); this.parentGroup = deferredLighting.lightGroup; } }