移除所有egret 依赖。移除renderablecomponent及所有依赖,移除camera。保持ecs基础框架
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
module es {
|
||||
export class GaussianBlurEffect extends egret.CustomFilter {
|
||||
// private static blur_frag = "precision mediump float;\n" +
|
||||
// "uniform vec2 blur;\n" +
|
||||
// "uniform sampler2D uSampler;\n" +
|
||||
// "varying vec2 vTextureCoord;\n" +
|
||||
// "uniform vec2 uTextureSize;\n" +
|
||||
// "void main()\n" +
|
||||
// "{\n " +
|
||||
// "const int sampleRadius = 5;\n" +
|
||||
// "const int samples = sampleRadius * 2 + 1;\n" +
|
||||
// "vec2 blurUv = blur / uTextureSize;\n" +
|
||||
// "vec4 color = vec4(0, 0, 0, 0);\n" +
|
||||
// "vec2 uv = vec2(0.0, 0.0);\n" +
|
||||
// "blurUv /= float(sampleRadius);\n" +
|
||||
|
||||
// "for (int i = -sampleRadius; i <= sampleRadius; i++) {\n" +
|
||||
// "uv.x = vTextureCoord.x + float(i) * blurUv.x;\n" +
|
||||
// "uv.y = vTextureCoord.y + float(i) * blurUv.y;\n" +
|
||||
// "color += texture2D(uSampler, uv);\n" +
|
||||
// "}\n" +
|
||||
|
||||
// "color /= float(samples);\n" +
|
||||
// "gl_FragColor = color;\n" +
|
||||
// "}";
|
||||
|
||||
private static blur_frag = "precision mediump float;\n" +
|
||||
"uniform sampler2D uSampler;\n" +
|
||||
"uniform float screenWidth;\n" +
|
||||
"uniform float screenHeight;\n" +
|
||||
|
||||
"float normpdf(in float x, in float sigma)\n" +
|
||||
"{\n" +
|
||||
"return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
|
||||
"}\n" +
|
||||
|
||||
"void main()\n" +
|
||||
"{\n" +
|
||||
"vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||
|
||||
"const int mSize = 11;\n" +
|
||||
"const int kSize = (mSize - 1)/2;\n" +
|
||||
"float kernel[mSize];\n" +
|
||||
"vec3 final_colour = vec3(0.0);\n" +
|
||||
|
||||
"float sigma = 7.0;\n" +
|
||||
"float z = 0.0;\n" +
|
||||
"for (int j = 0; j <= kSize; ++j)\n" +
|
||||
"{\n" +
|
||||
"kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
|
||||
"}\n" +
|
||||
|
||||
"for (int j = 0; j < mSize; ++j)\n" +
|
||||
"{\n" +
|
||||
"z += kernel[j];\n" +
|
||||
"}\n" +
|
||||
|
||||
"for (int i = -kSize; i <= kSize; ++i)\n" +
|
||||
"{\n" +
|
||||
"for (int j = -kSize; j <= kSize; ++j)\n" +
|
||||
"{\n" +
|
||||
"final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||
"}\n}\n" +
|
||||
"gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
|
||||
"}";
|
||||
|
||||
constructor() {
|
||||
super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag, {
|
||||
screenWidth: Core.graphicsDevice.viewport.width,
|
||||
screenHeight: Core.graphicsDevice.viewport.height
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
module es {
|
||||
export class PolygonLightEffect extends egret.CustomFilter {
|
||||
private static vertSrc = "attribute vec2 aVertexPosition;\n" +
|
||||
"attribute vec2 aTextureCoord;\n" +
|
||||
|
||||
"uniform vec2 projectionVector;\n" +
|
||||
|
||||
"varying vec2 vTextureCoord;\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" +
|
||||
"}";
|
||||
private static fragmentSrc = "precision lowp float;\n" +
|
||||
"varying vec2 vTextureCoord;\n" +
|
||||
"uniform sampler2D uSampler;\n" +
|
||||
|
||||
"#define SAMPLE_COUNT 15\n" +
|
||||
|
||||
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
|
||||
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
|
||||
|
||||
"void main(void) {\n" +
|
||||
"vec4 c = vec4(0, 0, 0, 0);\n" +
|
||||
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
|
||||
" c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
|
||||
"gl_FragColor = c;\n" +
|
||||
"}";
|
||||
|
||||
constructor() {
|
||||
super(PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
module es {
|
||||
export class Graphics {
|
||||
public static Instance: Graphics;
|
||||
/**
|
||||
* 用于绘制矩形、线条、圆等的精灵。
|
||||
* 将在启动时生成,但你可以用你的图集中的精灵代替,以减少纹理交换。应该是一个1x1的白色像素
|
||||
*/
|
||||
public pixelTexture: Sprite;
|
||||
|
||||
constructor(){
|
||||
let arrayBuffer = new ArrayBuffer(1);
|
||||
arrayBuffer[0] = 0xffffff;
|
||||
egret.BitmapData.create("arraybuffer", arrayBuffer, bitmapData => {
|
||||
let tex = new egret.Texture();
|
||||
tex.bitmapData = bitmapData;
|
||||
this.pixelTexture = new Sprite(tex);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
module es {
|
||||
export class GraphicsCapabilities extends egret.Capabilities {
|
||||
|
||||
public initialize(device: GraphicsDevice) {
|
||||
this.platformInitialize(device);
|
||||
}
|
||||
|
||||
private platformInitialize(device: GraphicsDevice) {
|
||||
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
|
||||
return;
|
||||
let capabilities = this;
|
||||
capabilities["isMobile"] = true;
|
||||
|
||||
let systemInfo = wx.getSystemInfoSync();
|
||||
let systemStr = systemInfo.system.toLowerCase();
|
||||
if (systemStr.indexOf("ios") > -1) {
|
||||
capabilities["os"] = "iOS";
|
||||
} else if (systemStr.indexOf("android") > -1) {
|
||||
capabilities["os"] = "Android";
|
||||
}
|
||||
|
||||
let language = systemInfo.language;
|
||||
if (language.indexOf('zh') > -1) {
|
||||
language = "zh-CN";
|
||||
} else {
|
||||
language = "en-US";
|
||||
}
|
||||
capabilities["language"] = language;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
module es {
|
||||
export class GraphicsDevice {
|
||||
public graphicsCapabilities: GraphicsCapabilities;
|
||||
|
||||
constructor() {
|
||||
this.setup();
|
||||
this.graphicsCapabilities = new GraphicsCapabilities();
|
||||
this.graphicsCapabilities.initialize(this);
|
||||
}
|
||||
|
||||
private _viewport: Viewport;
|
||||
|
||||
public get viewport(): Viewport {
|
||||
return this._viewport;
|
||||
}
|
||||
|
||||
private setup() {
|
||||
this._viewport = new Viewport(0, 0, Core._instance.stage.stageWidth, Core._instance.stage.stageHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
module es {
|
||||
export class PostProcessor {
|
||||
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" +
|
||||
"}";
|
||||
public enabled: boolean;
|
||||
public effect: egret.Filter;
|
||||
public scene: Scene;
|
||||
public shape: egret.Shape;
|
||||
|
||||
constructor(effect: egret.Filter = null) {
|
||||
this.enabled = true;
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public onAddedToScene(scene: Scene) {
|
||||
this.scene = scene;
|
||||
this.shape = new egret.Shape();
|
||||
this.shape.graphics.beginFill(0xFFFFFF, 1);
|
||||
this.shape.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height);
|
||||
this.shape.graphics.endFill();
|
||||
scene.addChild(this.shape);
|
||||
}
|
||||
|
||||
public process() {
|
||||
this.drawFullscreenQuad();
|
||||
}
|
||||
|
||||
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
|
||||
}
|
||||
|
||||
public unload() {
|
||||
if (this.effect) {
|
||||
this.effect = null;
|
||||
}
|
||||
|
||||
this.scene.removeChild(this.shape);
|
||||
this.scene = null;
|
||||
}
|
||||
|
||||
protected drawFullscreenQuad() {
|
||||
this.scene.filters = [this.effect];
|
||||
// this.shape.filters = [this.effect];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
module es {
|
||||
export class GaussianBlurPostProcessor extends PostProcessor {
|
||||
public onAddedToScene(scene: Scene) {
|
||||
super.onAddedToScene(scene);
|
||||
this.effect = new GaussianBlurEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
module es {
|
||||
export class PolyLight extends RenderableComponent {
|
||||
public power: number;
|
||||
private _lightEffect;
|
||||
private _indices: number[] = [];
|
||||
|
||||
constructor(radius: number, color: number, power: number) {
|
||||
super();
|
||||
|
||||
this.radius = radius;
|
||||
this.power = power;
|
||||
this.color = color;
|
||||
this.computeTriangleIndices();
|
||||
}
|
||||
|
||||
protected _radius: number;
|
||||
|
||||
public get radius() {
|
||||
return this._radius;
|
||||
}
|
||||
|
||||
public set radius(value: number) {
|
||||
this.setRadius(value);
|
||||
}
|
||||
|
||||
public setRadius(radius: number) {
|
||||
if (radius != this._radius) {
|
||||
this._radius = radius;
|
||||
this._areBoundsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public render(camera: Camera) {
|
||||
}
|
||||
|
||||
public reset() {
|
||||
|
||||
}
|
||||
|
||||
private computeTriangleIndices(totalTris: number = 20) {
|
||||
this._indices.length = 0;
|
||||
|
||||
for (let i = 0; i < totalTris; i += 2) {
|
||||
this._indices.push(0);
|
||||
this._indices.push(i + 2);
|
||||
this._indices.push(i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
module es {
|
||||
/**
|
||||
* 除了一个渲染层,只渲染所有的渲染器。
|
||||
* 当与RenderLayerRenderer一起使用时,将UI渲染与游戏的其他部分分离开来。
|
||||
*/
|
||||
export class RenderLayerExcludeRenderer extends Renderer {
|
||||
public excludedRenderLayers: number[];
|
||||
|
||||
constructor(renderOrder: number, ...excludedRenderLayers: number[]){
|
||||
super(renderOrder, null);
|
||||
this.excludedRenderLayers = excludedRenderLayers;
|
||||
}
|
||||
|
||||
public render(scene: es.Scene) {
|
||||
let cam = this.camera ? this.camera : scene.camera;
|
||||
this.beginRender(cam);
|
||||
|
||||
for (let i = 0; i < scene.renderableComponents.count; i ++) {
|
||||
let renderable = scene.renderableComponents.buffer[i];
|
||||
if (!this.excludedRenderLayers.contains(renderable.renderLayer) && renderable.enabled &&
|
||||
renderable.isVisibleFromCamera(cam))
|
||||
this.renderAfterStateCheck(renderable, cam);
|
||||
}
|
||||
|
||||
if (this.shouldDebugRender && Core.debugRenderEndabled)
|
||||
this.debugRender(scene, cam);
|
||||
}
|
||||
|
||||
protected debugRender(scene: es.Scene, cam: es.Camera) {
|
||||
for (let i = 0; i < scene.renderableComponents.count; i ++){
|
||||
let renderable = scene.renderableComponents.buffer[i];
|
||||
if (!this.excludedRenderLayers.contains(renderable.renderLayer) && renderable.enabled &&
|
||||
renderable.isVisibleFromCamera(cam))
|
||||
renderable.debugRender(cam);
|
||||
}
|
||||
|
||||
super.debugRender(scene, cam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,23 +13,12 @@ module es {
|
||||
* 指定场景调用渲染器的顺序
|
||||
*/
|
||||
public readonly renderOrder: number = 0;
|
||||
/**
|
||||
* 如果renderTarget不是null,这个渲染器将渲染到渲染目标而不是屏幕
|
||||
*/
|
||||
public renderTexture: egret.RenderTexture;
|
||||
/**
|
||||
* 这个渲染器的标志,决定它是否应该调试渲染。
|
||||
* render方法接收一个bool (debugRenderEnabled),让渲染器知道全局调试渲染是否打开/关闭。
|
||||
* 渲染器然后使用本地bool来决定它是否应该调试渲染。
|
||||
*/
|
||||
public shouldDebugRender: boolean = true;
|
||||
/**
|
||||
* 如果为true,场景将使用场景渲染目标调用setRenderTarget。
|
||||
* 如果渲染器有渲染纹理,默认实现返回true
|
||||
*/
|
||||
public get wantsToRenderToSceneRenderTarget(): boolean{
|
||||
return !!this.renderTexture;
|
||||
}
|
||||
|
||||
protected constructor(renderOrder: number, camera: Camera = null) {
|
||||
this.camera = camera;
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
module es {
|
||||
/**
|
||||
* 渲染器使用自己的不移动的摄像机进行渲染。
|
||||
*/
|
||||
export class ScreenSpaceRenderer extends Renderer {
|
||||
public renderLayers: number[];
|
||||
|
||||
constructor(renderOrder: number, ...renderLayers: number[]){
|
||||
super(renderOrder, null);
|
||||
renderLayers.sort();
|
||||
renderLayers.reverse();
|
||||
this.renderLayers = renderLayers;
|
||||
}
|
||||
|
||||
public render(scene: Scene) {
|
||||
this.beginRender(this.camera);
|
||||
|
||||
for (let i = 0; i < this.renderLayers.length; i ++){
|
||||
let renderables = scene.renderableComponents.componentsWithRenderLayer(this.renderLayers[i]);
|
||||
for (let j = 0; j < renderables.length; j ++){
|
||||
let renderable = renderables[j];
|
||||
if (renderable.enabled && renderable.isVisibleFromCamera(this.camera))
|
||||
this.renderAfterStateCheck(renderable, this.camera);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shouldDebugRender && Core.debugRenderEndabled)
|
||||
this.debugRender(scene, this.camera);
|
||||
}
|
||||
|
||||
protected debugRender(scene: es.Scene, cam: es.Camera) {
|
||||
for (let i = 0; i < this.renderLayers.length; i ++){
|
||||
let renderables = scene.renderableComponents.componentsWithRenderLayer(this.renderLayers[i]);
|
||||
for (let j = 0; j < renderables.length; j ++){
|
||||
let entity = renderables[j];
|
||||
if (entity.enabled)
|
||||
entity.debugRender(cam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
|
||||
super.onSceneBackBufferSizeChanged(newWidth, newHeight);
|
||||
|
||||
if (!this.camera)
|
||||
this.camera = Core.scene.createEntity("screenspace camera").addComponent(new Camera());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
module es {
|
||||
export class GaussianBlur {
|
||||
/**
|
||||
* 创建一个新的纹理,它是原始纹理的高斯模糊版本
|
||||
* @param image
|
||||
* @param deviation 偏差
|
||||
* @returns 模糊的纹理
|
||||
*/
|
||||
public static createBlurredTexture(image: egret.Texture, deviation: number = 1) {
|
||||
let pixelData = image.getPixels(0, 0, image.textureWidth, image.textureHeight);
|
||||
let srcData: Color[] = new Array(image.textureWidth * image.textureHeight);
|
||||
for (let i = 0; i < image.textureWidth; i++) {
|
||||
for (let j = 0; j < image.textureHeight; j++) {
|
||||
let width = image.textureWidth;
|
||||
let r = pixelData[i * 4 + j * width];
|
||||
let g = pixelData[i * 4 + j * width + 1];
|
||||
let b = pixelData[i * 4 + j * width + 2];
|
||||
let a = pixelData[i * 4 + j * width + 3];
|
||||
srcData[i + j * width] = new Color(r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 计算方式有问题 后面再研究研究
|
||||
let destData = this.createBlurredTextureData(srcData, image.textureWidth, image.textureHeight, deviation);
|
||||
let arrayBuffer = new ArrayBuffer(destData.length);
|
||||
destData.forEach((value, index) => {
|
||||
arrayBuffer[index] = value.packedValue;
|
||||
});
|
||||
egret.BitmapData.create("arraybuffer", arrayBuffer, (bitmapData) => {
|
||||
// TODO: 生成bitmapdata
|
||||
});
|
||||
}
|
||||
|
||||
public static createBlurredTextureData(srcData: Color[], width: number, height: number, deviation: number = 1) {
|
||||
let matrixR = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
let matrixG = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
let matrixB = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
let matrixA = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
|
||||
let destData: Color[] = new Array(width * height);
|
||||
|
||||
// 首先,我们计算出灰度,并将其存储在矩阵中
|
||||
for (let i = 0; i < width; i++) {
|
||||
for (let j = 0; j < height; j++) {
|
||||
matrixR.add({ x: i, y: j }, srcData[i + j * width].r);
|
||||
matrixG.add({ x: i, y: j }, srcData[i + j * width].g);
|
||||
matrixB.add({ x: i, y: j }, srcData[i + j * width].b);
|
||||
matrixA.add({ x: i, y: j }, srcData[i + j * width].a);
|
||||
}
|
||||
}
|
||||
|
||||
matrixR = this.gaussianConvolution(matrixR, deviation);
|
||||
matrixG = this.gaussianConvolution(matrixG, deviation);
|
||||
matrixB = this.gaussianConvolution(matrixB, deviation);
|
||||
matrixA = this.gaussianConvolution(matrixA, deviation);
|
||||
|
||||
for (let i = 0; i < width; i++) {
|
||||
for (let j = 0; j < height; j++) {
|
||||
let r = Math.min(255, matrixR.tryGetValue({x: i, y: j}));
|
||||
let g = Math.min(255, matrixG.tryGetValue({x: i, y: j}));
|
||||
let b = Math.min(255, matrixB.tryGetValue({x: i, y: j}));
|
||||
let a = Math.min(255, matrixA.tryGetValue({x: i, y: j}));
|
||||
destData[i + j * width] = new Color(r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
return destData;
|
||||
}
|
||||
|
||||
public static gaussianConvolution(matrix: FasterDictionary<{ x: number, y: number }, number>, deviation: number) {
|
||||
let kernel = this.calculateNormalized1DSampleKernel(deviation);
|
||||
let res1 = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
let res2 = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
|
||||
for (let i = 0; i < matrix._valuesInfo.length; i++) {
|
||||
for (let j = 0; j < matrix.valuesArray.length; j++)
|
||||
res1.add({ x: i, y: j }, this.processPoint(matrix, i, j, kernel, 0));
|
||||
}
|
||||
|
||||
for (let i = 0; i < matrix._valuesInfo.length; i++) {
|
||||
for (let j = 0; j < matrix.valuesArray.length; j++)
|
||||
res2.add({ x: i, y: j }, this.processPoint(res1, i, j, kernel, 1));
|
||||
}
|
||||
|
||||
return res2;
|
||||
}
|
||||
|
||||
public static processPoint(matrix: FasterDictionary<{ x: number, y: number }, number>,
|
||||
x: number,
|
||||
y: number,
|
||||
kernel: FasterDictionary<{ x: number, y: number }, number>,
|
||||
direction: number) {
|
||||
let res = 0;
|
||||
let half = kernel._valuesInfo.length / 2;
|
||||
for (let i = 0; i < kernel._valuesInfo.length; i++) {
|
||||
let cox = direction == 0 ? x + i - half : x;
|
||||
let coy = direction == 1 ? y + i - half : y;
|
||||
if (cox >= 0 && cox < matrix._valuesInfo.length && coy >= 0 && coy < matrix.valuesArray.length)
|
||||
res += matrix.tryGetValue({ x: cox, y: coy }) * kernel.tryGetValue({x: i, y: 0});
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static calculate1DSampleKernel(deviation: number) {
|
||||
let size = Math.ceil(deviation * 3) * 3 + 1;
|
||||
return this.calculate1DSampleKernelOfSize(deviation, size);
|
||||
}
|
||||
|
||||
public static calculate1DSampleKernelOfSize(deviation: number, size: number) {
|
||||
let ret = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
// let sum = 0;
|
||||
|
||||
let half = (size - 1) / 2;
|
||||
for (let i = 0; i < size; i++) {
|
||||
ret.add({x: i, y: 0}, 1 / (Math.sqrt(2 * Math.PI) * deviation) * Math.exp(-(i - half) * (i - half) / (2 * deviation * deviation)));
|
||||
// sum += ret.tryGetValue({x: i, y: 0});
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static calculateNormalized1DSampleKernel(deviation: number) {
|
||||
return this.normalizeMatrix(this.calculate1DSampleKernel(deviation));
|
||||
}
|
||||
|
||||
public static normalizeMatrix(matrix: FasterDictionary<{ x: number, y: number }, number>) {
|
||||
let ret = new FasterDictionary<{ x: number, y: number }, number>();
|
||||
let sum = 0;
|
||||
for (let i = 0; i < ret._valuesInfo.length; i++) {
|
||||
for (let j = 0; j < ret.valuesArray.length; j++) {
|
||||
sum += matrix.tryGetValue({x: i, y: j});
|
||||
}
|
||||
}
|
||||
|
||||
if (sum != 0) {
|
||||
for (let i = 0; i < ret._valuesInfo.length; i++) {
|
||||
for (let j = 0; j < ret.valuesArray.length; j++) {
|
||||
ret.add({x: i, y: j}, matrix.tryGetValue({x: i, y: j}) / sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
///<reference path="./SceneTransition.ts"/>
|
||||
module es {
|
||||
export class FadeTransition extends SceneTransition {
|
||||
public fadeToColor: number = 0x000000;
|
||||
public fadeOutDuration = 0.4;
|
||||
public fadeEaseType: Function = egret.Ease.quadInOut;
|
||||
public delayBeforeFadeInDuration = 0.1;
|
||||
private _mask: egret.Shape;
|
||||
private _alpha: number = 0;
|
||||
|
||||
constructor(sceneLoadAction: Function) {
|
||||
super(sceneLoadAction);
|
||||
this._mask = new egret.Shape();
|
||||
}
|
||||
|
||||
public async onBeginTransition() {
|
||||
if (!this._mask.parent)
|
||||
Core.scene.stage.addChild(this._mask);
|
||||
|
||||
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
||||
this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height);
|
||||
this._mask.graphics.endFill();
|
||||
|
||||
egret.Tween.get(this).to({_alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType)
|
||||
.call(async () => {
|
||||
await this.loadNextScene();
|
||||
}).wait(this.delayBeforeFadeInDuration).call(() => {
|
||||
egret.Tween.get(this).to({_alpha: 0}, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => {
|
||||
this.transitionComplete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected transitionComplete(){
|
||||
super.transitionComplete();
|
||||
|
||||
if (this._mask.parent)
|
||||
this._mask.parent.removeChild(this._mask);
|
||||
}
|
||||
|
||||
public render() {
|
||||
this._mask.graphics.clear();
|
||||
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
|
||||
this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height);
|
||||
this._mask.graphics.endFill();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,17 +45,6 @@ module es {
|
||||
this.transitionComplete();
|
||||
}
|
||||
|
||||
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
let start = reverseDirection ? 1 : 0;
|
||||
let end = reverseDirection ? 0 : 1;
|
||||
|
||||
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected transitionComplete() {
|
||||
Core._instance._sceneTransition = null;
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
module es {
|
||||
export class WindTransition extends SceneTransition {
|
||||
public duration = 1;
|
||||
public easeType = egret.Ease.quadOut;
|
||||
private _mask: egret.Shape;
|
||||
private _windEffect: egret.CustomFilter;
|
||||
|
||||
constructor(sceneLoadAction: Function) {
|
||||
super(sceneLoadAction);
|
||||
|
||||
let vertexSrc = "attribute vec2 aVertexPosition;\n" +
|
||||
"attribute vec2 aTextureCoord;\n" +
|
||||
|
||||
"uniform vec2 projectionVector;\n" +
|
||||
|
||||
"varying vec2 vTextureCoord;\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" +
|
||||
"}";
|
||||
let fragmentSrc = "precision lowp float;\n" +
|
||||
"varying vec2 vTextureCoord;\n" +
|
||||
"uniform sampler2D uSampler;\n" +
|
||||
"uniform float _progress;\n" +
|
||||
"uniform float _size;\n" +
|
||||
"uniform float _windSegments;\n" +
|
||||
|
||||
"void main(void) {\n" +
|
||||
"vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" +
|
||||
"float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" +
|
||||
"float r = x - floor(x);\n" +
|
||||
"float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" +
|
||||
"vec4 fg = texture2D(uSampler, vTextureCoord);\n" +
|
||||
"gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" +
|
||||
"}";
|
||||
|
||||
this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, {
|
||||
_progress: 0,
|
||||
_size: 0.3,
|
||||
_windSegments: 100
|
||||
});
|
||||
|
||||
this._mask = new egret.Shape();
|
||||
this._mask.graphics.beginFill(0xFFFFFF, 1);
|
||||
this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height);
|
||||
this._mask.graphics.endFill();
|
||||
this._mask.filters = [this._windEffect];
|
||||
Core.scene.stage.addChild(this._mask);
|
||||
}
|
||||
|
||||
public set windSegments(value: number) {
|
||||
this._windEffect.uniforms._windSegments = value;
|
||||
}
|
||||
|
||||
public set size(value: number) {
|
||||
this._windEffect.uniforms._size = value;
|
||||
}
|
||||
|
||||
public async onBeginTransition() {
|
||||
this.loadNextScene();
|
||||
await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType);
|
||||
this.transitionComplete();
|
||||
}
|
||||
|
||||
protected transitionComplete() {
|
||||
super.transitionComplete();
|
||||
|
||||
if (this._mask.parent)
|
||||
this._mask.parent.removeChild(this._mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user