Skip to content

Commit b3e25ff

Browse files
author
Mike Bond
committed
Try mixins for reusing defines in materials
1 parent 97a5c69 commit b3e25ff

File tree

7 files changed

+54
-132
lines changed

7 files changed

+54
-132
lines changed

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { IEffectCreationOptions } from "../../Materials/effect";
1515
import { MaterialDefines } from "../../Materials/materialDefines";
1616
import { PushMaterial } from "../../Materials/pushMaterial";
1717
import type { ColorCurves } from "../../Materials/colorCurves";
18-
import type { IImageProcessingConfigurationDefines } from "../../Materials/imageProcessingConfiguration.defines";
18+
import { ImageProcessingDefinesMixin } from "../../Materials/imageProcessingConfiguration.defines";
1919
import { ImageProcessingConfiguration } from "../../Materials/imageProcessingConfiguration";
2020
import type { BaseTexture } from "../../Materials/Textures/baseTexture";
2121
import { Texture } from "../../Materials/Textures/texture";
@@ -48,11 +48,13 @@ import {
4848
import { SerializationHelper } from "../../Misc/decorators.serialization";
4949
import { ShaderLanguage } from "../shaderLanguage";
5050

51+
class BackgroundMaterialDefinesBase extends MaterialDefines {}
52+
5153
/**
5254
* Background material defines definition.
5355
* @internal Mainly internal Use
5456
*/
55-
class BackgroundMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {
57+
class BackgroundMaterialDefines extends ImageProcessingDefinesMixin(BackgroundMaterialDefinesBase) {
5658
/**
5759
* True if the diffuse texture is in use.
5860
*/
@@ -135,23 +137,6 @@ class BackgroundMaterialDefines extends MaterialDefines implements IImageProcess
135137
*/
136138
public PROJECTED_GROUND = false;
137139

138-
public IMAGEPROCESSING = false;
139-
public VIGNETTE = false;
140-
public VIGNETTEBLENDMODEMULTIPLY = false;
141-
public VIGNETTEBLENDMODEOPAQUE = false;
142-
public TONEMAPPING = 0;
143-
public CONTRAST = false;
144-
public COLORCURVES = false;
145-
public COLORGRADING = false;
146-
public COLORGRADING3D = false;
147-
public SAMPLER3DGREENDEPTH = false;
148-
public SAMPLER3DBGRMAP = false;
149-
public DITHER = false;
150-
public IMAGEPROCESSINGPOSTPROCESS = false;
151-
public SKIPFINALCOLORCLAMP = false;
152-
public EXPOSURE = false;
153-
public MULTIVIEW = false;
154-
155140
// Reflection.
156141
public REFLECTION = false;
157142
public REFLECTIONMAP_3D = false;

packages/dev/core/src/Materials/Node/nodeMaterial.ts

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import type { NodeMaterialTeleportOutBlock } from "./Blocks/Teleport/teleportOut
6767
import type { NodeMaterialTeleportInBlock } from "./Blocks/Teleport/teleportInBlock";
6868
import { Logger } from "core/Misc/logger";
6969
import { PrepareDefinesForCamera, PrepareDefinesForPrePass } from "../materialHelper.functions";
70-
import type { IImageProcessingConfigurationDefines } from "../imageProcessingConfiguration.defines";
70+
import { ImageProcessingDefinesMixin } from "../imageProcessingConfiguration.defines";
7171
import { ShaderLanguage } from "../shaderLanguage";
7272
import { AbstractEngine } from "../../Engines/abstractEngine";
7373
import type { LoopBlock } from "./Blocks/loopBlock";
@@ -91,8 +91,10 @@ export interface INodeMaterialEditorOptions {
9191
};
9292
}
9393

94+
class NodeMaterialDefinesBase extends MaterialDefines {}
95+
9496
/** @internal */
95-
export class NodeMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {
97+
export class NodeMaterialDefines extends ImageProcessingDefinesMixin(NodeMaterialDefinesBase) {
9698
/** Normal */
9799
public NORMAL = false;
98100
/** Tangent */
@@ -177,37 +179,6 @@ export class NodeMaterialDefines extends MaterialDefines implements IImageProces
177179
/** Using a texture to store morph target data */
178180
public MORPHTARGETS_TEXTURE = false;
179181

180-
/** IMAGE PROCESSING */
181-
public IMAGEPROCESSING = false;
182-
/** Vignette */
183-
public VIGNETTE = false;
184-
/** Multiply blend mode for vignette */
185-
public VIGNETTEBLENDMODEMULTIPLY = false;
186-
/** Opaque blend mode for vignette */
187-
public VIGNETTEBLENDMODEOPAQUE = false;
188-
/** Tone mapping */
189-
public TONEMAPPING = 0;
190-
/** Contrast */
191-
public CONTRAST = false;
192-
/** Exposure */
193-
public EXPOSURE = false;
194-
/** Color curves */
195-
public COLORCURVES = false;
196-
/** Color grading */
197-
public COLORGRADING = false;
198-
/** 3D color grading */
199-
public COLORGRADING3D = false;
200-
/** Sampler green depth */
201-
public SAMPLER3DGREENDEPTH = false;
202-
/** Sampler for BGR map */
203-
public SAMPLER3DBGRMAP = false;
204-
/** Dithering */
205-
public DITHER = false;
206-
/** Using post process for image processing */
207-
public IMAGEPROCESSINGPOSTPROCESS = false;
208-
/** Skip color clamp */
209-
public SKIPFINALCOLORCLAMP = false;
210-
211182
/** MISC. */
212183
public BUMPDIRECTUV = 0;
213184
/** Camera is orthographic */

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { PBRBRDFConfiguration } from "./pbrBRDFConfiguration";
1616
import { PrePassConfiguration } from "../prePassConfiguration";
1717
import { Color3, TmpColors } from "../../Maths/math.color";
1818

19-
import type { IImageProcessingConfigurationDefines } from "../../Materials/imageProcessingConfiguration.defines";
19+
import { ImageProcessingDefinesMixin } from "../../Materials/imageProcessingConfiguration.defines";
2020
import { ImageProcessingConfiguration } from "../../Materials/imageProcessingConfiguration";
2121
import type { Effect, IEffectCreationOptions } from "../../Materials/effect";
2222
import type { IMaterialCompilationOptions, ICustomShaderNameResolveOptions } from "../../Materials/material";
@@ -71,11 +71,13 @@ import { MaterialHelperGeometryRendering } from "../materialHelper.geometryrende
7171

7272
const onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable<SubMesh> };
7373

74+
class PBRMaterialDefinesBase extends MaterialDefines {}
75+
7476
/**
7577
* Manages the defines for the PBR Material.
7678
* @internal
7779
*/
78-
export class PBRMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {
80+
export class PBRMaterialDefines extends ImageProcessingDefinesMixin(PBRMaterialDefinesBase) {
7981
public PBR = true;
8082

8183
public NUM_SAMPLES = "0";
@@ -256,25 +258,6 @@ export class PBRMaterialDefines extends MaterialDefines implements IImageProcess
256258
public NUM_MORPH_INFLUENCERS = 0;
257259
public MORPHTARGETS_TEXTURE = false;
258260

259-
public IMAGEPROCESSING = false;
260-
public VIGNETTE = false;
261-
public VIGNETTEBLENDMODEMULTIPLY = false;
262-
public VIGNETTEBLENDMODEOPAQUE = false;
263-
public TONEMAPPING = 0;
264-
public CONTRAST = false;
265-
public COLORCURVES = false;
266-
public COLORGRADING = false;
267-
public COLORGRADING3D = false;
268-
public SAMPLER3DGREENDEPTH = false;
269-
public SAMPLER3DBGRMAP = false;
270-
public DITHER = false;
271-
public IMAGEPROCESSINGPOSTPROCESS = false;
272-
public SKIPFINALCOLORCLAMP = false;
273-
public EXPOSURE = false;
274-
public MULTIVIEW = false;
275-
public ORDER_INDEPENDENT_TRANSPARENCY = false;
276-
public ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;
277-
278261
public USEPHYSICALLIGHTFALLOFF = false;
279262
public USEGLTFLIGHTFALLOFF = false;
280263
public TWOSIDEDLIGHTING = false;

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { SerializationHelper } from "../../Misc/decorators.serialization";
1515
import type { AbstractMesh } from "../../Meshes/abstractMesh";
1616
import type { Effect, IEffectCreationOptions } from "../../Materials/effect";
1717
import { MaterialDefines } from "../../Materials/materialDefines";
18-
import type { IImageProcessingConfigurationDefines } from "../../Materials/imageProcessingConfiguration.defines";
18+
import { ImageProcessingDefinesMixin } from "../../Materials/imageProcessingConfiguration.defines";
1919
import { EffectFallbacks } from "../effectFallbacks";
2020
import { AddClipPlaneUniforms } from "../clipPlaneMaterialHelper";
2121
import {
@@ -53,11 +53,13 @@ import type { SubMesh } from "../../Meshes/subMesh";
5353
import { Logger } from "core/Misc/logger";
5454

5555
const onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable<SubMesh> };
56+
57+
class PBRMaterial2DefinesBase extends MaterialDefines {}
5658
/**
5759
* Manages the defines for the PBR Material.
5860
* @internal
5961
*/
60-
export class PBRMaterial2Defines extends MaterialDefines implements IImageProcessingConfigurationDefines {
62+
export class PBRMaterial2Defines extends ImageProcessingDefinesMixin(PBRMaterial2DefinesBase) {
6163
public PBR = true;
6264

6365
public NUM_SAMPLES = "0";
@@ -238,25 +240,6 @@ export class PBRMaterial2Defines extends MaterialDefines implements IImageProces
238240
public NUM_MORPH_INFLUENCERS = 0;
239241
public MORPHTARGETS_TEXTURE = false;
240242

241-
public IMAGEPROCESSING = false;
242-
public VIGNETTE = false;
243-
public VIGNETTEBLENDMODEMULTIPLY = false;
244-
public VIGNETTEBLENDMODEOPAQUE = false;
245-
public TONEMAPPING = 0;
246-
public CONTRAST = false;
247-
public COLORCURVES = false;
248-
public COLORGRADING = false;
249-
public COLORGRADING3D = false;
250-
public SAMPLER3DGREENDEPTH = false;
251-
public SAMPLER3DBGRMAP = false;
252-
public DITHER = false;
253-
public IMAGEPROCESSINGPOSTPROCESS = false;
254-
public SKIPFINALCOLORCLAMP = false;
255-
public EXPOSURE = false;
256-
public MULTIVIEW = false;
257-
public ORDER_INDEPENDENT_TRANSPARENCY = false;
258-
public ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;
259-
260243
public USEPHYSICALLIGHTFALLOFF = false;
261244
public USEGLTFLIGHTFALLOFF = false;
262245
public TWOSIDEDLIGHTING = false;

packages/dev/core/src/Materials/imageProcessingConfiguration.defines.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,36 @@ export interface IImageProcessingConfigurationDefines {
2222
SKIPFINALCOLORCLAMP: boolean;
2323
}
2424

25+
type Constructor<T = {}> = new (...args: any[]) => T;
26+
27+
/**
28+
* Mixin to add Image processing defines to your material defines
29+
* @internal
30+
*/
31+
export function ImageProcessingDefinesMixin<Tbase extends Constructor>(base: Tbase) {
32+
return class extends base implements IImageProcessingConfigurationDefines {
33+
// Implement all members of IImageProcessingConfigurationDefines here
34+
public IMAGEPROCESSING = false;
35+
public VIGNETTE = false;
36+
public VIGNETTEBLENDMODEMULTIPLY = false;
37+
public VIGNETTEBLENDMODEOPAQUE = false;
38+
public TONEMAPPING = 0;
39+
public CONTRAST = false;
40+
public COLORCURVES = false;
41+
public COLORGRADING = false;
42+
public COLORGRADING3D = false;
43+
public SAMPLER3DGREENDEPTH = false;
44+
public SAMPLER3DBGRMAP = false;
45+
public DITHER = false;
46+
public IMAGEPROCESSINGPOSTPROCESS = false;
47+
public SKIPFINALCOLORCLAMP = false;
48+
public EXPOSURE = false;
49+
public MULTIVIEW = false;
50+
public ORDER_INDEPENDENT_TRANSPARENCY = false;
51+
public ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;
52+
};
53+
}
54+
2555
/**
2656
* @internal
2757
*/

packages/dev/core/src/Materials/standardMaterial.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { AbstractMesh } from "../Meshes/abstractMesh";
1414
import type { Mesh } from "../Meshes/mesh";
1515
import { PrePassConfiguration } from "./prePassConfiguration";
1616

17-
import type { IImageProcessingConfigurationDefines } from "./imageProcessingConfiguration.defines";
17+
import { ImageProcessingDefinesMixin } from "./imageProcessingConfiguration.defines";
1818
import { ImageProcessingConfiguration } from "./imageProcessingConfiguration";
1919
import type { ColorCurves } from "./colorCurves";
2020
import type { FresnelParameters } from "./fresnelParameters";
@@ -64,8 +64,10 @@ import { MaterialHelperGeometryRendering } from "./materialHelper.geometryrender
6464

6565
const onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable<SubMesh> };
6666

67+
class StandardMaterialDefinesBase extends MaterialDefines {}
68+
6769
/** @internal */
68-
export class StandardMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {
70+
export class StandardMaterialDefines extends ImageProcessingDefinesMixin(StandardMaterialDefinesBase) {
6971
public MAINUV1 = false;
7072
public MAINUV2 = false;
7173
public MAINUV3 = false;
@@ -211,23 +213,6 @@ export class StandardMaterialDefines extends MaterialDefines implements IImagePr
211213
public RGBDREFLECTION = false;
212214
public RGBDREFRACTION = false;
213215

214-
public IMAGEPROCESSING = false;
215-
public VIGNETTE = false;
216-
public VIGNETTEBLENDMODEMULTIPLY = false;
217-
public VIGNETTEBLENDMODEOPAQUE = false;
218-
public TONEMAPPING = 0;
219-
public CONTRAST = false;
220-
public COLORCURVES = false;
221-
public COLORGRADING = false;
222-
public COLORGRADING3D = false;
223-
public SAMPLER3DGREENDEPTH = false;
224-
public SAMPLER3DBGRMAP = false;
225-
public DITHER = false;
226-
public IMAGEPROCESSINGPOSTPROCESS = false;
227-
public SKIPFINALCOLORCLAMP = false;
228-
public MULTIVIEW = false;
229-
public ORDER_INDEPENDENT_TRANSPARENCY = false;
230-
public ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;
231216
public CAMERA_ORTHOGRAPHIC = false;
232217
public CAMERA_PERSPECTIVE = false;
233218
public AREALIGHTSUPPORTED = true;
@@ -242,7 +227,6 @@ export class StandardMaterialDefines extends MaterialDefines implements IImagePr
242227
* @internal
243228
*/
244229
public IS_REFRACTION_LINEAR = false;
245-
public EXPOSURE = false;
246230

247231
public DECAL_AFTER_DETAIL = false;
248232

packages/dev/materials/src/water/waterMaterial.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { BaseTexture } from "core/Materials/Textures/baseTexture";
1313
import { RenderTargetTexture } from "core/Materials/Textures/renderTargetTexture";
1414
import type { IEffectCreationOptions } from "core/Materials/effect";
1515
import { MaterialDefines } from "core/Materials/materialDefines";
16-
import type { IImageProcessingConfigurationDefines } from "core/Materials/imageProcessingConfiguration.defines";
16+
import { ImageProcessingDefinesMixin } from "core/Materials/imageProcessingConfiguration.defines";
1717
import { ImageProcessingConfiguration } from "core/Materials/imageProcessingConfiguration";
1818
import { PushMaterial } from "core/Materials/pushMaterial";
1919
import { MaterialFlags } from "core/Materials/materialFlags";
@@ -47,7 +47,9 @@ import {
4747

4848
import "core/Rendering/boundingBoxRenderer";
4949

50-
class WaterMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {
50+
class WaterMaterialDefinesBase extends MaterialDefines {}
51+
52+
class WaterMaterialDefines extends ImageProcessingDefinesMixin(WaterMaterialDefinesBase) {
5153
public BUMP = false;
5254
public REFLECTION = false;
5355
public CLIPPLANE = false;
@@ -77,22 +79,6 @@ class WaterMaterialDefines extends MaterialDefines implements IImageProcessingCo
7779
public BUMPAFFECTSREFLECTION = false;
7880
public USE_WORLD_COORDINATES = false;
7981

80-
public IMAGEPROCESSING = false;
81-
public VIGNETTE = false;
82-
public VIGNETTEBLENDMODEMULTIPLY = false;
83-
public VIGNETTEBLENDMODEOPAQUE = false;
84-
public TONEMAPPING = 0;
85-
public CONTRAST = false;
86-
public EXPOSURE = false;
87-
public COLORCURVES = false;
88-
public COLORGRADING = false;
89-
public COLORGRADING3D = false;
90-
public SAMPLER3DGREENDEPTH = false;
91-
public SAMPLER3DBGRMAP = false;
92-
public DITHER = false;
93-
public IMAGEPROCESSINGPOSTPROCESS = false;
94-
public SKIPFINALCOLORCLAMP = false;
95-
9682
constructor() {
9783
super();
9884
this.rebuild();

0 commit comments

Comments
 (0)