Skip to content

Commit 87ec6bf

Browse files
author
Mike Bond
committed
Add mixin for imageProcessing support in materials
1 parent d9c24d9 commit 87ec6bf

24 files changed

+339
-698
lines changed

packages/dev/core/src/Materials/Background/backgroundMaterial.ts

Lines changed: 4 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
2-
import { serialize, serializeAsColor3, expandToProperty, serializeAsTexture, serializeAsVector3, serializeAsImageProcessingConfiguration } from "../../Misc/decorators";
2+
import { serialize, serializeAsColor3, expandToProperty, serializeAsTexture, serializeAsVector3 } from "../../Misc/decorators";
33
import { SmartArray } from "../../Misc/smartArray";
4-
import type { Observer } from "../../Misc/observable";
54
import { Logger } from "../../Misc/logger";
65
import type { Nullable, int, float } from "../../types";
76
import type { Scene } from "../../scene";
@@ -14,7 +13,6 @@ import type { Mesh } from "../../Meshes/mesh";
1413
import type { IEffectCreationOptions } from "../../Materials/effect";
1514
import { MaterialDefines } from "../../Materials/materialDefines";
1615
import { PushMaterial } from "../../Materials/pushMaterial";
17-
import type { ColorCurves } from "../../Materials/colorCurves";
1816
import { ImageProcessingDefinesMixin } from "../../Materials/imageProcessingConfiguration.defines";
1917
import { ImageProcessingConfiguration } from "../../Materials/imageProcessingConfiguration";
2018
import type { BaseTexture } from "../../Materials/Textures/baseTexture";
@@ -47,6 +45,7 @@ import {
4745
} from "../materialHelper.functions";
4846
import { SerializationHelper } from "../../Misc/decorators.serialization";
4947
import { ShaderLanguage } from "../shaderLanguage";
48+
import { ImageProcessingMixin } from "../imageProcessing";
5049

5150
class BackgroundMaterialDefinesBase extends MaterialDefines {}
5251

@@ -187,11 +186,12 @@ class BackgroundMaterialDefines extends ImageProcessingDefinesMixin(BackgroundMa
187186
}
188187
}
189188

