123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- module BABYLON {
- export class ImageProcessingPostProcess extends PostProcess {
- /**
- * Default configuration related to image processing available in the PBR Material.
- */
- protected _imageProcessingConfiguration: ImageProcessingConfiguration;
- /**
- * Gets the image processing configuration used either in this material.
- */
- public get imageProcessingConfiguration(): ImageProcessingConfiguration {
- return this._imageProcessingConfiguration;
- }
- /**
- * Sets the Default image processing configuration used either in the this material.
- *
- * If sets to null, the scene one is in use.
- */
- public set imageProcessingConfiguration(value: ImageProcessingConfiguration) {
- this._attachImageProcessingConfiguration(value);
- }
- /**
- * Keep track of the image processing observer to allow dispose and replace.
- */
- private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>>;
- /**
- * Attaches a new image processing configuration to the PBR Material.
- * @param configuration
- */
- protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>, doNotBuild = false): void {
- if (configuration === this._imageProcessingConfiguration) {
- return;
- }
- // Detaches observer.
- if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
- this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
- }
- // Pick the scene configuration if needed.
- if (!configuration) {
- var scene = null;
- var engine = this.getEngine();
- var camera = this.getCamera();
- if (camera) {
- scene = camera.getScene();
- }
- else if (engine && engine.scenes) {
- var scenes = engine.scenes;
- scene = scenes[scenes.length - 1];
- }
- else {
- scene = BABYLON.Engine.LastCreatedScene;
- }
- this._imageProcessingConfiguration = (<Scene>scene).imageProcessingConfiguration;
- }
- else {
- this._imageProcessingConfiguration = configuration;
- }
- // Attaches observer.
- this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(conf => {
- this._updateParameters();
- });
- // Ensure the effect will be rebuilt.
- if (!doNotBuild) {
- this._updateParameters();
- }
- }
- /**
- * Gets Color curves setup used in the effect if colorCurvesEnabled is set to true .
- */
- public get colorCurves(): Nullable<ColorCurves> {
- return this.imageProcessingConfiguration.colorCurves;
- }
- /**
- * Sets Color curves setup used in the effect if colorCurvesEnabled is set to true .
- */
- public set colorCurves(value: Nullable<ColorCurves>) {
- this.imageProcessingConfiguration.colorCurves = value;
- }
- /**
- * Gets wether the color curves effect is enabled.
- */
- public get colorCurvesEnabled(): boolean {
- return this.imageProcessingConfiguration.colorCurvesEnabled;
- }
- /**
- * Sets wether the color curves effect is enabled.
- */
- public set colorCurvesEnabled(value: boolean) {
- this.imageProcessingConfiguration.colorCurvesEnabled = value;
- }
- /**
- * Gets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.
- */
- public get colorGradingTexture(): Nullable<BaseTexture> {
- return this.imageProcessingConfiguration.colorGradingTexture;
- }
- /**
- * Sets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.
- */
- public set colorGradingTexture(value: Nullable<BaseTexture>) {
- this.imageProcessingConfiguration.colorGradingTexture = value;
- }
- /**
- * Gets wether the color grading effect is enabled.
- */
- public get colorGradingEnabled(): boolean {
- return this.imageProcessingConfiguration.colorGradingEnabled;
- }
- /**
- * Gets wether the color grading effect is enabled.
- */
- public set colorGradingEnabled(value: boolean) {
- this.imageProcessingConfiguration.colorGradingEnabled = value;
- }
- /**
- * Gets exposure used in the effect.
- */
- public get exposure(): number {
- return this.imageProcessingConfiguration.exposure;
- }
- /**
- * Sets exposure used in the effect.
- */
- public set exposure(value: number) {
- this.imageProcessingConfiguration.exposure = value;
- }
- /**
- * Gets wether tonemapping is enabled or not.
- */
- public get toneMappingEnabled(): boolean {
- return this._imageProcessingConfiguration.toneMappingEnabled;
- };
- /**
- * Sets wether tonemapping is enabled or not
- */
- public set toneMappingEnabled(value: boolean) {
- this._imageProcessingConfiguration.toneMappingEnabled = value;
- };
- /**
- * Gets contrast used in the effect.
- */
- public get contrast(): number {
- return this.imageProcessingConfiguration.contrast;
- }
- /**
- * Sets contrast used in the effect.
- */
- public set contrast(value: number) {
- this.imageProcessingConfiguration.contrast = value;
- }
- /**
- * Gets Vignette stretch size.
- */
- public get vignetteStretch(): number {
- return this.imageProcessingConfiguration.vignetteStretch;
- }
- /**
- * Sets Vignette stretch size.
- */
- public set vignetteStretch(value: number) {
- this.imageProcessingConfiguration.vignetteStretch = value;
- }
- /**
- * Gets Vignette centre X Offset.
- */
- public get vignetteCentreX(): number {
- return this.imageProcessingConfiguration.vignetteCentreX;
- }
- /**
- * Sets Vignette centre X Offset.
- */
- public set vignetteCentreX(value: number) {
- this.imageProcessingConfiguration.vignetteCentreX = value;
- }
- /**
- * Gets Vignette centre Y Offset.
- */
- public get vignetteCentreY(): number {
- return this.imageProcessingConfiguration.vignetteCentreY;
- }
- /**
- * Sets Vignette centre Y Offset.
- */
- public set vignetteCentreY(value: number) {
- this.imageProcessingConfiguration.vignetteCentreY = value;
- }
- /**
- * Gets Vignette weight or intensity of the vignette effect.
- */
- public get vignetteWeight(): number {
- return this.imageProcessingConfiguration.vignetteWeight;
- }
- /**
- * Sets Vignette weight or intensity of the vignette effect.
- */
- public set vignetteWeight(value: number) {
- this.imageProcessingConfiguration.vignetteWeight = value;
- }
- /**
- * Gets Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)
- * if vignetteEnabled is set to true.
- */
- public get vignetteColor(): Color4 {
- return this.imageProcessingConfiguration.vignetteColor;
- }
- /**
- * Sets Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)
- * if vignetteEnabled is set to true.
- */
- public set vignetteColor(value: Color4) {
- this.imageProcessingConfiguration.vignetteColor = value;
- }
- /**
- * Gets Camera field of view used by the Vignette effect.
- */
- public get vignetteCameraFov(): number {
- return this.imageProcessingConfiguration.vignetteCameraFov;
- }
- /**
- * Sets Camera field of view used by the Vignette effect.
- */
- public set vignetteCameraFov(value: number) {
- this.imageProcessingConfiguration.vignetteCameraFov = value;
- }
- /**
- * Gets the vignette blend mode allowing different kind of effect.
- */
- public get vignetteBlendMode(): number {
- return this.imageProcessingConfiguration.vignetteBlendMode;
- }
- /**
- * Sets the vignette blend mode allowing different kind of effect.
- */
- public set vignetteBlendMode(value: number) {
- this.imageProcessingConfiguration.vignetteBlendMode = value;
- }
- /**
- * Gets wether the vignette effect is enabled.
- */
- public get vignetteEnabled(): boolean {
- return this.imageProcessingConfiguration.vignetteEnabled;
- }
- /**
- * Sets wether the vignette effect is enabled.
- */
- public set vignetteEnabled(value: boolean) {
- this.imageProcessingConfiguration.vignetteEnabled = value;
- }
- @serialize()
- private _fromLinearSpace = true;
- /**
- * Gets wether the input of the processing is in Gamma or Linear Space.
- */
- public get fromLinearSpace(): boolean {
- return this._fromLinearSpace;
- }
- /**
- * Sets wether the input of the processing is in Gamma or Linear Space.
- */
- public set fromLinearSpace(value: boolean) {
- if (this._fromLinearSpace === value) {
- return;
- }
- this._fromLinearSpace = value;
- this._updateParameters();
- }
- /**
- * Defines cache preventing GC.
- */
- private _defines: IImageProcessingConfigurationDefines & { FROMLINEARSPACE: boolean } = {
- IMAGEPROCESSING: false,
- VIGNETTE: false,
- VIGNETTEBLENDMODEMULTIPLY: false,
- VIGNETTEBLENDMODEOPAQUE: false,
- TONEMAPPING: false,
- CONTRAST: false,
- COLORCURVES: false,
- COLORGRADING: false,
- COLORGRADING3D: false,
- FROMLINEARSPACE: false,
- SAMPLER3DGREENDEPTH: false,
- SAMPLER3DBGRMAP: false,
- IMAGEPROCESSINGPOSTPROCESS: false,
- EXPOSURE: false,
- }
- constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera> = null, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
- super(name, "imageProcessing", [], [], options, camera, samplingMode, engine, reusable,
- null, textureType, "postprocess", null, true);
- // Setup the default processing configuration to the scene.
- this._attachImageProcessingConfiguration(null, true);
- this.imageProcessingConfiguration.applyByPostProcess = true;
- this.onApply = (effect: Effect) => {
- this.imageProcessingConfiguration.bind(effect, this.aspectRatio);
- };
- }
- public getClassName(): string {
- return "ImageProcessingPostProcess";
- }
- protected _updateParameters(): void {
- this._defines.FROMLINEARSPACE = this._fromLinearSpace;
- this.imageProcessingConfiguration.prepareDefines(this._defines, true);
- var defines = "";
- for (const define in this._defines) {
- if ((<any>this._defines)[define]) {
- defines += `#define ${define};\r\n`;
- }
- }
- var samplers = ["textureSampler"];
- ImageProcessingConfiguration.PrepareSamplers(samplers, this._defines);
- var uniforms = ["scale"];
- ImageProcessingConfiguration.PrepareUniforms(uniforms, this._defines);
- this.updateEffect(defines, uniforms, samplers);
- }
- public dispose(camera?: Camera): void {
- super.dispose(camera);
- if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
- this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
- }
-
- this.imageProcessingConfiguration.applyByPostProcess = false;
- }
- }
- }
|