2024-07-19 01:27:47 -05:00
|
|
|
import {Group, Layer} from '@pixi/layers';
|
2024-07-21 11:04:06 -05:00
|
|
|
import * as Lights from '@pixi/lights';
|
2024-07-19 01:27:47 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2024-07-21 11:04:06 -05:00
|
|
|
export class AmbientLight extends Lights.AmbientLight {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
this.parentGroup = deferredLighting.lightGroup;
|
2024-07-19 01:27:47 -05:00
|
|
|
}
|
2024-07-18 04:18:06 -05:00
|
|
|
}
|
|
|
|
|
2024-07-21 11:04:06 -05:00
|
|
|
export class PointLight extends Lights.PointLight {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
this.parentGroup = deferredLighting.lightGroup;
|
|
|
|
}
|
|
|
|
}
|