|
@@ -9,33 +9,33 @@ var BABYLON;
|
|
var LensRenderingPipeline = (function (_super) {
|
|
var LensRenderingPipeline = (function (_super) {
|
|
__extends(LensRenderingPipeline, _super);
|
|
__extends(LensRenderingPipeline, _super);
|
|
/**
|
|
/**
|
|
- * @constructor
|
|
|
|
- * @param {string} name - The rendering pipeline name
|
|
|
|
- * @param {object} parameters - An object containing all parameters (see below)
|
|
|
|
- * @param {BABYLON.Scene} scene - The scene linked to this pipeline
|
|
|
|
- * @param {number} ratio - The size of the postprocesses (0.5 means that your postprocess will have a width = canvas.width 0.5 and a height = canvas.height 0.5)
|
|
|
|
- * @param {BABYLON.Camera[]} cameras - The array of cameras that the rendering pipeline will be attached to
|
|
|
|
-
|
|
|
|
- Effect parameters are as follow:
|
|
|
|
- {
|
|
|
|
- chromatic_aberration: number; // from 0 to x (1 for realism)
|
|
|
|
- edge_blur: number; // from 0 to x (1 for realism)
|
|
|
|
- distortion: number; // from 0 to x (1 for realism)
|
|
|
|
- grain_amount: number; // from 0 to 1
|
|
|
|
- grain_texture: BABYLON.Texture; // texture to use for grain effect; if unset, use random B&W noise
|
|
|
|
- dof_focus_depth: number; // depth-of-field: focus depth; unset to disable
|
|
|
|
- dof_aperture: number; // depth-of-field: focus blur bias (default: 1)
|
|
|
|
- dof_pentagon: boolean; // depth-of-field: makes a pentagon-like "bokeh" effect
|
|
|
|
- dof_gain: boolean; // depth-of-field: depthOfField gain (default: 1)
|
|
|
|
- dof_threshold: boolean; // depth-of-field: depthOfField threshold (default: 1)
|
|
|
|
- blur_noise: boolean; // add a little bit of noise to the blur (default: true)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Note: if an effect parameter is unset, effect is disabled
|
|
|
|
- */
|
|
|
|
|
|
+ * @constructor
|
|
|
|
+ * @param {string} name - The rendering pipeline name
|
|
|
|
+ * @param {object} parameters - An object containing all parameters (see below)
|
|
|
|
+ * @param {BABYLON.Scene} scene - The scene linked to this pipeline
|
|
|
|
+ * @param {number} ratio - The size of the postprocesses (0.5 means that your postprocess will have a width = canvas.width 0.5 and a height = canvas.height 0.5)
|
|
|
|
+ * @param {BABYLON.Camera[]} cameras - The array of cameras that the rendering pipeline will be attached to
|
|
|
|
+
|
|
|
|
+ Effect parameters are as follow:
|
|
|
|
+ {
|
|
|
|
+ chromatic_aberration: number; // from 0 to x (1 for realism)
|
|
|
|
+ edge_blur: number; // from 0 to x (1 for realism)
|
|
|
|
+ distortion: number; // from 0 to x (1 for realism)
|
|
|
|
+ grain_amount: number; // from 0 to 1
|
|
|
|
+ grain_texture: BABYLON.Texture; // texture to use for grain effect; if unset, use random B&W noise
|
|
|
|
+ dof_focus_depth: number; // depth-of-field: focus depth; unset to disable
|
|
|
|
+ dof_aperture: number; // depth-of-field: focus blur bias (default: 1)
|
|
|
|
+ dof_pentagon: boolean; // depth-of-field: makes a pentagon-like "bokeh" effect
|
|
|
|
+ dof_gain: boolean; // depth-of-field: depthOfField gain (default: 1)
|
|
|
|
+ dof_threshold: boolean; // depth-of-field: depthOfField threshold (default: 1)
|
|
|
|
+ blur_noise: boolean; // add a little bit of noise to the blur (default: true)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Note: if an effect parameter is unset, effect is disabled
|
|
|
|
+ */
|
|
function LensRenderingPipeline(name, parameters, scene, ratio, cameras) {
|
|
function LensRenderingPipeline(name, parameters, scene, ratio, cameras) {
|
|
|
|
+ if (typeof ratio === "undefined") { ratio = 1.0; }
|
|
var _this = this;
|
|
var _this = this;
|
|
- if (ratio === void 0) { ratio = 1.0; }
|
|
|
|
_super.call(this, scene.getEngine(), name);
|
|
_super.call(this, scene.getEngine(), name);
|
|
// Lens effects can be of the following:
|
|
// Lens effects can be of the following:
|
|
// - chromatic aberration (slight shift of RGB colors)
|
|
// - chromatic aberration (slight shift of RGB colors)
|
|
@@ -56,15 +56,17 @@ var BABYLON;
|
|
* @type {string}
|
|
* @type {string}
|
|
*/
|
|
*/
|
|
this.LensDepthOfFieldEffect = "LensDepthOfFieldEffect";
|
|
this.LensDepthOfFieldEffect = "LensDepthOfFieldEffect";
|
|
|
|
+
|
|
this._scene = scene;
|
|
this._scene = scene;
|
|
|
|
+
|
|
// Fetch texture samplers
|
|
// Fetch texture samplers
|
|
this._depthTexture = scene.enableDepthRenderer().getDepthMap(); // Force depth renderer "on"
|
|
this._depthTexture = scene.enableDepthRenderer().getDepthMap(); // Force depth renderer "on"
|
|
if (parameters.grain_texture) {
|
|
if (parameters.grain_texture) {
|
|
this._grainTexture = parameters.grain_texture;
|
|
this._grainTexture = parameters.grain_texture;
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
this._createGrainTexture();
|
|
this._createGrainTexture();
|
|
}
|
|
}
|
|
|
|
+
|
|
// save parameters
|
|
// save parameters
|
|
this._edgeBlur = parameters.edge_blur ? parameters.edge_blur : 0;
|
|
this._edgeBlur = parameters.edge_blur ? parameters.edge_blur : 0;
|
|
this._grainAmount = parameters.grain_amount ? parameters.grain_amount : 0;
|
|
this._grainAmount = parameters.grain_amount ? parameters.grain_amount : 0;
|
|
@@ -76,9 +78,11 @@ var BABYLON;
|
|
this._dofAperture = parameters.dof_aperture ? parameters.dof_aperture : 1;
|
|
this._dofAperture = parameters.dof_aperture ? parameters.dof_aperture : 1;
|
|
this._dofPentagon = parameters.dof_pentagon !== undefined ? parameters.dof_pentagon : true;
|
|
this._dofPentagon = parameters.dof_pentagon !== undefined ? parameters.dof_pentagon : true;
|
|
this._blurNoise = parameters.blur_noise !== undefined ? parameters.blur_noise : true;
|
|
this._blurNoise = parameters.blur_noise !== undefined ? parameters.blur_noise : true;
|
|
|
|
+
|
|
// Create effects
|
|
// Create effects
|
|
this._createChromaticAberrationPostProcess(ratio);
|
|
this._createChromaticAberrationPostProcess(ratio);
|
|
this._createDepthOfFieldPostProcess(ratio);
|
|
this._createDepthOfFieldPostProcess(ratio);
|
|
|
|
+
|
|
// Set up pipeline
|
|
// Set up pipeline
|
|
this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.LensChromaticAberrationEffect, function () {
|
|
this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.LensChromaticAberrationEffect, function () {
|
|
return _this._chromaticAberrationPostProcess;
|
|
return _this._chromaticAberrationPostProcess;
|
|
@@ -86,6 +90,7 @@ var BABYLON;
|
|
this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.LensDepthOfFieldEffect, function () {
|
|
this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.LensDepthOfFieldEffect, function () {
|
|
return _this._depthOfFieldPostProcess;
|
|
return _this._depthOfFieldPostProcess;
|
|
}, true));
|
|
}, true));
|
|
|
|
+
|
|
// Finish
|
|
// Finish
|
|
scene.postProcessRenderPipelineManager.addPipeline(this);
|
|
scene.postProcessRenderPipelineManager.addPipeline(this);
|
|
if (cameras) {
|
|
if (cameras) {
|
|
@@ -144,74 +149,80 @@ var BABYLON;
|
|
LensRenderingPipeline.prototype.disableNoiseBlur = function () {
|
|
LensRenderingPipeline.prototype.disableNoiseBlur = function () {
|
|
this._blurNoise = false;
|
|
this._blurNoise = false;
|
|
};
|
|
};
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Removes the internal pipeline assets and detaches the pipeline from the scene cameras
|
|
|
|
- */
|
|
|
|
|
|
+ * Removes the internal pipeline assets and detaches the pipeline from the scene cameras
|
|
|
|
+ */
|
|
LensRenderingPipeline.prototype.dispose = function (disableDepthRender) {
|
|
LensRenderingPipeline.prototype.dispose = function (disableDepthRender) {
|
|
- if (disableDepthRender === void 0) { disableDepthRender = false; }
|
|
|
|
|
|
+ if (typeof disableDepthRender === "undefined") { disableDepthRender = false; }
|
|
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
|
|
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
|
|
- // this._originalColorPostProcess = undefined;
|
|
|
|
|
|
+
|
|
this._chromaticAberrationPostProcess = undefined;
|
|
this._chromaticAberrationPostProcess = undefined;
|
|
this._depthOfFieldPostProcess = undefined;
|
|
this._depthOfFieldPostProcess = undefined;
|
|
|
|
+
|
|
this._grainTexture.dispose();
|
|
this._grainTexture.dispose();
|
|
|
|
+
|
|
if (disableDepthRender)
|
|
if (disableDepthRender)
|
|
this._scene.disableDepthRenderer();
|
|
this._scene.disableDepthRenderer();
|
|
};
|
|
};
|
|
|
|
+
|
|
// colors shifting and distortion
|
|
// colors shifting and distortion
|
|
LensRenderingPipeline.prototype._createChromaticAberrationPostProcess = function (ratio) {
|
|
LensRenderingPipeline.prototype._createChromaticAberrationPostProcess = function (ratio) {
|
|
var _this = this;
|
|
var _this = this;
|
|
- this._chromaticAberrationPostProcess = new BABYLON.PostProcess("LensChromaticAberration", "./chromaticAberration", ["chromatic_aberration", "screen_width", "screen_height"], [], ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
|
|
|
|
|
|
+ this._chromaticAberrationPostProcess = new BABYLON.PostProcess("LensChromaticAberration", "chromaticAberration", ["chromatic_aberration", "screen_width", "screen_height"], [], ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
|
|
|
|
+
|
|
this._chromaticAberrationPostProcess.onApply = function (effect) {
|
|
this._chromaticAberrationPostProcess.onApply = function (effect) {
|
|
effect.setFloat('chromatic_aberration', _this._chromaticAberration);
|
|
effect.setFloat('chromatic_aberration', _this._chromaticAberration);
|
|
effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
|
|
effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
|
|
effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
|
|
effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
+
|
|
// colors shifting and distortion
|
|
// colors shifting and distortion
|
|
LensRenderingPipeline.prototype._createDepthOfFieldPostProcess = function (ratio) {
|
|
LensRenderingPipeline.prototype._createDepthOfFieldPostProcess = function (ratio) {
|
|
var _this = this;
|
|
var _this = this;
|
|
- this._depthOfFieldPostProcess = new BABYLON.PostProcess("LensDepthOfField", "./depthOfField", [
|
|
|
|
- "gain",
|
|
|
|
- "threshold",
|
|
|
|
- "focus_depth",
|
|
|
|
- "aperture",
|
|
|
|
- "pentagon",
|
|
|
|
- "maxZ",
|
|
|
|
- "edge_blur",
|
|
|
|
- "chromatic_aberration",
|
|
|
|
- "distortion",
|
|
|
|
- "blur_noise",
|
|
|
|
- "grain_amount",
|
|
|
|
- "screen_width",
|
|
|
|
- "screen_height"
|
|
|
|
|
|
+ this._depthOfFieldPostProcess = new BABYLON.PostProcess("LensDepthOfField", "depthOfField", [
|
|
|
|
+ "gain", "threshold", "focus_depth", "aperture", "pentagon", "maxZ", "edge_blur",
|
|
|
|
+ "chromatic_aberration", "distortion", "blur_noise", "grain_amount", "screen_width", "screen_height"
|
|
], ["depthSampler", "grainSampler"], ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
|
|
], ["depthSampler", "grainSampler"], ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
|
|
|
|
+
|
|
this._depthOfFieldPostProcess.onApply = function (effect) {
|
|
this._depthOfFieldPostProcess.onApply = function (effect) {
|
|
effect.setBool('pentagon', _this._dofPentagon);
|
|
effect.setBool('pentagon', _this._dofPentagon);
|
|
effect.setBool('blur_noise', _this._blurNoise);
|
|
effect.setBool('blur_noise', _this._blurNoise);
|
|
effect.setFloat('maxZ', _this._scene.activeCamera.maxZ);
|
|
effect.setFloat('maxZ', _this._scene.activeCamera.maxZ);
|
|
effect.setFloat('grain_amount', _this._grainAmount);
|
|
effect.setFloat('grain_amount', _this._grainAmount);
|
|
|
|
+
|
|
effect.setTexture("depthSampler", _this._depthTexture);
|
|
effect.setTexture("depthSampler", _this._depthTexture);
|
|
effect.setTexture("grainSampler", _this._grainTexture);
|
|
effect.setTexture("grainSampler", _this._grainTexture);
|
|
|
|
+
|
|
effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
|
|
effect.setFloat('screen_width', _this._scene.getEngine().getRenderWidth());
|
|
effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
|
|
effect.setFloat('screen_height', _this._scene.getEngine().getRenderHeight());
|
|
|
|
+
|
|
effect.setFloat('distortion', _this._distortion);
|
|
effect.setFloat('distortion', _this._distortion);
|
|
|
|
+
|
|
effect.setFloat('focus_depth', _this._dofDepth);
|
|
effect.setFloat('focus_depth', _this._dofDepth);
|
|
effect.setFloat('aperture', _this._dofAperture);
|
|
effect.setFloat('aperture', _this._dofAperture);
|
|
effect.setFloat('gain', _this._highlightsGain);
|
|
effect.setFloat('gain', _this._highlightsGain);
|
|
effect.setFloat('threshold', _this._highlightsThreshold);
|
|
effect.setFloat('threshold', _this._highlightsThreshold);
|
|
|
|
+
|
|
effect.setFloat('edge_blur', _this._edgeBlur);
|
|
effect.setFloat('edge_blur', _this._edgeBlur);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
+
|
|
// creates a black and white random noise texture, 512x512
|
|
// creates a black and white random noise texture, 512x512
|
|
LensRenderingPipeline.prototype._createGrainTexture = function () {
|
|
LensRenderingPipeline.prototype._createGrainTexture = function () {
|
|
var size = 512;
|
|
var size = 512;
|
|
|
|
+
|
|
this._grainTexture = new BABYLON.DynamicTexture("LensNoiseTexture", size, this._scene, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
|
|
this._grainTexture = new BABYLON.DynamicTexture("LensNoiseTexture", size, this._scene, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
|
|
this._grainTexture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
|
|
this._grainTexture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
|
|
this._grainTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
|
|
this._grainTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
|
|
|
|
+
|
|
var context = this._grainTexture.getContext();
|
|
var context = this._grainTexture.getContext();
|
|
|
|
+
|
|
var rand = function (min, max) {
|
|
var rand = function (min, max) {
|
|
return Math.random() * (max - min) + min;
|
|
return Math.random() * (max - min) + min;
|
|
};
|
|
};
|
|
|
|
+
|
|
var value;
|
|
var value;
|
|
for (var x = 0; x < size; x++) {
|
|
for (var x = 0; x < size; x++) {
|
|
for (var y = 0; y < size; y++) {
|
|
for (var y = 0; y < size; y++) {
|
|
@@ -226,4 +237,4 @@ var BABYLON;
|
|
})(BABYLON.PostProcessRenderPipeline);
|
|
})(BABYLON.PostProcessRenderPipeline);
|
|
BABYLON.LensRenderingPipeline = LensRenderingPipeline;
|
|
BABYLON.LensRenderingPipeline = LensRenderingPipeline;
|
|
})(BABYLON || (BABYLON = {}));
|
|
})(BABYLON || (BABYLON = {}));
|
|
-//# sourceMappingURL=babylon.lensRenderingPipeline.js.map
|
|
|
|
|
|
+//# sourceMappingURL=babylon.lensRenderingPipeline.js.map
|