diff --git a/packages/dev/core/src/Materials/Textures/baseTexture.ts b/packages/dev/core/src/Materials/Textures/baseTexture.ts index a5d723ed022..af064021a78 100644 --- a/packages/dev/core/src/Materials/Textures/baseTexture.ts +++ b/packages/dev/core/src/Materials/Textures/baseTexture.ts @@ -103,6 +103,13 @@ export class BaseTexture extends ThinTexture implements IAnimatable { @serialize("coordinatesIndex") protected _coordinatesIndex = 0; + /** + * Gets or sets a boolean indicating that the texture should try to reduce shader code if there is no UV manipulation. + * (ie. when texture.getTextureMatrix().isIdentityAs3x2() returns true) + */ + @serialize() + public optimizeUVAllocation = true; + /** * Define the UV channel to use starting from 0 and defaulting to 0. * This is part of the texture as textures usually maps to one uv set. diff --git a/packages/dev/core/src/Materials/Textures/texture.ts b/packages/dev/core/src/Materials/Textures/texture.ts index 518c68ac159..6d9afa5b985 100644 --- a/packages/dev/core/src/Materials/Textures/texture.ts +++ b/packages/dev/core/src/Materials/Textures/texture.ts @@ -735,11 +735,13 @@ export class Texture extends BaseTexture { return this._cachedTextureMatrix; } - // We flag the materials that are using this texture as "texture dirty" because depending on the fact that the matrix is the identity or not, some defines - // will get different values (see MaterialHelper.PrepareDefinesForMergedUV), meaning we should regenerate the effect accordingly - scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => { - return mat.hasTexture(this); - }); + if (this.optimizeUVAllocation) { + // We flag the materials that are using this texture as "texture dirty" because depending on the fact that the matrix is the identity or not, some defines + // will get different values (see MaterialHelper.PrepareDefinesForMergedUV), meaning we should regenerate the effect accordingly + scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => { + return mat.hasTexture(this); + }); + } return this._cachedTextureMatrix; } diff --git a/packages/dev/core/src/Materials/materialHelper.ts b/packages/dev/core/src/Materials/materialHelper.ts index 37d2d11334f..523edd93532 100644 --- a/packages/dev/core/src/Materials/materialHelper.ts +++ b/packages/dev/core/src/Materials/materialHelper.ts @@ -47,7 +47,7 @@ export class MaterialHelper { public static PrepareDefinesForMergedUV(texture: BaseTexture, defines: any, key: string): void { defines._needUVs = true; defines[key] = true; - if (texture.getTextureMatrix().isIdentityAs3x2()) { + if (texture.optimizeUVAllocation && texture.getTextureMatrix().isIdentityAs3x2()) { defines[key + "DIRECTUV"] = texture.coordinatesIndex + 1; defines["MAINUV" + (texture.coordinatesIndex + 1)] = true; } else {