2020-07-23 11:00:46 +08:00
|
|
|
module es {
|
|
|
|
|
export class PostProcessor {
|
|
|
|
|
public enabled: boolean;
|
|
|
|
|
public effect: egret.Filter;
|
|
|
|
|
public scene: Scene;
|
|
|
|
|
public shape: egret.Shape;
|
|
|
|
|
|
|
|
|
|
public static default_vert = "attribute vec2 aVertexPosition;\n" +
|
|
|
|
|
"attribute vec2 aTextureCoord;\n" +
|
|
|
|
|
"attribute vec2 aColor;\n" +
|
|
|
|
|
|
|
|
|
|
"uniform vec2 projectionVector;\n" +
|
|
|
|
|
//"uniform vec2 offsetVector;\n" +
|
|
|
|
|
|
|
|
|
|
"varying vec2 vTextureCoord;\n" +
|
|
|
|
|
"varying vec4 vColor;\n" +
|
|
|
|
|
|
|
|
|
|
"const vec2 center = vec2(-1.0, 1.0);\n" +
|
|
|
|
|
|
|
|
|
|
"void main(void) {\n" +
|
|
|
|
|
"gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
|
|
|
|
"vTextureCoord = aTextureCoord;\n" +
|
|
|
|
|
"vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
|
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
constructor(effect: egret.Filter = null){
|
|
|
|
|
this.enabled = true;
|
|
|
|
|
this.effect = effect;
|
|
|
|
|
}
|
2020-06-23 09:10:40 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public onAddedToScene(scene: Scene){
|
|
|
|
|
this.scene = scene;
|
|
|
|
|
this.shape = new egret.Shape();
|
|
|
|
|
this.shape.graphics.beginFill(0xFFFFFF, 1);
|
|
|
|
|
this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
|
|
|
|
this.shape.graphics.endFill();
|
|
|
|
|
scene.addChild(this.shape);
|
|
|
|
|
}
|
2020-06-23 09:10:40 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public process(){
|
|
|
|
|
this.drawFullscreenQuad();
|
|
|
|
|
}
|
2020-06-23 16:18:14 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
|
2020-06-23 09:10:40 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
protected drawFullscreenQuad(){
|
|
|
|
|
this.scene.filters = [this.effect];
|
|
|
|
|
// this.shape.filters = [this.effect];
|
2020-06-23 09:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public unload(){
|
|
|
|
|
if (this.effect){
|
|
|
|
|
this.effect = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.scene.removeChild(this.shape);
|
|
|
|
|
this.scene = null;
|
|
|
|
|
}
|
2020-06-23 09:10:40 +08:00
|
|
|
}
|
2020-07-23 11:00:46 +08:00
|
|
|
}
|