189+
class BackgroundMaterialBase extends ImageProcessingMixin(PushMaterial) {}
190190
/**
191191
* Background material used to create an efficient environment around your scene.
192192
* #157MGZ: simple test
193193
*/
194-
export class BackgroundMaterial extends PushMaterial {
194+
export class BackgroundMaterial extends BackgroundMaterialBase {
195195
/**
196196
* Standard reflectance value at parallel view angle.
197197
*/
@@ -439,168 +439,6 @@ export class BackgroundMaterial extends PushMaterial {
439439
@expandToProperty("_markAllSubMeshesAsLightsDirty")
440440
public shadowOnly: boolean = false;
441441

442-
/**
443-
* Default configuration related to image processing available in the Background Material.
444-
*/
445-
@serializeAsImageProcessingConfiguration()
446-
protected _imageProcessingConfiguration: ImageProcessingConfiguration;
447-
448-
/**
449-
* Keep track of the image processing observer to allow dispose and replace.
450-
*/
451-
private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>> = null;
452-
453-
/**
454-
* Attaches a new image processing configuration to the PBR Material.
455-
* @param configuration (if null the scene configuration will be use)
456-
*/
457-
protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void {
458-
if (configuration === this._imageProcessingConfiguration) {
459-
return;
460-
}
461-
462-
// Detaches observer.
463-
if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
464-
this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
465-
}
466-
467-
// Pick the scene configuration if needed.
468-
if (!configuration) {
469-
this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
470-
} else {
471-
this._imageProcessingConfiguration = configuration;
472-
}
473-
474-
// Attaches observer.
475-
if (this._imageProcessingConfiguration) {
476-
this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {
477-
this._computePrimaryColorFromPerceptualColor();
478-
this._markAllSubMeshesAsImageProcessingDirty();
479-
});
480-
}
481-
}
482-
483-
/**
484-
* Gets the image processing configuration used either in this material.
485-
*/
486-
public get imageProcessingConfiguration(): Nullable<ImageProcessingConfiguration> {
487-
return this._imageProcessingConfiguration;
488-
}
489-
490-
/**
491-
* Sets the Default image processing configuration used either in the this material.
492-
*
493-
* If sets to null, the scene one is in use.
494-
*/
495-
public set imageProcessingConfiguration(value: Nullable<ImageProcessingConfiguration>) {
496-
this._attachImageProcessingConfiguration(value);
497-
498-
// Ensure the effect will be rebuilt.
499-
this._markAllSubMeshesAsTexturesDirty();
500-
}
501-
502-
/**
503-
* Gets whether the color curves effect is enabled.
504-
*/
505-
public get cameraColorCurvesEnabled(): boolean {
506-
return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurvesEnabled;
507-
}
508-
/**
509-
* Sets whether the color curves effect is enabled.
510-
*/
511-
public set cameraColorCurvesEnabled(value: boolean) {
512-
(<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurvesEnabled = value;
513-
}
514-
515-
/**
516-
* Gets whether the color grading effect is enabled.
517-
*/
518-
public get cameraColorGradingEnabled(): boolean {
519-
return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingEnabled;
520-
}
521-
/**
522-
* Gets whether the color grading effect is enabled.
523-
*/
524-
public set cameraColorGradingEnabled(value: boolean) {
525-
(<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingEnabled = value;
526-
}
527-
528-
/**
529-
* Gets whether tonemapping is enabled or not.
530-
*/
531-
public get cameraToneMappingEnabled(): boolean {
532-
return this._imageProcessingConfiguration.toneMappingEnabled;
533-
}
534-
/**
535-
* Sets whether tonemapping is enabled or not
536-
*/
537-
public set cameraToneMappingEnabled(value: boolean) {
538-
this._imageProcessingConfiguration.toneMappingEnabled = value;
539-
}
540-
541-
/**
542-
* The camera exposure used on this material.
543-
* This property is here and not in the camera to allow controlling exposure without full screen post process.
544-
* This corresponds to a photographic exposure.
545-
*/
546-
public get cameraExposure(): float {
547-
return this._imageProcessingConfiguration.exposure;
548-
}
549-
/**
550-
* The camera exposure used on this material.
551-
* This property is here and not in the camera to allow controlling exposure without full screen post process.
552-
* This corresponds to a photographic exposure.
553-
*/
554-
public set cameraExposure(value: float) {
555-
this._imageProcessingConfiguration.exposure = value;
556-
}
557-
558-
/**
559-
* Gets The camera contrast used on this material.
560-
*/
561-
public get cameraContrast(): float {
562-
return this._imageProcessingConfiguration.contrast;
563-
}
564-
565-
/**
566-
* Sets The camera contrast used on this material.
567-
*/
568-
public set cameraContrast(value: float) {
569-
this._imageProcessingConfiguration.contrast = value;
570-
}
571-
572-
/**
573-
* Gets the Color Grading 2D Lookup Texture.
574-
*/
575-
public get cameraColorGradingTexture(): Nullable<BaseTexture> {
576-
return this._imageProcessingConfiguration.colorGradingTexture;
577-
}
578-
/**
579-
* Sets the Color Grading 2D Lookup Texture.
580-
*/
581-
public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
582-
(<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingTexture = value;
583-
}
584-
585-
/**
586-
* The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).
587-
* They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
588-
* These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
589-
* corresponding to low luminance, medium luminance, and high luminance areas respectively.
590-
*/
591-
public get cameraColorCurves(): Nullable<ColorCurves> {
592-
return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurves;
593-
}
594-
/**
595-
* The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).
596-
* They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
597-
* These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
598-
* corresponding to low luminance, medium luminance, and high luminance areas respectively.
599-
*/
600-
public set cameraColorCurves(value: Nullable<ColorCurves>) {
601-
(<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurves = value;
602-
}
603-
604442
/**
605443
* Due to a bug in iOS10, video tags (which are using the background material) are in BGR and not RGB.
606444
* Setting this flag to true (not done automatically!) will convert it back to RGB.

packages/dev/core/src/Materials/PBR/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export * from "./pbrBRDFConfiguration";
55
export * from "./pbrClearCoatConfiguration";
66
export * from "./pbrIridescenceConfiguration";
77
export * from "./pbrMaterial";
8-
export * from "./pbrMaterial2";
8+
export * from "./pbr2Material";
99
export * from "./pbrMetallicRoughnessMaterial";
1010
export * from "./pbrSpecularGlossinessMaterial";
1111
export * from "./pbrSheenConfiguration";

0 commit comments

Comments
 (0)