Skip to content

Commit

Permalink
Fix #12987 (#12995)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh authored Sep 19, 2022
1 parent d0d52bd commit 318e204
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/dev/core/src/Materials/Textures/baseTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions packages/dev/core/src/Materials/Textures/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Materials/materialHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 318e204

Please sign in to comment.