gaussianblur 特效
This commit is contained in:
7
demo/libs/framework/framework.d.ts
vendored
7
demo/libs/framework/framework.d.ts
vendored
@@ -627,6 +627,7 @@ declare class GaussianBlurEffect extends egret.CustomFilter {
|
|||||||
private _blurAmount;
|
private _blurAmount;
|
||||||
private _horizontalBlurDelta;
|
private _horizontalBlurDelta;
|
||||||
private _verticalBlurDelta;
|
private _verticalBlurDelta;
|
||||||
|
private _sampleCount;
|
||||||
blurAmount: number;
|
blurAmount: number;
|
||||||
horizontalBlurDelta: number;
|
horizontalBlurDelta: number;
|
||||||
verticalBlurDelta: number;
|
verticalBlurDelta: number;
|
||||||
@@ -644,9 +645,9 @@ declare class PostProcessor {
|
|||||||
shape: egret.Shape;
|
shape: egret.Shape;
|
||||||
constructor(effect?: egret.CustomFilter);
|
constructor(effect?: egret.CustomFilter);
|
||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
process(source: egret.DisplayObject): void;
|
process(): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
protected drawFullscreenQuad(texture: egret.DisplayObject, effect?: egret.CustomFilter): void;
|
protected drawFullscreenQuad(): void;
|
||||||
unload(): void;
|
unload(): void;
|
||||||
}
|
}
|
||||||
declare class BloomSettings {
|
declare class BloomSettings {
|
||||||
@@ -665,7 +666,7 @@ declare class GaussianBlurPostProcessor extends PostProcessor {
|
|||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
private updateEffectDeltas;
|
private updateEffectDeltas;
|
||||||
process(source: egret.DisplayObject): void;
|
process(): void;
|
||||||
}
|
}
|
||||||
declare abstract class Renderer {
|
declare abstract class Renderer {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
|
|||||||
@@ -1149,7 +1149,12 @@ var Scene = (function (_super) {
|
|||||||
renderer.unload();
|
renderer.unload();
|
||||||
};
|
};
|
||||||
Scene.prototype.begin = function () {
|
Scene.prototype.begin = function () {
|
||||||
SceneManager.stage.addChildAt(this, 0);
|
if (SceneManager.sceneTransition) {
|
||||||
|
SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SceneManager.stage.addChild(this);
|
||||||
|
}
|
||||||
if (this._renderers.length == 0) {
|
if (this._renderers.length == 0) {
|
||||||
this.addRenderer(new DefaultRenderer());
|
this.addRenderer(new DefaultRenderer());
|
||||||
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
||||||
@@ -1204,7 +1209,7 @@ var Scene = (function (_super) {
|
|||||||
if (this._postProcessors[i].enable) {
|
if (this._postProcessors[i].enable) {
|
||||||
var isEven = MathHelper.isEven(enabledCounter);
|
var isEven = MathHelper.isEven(enabledCounter);
|
||||||
enabledCounter++;
|
enabledCounter++;
|
||||||
this._postProcessors[i].process(this);
|
this._postProcessors[i].process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1302,7 +1307,7 @@ var SceneManager = (function () {
|
|||||||
};
|
};
|
||||||
SceneManager.startSceneTransition = function (sceneTransition) {
|
SceneManager.startSceneTransition = function (sceneTransition) {
|
||||||
if (this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
console.error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sceneTransition = sceneTransition;
|
this.sceneTransition = sceneTransition;
|
||||||
@@ -3005,6 +3010,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
_this._blurAmount = 2;
|
_this._blurAmount = 2;
|
||||||
_this._horizontalBlurDelta = 0.01;
|
_this._horizontalBlurDelta = 0.01;
|
||||||
_this._verticalBlurDelta = 0.01;
|
_this._verticalBlurDelta = 0.01;
|
||||||
|
_this._sampleCount = 15;
|
||||||
_this._sampleWeights = [];
|
_this._sampleWeights = [];
|
||||||
_this._verticalSampleOffsets = [];
|
_this._verticalSampleOffsets = [];
|
||||||
_this._horizontalSampleOffsets = [];
|
_this._horizontalSampleOffsets = [];
|
||||||
@@ -3065,7 +3071,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
GaussianBlurEffect.prototype.calculateSampleWeights = function () {
|
GaussianBlurEffect.prototype.calculateSampleWeights = function () {
|
||||||
this._sampleWeights[0] = this.computeGaussian(0);
|
this._sampleWeights[0] = this.computeGaussian(0);
|
||||||
var totalWeights = this._sampleWeights[0];
|
var totalWeights = this._sampleWeights[0];
|
||||||
for (var i = 0; i < 15 / 2; i++) {
|
for (var i = 0; i < this._sampleCount / 2; i++) {
|
||||||
var weight = this.computeGaussian(i + 1);
|
var weight = this.computeGaussian(i + 1);
|
||||||
this._sampleWeights[i * 2 + 1] = weight;
|
this._sampleWeights[i * 2 + 1] = weight;
|
||||||
this._sampleWeights[i * 2 + 2] = weight;
|
this._sampleWeights[i * 2 + 2] = weight;
|
||||||
@@ -3077,9 +3083,9 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
this.uniforms._sampleWeights = this._sampleWeights;
|
this.uniforms._sampleWeights = this._sampleWeights;
|
||||||
};
|
};
|
||||||
GaussianBlurEffect.prototype.setBlurEffectParameters = function (dx, dy, offsets) {
|
GaussianBlurEffect.prototype.setBlurEffectParameters = function (dx, dy, offsets) {
|
||||||
for (var i = 0; i < 15 / 2; i++) {
|
for (var i = 0; i < this._sampleCount / 2; i++) {
|
||||||
var sampleOffset = i * 2 + 1.5;
|
var sampleOffset = i * 2 + 1.5;
|
||||||
var delta = Vector2.subtract(new Vector2(dx, dy), new Vector2(sampleOffset));
|
var delta = Vector2.multiply(new Vector2(dx, dy), new Vector2(sampleOffset));
|
||||||
offsets[i * 2 + 1] = delta;
|
offsets[i * 2 + 1] = delta;
|
||||||
offsets[i * 2 + 2] = new Vector2(-delta);
|
offsets[i * 2 + 2] = new Vector2(-delta);
|
||||||
}
|
}
|
||||||
@@ -3103,9 +3109,9 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
|
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
|
||||||
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
||||||
"void main(void) {\n" +
|
"void main(void) {\n" +
|
||||||
"vec4 c = 0;\n" +
|
"vec4 c = vec4(0, 0, 0, 0);\n" +
|
||||||
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
||||||
" c += texture2D( s0, texCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
" c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
||||||
"gl_FragColor = c;\n" +
|
"gl_FragColor = c;\n" +
|
||||||
"}";
|
"}";
|
||||||
return GaussianBlurEffect;
|
return GaussianBlurEffect;
|
||||||
@@ -3119,15 +3125,17 @@ var PostProcessor = (function () {
|
|||||||
PostProcessor.prototype.onAddedToScene = function (scene) {
|
PostProcessor.prototype.onAddedToScene = function (scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.shape = new egret.Shape();
|
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);
|
scene.addChild(this.shape);
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.process = function (source) {
|
PostProcessor.prototype.process = function () {
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
||||||
PostProcessor.prototype.drawFullscreenQuad = function (texture, effect) {
|
PostProcessor.prototype.drawFullscreenQuad = function () {
|
||||||
if (effect === void 0) { effect = null; }
|
this.shape.filters = [this.effect];
|
||||||
texture.filters = [effect];
|
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.unload = function () {
|
PostProcessor.prototype.unload = function () {
|
||||||
if (this.effect) {
|
if (this.effect) {
|
||||||
@@ -3189,12 +3197,12 @@ var GaussianBlurPostProcessor = (function (_super) {
|
|||||||
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
||||||
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
||||||
};
|
};
|
||||||
GaussianBlurPostProcessor.prototype.process = function (source) {
|
GaussianBlurPostProcessor.prototype.process = function () {
|
||||||
var effect = this.effect;
|
var effect = this.effect;
|
||||||
effect.prepareForHorizontalBlur();
|
effect.prepareForHorizontalBlur();
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
effect.prepareForVerticalBlur();
|
effect.prepareForVerticalBlur();
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
};
|
};
|
||||||
return GaussianBlurPostProcessor;
|
return GaussianBlurPostProcessor;
|
||||||
}(PostProcessor));
|
}(PostProcessor));
|
||||||
|
|||||||
2
demo/libs/framework/framework.min.js
vendored
2
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -18,7 +18,6 @@ class MainScene extends Scene {
|
|||||||
let bgSprite = new Sprite(RES.getRes("bg_jpg"));
|
let bgSprite = new Sprite(RES.getRes("bg_jpg"));
|
||||||
let bg = this.createEntity("bg");
|
let bg = this.createEntity("bg");
|
||||||
bg.position = new Vector2(0, 0);
|
bg.position = new Vector2(0, 0);
|
||||||
bg.scale = new Vector2(0.5);
|
|
||||||
bg.addComponent(new SpriteRenderer()).setSprite(bgSprite);
|
bg.addComponent(new SpriteRenderer()).setSprite(bgSprite);
|
||||||
|
|
||||||
for (let i = 0; i < 20; i ++){
|
for (let i = 0; i < 20; i ++){
|
||||||
@@ -31,12 +30,20 @@ class MainScene extends Scene {
|
|||||||
|
|
||||||
let button = new eui.Button();
|
let button = new eui.Button();
|
||||||
button.label = "切换场景";
|
button.label = "切换场景";
|
||||||
this.stage.addChild(button);
|
this.addChild(button);
|
||||||
button.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{
|
button.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{
|
||||||
SceneManager.startSceneTransition(new WindTransition(()=>{
|
SceneManager.startSceneTransition(new WindTransition(()=>{
|
||||||
return new MainScene();
|
return new MainScene();
|
||||||
}));
|
}));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
let cancel = new eui.Button();
|
||||||
|
cancel.label = "打开高斯模糊";
|
||||||
|
cancel.y = 100;
|
||||||
|
this.addChild(cancel);
|
||||||
|
cancel.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{
|
||||||
|
this.addPostProcessor(new GaussianBlurPostProcessor());
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public breadthfirstTest(){
|
public breadthfirstTest(){
|
||||||
|
|||||||
7
source/bin/framework.d.ts
vendored
7
source/bin/framework.d.ts
vendored
@@ -627,6 +627,7 @@ declare class GaussianBlurEffect extends egret.CustomFilter {
|
|||||||
private _blurAmount;
|
private _blurAmount;
|
||||||
private _horizontalBlurDelta;
|
private _horizontalBlurDelta;
|
||||||
private _verticalBlurDelta;
|
private _verticalBlurDelta;
|
||||||
|
private _sampleCount;
|
||||||
blurAmount: number;
|
blurAmount: number;
|
||||||
horizontalBlurDelta: number;
|
horizontalBlurDelta: number;
|
||||||
verticalBlurDelta: number;
|
verticalBlurDelta: number;
|
||||||
@@ -644,9 +645,9 @@ declare class PostProcessor {
|
|||||||
shape: egret.Shape;
|
shape: egret.Shape;
|
||||||
constructor(effect?: egret.CustomFilter);
|
constructor(effect?: egret.CustomFilter);
|
||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
process(source: egret.DisplayObject): void;
|
process(): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
protected drawFullscreenQuad(texture: egret.DisplayObject, effect?: egret.CustomFilter): void;
|
protected drawFullscreenQuad(): void;
|
||||||
unload(): void;
|
unload(): void;
|
||||||
}
|
}
|
||||||
declare class BloomSettings {
|
declare class BloomSettings {
|
||||||
@@ -665,7 +666,7 @@ declare class GaussianBlurPostProcessor extends PostProcessor {
|
|||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
private updateEffectDeltas;
|
private updateEffectDeltas;
|
||||||
process(source: egret.DisplayObject): void;
|
process(): void;
|
||||||
}
|
}
|
||||||
declare abstract class Renderer {
|
declare abstract class Renderer {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
|
|||||||
@@ -1149,7 +1149,12 @@ var Scene = (function (_super) {
|
|||||||
renderer.unload();
|
renderer.unload();
|
||||||
};
|
};
|
||||||
Scene.prototype.begin = function () {
|
Scene.prototype.begin = function () {
|
||||||
SceneManager.stage.addChildAt(this, 0);
|
if (SceneManager.sceneTransition) {
|
||||||
|
SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SceneManager.stage.addChild(this);
|
||||||
|
}
|
||||||
if (this._renderers.length == 0) {
|
if (this._renderers.length == 0) {
|
||||||
this.addRenderer(new DefaultRenderer());
|
this.addRenderer(new DefaultRenderer());
|
||||||
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
||||||
@@ -1204,7 +1209,7 @@ var Scene = (function (_super) {
|
|||||||
if (this._postProcessors[i].enable) {
|
if (this._postProcessors[i].enable) {
|
||||||
var isEven = MathHelper.isEven(enabledCounter);
|
var isEven = MathHelper.isEven(enabledCounter);
|
||||||
enabledCounter++;
|
enabledCounter++;
|
||||||
this._postProcessors[i].process(this);
|
this._postProcessors[i].process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1302,7 +1307,7 @@ var SceneManager = (function () {
|
|||||||
};
|
};
|
||||||
SceneManager.startSceneTransition = function (sceneTransition) {
|
SceneManager.startSceneTransition = function (sceneTransition) {
|
||||||
if (this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
console.error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sceneTransition = sceneTransition;
|
this.sceneTransition = sceneTransition;
|
||||||
@@ -3005,6 +3010,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
_this._blurAmount = 2;
|
_this._blurAmount = 2;
|
||||||
_this._horizontalBlurDelta = 0.01;
|
_this._horizontalBlurDelta = 0.01;
|
||||||
_this._verticalBlurDelta = 0.01;
|
_this._verticalBlurDelta = 0.01;
|
||||||
|
_this._sampleCount = 15;
|
||||||
_this._sampleWeights = [];
|
_this._sampleWeights = [];
|
||||||
_this._verticalSampleOffsets = [];
|
_this._verticalSampleOffsets = [];
|
||||||
_this._horizontalSampleOffsets = [];
|
_this._horizontalSampleOffsets = [];
|
||||||
@@ -3065,7 +3071,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
GaussianBlurEffect.prototype.calculateSampleWeights = function () {
|
GaussianBlurEffect.prototype.calculateSampleWeights = function () {
|
||||||
this._sampleWeights[0] = this.computeGaussian(0);
|
this._sampleWeights[0] = this.computeGaussian(0);
|
||||||
var totalWeights = this._sampleWeights[0];
|
var totalWeights = this._sampleWeights[0];
|
||||||
for (var i = 0; i < 15 / 2; i++) {
|
for (var i = 0; i < this._sampleCount / 2; i++) {
|
||||||
var weight = this.computeGaussian(i + 1);
|
var weight = this.computeGaussian(i + 1);
|
||||||
this._sampleWeights[i * 2 + 1] = weight;
|
this._sampleWeights[i * 2 + 1] = weight;
|
||||||
this._sampleWeights[i * 2 + 2] = weight;
|
this._sampleWeights[i * 2 + 2] = weight;
|
||||||
@@ -3077,9 +3083,9 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
this.uniforms._sampleWeights = this._sampleWeights;
|
this.uniforms._sampleWeights = this._sampleWeights;
|
||||||
};
|
};
|
||||||
GaussianBlurEffect.prototype.setBlurEffectParameters = function (dx, dy, offsets) {
|
GaussianBlurEffect.prototype.setBlurEffectParameters = function (dx, dy, offsets) {
|
||||||
for (var i = 0; i < 15 / 2; i++) {
|
for (var i = 0; i < this._sampleCount / 2; i++) {
|
||||||
var sampleOffset = i * 2 + 1.5;
|
var sampleOffset = i * 2 + 1.5;
|
||||||
var delta = Vector2.subtract(new Vector2(dx, dy), new Vector2(sampleOffset));
|
var delta = Vector2.multiply(new Vector2(dx, dy), new Vector2(sampleOffset));
|
||||||
offsets[i * 2 + 1] = delta;
|
offsets[i * 2 + 1] = delta;
|
||||||
offsets[i * 2 + 2] = new Vector2(-delta);
|
offsets[i * 2 + 2] = new Vector2(-delta);
|
||||||
}
|
}
|
||||||
@@ -3103,9 +3109,9 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
|
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
|
||||||
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
||||||
"void main(void) {\n" +
|
"void main(void) {\n" +
|
||||||
"vec4 c = 0;\n" +
|
"vec4 c = vec4(0, 0, 0, 0);\n" +
|
||||||
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
||||||
" c += texture2D( s0, texCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
" c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
||||||
"gl_FragColor = c;\n" +
|
"gl_FragColor = c;\n" +
|
||||||
"}";
|
"}";
|
||||||
return GaussianBlurEffect;
|
return GaussianBlurEffect;
|
||||||
@@ -3119,15 +3125,17 @@ var PostProcessor = (function () {
|
|||||||
PostProcessor.prototype.onAddedToScene = function (scene) {
|
PostProcessor.prototype.onAddedToScene = function (scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.shape = new egret.Shape();
|
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);
|
scene.addChild(this.shape);
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.process = function (source) {
|
PostProcessor.prototype.process = function () {
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
||||||
PostProcessor.prototype.drawFullscreenQuad = function (texture, effect) {
|
PostProcessor.prototype.drawFullscreenQuad = function () {
|
||||||
if (effect === void 0) { effect = null; }
|
this.shape.filters = [this.effect];
|
||||||
texture.filters = [effect];
|
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.unload = function () {
|
PostProcessor.prototype.unload = function () {
|
||||||
if (this.effect) {
|
if (this.effect) {
|
||||||
@@ -3189,12 +3197,12 @@ var GaussianBlurPostProcessor = (function (_super) {
|
|||||||
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
||||||
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
||||||
};
|
};
|
||||||
GaussianBlurPostProcessor.prototype.process = function (source) {
|
GaussianBlurPostProcessor.prototype.process = function () {
|
||||||
var effect = this.effect;
|
var effect = this.effect;
|
||||||
effect.prepareForHorizontalBlur();
|
effect.prepareForHorizontalBlur();
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
effect.prepareForVerticalBlur();
|
effect.prepareForVerticalBlur();
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
};
|
};
|
||||||
return GaussianBlurPostProcessor;
|
return GaussianBlurPostProcessor;
|
||||||
}(PostProcessor));
|
}(PostProcessor));
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -95,7 +95,12 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public begin() {
|
public begin() {
|
||||||
SceneManager.stage.addChildAt(this, 0);
|
if (SceneManager.sceneTransition){
|
||||||
|
SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1);
|
||||||
|
}else{
|
||||||
|
SceneManager.stage.addChild(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (this._renderers.length == 0) {
|
if (this._renderers.length == 0) {
|
||||||
this.addRenderer(new DefaultRenderer());
|
this.addRenderer(new DefaultRenderer());
|
||||||
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
||||||
@@ -180,7 +185,7 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
let isEven = MathHelper.isEven(enabledCounter);
|
let isEven = MathHelper.isEven(enabledCounter);
|
||||||
enabledCounter ++;
|
enabledCounter ++;
|
||||||
|
|
||||||
this._postProcessors[i].process(this);
|
this._postProcessors[i].process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class SceneManager {
|
|||||||
*/
|
*/
|
||||||
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
|
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
|
||||||
if (this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
console.error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ class GaussianBlurEffect extends egret.CustomFilter {
|
|||||||
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
||||||
|
|
||||||
"void main(void) {\n" +
|
"void main(void) {\n" +
|
||||||
"vec4 c = 0;\n" +
|
"vec4 c = vec4(0, 0, 0, 0);\n" +
|
||||||
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
||||||
" c += texture2D( s0, texCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
" c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
||||||
"gl_FragColor = c;\n" +
|
"gl_FragColor = c;\n" +
|
||||||
"}";
|
"}";
|
||||||
private _sampleWeights: number[];
|
private _sampleWeights: number[];
|
||||||
@@ -33,6 +33,7 @@ class GaussianBlurEffect extends egret.CustomFilter {
|
|||||||
private _blurAmount = 2;
|
private _blurAmount = 2;
|
||||||
private _horizontalBlurDelta = 0.01;
|
private _horizontalBlurDelta = 0.01;
|
||||||
private _verticalBlurDelta = 0.01;
|
private _verticalBlurDelta = 0.01;
|
||||||
|
private _sampleCount: number = 15;
|
||||||
|
|
||||||
public get blurAmount(){
|
public get blurAmount(){
|
||||||
return this._blurAmount;
|
return this._blurAmount;
|
||||||
@@ -94,7 +95,7 @@ class GaussianBlurEffect extends egret.CustomFilter {
|
|||||||
this._sampleWeights[0] = this.computeGaussian(0);
|
this._sampleWeights[0] = this.computeGaussian(0);
|
||||||
let totalWeights = this._sampleWeights[0];
|
let totalWeights = this._sampleWeights[0];
|
||||||
|
|
||||||
for (let i = 0; i < 15 / 2; i ++){
|
for (let i = 0; i < this._sampleCount / 2; i ++){
|
||||||
let weight = this.computeGaussian(i + 1);
|
let weight = this.computeGaussian(i + 1);
|
||||||
this._sampleWeights[i * 2 + 1] = weight;
|
this._sampleWeights[i * 2 + 1] = weight;
|
||||||
this._sampleWeights[i * 2 + 2] = weight;
|
this._sampleWeights[i * 2 + 2] = weight;
|
||||||
@@ -110,9 +111,9 @@ class GaussianBlurEffect extends egret.CustomFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setBlurEffectParameters(dx: number, dy: number, offsets: Vector2[]){
|
private setBlurEffectParameters(dx: number, dy: number, offsets: Vector2[]){
|
||||||
for (let i = 0; i < 15 / 2; i ++){
|
for (let i = 0; i < this._sampleCount / 2; i ++){
|
||||||
let sampleOffset = i * 2 + 1.5;
|
let sampleOffset = i * 2 + 1.5;
|
||||||
let delta = Vector2.subtract( new Vector2(dx, dy), new Vector2(sampleOffset));
|
let delta = Vector2.multiply( new Vector2(dx, dy), new Vector2(sampleOffset));
|
||||||
|
|
||||||
offsets[i * 2 + 1] = delta;
|
offsets[i * 2 + 1] = delta;
|
||||||
offsets[i * 2 + 2] = new Vector2(-delta);
|
offsets[i * 2 + 2] = new Vector2(-delta);
|
||||||
|
|||||||
@@ -12,17 +12,20 @@ class PostProcessor {
|
|||||||
public onAddedToScene(scene: Scene){
|
public onAddedToScene(scene: Scene){
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.shape = new egret.Shape();
|
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);
|
scene.addChild(this.shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
public process(source: egret.DisplayObject){
|
public process(){
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
|
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
|
||||||
|
|
||||||
protected drawFullscreenQuad(texture: egret.DisplayObject, effect: egret.CustomFilter = null){
|
protected drawFullscreenQuad(){
|
||||||
texture.filters = [effect];
|
this.shape.filters = [this.effect];
|
||||||
}
|
}
|
||||||
|
|
||||||
public unload(){
|
public unload(){
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ class GaussianBlurPostProcessor extends PostProcessor {
|
|||||||
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public process(source: egret.DisplayObject){
|
public process(){
|
||||||
let effect = this.effect as GaussianBlurEffect;
|
let effect = this.effect as GaussianBlurEffect;
|
||||||
effect.prepareForHorizontalBlur();
|
effect.prepareForHorizontalBlur();
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
|
|
||||||
effect.prepareForVerticalBlur();
|
effect.prepareForVerticalBlur();
|
||||||
this.drawFullscreenQuad(source, this.effect);
|
this.drawFullscreenQuad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user