shader
This commit is contained in:
42
demo/libs/framework/framework.d.ts
vendored
42
demo/libs/framework/framework.d.ts
vendored
@@ -407,6 +407,7 @@ declare abstract class RenderableComponent extends Component implements IRendera
|
|||||||
protected _areBoundsDirty: boolean;
|
protected _areBoundsDirty: boolean;
|
||||||
protected _bounds: Rectangle;
|
protected _bounds: Rectangle;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
|
color: number;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly height: number;
|
readonly height: number;
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
@@ -619,31 +620,21 @@ declare class Time {
|
|||||||
static update(currentTime: number): void;
|
static update(currentTime: number): void;
|
||||||
}
|
}
|
||||||
declare class GaussianBlurEffect extends egret.CustomFilter {
|
declare class GaussianBlurEffect extends egret.CustomFilter {
|
||||||
|
private static blur_frag;
|
||||||
|
constructor();
|
||||||
|
}
|
||||||
|
declare class PolygonLightEffect extends egret.CustomFilter {
|
||||||
private static vertSrc;
|
private static vertSrc;
|
||||||
private static fragmentSrc;
|
private static fragmentSrc;
|
||||||
private _sampleWeights;
|
|
||||||
private _verticalSampleOffsets;
|
|
||||||
private _horizontalSampleOffsets;
|
|
||||||
private _blurAmount;
|
|
||||||
private _horizontalBlurDelta;
|
|
||||||
private _verticalBlurDelta;
|
|
||||||
private _sampleCount;
|
|
||||||
blurAmount: number;
|
|
||||||
horizontalBlurDelta: number;
|
|
||||||
verticalBlurDelta: number;
|
|
||||||
constructor();
|
constructor();
|
||||||
prepareForHorizontalBlur(): void;
|
|
||||||
prepareForVerticalBlur(): void;
|
|
||||||
private calculateSampleWeights;
|
|
||||||
private setBlurEffectParameters;
|
|
||||||
private computeGaussian;
|
|
||||||
}
|
}
|
||||||
declare class PostProcessor {
|
declare class PostProcessor {
|
||||||
enable: boolean;
|
enable: boolean;
|
||||||
effect: egret.CustomFilter;
|
effect: egret.Filter;
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
shape: egret.Shape;
|
shape: egret.Shape;
|
||||||
constructor(effect?: egret.CustomFilter);
|
static default_vert: string;
|
||||||
|
constructor(effect?: egret.Filter);
|
||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
process(): void;
|
process(): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
@@ -661,12 +652,7 @@ declare class BloomSettings {
|
|||||||
static presetSettings: BloomSettings[];
|
static presetSettings: BloomSettings[];
|
||||||
}
|
}
|
||||||
declare class GaussianBlurPostProcessor extends PostProcessor {
|
declare class GaussianBlurPostProcessor extends PostProcessor {
|
||||||
private _renderTargetScale;
|
|
||||||
renderTargetScale: number;
|
|
||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
|
||||||
private updateEffectDeltas;
|
|
||||||
process(): void;
|
|
||||||
}
|
}
|
||||||
declare abstract class Renderer {
|
declare abstract class Renderer {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
@@ -689,6 +675,18 @@ interface IRenderable {
|
|||||||
declare class ScreenSpaceRenderer extends Renderer {
|
declare class ScreenSpaceRenderer extends Renderer {
|
||||||
render(scene: Scene): void;
|
render(scene: Scene): void;
|
||||||
}
|
}
|
||||||
|
declare class PolyLight extends RenderableComponent {
|
||||||
|
power: number;
|
||||||
|
protected _radius: number;
|
||||||
|
private _lightEffect;
|
||||||
|
private _indices;
|
||||||
|
readonly bounds: Rectangle;
|
||||||
|
radius: number;
|
||||||
|
constructor(radius: number, color: number, power: number);
|
||||||
|
private computeTriangleIndices;
|
||||||
|
setRadius(radius: number): void;
|
||||||
|
render(camera: Camera): void;
|
||||||
|
}
|
||||||
declare abstract class SceneTransition {
|
declare abstract class SceneTransition {
|
||||||
private _hasPreviousSceneRender;
|
private _hasPreviousSceneRender;
|
||||||
loadsNewScene: boolean;
|
loadsNewScene: boolean;
|
||||||
|
|||||||
@@ -1993,6 +1993,7 @@ var RenderableComponent = (function (_super) {
|
|||||||
_this._areBoundsDirty = true;
|
_this._areBoundsDirty = true;
|
||||||
_this._bounds = new Rectangle();
|
_this._bounds = new Rectangle();
|
||||||
_this._localOffset = Vector2.zero;
|
_this._localOffset = Vector2.zero;
|
||||||
|
_this.color = 0x000000;
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
Object.defineProperty(RenderableComponent.prototype, "width", {
|
Object.defineProperty(RenderableComponent.prototype, "width", {
|
||||||
@@ -3006,94 +3007,52 @@ var Time = (function () {
|
|||||||
var GaussianBlurEffect = (function (_super) {
|
var GaussianBlurEffect = (function (_super) {
|
||||||
__extends(GaussianBlurEffect, _super);
|
__extends(GaussianBlurEffect, _super);
|
||||||
function GaussianBlurEffect() {
|
function GaussianBlurEffect() {
|
||||||
var _this = _super.call(this, GaussianBlurEffect.vertSrc, GaussianBlurEffect.fragmentSrc) || this;
|
return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, {
|
||||||
_this._blurAmount = 2;
|
screenWidth: SceneManager.stage.stageWidth,
|
||||||
_this._horizontalBlurDelta = 0.01;
|
screenHeight: SceneManager.stage.stageHeight
|
||||||
_this._verticalBlurDelta = 0.01;
|
}) || this;
|
||||||
_this._sampleCount = 15;
|
|
||||||
_this._sampleWeights = [];
|
|
||||||
_this._verticalSampleOffsets = [];
|
|
||||||
_this._horizontalSampleOffsets = [];
|
|
||||||
_this._verticalSampleOffsets[0] = Vector2.zero;
|
|
||||||
_this._horizontalSampleOffsets[0] = Vector2.zero;
|
|
||||||
_this.calculateSampleWeights();
|
|
||||||
_this.setBlurEffectParameters(_this._horizontalBlurDelta, 0, _this._horizontalSampleOffsets);
|
|
||||||
_this.prepareForHorizontalBlur();
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
Object.defineProperty(GaussianBlurEffect.prototype, "blurAmount", {
|
GaussianBlurEffect.blur_frag = "precision mediump float;\n" +
|
||||||
get: function () {
|
"uniform sampler2D uSampler;\n" +
|
||||||
return this._blurAmount;
|
"uniform float screenWidth;\n" +
|
||||||
},
|
"uniform float screenHeight;\n" +
|
||||||
set: function (value) {
|
"float normpdf(in float x, in float sigma)\n" +
|
||||||
if (this._blurAmount != value) {
|
"{\n" +
|
||||||
if (value == 0)
|
"return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
|
||||||
value = 0.001;
|
"}\n" +
|
||||||
this._blurAmount = value;
|
"void main()\n" +
|
||||||
this.calculateSampleWeights();
|
"{\n" +
|
||||||
}
|
"vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||||
},
|
"const int mSize = 11;\n" +
|
||||||
enumerable: true,
|
"const int kSize = (mSize - 1)/2;\n" +
|
||||||
configurable: true
|
"float kernel[mSize];\n" +
|
||||||
});
|
"vec3 final_colour = vec3(0.0);\n" +
|
||||||
Object.defineProperty(GaussianBlurEffect.prototype, "horizontalBlurDelta", {
|
"float sigma = 7.0;\n" +
|
||||||
get: function () {
|
"float z = 0.0;\n" +
|
||||||
return this._horizontalBlurDelta;
|
"for (int j = 0; j <= kSize; ++j)\n" +
|
||||||
},
|
"{\n" +
|
||||||
set: function (value) {
|
"kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
|
||||||
if (value != this._horizontalBlurDelta) {
|
"}\n" +
|
||||||
this._horizontalBlurDelta = value;
|
"for (int j = 0; j < mSize; ++j)\n" +
|
||||||
this.setBlurEffectParameters(this._horizontalBlurDelta, 0, this._horizontalSampleOffsets);
|
"{\n" +
|
||||||
}
|
"z += kernel[j];\n" +
|
||||||
},
|
"}\n" +
|
||||||
enumerable: true,
|
"for (int i = -kSize; i <= kSize; ++i)\n" +
|
||||||
configurable: true
|
"{\n" +
|
||||||
});
|
"for (int j = -kSize; j <= kSize; ++j)\n" +
|
||||||
Object.defineProperty(GaussianBlurEffect.prototype, "verticalBlurDelta", {
|
"{\n" +
|
||||||
get: function () {
|
"final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||||
return this._verticalBlurDelta;
|
"}\n}\n" +
|
||||||
},
|
"gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
|
||||||
set: function (value) {
|
"}";
|
||||||
if (value != this._verticalBlurDelta) {
|
return GaussianBlurEffect;
|
||||||
this._verticalBlurDelta = value;
|
}(egret.CustomFilter));
|
||||||
this.setBlurEffectParameters(0, this._verticalBlurDelta, this._verticalSampleOffsets);
|
var PolygonLightEffect = (function (_super) {
|
||||||
}
|
__extends(PolygonLightEffect, _super);
|
||||||
},
|
function PolygonLightEffect() {
|
||||||
enumerable: true,
|
return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this;
|
||||||
configurable: true
|
}
|
||||||
});
|
PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" +
|
||||||
GaussianBlurEffect.prototype.prepareForHorizontalBlur = function () {
|
|
||||||
this.uniforms._sampleOffsets = this._horizontalSampleOffsets;
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.prepareForVerticalBlur = function () {
|
|
||||||
this.uniforms._sampleOffsets = this._verticalSampleOffsets;
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.calculateSampleWeights = function () {
|
|
||||||
this._sampleWeights[0] = this.computeGaussian(0);
|
|
||||||
var totalWeights = this._sampleWeights[0];
|
|
||||||
for (var i = 0; i < this._sampleCount / 2; i++) {
|
|
||||||
var weight = this.computeGaussian(i + 1);
|
|
||||||
this._sampleWeights[i * 2 + 1] = weight;
|
|
||||||
this._sampleWeights[i * 2 + 2] = weight;
|
|
||||||
totalWeights += weight * 2;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < this._sampleWeights.length; i++) {
|
|
||||||
this._sampleWeights[i] /= totalWeights;
|
|
||||||
}
|
|
||||||
this.uniforms._sampleWeights = this._sampleWeights;
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.setBlurEffectParameters = function (dx, dy, offsets) {
|
|
||||||
for (var i = 0; i < this._sampleCount / 2; i++) {
|
|
||||||
var sampleOffset = i * 2 + 1.5;
|
|
||||||
var delta = Vector2.multiply(new Vector2(dx, dy), new Vector2(sampleOffset));
|
|
||||||
offsets[i * 2 + 1] = delta;
|
|
||||||
offsets[i * 2 + 2] = new Vector2(-delta);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.computeGaussian = function (n) {
|
|
||||||
return ((1 / Math.sqrt(2 * Math.PI * this._blurAmount)) * Math.exp(-(n * n) / (2 * this._blurAmount * this._blurAmount)));
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.vertSrc = "attribute vec2 aVertexPosition;\n" +
|
|
||||||
"attribute vec2 aTextureCoord;\n" +
|
"attribute vec2 aTextureCoord;\n" +
|
||||||
"uniform vec2 projectionVector;\n" +
|
"uniform vec2 projectionVector;\n" +
|
||||||
"varying vec2 vTextureCoord;\n" +
|
"varying vec2 vTextureCoord;\n" +
|
||||||
@@ -3102,7 +3061,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
||||||
" vTextureCoord = aTextureCoord;\n" +
|
" vTextureCoord = aTextureCoord;\n" +
|
||||||
"}";
|
"}";
|
||||||
GaussianBlurEffect.fragmentSrc = "precision lowp float;\n" +
|
PolygonLightEffect.fragmentSrc = "precision lowp float;\n" +
|
||||||
"varying vec2 vTextureCoord;\n" +
|
"varying vec2 vTextureCoord;\n" +
|
||||||
"uniform sampler2D uSampler;\n" +
|
"uniform sampler2D uSampler;\n" +
|
||||||
"#define SAMPLE_COUNT 15\n" +
|
"#define SAMPLE_COUNT 15\n" +
|
||||||
@@ -3114,7 +3073,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
" c += texture2D( uSampler, vTextureCoord + _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 PolygonLightEffect;
|
||||||
}(egret.CustomFilter));
|
}(egret.CustomFilter));
|
||||||
var PostProcessor = (function () {
|
var PostProcessor = (function () {
|
||||||
function PostProcessor(effect) {
|
function PostProcessor(effect) {
|
||||||
@@ -3135,7 +3094,7 @@ var PostProcessor = (function () {
|
|||||||
};
|
};
|
||||||
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
||||||
PostProcessor.prototype.drawFullscreenQuad = function () {
|
PostProcessor.prototype.drawFullscreenQuad = function () {
|
||||||
this.shape.filters = [this.effect];
|
this.scene.filters = [this.effect];
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.unload = function () {
|
PostProcessor.prototype.unload = function () {
|
||||||
if (this.effect) {
|
if (this.effect) {
|
||||||
@@ -3144,6 +3103,18 @@ var PostProcessor = (function () {
|
|||||||
this.scene.removeChild(this.shape);
|
this.scene.removeChild(this.shape);
|
||||||
this.scene = null;
|
this.scene = null;
|
||||||
};
|
};
|
||||||
|
PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" +
|
||||||
|
"attribute vec2 aTextureCoord;\n" +
|
||||||
|
"attribute vec2 aColor;\n" +
|
||||||
|
"uniform vec2 projectionVector;\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" +
|
||||||
|
"}";
|
||||||
return PostProcessor;
|
return PostProcessor;
|
||||||
}());
|
}());
|
||||||
var BloomSettings = (function () {
|
var BloomSettings = (function () {
|
||||||
@@ -3168,42 +3139,12 @@ var BloomSettings = (function () {
|
|||||||
var GaussianBlurPostProcessor = (function (_super) {
|
var GaussianBlurPostProcessor = (function (_super) {
|
||||||
__extends(GaussianBlurPostProcessor, _super);
|
__extends(GaussianBlurPostProcessor, _super);
|
||||||
function GaussianBlurPostProcessor() {
|
function GaussianBlurPostProcessor() {
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
_this._renderTargetScale = 1;
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
Object.defineProperty(GaussianBlurPostProcessor.prototype, "renderTargetScale", {
|
|
||||||
get: function () {
|
|
||||||
return this._renderTargetScale;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
if (this._renderTargetScale != value) {
|
|
||||||
this._renderTargetScale = value;
|
|
||||||
this.updateEffectDeltas();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) {
|
GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) {
|
||||||
_super.prototype.onAddedToScene.call(this, scene);
|
_super.prototype.onAddedToScene.call(this, scene);
|
||||||
this.effect = new GaussianBlurEffect();
|
this.effect = new GaussianBlurEffect();
|
||||||
};
|
};
|
||||||
GaussianBlurPostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) {
|
|
||||||
this.updateEffectDeltas();
|
|
||||||
};
|
|
||||||
GaussianBlurPostProcessor.prototype.updateEffectDeltas = function () {
|
|
||||||
var effect = this.effect;
|
|
||||||
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
|
||||||
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
|
||||||
};
|
|
||||||
GaussianBlurPostProcessor.prototype.process = function () {
|
|
||||||
var effect = this.effect;
|
|
||||||
effect.prepareForHorizontalBlur();
|
|
||||||
this.drawFullscreenQuad();
|
|
||||||
effect.prepareForVerticalBlur();
|
|
||||||
this.drawFullscreenQuad();
|
|
||||||
};
|
|
||||||
return GaussianBlurPostProcessor;
|
return GaussianBlurPostProcessor;
|
||||||
}(PostProcessor));
|
}(PostProcessor));
|
||||||
var Renderer = (function () {
|
var Renderer = (function () {
|
||||||
@@ -3248,6 +3189,57 @@ var ScreenSpaceRenderer = (function (_super) {
|
|||||||
};
|
};
|
||||||
return ScreenSpaceRenderer;
|
return ScreenSpaceRenderer;
|
||||||
}(Renderer));
|
}(Renderer));
|
||||||
|
var PolyLight = (function (_super) {
|
||||||
|
__extends(PolyLight, _super);
|
||||||
|
function PolyLight(radius, color, power) {
|
||||||
|
var _this = _super.call(this) || this;
|
||||||
|
_this._indices = [];
|
||||||
|
_this.radius = radius;
|
||||||
|
_this.power = power;
|
||||||
|
_this.color = color;
|
||||||
|
_this.computeTriangleIndices();
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
Object.defineProperty(PolyLight.prototype, "bounds", {
|
||||||
|
get: function () {
|
||||||
|
if (this._areBoundsDirty) {
|
||||||
|
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2);
|
||||||
|
this._areBoundsDirty = false;
|
||||||
|
}
|
||||||
|
return this._bounds;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(PolyLight.prototype, "radius", {
|
||||||
|
get: function () {
|
||||||
|
return this._radius;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setRadius(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
PolyLight.prototype.computeTriangleIndices = function (totalTris) {
|
||||||
|
if (totalTris === void 0) { totalTris = 20; }
|
||||||
|
this._indices.length = 0;
|
||||||
|
for (var i = 0; i < totalTris; i += 2) {
|
||||||
|
this._indices.push(0);
|
||||||
|
this._indices.push(i + 2);
|
||||||
|
this._indices.push(i + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PolyLight.prototype.setRadius = function (radius) {
|
||||||
|
if (radius != this._radius) {
|
||||||
|
this._radius = radius;
|
||||||
|
this._areBoundsDirty = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PolyLight.prototype.render = function (camera) {
|
||||||
|
};
|
||||||
|
return PolyLight;
|
||||||
|
}(RenderableComponent));
|
||||||
var SceneTransition = (function () {
|
var SceneTransition = (function () {
|
||||||
function SceneTransition(sceneLoadAction) {
|
function SceneTransition(sceneLoadAction) {
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
this.sceneLoadAction = sceneLoadAction;
|
||||||
|
|||||||
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
42
source/bin/framework.d.ts
vendored
42
source/bin/framework.d.ts
vendored
@@ -407,6 +407,7 @@ declare abstract class RenderableComponent extends Component implements IRendera
|
|||||||
protected _areBoundsDirty: boolean;
|
protected _areBoundsDirty: boolean;
|
||||||
protected _bounds: Rectangle;
|
protected _bounds: Rectangle;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
|
color: number;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly height: number;
|
readonly height: number;
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
@@ -619,31 +620,21 @@ declare class Time {
|
|||||||
static update(currentTime: number): void;
|
static update(currentTime: number): void;
|
||||||
}
|
}
|
||||||
declare class GaussianBlurEffect extends egret.CustomFilter {
|
declare class GaussianBlurEffect extends egret.CustomFilter {
|
||||||
|
private static blur_frag;
|
||||||
|
constructor();
|
||||||
|
}
|
||||||
|
declare class PolygonLightEffect extends egret.CustomFilter {
|
||||||
private static vertSrc;
|
private static vertSrc;
|
||||||
private static fragmentSrc;
|
private static fragmentSrc;
|
||||||
private _sampleWeights;
|
|
||||||
private _verticalSampleOffsets;
|
|
||||||
private _horizontalSampleOffsets;
|
|
||||||
private _blurAmount;
|
|
||||||
private _horizontalBlurDelta;
|
|
||||||
private _verticalBlurDelta;
|
|
||||||
private _sampleCount;
|
|
||||||
blurAmount: number;
|
|
||||||
horizontalBlurDelta: number;
|
|
||||||
verticalBlurDelta: number;
|
|
||||||
constructor();
|
constructor();
|
||||||
prepareForHorizontalBlur(): void;
|
|
||||||
prepareForVerticalBlur(): void;
|
|
||||||
private calculateSampleWeights;
|
|
||||||
private setBlurEffectParameters;
|
|
||||||
private computeGaussian;
|
|
||||||
}
|
}
|
||||||
declare class PostProcessor {
|
declare class PostProcessor {
|
||||||
enable: boolean;
|
enable: boolean;
|
||||||
effect: egret.CustomFilter;
|
effect: egret.Filter;
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
shape: egret.Shape;
|
shape: egret.Shape;
|
||||||
constructor(effect?: egret.CustomFilter);
|
static default_vert: string;
|
||||||
|
constructor(effect?: egret.Filter);
|
||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
process(): void;
|
process(): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
@@ -661,12 +652,7 @@ declare class BloomSettings {
|
|||||||
static presetSettings: BloomSettings[];
|
static presetSettings: BloomSettings[];
|
||||||
}
|
}
|
||||||
declare class GaussianBlurPostProcessor extends PostProcessor {
|
declare class GaussianBlurPostProcessor extends PostProcessor {
|
||||||
private _renderTargetScale;
|
|
||||||
renderTargetScale: number;
|
|
||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
|
||||||
private updateEffectDeltas;
|
|
||||||
process(): void;
|
|
||||||
}
|
}
|
||||||
declare abstract class Renderer {
|
declare abstract class Renderer {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
@@ -689,6 +675,18 @@ interface IRenderable {
|
|||||||
declare class ScreenSpaceRenderer extends Renderer {
|
declare class ScreenSpaceRenderer extends Renderer {
|
||||||
render(scene: Scene): void;
|
render(scene: Scene): void;
|
||||||
}
|
}
|
||||||
|
declare class PolyLight extends RenderableComponent {
|
||||||
|
power: number;
|
||||||
|
protected _radius: number;
|
||||||
|
private _lightEffect;
|
||||||
|
private _indices;
|
||||||
|
readonly bounds: Rectangle;
|
||||||
|
radius: number;
|
||||||
|
constructor(radius: number, color: number, power: number);
|
||||||
|
private computeTriangleIndices;
|
||||||
|
setRadius(radius: number): void;
|
||||||
|
render(camera: Camera): void;
|
||||||
|
}
|
||||||
declare abstract class SceneTransition {
|
declare abstract class SceneTransition {
|
||||||
private _hasPreviousSceneRender;
|
private _hasPreviousSceneRender;
|
||||||
loadsNewScene: boolean;
|
loadsNewScene: boolean;
|
||||||
|
|||||||
@@ -1993,6 +1993,7 @@ var RenderableComponent = (function (_super) {
|
|||||||
_this._areBoundsDirty = true;
|
_this._areBoundsDirty = true;
|
||||||
_this._bounds = new Rectangle();
|
_this._bounds = new Rectangle();
|
||||||
_this._localOffset = Vector2.zero;
|
_this._localOffset = Vector2.zero;
|
||||||
|
_this.color = 0x000000;
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
Object.defineProperty(RenderableComponent.prototype, "width", {
|
Object.defineProperty(RenderableComponent.prototype, "width", {
|
||||||
@@ -3006,94 +3007,52 @@ var Time = (function () {
|
|||||||
var GaussianBlurEffect = (function (_super) {
|
var GaussianBlurEffect = (function (_super) {
|
||||||
__extends(GaussianBlurEffect, _super);
|
__extends(GaussianBlurEffect, _super);
|
||||||
function GaussianBlurEffect() {
|
function GaussianBlurEffect() {
|
||||||
var _this = _super.call(this, GaussianBlurEffect.vertSrc, GaussianBlurEffect.fragmentSrc) || this;
|
return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, {
|
||||||
_this._blurAmount = 2;
|
screenWidth: SceneManager.stage.stageWidth,
|
||||||
_this._horizontalBlurDelta = 0.01;
|
screenHeight: SceneManager.stage.stageHeight
|
||||||
_this._verticalBlurDelta = 0.01;
|
}) || this;
|
||||||
_this._sampleCount = 15;
|
|
||||||
_this._sampleWeights = [];
|
|
||||||
_this._verticalSampleOffsets = [];
|
|
||||||
_this._horizontalSampleOffsets = [];
|
|
||||||
_this._verticalSampleOffsets[0] = Vector2.zero;
|
|
||||||
_this._horizontalSampleOffsets[0] = Vector2.zero;
|
|
||||||
_this.calculateSampleWeights();
|
|
||||||
_this.setBlurEffectParameters(_this._horizontalBlurDelta, 0, _this._horizontalSampleOffsets);
|
|
||||||
_this.prepareForHorizontalBlur();
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
Object.defineProperty(GaussianBlurEffect.prototype, "blurAmount", {
|
GaussianBlurEffect.blur_frag = "precision mediump float;\n" +
|
||||||
get: function () {
|
"uniform sampler2D uSampler;\n" +
|
||||||
return this._blurAmount;
|
"uniform float screenWidth;\n" +
|
||||||
},
|
"uniform float screenHeight;\n" +
|
||||||
set: function (value) {
|
"float normpdf(in float x, in float sigma)\n" +
|
||||||
if (this._blurAmount != value) {
|
"{\n" +
|
||||||
if (value == 0)
|
"return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
|
||||||
value = 0.001;
|
"}\n" +
|
||||||
this._blurAmount = value;
|
"void main()\n" +
|
||||||
this.calculateSampleWeights();
|
"{\n" +
|
||||||
}
|
"vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||||
},
|
"const int mSize = 11;\n" +
|
||||||
enumerable: true,
|
"const int kSize = (mSize - 1)/2;\n" +
|
||||||
configurable: true
|
"float kernel[mSize];\n" +
|
||||||
});
|
"vec3 final_colour = vec3(0.0);\n" +
|
||||||
Object.defineProperty(GaussianBlurEffect.prototype, "horizontalBlurDelta", {
|
"float sigma = 7.0;\n" +
|
||||||
get: function () {
|
"float z = 0.0;\n" +
|
||||||
return this._horizontalBlurDelta;
|
"for (int j = 0; j <= kSize; ++j)\n" +
|
||||||
},
|
"{\n" +
|
||||||
set: function (value) {
|
"kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
|
||||||
if (value != this._horizontalBlurDelta) {
|
"}\n" +
|
||||||
this._horizontalBlurDelta = value;
|
"for (int j = 0; j < mSize; ++j)\n" +
|
||||||
this.setBlurEffectParameters(this._horizontalBlurDelta, 0, this._horizontalSampleOffsets);
|
"{\n" +
|
||||||
}
|
"z += kernel[j];\n" +
|
||||||
},
|
"}\n" +
|
||||||
enumerable: true,
|
"for (int i = -kSize; i <= kSize; ++i)\n" +
|
||||||
configurable: true
|
"{\n" +
|
||||||
});
|
"for (int j = -kSize; j <= kSize; ++j)\n" +
|
||||||
Object.defineProperty(GaussianBlurEffect.prototype, "verticalBlurDelta", {
|
"{\n" +
|
||||||
get: function () {
|
"final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||||
return this._verticalBlurDelta;
|
"}\n}\n" +
|
||||||
},
|
"gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
|
||||||
set: function (value) {
|
"}";
|
||||||
if (value != this._verticalBlurDelta) {
|
return GaussianBlurEffect;
|
||||||
this._verticalBlurDelta = value;
|
}(egret.CustomFilter));
|
||||||
this.setBlurEffectParameters(0, this._verticalBlurDelta, this._verticalSampleOffsets);
|
var PolygonLightEffect = (function (_super) {
|
||||||
}
|
__extends(PolygonLightEffect, _super);
|
||||||
},
|
function PolygonLightEffect() {
|
||||||
enumerable: true,
|
return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this;
|
||||||
configurable: true
|
}
|
||||||
});
|
PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" +
|
||||||
GaussianBlurEffect.prototype.prepareForHorizontalBlur = function () {
|
|
||||||
this.uniforms._sampleOffsets = this._horizontalSampleOffsets;
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.prepareForVerticalBlur = function () {
|
|
||||||
this.uniforms._sampleOffsets = this._verticalSampleOffsets;
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.calculateSampleWeights = function () {
|
|
||||||
this._sampleWeights[0] = this.computeGaussian(0);
|
|
||||||
var totalWeights = this._sampleWeights[0];
|
|
||||||
for (var i = 0; i < this._sampleCount / 2; i++) {
|
|
||||||
var weight = this.computeGaussian(i + 1);
|
|
||||||
this._sampleWeights[i * 2 + 1] = weight;
|
|
||||||
this._sampleWeights[i * 2 + 2] = weight;
|
|
||||||
totalWeights += weight * 2;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < this._sampleWeights.length; i++) {
|
|
||||||
this._sampleWeights[i] /= totalWeights;
|
|
||||||
}
|
|
||||||
this.uniforms._sampleWeights = this._sampleWeights;
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.setBlurEffectParameters = function (dx, dy, offsets) {
|
|
||||||
for (var i = 0; i < this._sampleCount / 2; i++) {
|
|
||||||
var sampleOffset = i * 2 + 1.5;
|
|
||||||
var delta = Vector2.multiply(new Vector2(dx, dy), new Vector2(sampleOffset));
|
|
||||||
offsets[i * 2 + 1] = delta;
|
|
||||||
offsets[i * 2 + 2] = new Vector2(-delta);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.prototype.computeGaussian = function (n) {
|
|
||||||
return ((1 / Math.sqrt(2 * Math.PI * this._blurAmount)) * Math.exp(-(n * n) / (2 * this._blurAmount * this._blurAmount)));
|
|
||||||
};
|
|
||||||
GaussianBlurEffect.vertSrc = "attribute vec2 aVertexPosition;\n" +
|
|
||||||
"attribute vec2 aTextureCoord;\n" +
|
"attribute vec2 aTextureCoord;\n" +
|
||||||
"uniform vec2 projectionVector;\n" +
|
"uniform vec2 projectionVector;\n" +
|
||||||
"varying vec2 vTextureCoord;\n" +
|
"varying vec2 vTextureCoord;\n" +
|
||||||
@@ -3102,7 +3061,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
||||||
" vTextureCoord = aTextureCoord;\n" +
|
" vTextureCoord = aTextureCoord;\n" +
|
||||||
"}";
|
"}";
|
||||||
GaussianBlurEffect.fragmentSrc = "precision lowp float;\n" +
|
PolygonLightEffect.fragmentSrc = "precision lowp float;\n" +
|
||||||
"varying vec2 vTextureCoord;\n" +
|
"varying vec2 vTextureCoord;\n" +
|
||||||
"uniform sampler2D uSampler;\n" +
|
"uniform sampler2D uSampler;\n" +
|
||||||
"#define SAMPLE_COUNT 15\n" +
|
"#define SAMPLE_COUNT 15\n" +
|
||||||
@@ -3114,7 +3073,7 @@ var GaussianBlurEffect = (function (_super) {
|
|||||||
" c += texture2D( uSampler, vTextureCoord + _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 PolygonLightEffect;
|
||||||
}(egret.CustomFilter));
|
}(egret.CustomFilter));
|
||||||
var PostProcessor = (function () {
|
var PostProcessor = (function () {
|
||||||
function PostProcessor(effect) {
|
function PostProcessor(effect) {
|
||||||
@@ -3135,7 +3094,7 @@ var PostProcessor = (function () {
|
|||||||
};
|
};
|
||||||
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
|
||||||
PostProcessor.prototype.drawFullscreenQuad = function () {
|
PostProcessor.prototype.drawFullscreenQuad = function () {
|
||||||
this.shape.filters = [this.effect];
|
this.scene.filters = [this.effect];
|
||||||
};
|
};
|
||||||
PostProcessor.prototype.unload = function () {
|
PostProcessor.prototype.unload = function () {
|
||||||
if (this.effect) {
|
if (this.effect) {
|
||||||
@@ -3144,6 +3103,18 @@ var PostProcessor = (function () {
|
|||||||
this.scene.removeChild(this.shape);
|
this.scene.removeChild(this.shape);
|
||||||
this.scene = null;
|
this.scene = null;
|
||||||
};
|
};
|
||||||
|
PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" +
|
||||||
|
"attribute vec2 aTextureCoord;\n" +
|
||||||
|
"attribute vec2 aColor;\n" +
|
||||||
|
"uniform vec2 projectionVector;\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" +
|
||||||
|
"}";
|
||||||
return PostProcessor;
|
return PostProcessor;
|
||||||
}());
|
}());
|
||||||
var BloomSettings = (function () {
|
var BloomSettings = (function () {
|
||||||
@@ -3168,42 +3139,12 @@ var BloomSettings = (function () {
|
|||||||
var GaussianBlurPostProcessor = (function (_super) {
|
var GaussianBlurPostProcessor = (function (_super) {
|
||||||
__extends(GaussianBlurPostProcessor, _super);
|
__extends(GaussianBlurPostProcessor, _super);
|
||||||
function GaussianBlurPostProcessor() {
|
function GaussianBlurPostProcessor() {
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
_this._renderTargetScale = 1;
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
Object.defineProperty(GaussianBlurPostProcessor.prototype, "renderTargetScale", {
|
|
||||||
get: function () {
|
|
||||||
return this._renderTargetScale;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
if (this._renderTargetScale != value) {
|
|
||||||
this._renderTargetScale = value;
|
|
||||||
this.updateEffectDeltas();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) {
|
GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) {
|
||||||
_super.prototype.onAddedToScene.call(this, scene);
|
_super.prototype.onAddedToScene.call(this, scene);
|
||||||
this.effect = new GaussianBlurEffect();
|
this.effect = new GaussianBlurEffect();
|
||||||
};
|
};
|
||||||
GaussianBlurPostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) {
|
|
||||||
this.updateEffectDeltas();
|
|
||||||
};
|
|
||||||
GaussianBlurPostProcessor.prototype.updateEffectDeltas = function () {
|
|
||||||
var effect = this.effect;
|
|
||||||
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
|
||||||
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
|
||||||
};
|
|
||||||
GaussianBlurPostProcessor.prototype.process = function () {
|
|
||||||
var effect = this.effect;
|
|
||||||
effect.prepareForHorizontalBlur();
|
|
||||||
this.drawFullscreenQuad();
|
|
||||||
effect.prepareForVerticalBlur();
|
|
||||||
this.drawFullscreenQuad();
|
|
||||||
};
|
|
||||||
return GaussianBlurPostProcessor;
|
return GaussianBlurPostProcessor;
|
||||||
}(PostProcessor));
|
}(PostProcessor));
|
||||||
var Renderer = (function () {
|
var Renderer = (function () {
|
||||||
@@ -3248,6 +3189,57 @@ var ScreenSpaceRenderer = (function (_super) {
|
|||||||
};
|
};
|
||||||
return ScreenSpaceRenderer;
|
return ScreenSpaceRenderer;
|
||||||
}(Renderer));
|
}(Renderer));
|
||||||
|
var PolyLight = (function (_super) {
|
||||||
|
__extends(PolyLight, _super);
|
||||||
|
function PolyLight(radius, color, power) {
|
||||||
|
var _this = _super.call(this) || this;
|
||||||
|
_this._indices = [];
|
||||||
|
_this.radius = radius;
|
||||||
|
_this.power = power;
|
||||||
|
_this.color = color;
|
||||||
|
_this.computeTriangleIndices();
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
Object.defineProperty(PolyLight.prototype, "bounds", {
|
||||||
|
get: function () {
|
||||||
|
if (this._areBoundsDirty) {
|
||||||
|
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2);
|
||||||
|
this._areBoundsDirty = false;
|
||||||
|
}
|
||||||
|
return this._bounds;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(PolyLight.prototype, "radius", {
|
||||||
|
get: function () {
|
||||||
|
return this._radius;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setRadius(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
PolyLight.prototype.computeTriangleIndices = function (totalTris) {
|
||||||
|
if (totalTris === void 0) { totalTris = 20; }
|
||||||
|
this._indices.length = 0;
|
||||||
|
for (var i = 0; i < totalTris; i += 2) {
|
||||||
|
this._indices.push(0);
|
||||||
|
this._indices.push(i + 2);
|
||||||
|
this._indices.push(i + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PolyLight.prototype.setRadius = function (radius) {
|
||||||
|
if (radius != this._radius) {
|
||||||
|
this._radius = radius;
|
||||||
|
this._areBoundsDirty = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PolyLight.prototype.render = function (camera) {
|
||||||
|
};
|
||||||
|
return PolyLight;
|
||||||
|
}(RenderableComponent));
|
||||||
var SceneTransition = (function () {
|
var SceneTransition = (function () {
|
||||||
function SceneTransition(sceneLoadAction) {
|
function SceneTransition(sceneLoadAction) {
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
this.sceneLoadAction = sceneLoadAction;
|
||||||
|
|||||||
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
@@ -7,6 +7,8 @@ abstract class RenderableComponent extends Component implements IRenderable {
|
|||||||
protected _bounds: Rectangle = new Rectangle();
|
protected _bounds: Rectangle = new Rectangle();
|
||||||
protected _localOffset: Vector2 = Vector2.zero;
|
protected _localOffset: Vector2 = Vector2.zero;
|
||||||
|
|
||||||
|
public color: number = 0x000000;
|
||||||
|
|
||||||
public get width(){
|
public get width(){
|
||||||
return this.getWidth();
|
return this.getWidth();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,126 +1,72 @@
|
|||||||
class GaussianBlurEffect extends egret.CustomFilter {
|
class GaussianBlurEffect extends egret.CustomFilter {
|
||||||
private static vertSrc = "attribute vec2 aVertexPosition;\n" +
|
// private static blur_frag = "precision mediump float;\n" +
|
||||||
"attribute vec2 aTextureCoord;\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" +
|
||||||
|
// "}";
|
||||||
|
|
||||||
"uniform vec2 projectionVector;\n" +
|
private static blur_frag = "precision mediump float;\n" +
|
||||||
|
"uniform sampler2D uSampler;\n" +
|
||||||
|
"uniform float screenWidth;\n" +
|
||||||
|
"uniform float screenHeight;\n" +
|
||||||
|
|
||||||
"varying vec2 vTextureCoord;\n" +
|
"float normpdf(in float x, in float sigma)\n" +
|
||||||
|
"{\n" +
|
||||||
|
"return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
|
||||||
|
"}\n" +
|
||||||
|
|
||||||
"const vec2 center = vec2(-1.0, 1.0);\n" +
|
"void main()\n" +
|
||||||
|
"{\n" +
|
||||||
|
"vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
|
||||||
|
|
||||||
"void main(void) {\n" +
|
"const int mSize = 11;\n" +
|
||||||
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
"const int kSize = (mSize - 1)/2;\n" +
|
||||||
" vTextureCoord = aTextureCoord;\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" +
|
||||||
"}";
|
"}";
|
||||||
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" +
|
|
||||||
"}";
|
|
||||||
private _sampleWeights: number[];
|
|
||||||
private _verticalSampleOffsets: Vector2[];
|
|
||||||
private _horizontalSampleOffsets: Vector2[];
|
|
||||||
private _blurAmount = 2;
|
|
||||||
private _horizontalBlurDelta = 0.01;
|
|
||||||
private _verticalBlurDelta = 0.01;
|
|
||||||
private _sampleCount: number = 15;
|
|
||||||
|
|
||||||
public get blurAmount(){
|
|
||||||
return this._blurAmount;
|
|
||||||
}
|
|
||||||
public set blurAmount(value: number){
|
|
||||||
if (this._blurAmount != value){
|
|
||||||
if (value == 0)
|
|
||||||
value = 0.001;
|
|
||||||
|
|
||||||
this._blurAmount = value;
|
|
||||||
this.calculateSampleWeights();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public get horizontalBlurDelta(){
|
|
||||||
return this._horizontalBlurDelta;
|
|
||||||
}
|
|
||||||
public set horizontalBlurDelta(value: number){
|
|
||||||
if (value != this._horizontalBlurDelta){
|
|
||||||
this._horizontalBlurDelta = value;
|
|
||||||
this.setBlurEffectParameters(this._horizontalBlurDelta, 0, this._horizontalSampleOffsets);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public get verticalBlurDelta(){
|
|
||||||
return this._verticalBlurDelta;
|
|
||||||
}
|
|
||||||
public set verticalBlurDelta(value: number){
|
|
||||||
if (value != this._verticalBlurDelta){
|
|
||||||
this._verticalBlurDelta = value;
|
|
||||||
this.setBlurEffectParameters(0, this._verticalBlurDelta, this._verticalSampleOffsets);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(){
|
constructor(){
|
||||||
super(GaussianBlurEffect.vertSrc, GaussianBlurEffect.fragmentSrc);
|
super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{
|
||||||
|
screenWidth: SceneManager.stage.stageWidth,
|
||||||
this._sampleWeights = [];
|
screenHeight: SceneManager.stage.stageHeight
|
||||||
this._verticalSampleOffsets = [];
|
});
|
||||||
this._horizontalSampleOffsets = [];
|
|
||||||
|
|
||||||
this._verticalSampleOffsets[0] = Vector2.zero;
|
|
||||||
this._horizontalSampleOffsets[0] = Vector2.zero;
|
|
||||||
|
|
||||||
this.calculateSampleWeights();
|
|
||||||
this.setBlurEffectParameters(this._horizontalBlurDelta, 0, this._horizontalSampleOffsets);
|
|
||||||
this.prepareForHorizontalBlur();
|
|
||||||
}
|
|
||||||
|
|
||||||
public prepareForHorizontalBlur(){
|
|
||||||
this.uniforms._sampleOffsets = this._horizontalSampleOffsets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public prepareForVerticalBlur(){
|
|
||||||
this.uniforms._sampleOffsets = this._verticalSampleOffsets;
|
|
||||||
}
|
|
||||||
|
|
||||||
private calculateSampleWeights(){
|
|
||||||
this._sampleWeights[0] = this.computeGaussian(0);
|
|
||||||
let totalWeights = this._sampleWeights[0];
|
|
||||||
|
|
||||||
for (let i = 0; i < this._sampleCount / 2; i ++){
|
|
||||||
let weight = this.computeGaussian(i + 1);
|
|
||||||
this._sampleWeights[i * 2 + 1] = weight;
|
|
||||||
this._sampleWeights[i * 2 + 2] = weight;
|
|
||||||
|
|
||||||
totalWeights += weight * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < this._sampleWeights.length; i ++){
|
|
||||||
this._sampleWeights[i] /= totalWeights;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.uniforms._sampleWeights = this._sampleWeights;
|
|
||||||
}
|
|
||||||
|
|
||||||
private setBlurEffectParameters(dx: number, dy: number, offsets: Vector2[]){
|
|
||||||
for (let i = 0; i < this._sampleCount / 2; i ++){
|
|
||||||
let sampleOffset = i * 2 + 1.5;
|
|
||||||
let delta = Vector2.multiply( new Vector2(dx, dy), new Vector2(sampleOffset));
|
|
||||||
|
|
||||||
offsets[i * 2 + 1] = delta;
|
|
||||||
offsets[i * 2 + 2] = new Vector2(-delta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private computeGaussian(n: number){
|
|
||||||
return ((1 / Math.sqrt(2 * Math.PI * this._blurAmount)) * Math.exp(-(n * n) / (2 * this._blurAmount * this._blurAmount)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
34
source/src/Graphics/Effects/PolygonLightEffect.ts
Normal file
34
source/src/Graphics/Effects/PolygonLightEffect.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
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,10 +1,28 @@
|
|||||||
class PostProcessor {
|
class PostProcessor {
|
||||||
public enable: boolean;
|
public enable: boolean;
|
||||||
public effect: egret.CustomFilter;
|
public effect: egret.Filter;
|
||||||
public scene: Scene;
|
public scene: Scene;
|
||||||
public shape: egret.Shape;
|
public shape: egret.Shape;
|
||||||
|
|
||||||
constructor(effect: egret.CustomFilter = null){
|
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.enable = true;
|
this.enable = true;
|
||||||
this.effect = effect;
|
this.effect = effect;
|
||||||
}
|
}
|
||||||
@@ -25,7 +43,8 @@ class PostProcessor {
|
|||||||
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
|
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
|
||||||
|
|
||||||
protected drawFullscreenQuad(){
|
protected drawFullscreenQuad(){
|
||||||
this.shape.filters = [this.effect];
|
this.scene.filters = [this.effect];
|
||||||
|
// this.shape.filters = [this.effect];
|
||||||
}
|
}
|
||||||
|
|
||||||
public unload(){
|
public unload(){
|
||||||
|
|||||||
@@ -1,36 +1,6 @@
|
|||||||
class GaussianBlurPostProcessor extends PostProcessor {
|
class GaussianBlurPostProcessor extends PostProcessor {
|
||||||
private _renderTargetScale = 1;
|
|
||||||
public get renderTargetScale(){
|
|
||||||
return this._renderTargetScale;
|
|
||||||
}
|
|
||||||
public set renderTargetScale(value: number){
|
|
||||||
if (this._renderTargetScale != value){
|
|
||||||
this._renderTargetScale = value;
|
|
||||||
this.updateEffectDeltas();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public onAddedToScene(scene: Scene){
|
public onAddedToScene(scene: Scene){
|
||||||
super.onAddedToScene(scene);
|
super.onAddedToScene(scene);
|
||||||
this.effect = new GaussianBlurEffect();
|
this.effect = new GaussianBlurEffect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){
|
|
||||||
this.updateEffectDeltas();
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateEffectDeltas(){
|
|
||||||
let effect = this.effect as GaussianBlurEffect;
|
|
||||||
effect.horizontalBlurDelta = 1 / (this.scene.stage.stageWidth * this._renderTargetScale);
|
|
||||||
effect.verticalBlurDelta = 1 / (this.scene.stage.stageHeight * this._renderTargetScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
public process(){
|
|
||||||
let effect = this.effect as GaussianBlurEffect;
|
|
||||||
effect.prepareForHorizontalBlur();
|
|
||||||
this.drawFullscreenQuad();
|
|
||||||
|
|
||||||
effect.prepareForVerticalBlur();
|
|
||||||
this.drawFullscreenQuad();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
52
source/src/Graphics/Renderers/PolygonLight/PolyLight.ts
Normal file
52
source/src/Graphics/Renderers/PolygonLight/PolyLight.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
class PolyLight extends RenderableComponent {
|
||||||
|
public power: number;
|
||||||
|
protected _radius: number;
|
||||||
|
private _lightEffect;
|
||||||
|
private _indices: number[] = [];
|
||||||
|
|
||||||
|
public get bounds(){
|
||||||
|
if (this._areBoundsDirty){
|
||||||
|
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(this._radius),
|
||||||
|
Vector2.one, 0, this._radius * 2, this._radius * 2);
|
||||||
|
this._areBoundsDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get radius(){
|
||||||
|
return this._radius;
|
||||||
|
}
|
||||||
|
public set radius(value: number){
|
||||||
|
this.setRadius(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(radius: number, color: number, power: number){
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.radius = radius;
|
||||||
|
this.power = power;
|
||||||
|
this.color = color;
|
||||||
|
this.computeTriangleIndices();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public setRadius(radius: number){
|
||||||
|
if (radius != this._radius){
|
||||||
|
this._radius = radius;
|
||||||
|
this._areBoundsDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(camera: Camera) {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user