|
@@ -9,27 +9,7 @@
|
|
/**
|
|
/**
|
|
* ID of the sharpen post process,
|
|
* ID of the sharpen post process,
|
|
*/
|
|
*/
|
|
- readonly SharpenPostProcessId: string = "SharpenPostProcessEffect";
|
|
|
|
- /**
|
|
|
|
- * ID of the pass post process used for bloom,
|
|
|
|
- */
|
|
|
|
- readonly PassPostProcessId: string = "PassPostProcessEffect";
|
|
|
|
- /**
|
|
|
|
- * ID of the highlight post process used for bloom,
|
|
|
|
- */
|
|
|
|
- readonly HighLightsPostProcessId: string = "HighLightsPostProcessEffect";
|
|
|
|
- /**
|
|
|
|
- * ID of the blurX post process used for bloom,
|
|
|
|
- */
|
|
|
|
- readonly BlurXPostProcessId: string = "BlurXPostProcessEffect";
|
|
|
|
- /**
|
|
|
|
- * ID of the blurY post process used for bloom,
|
|
|
|
- */
|
|
|
|
- readonly BlurYPostProcessId: string = "BlurYPostProcessEffect";
|
|
|
|
- /**
|
|
|
|
- * ID of the copy back post process used for bloom,
|
|
|
|
- */
|
|
|
|
- readonly CopyBackPostProcessId: string = "CopyBackPostProcessEffect";
|
|
|
|
|
|
+ private readonly SharpenPostProcessId: string = "SharpenPostProcessEffect";
|
|
/**
|
|
/**
|
|
* ID of the image processing post process;
|
|
* ID of the image processing post process;
|
|
*/
|
|
*/
|
|
@@ -39,13 +19,13 @@
|
|
*/
|
|
*/
|
|
readonly FxaaPostProcessId: string = "FxaaPostProcessEffect";
|
|
readonly FxaaPostProcessId: string = "FxaaPostProcessEffect";
|
|
/**
|
|
/**
|
|
- * ID of the final merge post process;
|
|
|
|
|
|
+ * ID of the chromatic aberration post process,
|
|
*/
|
|
*/
|
|
- readonly FinalMergePostProcessId: string = "FinalMergePostProcessEffect";
|
|
|
|
|
|
+ private readonly ChromaticAberrationPostProcessId: string = "ChromaticAberrationPostProcessEffect";
|
|
/**
|
|
/**
|
|
- * ID of the chromatic aberration post process,
|
|
|
|
|
|
+ * ID of the grain post process
|
|
*/
|
|
*/
|
|
- readonly ChromaticAberrationPostProcessId: string = "ChromaticAberrationPostProcessEffect";
|
|
|
|
|
|
+ private readonly GrainPostProcessId: string = "GrainPostProcessEffect";
|
|
|
|
|
|
// Post-processes
|
|
// Post-processes
|
|
/**
|
|
/**
|
|
@@ -53,26 +33,7 @@
|
|
*/
|
|
*/
|
|
public sharpen: SharpenPostProcess;
|
|
public sharpen: SharpenPostProcess;
|
|
private _sharpenEffect: PostProcessRenderEffect;
|
|
private _sharpenEffect: PostProcessRenderEffect;
|
|
- /**
|
|
|
|
- * First pass of bloom to capture the original image texture for later use.
|
|
|
|
- */
|
|
|
|
- public pass: PassPostProcess;
|
|
|
|
- /**
|
|
|
|
- * Second pass of bloom used to brighten bright portions of the image.
|
|
|
|
- */
|
|
|
|
- public highlights: HighlightsPostProcess;
|
|
|
|
- /**
|
|
|
|
- * BlurX post process used in coordination with blurY to guassian blur the highlighted image.
|
|
|
|
- */
|
|
|
|
- public blurX: BlurPostProcess;
|
|
|
|
- /**
|
|
|
|
- * BlurY post process used in coordination with blurX to guassian blur the highlighted image.
|
|
|
|
- */
|
|
|
|
- public blurY: BlurPostProcess;
|
|
|
|
- /**
|
|
|
|
- * Final pass run for bloom to copy the resulting bloom texture back to screen.
|
|
|
|
- */
|
|
|
|
- public copyBack: PassPostProcess;
|
|
|
|
|
|
+ private bloom: BloomEffect;
|
|
/**
|
|
/**
|
|
* Depth of field effect, applies a blur based on how far away objects are from the focus distance.
|
|
* Depth of field effect, applies a blur based on how far away objects are from the focus distance.
|
|
*/
|
|
*/
|
|
@@ -86,31 +47,33 @@
|
|
*/
|
|
*/
|
|
public imageProcessing: ImageProcessingPostProcess;
|
|
public imageProcessing: ImageProcessingPostProcess;
|
|
/**
|
|
/**
|
|
- * Final post process to merge results of all previous passes
|
|
|
|
- */
|
|
|
|
- public finalMerge: PassPostProcess;
|
|
|
|
- /**
|
|
|
|
* Chromatic aberration post process which will shift rgb colors in the image
|
|
* Chromatic aberration post process which will shift rgb colors in the image
|
|
*/
|
|
*/
|
|
public chromaticAberration: ChromaticAberrationPostProcess;
|
|
public chromaticAberration: ChromaticAberrationPostProcess;
|
|
private _chromaticAberrationEffect: PostProcessRenderEffect;
|
|
private _chromaticAberrationEffect: PostProcessRenderEffect;
|
|
|
|
+ /**
|
|
|
|
+ * Grain post process which add noise to the image
|
|
|
|
+ */
|
|
|
|
+ public grain: GrainPostProcess;
|
|
|
|
+ private _grainEffect: PostProcessRenderEffect;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Animations which can be used to tweak settings over a period of time
|
|
* Animations which can be used to tweak settings over a period of time
|
|
*/
|
|
*/
|
|
public animations: Animation[] = [];
|
|
public animations: Animation[] = [];
|
|
|
|
|
|
|
|
+ private _imageProcessingConfigurationObserver:Nullable<Observer<ImageProcessingConfiguration>> = null;
|
|
// Values
|
|
// Values
|
|
private _sharpenEnabled:boolean = false;
|
|
private _sharpenEnabled:boolean = false;
|
|
private _bloomEnabled: boolean = false;
|
|
private _bloomEnabled: boolean = false;
|
|
private _depthOfFieldEnabled: boolean = false;
|
|
private _depthOfFieldEnabled: boolean = false;
|
|
private _depthOfFieldBlurLevel = DepthOfFieldEffectBlurLevel.Low;
|
|
private _depthOfFieldBlurLevel = DepthOfFieldEffectBlurLevel.Low;
|
|
private _fxaaEnabled: boolean = false;
|
|
private _fxaaEnabled: boolean = false;
|
|
- private _msaaEnabled: boolean = false;
|
|
|
|
private _imageProcessingEnabled: boolean = true;
|
|
private _imageProcessingEnabled: boolean = true;
|
|
private _defaultPipelineTextureType: number;
|
|
private _defaultPipelineTextureType: number;
|
|
- private _bloomScale: number = 0.6;
|
|
|
|
|
|
+ private _bloomScale: number = 0.5;
|
|
private _chromaticAberrationEnabled:boolean = false;
|
|
private _chromaticAberrationEnabled:boolean = false;
|
|
|
|
+ private _grainEnabled:boolean = false;
|
|
|
|
|
|
private _buildAllowed = true;
|
|
private _buildAllowed = true;
|
|
|
|
|
|
@@ -131,18 +94,31 @@
|
|
return this._sharpenEnabled;
|
|
return this._sharpenEnabled;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ private _resizeObserver:Nullable<Observer<Engine>> = null;
|
|
|
|
+ private _hardwareScaleLevel = 1.0;
|
|
|
|
+ private _bloomKernel: number = 64;
|
|
/**
|
|
/**
|
|
* Specifies the size of the bloom blur kernel, relative to the final output size
|
|
* Specifies the size of the bloom blur kernel, relative to the final output size
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public bloomKernel: number = 64;
|
|
|
|
|
|
+ public get bloomKernel(): number{
|
|
|
|
+ return this._bloomKernel;
|
|
|
|
+ }
|
|
|
|
+ public set bloomKernel(value: number){
|
|
|
|
+ this._bloomKernel = value;
|
|
|
|
+ this.bloom.kernel = value/this._hardwareScaleLevel;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Specifies the weight of the bloom in the final rendering
|
|
* Specifies the weight of the bloom in the final rendering
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
private _bloomWeight: number = 0.15;
|
|
private _bloomWeight: number = 0.15;
|
|
|
|
+ /**
|
|
|
|
+ * Specifies the luma threshold for the area that will be blurred by the bloom
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ private _bloomThreshold: number = 0.9;
|
|
|
|
|
|
@serialize()
|
|
@serialize()
|
|
private _hdr: boolean;
|
|
private _hdr: boolean;
|
|
@@ -154,11 +130,9 @@
|
|
if (this._bloomWeight === value) {
|
|
if (this._bloomWeight === value) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ this.bloom.weight = value;
|
|
|
|
+
|
|
this._bloomWeight = value;
|
|
this._bloomWeight = value;
|
|
-
|
|
|
|
- if (this._hdr && this.copyBack) {
|
|
|
|
- this.copyBack.alphaConstants = new Color4(value, value, value, value);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@serialize()
|
|
@serialize()
|
|
@@ -167,6 +141,22 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * The strength of the bloom.
|
|
|
|
+ */
|
|
|
|
+ public set bloomThreshold(value: number) {
|
|
|
|
+ if (this._bloomThreshold === value) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.bloom.threshold = value;
|
|
|
|
+ this._bloomThreshold = value;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @serialize()
|
|
|
|
+ public get bloomThreshold(): number {
|
|
|
|
+ return this._bloomThreshold;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* The scale of the bloom, lower value will provide better performance.
|
|
* The scale of the bloom, lower value will provide better performance.
|
|
*/
|
|
*/
|
|
public set bloomScale(value: number) {
|
|
public set bloomScale(value: number) {
|
|
@@ -175,6 +165,9 @@
|
|
}
|
|
}
|
|
this._bloomScale = value;
|
|
this._bloomScale = value;
|
|
|
|
|
|
|
|
+ // recreate bloom and dispose old as this setting is not dynamic
|
|
|
|
+ this._rebuildBloom();
|
|
|
|
+
|
|
this._buildPipeline();
|
|
this._buildPipeline();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -200,6 +193,16 @@
|
|
return this._bloomEnabled;
|
|
return this._bloomEnabled;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _rebuildBloom(){
|
|
|
|
+ // recreate bloom and dispose old as this setting is not dynamic
|
|
|
|
+ var oldBloom = this.bloom;
|
|
|
|
+ this.bloom = new BloomEffect(this._scene, this.bloomScale, this._bloomWeight, this.bloomKernel, this._defaultPipelineTextureType, false);
|
|
|
|
+ this.bloom.threshold = oldBloom.threshold;
|
|
|
|
+ for (var i = 0; i < this._cameras.length; i++) {
|
|
|
|
+ oldBloom.disposeEffects(this._cameras[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* If the depth of field is enabled.
|
|
* If the depth of field is enabled.
|
|
*/
|
|
*/
|
|
@@ -234,7 +237,7 @@
|
|
// recreate dof and dispose old as this setting is not dynamic
|
|
// recreate dof and dispose old as this setting is not dynamic
|
|
var oldDof = this.depthOfField;
|
|
var oldDof = this.depthOfField;
|
|
|
|
|
|
- this.depthOfField = new DepthOfFieldEffect(this._scene, null, this._depthOfFieldBlurLevel, this._defaultPipelineTextureType);
|
|
|
|
|
|
+ this.depthOfField = new DepthOfFieldEffect(this._scene, null, this._depthOfFieldBlurLevel, this._defaultPipelineTextureType, false);
|
|
this.depthOfField.focalLength = oldDof.focalLength;
|
|
this.depthOfField.focalLength = oldDof.focalLength;
|
|
this.depthOfField.focusDistance = oldDof.focusDistance;
|
|
this.depthOfField.focusDistance = oldDof.focusDistance;
|
|
this.depthOfField.fStop = oldDof.fStop;
|
|
this.depthOfField.fStop = oldDof.fStop;
|
|
@@ -264,21 +267,22 @@
|
|
return this._fxaaEnabled;
|
|
return this._fxaaEnabled;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _samples = 1;
|
|
/**
|
|
/**
|
|
- * If the multisample anti-aliasing is enabled.
|
|
|
|
|
|
+ * MSAA sample count, setting this to 4 will provide 4x anti aliasing. (default: 1)
|
|
*/
|
|
*/
|
|
- public set msaaEnabled(enabled: boolean) {
|
|
|
|
- if (this._msaaEnabled === enabled) {
|
|
|
|
|
|
+ public set samples(sampleCount: number) {
|
|
|
|
+ if (this._samples === sampleCount) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this._msaaEnabled = enabled;
|
|
|
|
|
|
+ this._samples = sampleCount;
|
|
|
|
|
|
this._buildPipeline();
|
|
this._buildPipeline();
|
|
}
|
|
}
|
|
|
|
|
|
@serialize()
|
|
@serialize()
|
|
- public get msaaEnabled(): boolean {
|
|
|
|
- return this._msaaEnabled;
|
|
|
|
|
|
+ public get samples(): number {
|
|
|
|
+ return this._samples;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -314,6 +318,22 @@
|
|
public get chromaticAberrationEnabled(): boolean {
|
|
public get chromaticAberrationEnabled(): boolean {
|
|
return this._chromaticAberrationEnabled;
|
|
return this._chromaticAberrationEnabled;
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * Enable or disable the grain process from the pipeline
|
|
|
|
+ */
|
|
|
|
+ public set grainEnabled(enabled: boolean) {
|
|
|
|
+ if (this._grainEnabled === enabled) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this._grainEnabled = enabled;
|
|
|
|
+
|
|
|
|
+ this._buildPipeline();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @serialize()
|
|
|
|
+ public get grainEnabled(): boolean {
|
|
|
|
+ return this._grainEnabled;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @constructor
|
|
* @constructor
|
|
@@ -358,9 +378,23 @@
|
|
|
|
|
|
this.depthOfField = new DepthOfFieldEffect(this._scene, null, this._depthOfFieldBlurLevel, this._defaultPipelineTextureType, true);
|
|
this.depthOfField = new DepthOfFieldEffect(this._scene, null, this._depthOfFieldBlurLevel, this._defaultPipelineTextureType, true);
|
|
|
|
|
|
|
|
+ this.bloom = new BloomEffect(this._scene, this._bloomScale, this._bloomWeight, this.bloomKernel, this._defaultPipelineTextureType, true);
|
|
|
|
+
|
|
this.chromaticAberration = new ChromaticAberrationPostProcess("ChromaticAberration", engine.getRenderWidth(), engine.getRenderHeight(), 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType, true);
|
|
this.chromaticAberration = new ChromaticAberrationPostProcess("ChromaticAberration", engine.getRenderWidth(), engine.getRenderHeight(), 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType, true);
|
|
this._chromaticAberrationEffect = new PostProcessRenderEffect(engine, this.ChromaticAberrationPostProcessId, () => { return this.chromaticAberration; }, true);
|
|
this._chromaticAberrationEffect = new PostProcessRenderEffect(engine, this.ChromaticAberrationPostProcessId, () => { return this.chromaticAberration; }, true);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ this.grain = new GrainPostProcess("Grain", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType, true);
|
|
|
|
+ this._grainEffect = new PostProcessRenderEffect(engine, this.GrainPostProcessId, () => { return this.grain; }, true);
|
|
|
|
+
|
|
|
|
+ this._resizeObserver = engine.onResizeObservable.add(()=>{
|
|
|
|
+ this._hardwareScaleLevel = engine.getHardwareScalingLevel();
|
|
|
|
+ this.bloomKernel = this.bloomKernel
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ this._imageProcessingConfigurationObserver = this._scene.imageProcessingConfiguration.onUpdateParameters.add(()=>{
|
|
|
|
+ this.bloom._downscale._exposure = this._scene.imageProcessingConfiguration.exposure;
|
|
|
|
+ })
|
|
|
|
+
|
|
this._buildPipeline();
|
|
this._buildPipeline();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -374,14 +408,17 @@
|
|
this._buildAllowed = previousState;
|
|
this._buildAllowed = previousState;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _hasCleared = false;
|
|
private _prevPostProcess:Nullable<PostProcess> = null;
|
|
private _prevPostProcess:Nullable<PostProcess> = null;
|
|
private _prevPrevPostProcess:Nullable<PostProcess> = null;
|
|
private _prevPrevPostProcess:Nullable<PostProcess> = null;
|
|
|
|
|
|
private _setAutoClearAndTextureSharing(postProcess:PostProcess, skipTextureSharing = false){
|
|
private _setAutoClearAndTextureSharing(postProcess:PostProcess, skipTextureSharing = false){
|
|
- if(this._prevPostProcess && this._prevPostProcess.autoClear){
|
|
|
|
|
|
+ if(this._hasCleared){
|
|
postProcess.autoClear = false;
|
|
postProcess.autoClear = false;
|
|
}else{
|
|
}else{
|
|
postProcess.autoClear = true;
|
|
postProcess.autoClear = true;
|
|
|
|
+ this._scene.autoClear = false;
|
|
|
|
+ this._hasCleared = true;
|
|
}
|
|
}
|
|
|
|
|
|
if(!skipTextureSharing){
|
|
if(!skipTextureSharing){
|
|
@@ -402,7 +439,8 @@
|
|
if (!this._buildAllowed) {
|
|
if (!this._buildAllowed) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ this._scene.autoClear = true;
|
|
|
|
+
|
|
var engine = this._scene.getEngine();
|
|
var engine = this._scene.getEngine();
|
|
|
|
|
|
this._disposePostProcesses();
|
|
this._disposePostProcesses();
|
|
@@ -414,14 +452,7 @@
|
|
this._reset();
|
|
this._reset();
|
|
this._prevPostProcess = null;
|
|
this._prevPostProcess = null;
|
|
this._prevPrevPostProcess = null;
|
|
this._prevPrevPostProcess = null;
|
|
-
|
|
|
|
- if (this.sharpenEnabled) {
|
|
|
|
- if(!this.sharpen.isReady()){
|
|
|
|
- this.sharpen.updateEffect();
|
|
|
|
- }
|
|
|
|
- this.addEffect(this._sharpenEffect);
|
|
|
|
- this._setAutoClearAndTextureSharing(this.sharpen);
|
|
|
|
- }
|
|
|
|
|
|
+ this._hasCleared = false;
|
|
|
|
|
|
if (this.depthOfFieldEnabled) {
|
|
if (this.depthOfFieldEnabled) {
|
|
var depthTexture = this._scene.enableDepthRenderer(this._cameras[0]).getDepthMap();
|
|
var depthTexture = this._scene.enableDepthRenderer(this._cameras[0]).getDepthMap();
|
|
@@ -430,90 +461,41 @@
|
|
this.depthOfField._updateEffects();
|
|
this.depthOfField._updateEffects();
|
|
}
|
|
}
|
|
this.addEffect(this.depthOfField);
|
|
this.addEffect(this.depthOfField);
|
|
- this._setAutoClearAndTextureSharing(this.depthOfField._depthOfFieldMerge);
|
|
|
|
|
|
+ this._setAutoClearAndTextureSharing(this.depthOfField._effects[0], true);
|
|
}
|
|
}
|
|
|
|
|
|
if (this.bloomEnabled) {
|
|
if (this.bloomEnabled) {
|
|
- this.pass = new PassPostProcess("sceneRenderTarget", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this._setAutoClearAndTextureSharing(this.pass, true);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.PassPostProcessId, () => { return this.pass; }, true));
|
|
|
|
-
|
|
|
|
- if (!this._hdr) { // Need to enhance highlights if not using float rendering
|
|
|
|
- this.highlights = new HighlightsPostProcess("highlights", this.bloomScale, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.HighLightsPostProcessId, () => { return this.highlights; }, true));
|
|
|
|
- this.highlights.autoClear = false;
|
|
|
|
- this.highlights.alwaysForcePOT = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.blurX = new BlurPostProcess("horizontal blur", new Vector2(1.0, 0), 10.0, this.bloomScale, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.BlurXPostProcessId, () => { return this.blurX; }, true));
|
|
|
|
- this.blurX.alwaysForcePOT = true;
|
|
|
|
- this.blurX.autoClear = false;
|
|
|
|
- this.blurX.onActivateObservable.add(() => {
|
|
|
|
- let dw = this.blurX.width / engine.getRenderWidth(true);
|
|
|
|
- this.blurX.kernel = this.bloomKernel * dw;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- this.blurY = new BlurPostProcess("vertical blur", new Vector2(0, 1.0), 10.0, this.bloomScale, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.BlurYPostProcessId, () => { return this.blurY; }, true));
|
|
|
|
- this.blurY.alwaysForcePOT = true;
|
|
|
|
- this.blurY.autoClear = false;
|
|
|
|
- this.blurY.onActivateObservable.add(() => {
|
|
|
|
- let dh = this.blurY.height / engine.getRenderHeight(true);
|
|
|
|
- this.blurY.kernel = this.bloomKernel * dh;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- this.copyBack = new PassPostProcess("bloomBlendBlit", this.bloomScale, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.CopyBackPostProcessId, () => { return this.copyBack; }, true));
|
|
|
|
- this.copyBack.alwaysForcePOT = true;
|
|
|
|
- if (this._hdr) {
|
|
|
|
- this.copyBack.alphaMode = Engine.ALPHA_INTERPOLATE;
|
|
|
|
- let w = this.bloomWeight;
|
|
|
|
- this.copyBack.alphaConstants = new Color4(w, w, w, w);
|
|
|
|
- } else {
|
|
|
|
- this.copyBack.alphaMode = Engine.ALPHA_SCREENMODE;
|
|
|
|
- }
|
|
|
|
- this.copyBack.autoClear = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._imageProcessingEnabled) {
|
|
|
|
- this.imageProcessing = new ImageProcessingPostProcess("imageProcessing", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- if (this._hdr) {
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.ImageProcessingPostProcessId, () => { return this.imageProcessing; }, true));
|
|
|
|
- } else {
|
|
|
|
- this._scene.imageProcessingConfiguration.applyByPostProcess = false;
|
|
|
|
|
|
+ if(!this.bloom._isReady()){
|
|
|
|
+ this.bloom._updateEffects();
|
|
}
|
|
}
|
|
|
|
+ this.addEffect(this.bloom);
|
|
|
|
+ this._setAutoClearAndTextureSharing(this.bloom._effects[0], true);
|
|
}
|
|
}
|
|
|
|
|
|
- if (this._hdr && this.imageProcessing) {
|
|
|
|
- this.finalMerge = this.imageProcessing;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- this.finalMerge = new PassPostProcess("finalMerge", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.FinalMergePostProcessId, () => { return this.finalMerge; }, true));
|
|
|
|
- this._setAutoClearAndTextureSharing(this.finalMerge, true);
|
|
|
|
-
|
|
|
|
- this.finalMerge.autoClear = !this.bloomEnabled && (!this._hdr || !this.imageProcessing);
|
|
|
|
|
|
+ if (this._imageProcessingEnabled) {
|
|
|
|
+ this.imageProcessing = new ImageProcessingPostProcess("imageProcessing", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
+ if (this._hdr) {
|
|
|
|
+ this.addEffect(new PostProcessRenderEffect(engine, this.ImageProcessingPostProcessId, () => { return this.imageProcessing; }, true));
|
|
|
|
+ this._setAutoClearAndTextureSharing(this.imageProcessing);
|
|
|
|
+ } else {
|
|
|
|
+ this._scene.imageProcessingConfiguration.applyByPostProcess = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.bloomEnabled) {
|
|
|
|
- if (this._hdr) { // Share render targets to save memory
|
|
|
|
- this.copyBack.shareOutputWith(this.blurX);
|
|
|
|
- if (this.imageProcessing) {
|
|
|
|
- this.imageProcessing.shareOutputWith(this.pass);
|
|
|
|
- this.imageProcessing.autoClear = false;
|
|
|
|
- } else {
|
|
|
|
- this.finalMerge.shareOutputWith(this.pass);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- this.finalMerge.shareOutputWith(this.pass);
|
|
|
|
|
|
+ if (this.sharpenEnabled) {
|
|
|
|
+ if(!this.sharpen.isReady()){
|
|
|
|
+ this.sharpen.updateEffect();
|
|
}
|
|
}
|
|
|
|
+ this.addEffect(this._sharpenEffect);
|
|
|
|
+ this._setAutoClearAndTextureSharing(this.sharpen);
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.fxaaEnabled) {
|
|
|
|
- this.fxaa = new FxaaPostProcess("fxaa", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
- this.addEffect(new PostProcessRenderEffect(engine, this.FxaaPostProcessId, () => { return this.fxaa; }, true));
|
|
|
|
- this._setAutoClearAndTextureSharing(this.fxaa);
|
|
|
|
|
|
+ if (this.grainEnabled) {
|
|
|
|
+ if(!this.grain.isReady()){
|
|
|
|
+ this.grain.updateEffect();
|
|
|
|
+ }
|
|
|
|
+ this.addEffect(this._grainEffect);
|
|
|
|
+ this._setAutoClearAndTextureSharing(this.grain);
|
|
}
|
|
}
|
|
|
|
|
|
if (this.chromaticAberrationEnabled) {
|
|
if (this.chromaticAberrationEnabled) {
|
|
@@ -524,14 +506,19 @@
|
|
this._setAutoClearAndTextureSharing(this.chromaticAberration);
|
|
this._setAutoClearAndTextureSharing(this.chromaticAberration);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this.fxaaEnabled) {
|
|
|
|
+ this.fxaa = new FxaaPostProcess("fxaa", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
|
|
|
|
+ this.addEffect(new PostProcessRenderEffect(engine, this.FxaaPostProcessId, () => { return this.fxaa; }, true));
|
|
|
|
+ this._setAutoClearAndTextureSharing(this.fxaa, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._cameras !== null) {
|
|
if (this._cameras !== null) {
|
|
this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name, this._cameras);
|
|
this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name, this._cameras);
|
|
}
|
|
}
|
|
|
|
|
|
- if(this.msaaEnabled){
|
|
|
|
- if(!this._enableMSAAOnFirstPostProcess()){
|
|
|
|
- BABYLON.Tools.Warn("MSAA failed to enable, MSAA is only supported in browsers that support webGL >= 2.0");
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ if(!this._enableMSAAOnFirstPostProcess(this.samples) && this.samples > 1){
|
|
|
|
+ BABYLON.Tools.Warn("MSAA failed to enable, MSAA is only supported in browsers that support webGL >= 2.0");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -539,26 +526,6 @@
|
|
for (var i = 0; i < this._cameras.length; i++) {
|
|
for (var i = 0; i < this._cameras.length; i++) {
|
|
var camera = this._cameras[i];
|
|
var camera = this._cameras[i];
|
|
|
|
|
|
- if (this.pass) {
|
|
|
|
- this.pass.dispose(camera);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.highlights) {
|
|
|
|
- this.highlights.dispose(camera);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.blurX) {
|
|
|
|
- this.blurX.dispose(camera);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.blurY) {
|
|
|
|
- this.blurY.dispose(camera);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.copyBack) {
|
|
|
|
- this.copyBack.dispose(camera);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (this.imageProcessing) {
|
|
if (this.imageProcessing) {
|
|
this.imageProcessing.dispose(camera);
|
|
this.imageProcessing.dispose(camera);
|
|
}
|
|
}
|
|
@@ -567,10 +534,6 @@
|
|
this.fxaa.dispose(camera);
|
|
this.fxaa.dispose(camera);
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.finalMerge) {
|
|
|
|
- this.finalMerge.dispose(camera);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// These are created in the constructor and should not be disposed on every pipeline change
|
|
// These are created in the constructor and should not be disposed on every pipeline change
|
|
if(disposeNonRecreated){
|
|
if(disposeNonRecreated){
|
|
if (this.sharpen) {
|
|
if (this.sharpen) {
|
|
@@ -580,26 +543,33 @@
|
|
if(this.depthOfField){
|
|
if(this.depthOfField){
|
|
this.depthOfField.disposeEffects(camera);
|
|
this.depthOfField.disposeEffects(camera);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(this.bloom){
|
|
|
|
+ this.bloom.disposeEffects(camera);
|
|
|
|
+ }
|
|
|
|
|
|
if(this.chromaticAberration){
|
|
if(this.chromaticAberration){
|
|
this.chromaticAberration.dispose(camera);
|
|
this.chromaticAberration.dispose(camera);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(this.grain){
|
|
|
|
+ this.grain.dispose(camera);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- (<any>this.pass) = null;
|
|
|
|
- (<any>this.highlights) = null;
|
|
|
|
- (<any>this.blurX) = null;
|
|
|
|
- (<any>this.blurY) = null;
|
|
|
|
- (<any>this.copyBack) = null;
|
|
|
|
|
|
+
|
|
(<any>this.imageProcessing) = null;
|
|
(<any>this.imageProcessing) = null;
|
|
(<any>this.fxaa) = null;
|
|
(<any>this.fxaa) = null;
|
|
- (<any>this.finalMerge) = null;
|
|
|
|
|
|
|
|
if(disposeNonRecreated){
|
|
if(disposeNonRecreated){
|
|
(<any>this.sharpen) = null;
|
|
(<any>this.sharpen) = null;
|
|
|
|
+ (<any>this._sharpenEffect) = null;
|
|
(<any>this.depthOfField) = null;
|
|
(<any>this.depthOfField) = null;
|
|
|
|
+ (<any>this.bloom) = null;
|
|
(<any>this.chromaticAberration) = null;
|
|
(<any>this.chromaticAberration) = null;
|
|
|
|
+ (<any>this._chromaticAberrationEffect) = null;
|
|
|
|
+ (<any>this.grain) = null;
|
|
|
|
+ (<any>this._grainEffect) = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -608,9 +578,13 @@
|
|
*/
|
|
*/
|
|
public dispose(): void {
|
|
public dispose(): void {
|
|
this._disposePostProcesses(true);
|
|
this._disposePostProcesses(true);
|
|
-
|
|
|
|
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
|
|
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
|
|
-
|
|
|
|
|
|
+ this._scene.autoClear = true;
|
|
|
|
+ if(this._resizeObserver){
|
|
|
|
+ this._scene.getEngine().onResizeObservable.remove(this._resizeObserver);
|
|
|
|
+ this._resizeObserver = null;
|
|
|
|
+ }
|
|
|
|
+ this._scene.imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingConfigurationObserver)
|
|
super.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
|