From add318a2bf8de3bf09b37170b1edb7f1691b3f73 Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Mon, 4 Nov 2024 15:15:20 -0800 Subject: [PATCH] Better alpha handling --- packages/dev/core/src/Layers/effectLayer.ts | 4 +- .../src/Lights/Shadows/shadowGenerator.ts | 2 +- .../Background/backgroundMaterial.ts | 2 +- .../core/src/Materials/PBR/pbrBaseMaterial.ts | 59 ++++++------------ packages/dev/core/src/Materials/material.ts | 60 +++++++++++-------- .../dev/core/src/Materials/shaderMaterial.ts | 2 +- .../core/src/Materials/standardMaterial.ts | 48 +++------------ .../volumetricLightScatteringPostProcess.ts | 4 +- .../dev/core/src/Rendering/depthRenderer.ts | 4 +- .../src/Rendering/geometryBufferRenderer.ts | 4 +- .../dev/core/src/Rendering/outlineRenderer.ts | 4 +- .../dev/core/src/Rendering/renderingGroup.ts | 2 +- .../dev/materials/src/cell/cellMaterial.ts | 2 +- packages/dev/materials/src/fur/furMaterial.ts | 2 +- .../src/gradient/gradientMaterial.ts | 2 +- .../dev/materials/src/lava/lavaMaterial.ts | 2 +- packages/dev/materials/src/mix/mixMaterial.ts | 2 +- .../materials/src/normal/normalMaterial.ts | 2 +- .../src/shadowOnly/shadowOnlyMaterial.ts | 2 +- .../materials/src/simple/simpleMaterial.ts | 2 +- .../materials/src/terrain/terrainMaterial.ts | 2 +- .../src/triPlanar/triPlanarMaterial.ts | 2 +- .../dev/materials/src/water/waterMaterial.ts | 2 +- 23 files changed, 87 insertions(+), 130 deletions(-) diff --git a/packages/dev/core/src/Layers/effectLayer.ts b/packages/dev/core/src/Layers/effectLayer.ts index c3102efb479..a387182eae8 100644 --- a/packages/dev/core/src/Layers/effectLayer.ts +++ b/packages/dev/core/src/Layers/effectLayer.ts @@ -595,7 +595,7 @@ export abstract class EffectLayer { // Diffuse if (material) { - const needAlphaTest = material.needAlphaTesting(); + const needAlphaTest = material.needAlphaTestingForMesh(mesh); const diffuseTexture = material.getAlphaTestTexture(); const needAlphaBlendFromDiffuse = @@ -986,7 +986,7 @@ export abstract class EffectLayer { } if (!renderingMaterial) { - const needAlphaTest = material.needAlphaTesting(); + const needAlphaTest = material.needAlphaTestingForMesh(effectiveMesh); const diffuseTexture = material.getAlphaTestTexture(); const needAlphaBlendFromDiffuse = diff --git a/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts b/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts index 28c921eb0ec..04cda71aca0 100644 --- a/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts +++ b/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts @@ -1564,7 +1564,7 @@ export class ShadowGenerator implements IShadowGenerator { } // Alpha test - const needAlphaTesting = material.needAlphaTesting(); + const needAlphaTesting = material.needAlphaTestingForMesh(mesh); if (needAlphaTesting || material.needAlphaBlending()) { if (this.useOpacityTextureForTransparentShadow) { diff --git a/packages/dev/core/src/Materials/Background/backgroundMaterial.ts b/packages/dev/core/src/Materials/Background/backgroundMaterial.ts index 6c95d076ae4..e3ab1e457f5 100644 --- a/packages/dev/core/src/Materials/Background/backgroundMaterial.ts +++ b/packages/dev/core/src/Materials/Background/backgroundMaterial.ts @@ -889,7 +889,7 @@ export class BackgroundMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Values that need to be evaluated on every frame PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances, null, subMesh.getRenderingMesh().hasThinInstances); diff --git a/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts b/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts index 77138c03e49..846b980c711 100644 --- a/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts +++ b/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts @@ -725,12 +725,6 @@ export abstract class PBRBaseMaterial extends PushMaterial { */ public _alphaCutOff = 0.4; - /** - * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations. - * @internal - */ - public override _forceAlphaTest = false; - /** * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested. * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel) @@ -1001,55 +995,38 @@ export abstract class PBRBaseMaterial extends PushMaterial { return "PBRBaseMaterial"; } - /** - * Returns true if alpha blending should be disabled. - */ - protected override get _disableAlphaBlending(): boolean { - return ( - this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_OPAQUE || - this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST || - this.subSurface?.disableAlphaBlending - ); + protected _shouldUseAlphaFromAlbedoTexture(): boolean { + return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE; } - /** - * @returns whether or not this material should be rendered in alpha blend mode. - */ + protected override _hasAlpha(mesh: AbstractMesh): boolean { + return super._hasAlpha(mesh) || this._shouldUseAlphaFromAlbedoTexture() || this._opacityTexture != null; + } + + /** @override */ public override needAlphaBlending(): boolean { - if (this._disableAlphaBlending) { + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; + } + + if (this.subSurface?.disableAlphaBlending) { return false; } - return this.alpha < 1.0 || this._opacityTexture != null || this._shouldUseAlphaFromAlbedoTexture(); + return super.needAlphaBlending(); } - /** - * @returns whether or not this material should be rendered in alpha test mode. - */ + /** @override */ public override needAlphaTesting(): boolean { - if (this._forceAlphaTest) { - return true; + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; } if (this.subSurface?.disableAlphaBlending) { return false; } - return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST); - } - - /** - * @returns whether or not the alpha value of the albedo texture should be used for alpha blending. - */ - protected _shouldUseAlphaFromAlbedoTexture(): boolean { - return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE; - } - - /** - * @returns whether or not there is a usable alpha channel for transparency. - */ - protected _hasAlphaChannel(): boolean { - return (this._albedoTexture != null && this._albedoTexture.hasAlpha) || this._opacityTexture != null; + return super.needAlphaTesting(); } /** @@ -1894,7 +1871,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, - this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, + this.needAlphaTestingForMesh(mesh), defines, this._applyDecalMapAfterDetailMap ); diff --git a/packages/dev/core/src/Materials/material.ts b/packages/dev/core/src/Materials/material.ts index 09aac5b7ed3..f94c26aad58 100644 --- a/packages/dev/core/src/Materials/material.ts +++ b/packages/dev/core/src/Materials/material.ts @@ -1081,11 +1081,6 @@ export class Material implements IAnimatable, IClipPlanesHolder { return this.sideOrientation !== null ? this.sideOrientation : mesh.sideOrientation; } - /** - * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations. - */ - protected _forceAlphaTest = false; - /** * The transparency mode of the material. */ @@ -1117,16 +1112,23 @@ export class Material implements IAnimatable, IClipPlanesHolder { this._transparencyMode = value; - this._forceAlphaTest = value === Material.MATERIAL_ALPHATESTANDBLEND; - this._markAllSubMeshesAsTexturesAndMiscDirty(); } - /** - * Returns true if alpha blending should be disabled. - */ - protected get _disableAlphaBlending(): boolean { - return this._transparencyMode === Material.MATERIAL_OPAQUE || this._transparencyMode === Material.MATERIAL_ALPHATEST; + protected get _hasTransparencyMode(): boolean { + return this._transparencyMode != null; + } + + protected get _transparencyModeIsBlend(): boolean { + return this._transparencyMode === Material.MATERIAL_ALPHABLEND || this._transparencyMode === Material.MATERIAL_ALPHATESTANDBLEND; + } + + protected get _transparencyModeIsTest(): boolean { + return this._transparencyMode === Material.MATERIAL_ALPHATEST || this._transparencyMode === Material.MATERIAL_ALPHATESTANDBLEND; + } + + protected _hasAlpha(mesh: AbstractMesh): boolean { + return this.alpha < 1.0 || mesh.hasVertexAlpha; } /** @@ -1134,8 +1136,8 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @returns a boolean specifying if alpha blending is needed */ public needAlphaBlending(): boolean { - if (this._disableAlphaBlending) { - return false; + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; } return this.alpha < 1.0; @@ -1147,15 +1149,15 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @returns a boolean specifying if alpha blending is needed for the mesh */ public needAlphaBlendingForMesh(mesh: AbstractMesh): boolean { - if (mesh.visibility < 1.0) { - return true; + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; } - if (this._disableAlphaBlending) { - return false; + if (this.needAlphaBlending()) { + return true; } - return mesh.hasVertexAlpha || this.needAlphaBlending(); + return this._hasAlpha(mesh) || mesh.visibility < 1.0; } /** @@ -1163,20 +1165,28 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @returns a boolean specifying if an alpha test is needed. */ public needAlphaTesting(): boolean { - if (this._forceAlphaTest) { - return true; + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; } return false; } /** - * Specifies if material alpha testing should be turned on for the mesh + * Specifies whether or not this material should be rendered in alpha test mode when used with the given mesh. * @param mesh defines the mesh to check - * @returns a boolean specifying if alpha testing should be turned on for the mesh + * @returns a boolean specifying if an alpha test is needed. */ - protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean { - return !this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting(); + public needAlphaTestingForMesh(mesh: AbstractMesh): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; + } + + if (this.needAlphaTesting()) { + return true; + } + + return this._hasAlpha(mesh); } /** diff --git a/packages/dev/core/src/Materials/shaderMaterial.ts b/packages/dev/core/src/Materials/shaderMaterial.ts index 00d3db8d18c..9b9f8cc36d7 100644 --- a/packages/dev/core/src/Materials/shaderMaterial.ts +++ b/packages/dev/core/src/Materials/shaderMaterial.ts @@ -855,7 +855,7 @@ export class ShaderMaterial extends PushMaterial { } // Alpha test - if (mesh && this._shouldTurnAlphaTestOn(mesh)) { + if (mesh && this.needAlphaTestingForMesh(mesh)) { defines.push("#define ALPHATEST"); } diff --git a/packages/dev/core/src/Materials/standardMaterial.ts b/packages/dev/core/src/Materials/standardMaterial.ts index 13591cfe65c..14cdce7be75 100644 --- a/packages/dev/core/src/Materials/standardMaterial.ts +++ b/packages/dev/core/src/Materials/standardMaterial.ts @@ -866,47 +866,17 @@ export class StandardMaterial extends PushMaterial { return "StandardMaterial"; } - /** - * Specifies if the material will require alpha blending - * @returns a boolean specifying if alpha blending is needed - */ - public override needAlphaBlending(): boolean { - if (this._disableAlphaBlending) { - return false; - } - - return ( - this.alpha < 1.0 || - this._opacityTexture != null || - this._shouldUseAlphaFromDiffuseTexture() || - (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled) - ); - } - - /** - * Specifies if this material should be rendered in alpha test mode - * @returns a boolean specifying if an alpha test is needed. - */ - public override needAlphaTesting(): boolean { - if (this._forceAlphaTest) { - return true; - } - - return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST); - } - - /** - * @returns whether or not the alpha value of the diffuse texture should be used for alpha blending. - */ protected _shouldUseAlphaFromDiffuseTexture(): boolean { return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture && this._transparencyMode !== Material.MATERIAL_OPAQUE; } - /** - * @returns whether or not there is a usable alpha channel for transparency. - */ - protected _hasAlphaChannel(): boolean { - return (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._opacityTexture != null; + protected override _hasAlpha(mesh: AbstractMesh): boolean { + return super._hasAlpha(mesh) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityTexture != null; + } + + /** @override */ + public override needAlphaBlending(): boolean { + return super.needAlphaBlending() || this._opacityFresnelParameters?.isEnabled; } /** @@ -1221,7 +1191,7 @@ export class StandardMaterial extends PushMaterial { this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, - this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, + this.needAlphaTestingForMesh(mesh), defines, this._applyDecalMapAfterDetailMap ); @@ -1687,7 +1657,7 @@ export class StandardMaterial extends PushMaterial { BindTextureMatrix(this._opacityTexture, ubo, "opacity"); } - if (this._hasAlphaChannel()) { + if (this._hasAlpha(mesh)) { ubo.updateFloat("alphaCutOff", this.alphaCutOff); } diff --git a/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts b/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts index 7a812024306..5716618229b 100644 --- a/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts +++ b/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts @@ -213,7 +213,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess { // Alpha test if (material) { - if (material.needAlphaTesting()) { + if (material.needAlphaTestingForMesh(mesh)) { defines.push("#define ALPHATEST"); } @@ -463,7 +463,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess { effect.setMatrix("viewProjection", scene.getTransformMatrix()); // Alpha test - if (material.needAlphaTesting()) { + if (material.needAlphaTestingForMesh(effectiveMesh)) { const alphaTexture = material.getAlphaTestTexture(); if (alphaTexture) { diff --git a/packages/dev/core/src/Rendering/depthRenderer.ts b/packages/dev/core/src/Rendering/depthRenderer.ts index 7ae6085e2ce..5412d8b0c97 100644 --- a/packages/dev/core/src/Rendering/depthRenderer.ts +++ b/packages/dev/core/src/Rendering/depthRenderer.ts @@ -284,7 +284,7 @@ export class DepthRenderer { if (!renderingMaterial) { // Alpha test - if (material.needAlphaTesting()) { + if (material.needAlphaTestingForMesh(effectiveMesh)) { const alphaTexture = material.getAlphaTestTexture(); if (alphaTexture) { @@ -404,7 +404,7 @@ export class DepthRenderer { const attribs = [VertexBuffer.PositionKind]; // Alpha test - if (material.needAlphaTesting() && material.getAlphaTestTexture()) { + if (material.needAlphaTestingForMesh(mesh) && material.getAlphaTestTexture()) { defines.push("#define ALPHATEST"); if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) { attribs.push(VertexBuffer.UVKind); diff --git a/packages/dev/core/src/Rendering/geometryBufferRenderer.ts b/packages/dev/core/src/Rendering/geometryBufferRenderer.ts index f7c9c50da7a..214f7e7d30f 100644 --- a/packages/dev/core/src/Rendering/geometryBufferRenderer.ts +++ b/packages/dev/core/src/Rendering/geometryBufferRenderer.ts @@ -524,7 +524,7 @@ export class GeometryBufferRenderer { if (material) { let needUv = false; // Alpha test - if (material.needAlphaTesting() && material.getAlphaTestTexture()) { + if (material.needAlphaTestingForMesh(mesh) && material.getAlphaTestTexture()) { defines.push("#define ALPHATEST"); defines.push(`#define ALPHATEST_UV${material.getAlphaTestTexture().coordinatesIndex + 1}`); needUv = true; @@ -1045,7 +1045,7 @@ export class GeometryBufferRenderer { material._preBind(drawWrapper, sideOrientation); // Alpha test - if (material.needAlphaTesting()) { + if (material.needAlphaTestingForMesh(effectiveMesh)) { const alphaTexture = material.getAlphaTestTexture(); if (alphaTexture) { effect.setTexture("diffuseSampler", alphaTexture); diff --git a/packages/dev/core/src/Rendering/outlineRenderer.ts b/packages/dev/core/src/Rendering/outlineRenderer.ts index 3dde8450679..c3cde9070ec 100644 --- a/packages/dev/core/src/Rendering/outlineRenderer.ts +++ b/packages/dev/core/src/Rendering/outlineRenderer.ts @@ -242,7 +242,7 @@ export class OutlineRenderer implements ISceneComponent { } // Alpha test - if (material && material.needAlphaTesting()) { + if (material && material.needAlphaTestingForMesh(effectiveMesh)) { const alphaTexture = material.getAlphaTestTexture(); if (alphaTexture) { effect.setTexture("diffuseSampler", alphaTexture); @@ -288,7 +288,7 @@ export class OutlineRenderer implements ISceneComponent { const scene = mesh.getScene(); // Alpha test - if (material.needAlphaTesting()) { + if (material.needAlphaTestingForMesh(mesh)) { defines.push("#define ALPHATEST"); if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) { attribs.push(VertexBuffer.UVKind); diff --git a/packages/dev/core/src/Rendering/renderingGroup.ts b/packages/dev/core/src/Rendering/renderingGroup.ts index a147d5a5bbb..98aa1c9b567 100644 --- a/packages/dev/core/src/Rendering/renderingGroup.ts +++ b/packages/dev/core/src/Rendering/renderingGroup.ts @@ -411,7 +411,7 @@ export class RenderingGroup { if (material.needAlphaBlendingForMesh(mesh)) { // Transparent this._transparentSubMeshes.push(subMesh); - } else if (material.needAlphaTesting()) { + } else if (material.needAlphaTestingForMesh(mesh)) { // Alpha test if (material.needDepthPrePass) { this._depthOnlySubMeshes.push(subMesh); diff --git a/packages/dev/materials/src/cell/cellMaterial.ts b/packages/dev/materials/src/cell/cellMaterial.ts index cff176a2628..57b208893c1 100644 --- a/packages/dev/materials/src/cell/cellMaterial.ts +++ b/packages/dev/materials/src/cell/cellMaterial.ts @@ -152,7 +152,7 @@ export class CellMaterial extends PushMaterial { defines.CELLBASIC = !this.computeHighLevel; // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/fur/furMaterial.ts b/packages/dev/materials/src/fur/furMaterial.ts index b5360a50ae7..b498fcc49fe 100644 --- a/packages/dev/materials/src/fur/furMaterial.ts +++ b/packages/dev/materials/src/fur/furMaterial.ts @@ -228,7 +228,7 @@ export class FurMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/gradient/gradientMaterial.ts b/packages/dev/materials/src/gradient/gradientMaterial.ts index e23b0316c01..0fbe89e1520 100644 --- a/packages/dev/materials/src/gradient/gradientMaterial.ts +++ b/packages/dev/materials/src/gradient/gradientMaterial.ts @@ -142,7 +142,7 @@ export class GradientMaterial extends PushMaterial { PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false); - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/lava/lavaMaterial.ts b/packages/dev/materials/src/lava/lavaMaterial.ts index 10f387a1002..ff5ce31f637 100644 --- a/packages/dev/materials/src/lava/lavaMaterial.ts +++ b/packages/dev/materials/src/lava/lavaMaterial.ts @@ -210,7 +210,7 @@ export class LavaMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = true; diff --git a/packages/dev/materials/src/mix/mixMaterial.ts b/packages/dev/materials/src/mix/mixMaterial.ts index 78c3c627107..01894d3700e 100644 --- a/packages/dev/materials/src/mix/mixMaterial.ts +++ b/packages/dev/materials/src/mix/mixMaterial.ts @@ -240,7 +240,7 @@ export class MixMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/normal/normalMaterial.ts b/packages/dev/materials/src/normal/normalMaterial.ts index 78fc4bd2941..d2ffc1c7d1b 100644 --- a/packages/dev/materials/src/normal/normalMaterial.ts +++ b/packages/dev/materials/src/normal/normalMaterial.ts @@ -184,7 +184,7 @@ export class NormalMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = true; diff --git a/packages/dev/materials/src/shadowOnly/shadowOnlyMaterial.ts b/packages/dev/materials/src/shadowOnly/shadowOnlyMaterial.ts index 3c7f4afee8c..712d29dd4c3 100644 --- a/packages/dev/materials/src/shadowOnly/shadowOnlyMaterial.ts +++ b/packages/dev/materials/src/shadowOnly/shadowOnlyMaterial.ts @@ -141,7 +141,7 @@ export class ShadowOnlyMaterial extends PushMaterial { PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false); - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, 1); diff --git a/packages/dev/materials/src/simple/simpleMaterial.ts b/packages/dev/materials/src/simple/simpleMaterial.ts index 168ee233fb6..49c4b768414 100644 --- a/packages/dev/materials/src/simple/simpleMaterial.ts +++ b/packages/dev/materials/src/simple/simpleMaterial.ts @@ -141,7 +141,7 @@ export class SimpleMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/terrain/terrainMaterial.ts b/packages/dev/materials/src/terrain/terrainMaterial.ts index 32511fb8382..988603f8773 100644 --- a/packages/dev/materials/src/terrain/terrainMaterial.ts +++ b/packages/dev/materials/src/terrain/terrainMaterial.ts @@ -203,7 +203,7 @@ export class TerrainMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/triPlanar/triPlanarMaterial.ts b/packages/dev/materials/src/triPlanar/triPlanarMaterial.ts index 86f2c2ec969..b90717f06cd 100644 --- a/packages/dev/materials/src/triPlanar/triPlanarMaterial.ts +++ b/packages/dev/materials/src/triPlanar/triPlanarMaterial.ts @@ -205,7 +205,7 @@ export class TriPlanarMaterial extends PushMaterial { } // Misc. - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); // Lights defines._needNormals = PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting); diff --git a/packages/dev/materials/src/water/waterMaterial.ts b/packages/dev/materials/src/water/waterMaterial.ts index 3ebabdcbcd9..88d03c6a9a2 100644 --- a/packages/dev/materials/src/water/waterMaterial.ts +++ b/packages/dev/materials/src/water/waterMaterial.ts @@ -394,7 +394,7 @@ export class WaterMaterial extends PushMaterial { PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false); - PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines); + PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines); if (defines._areMiscDirty) { defines.FRESNELSEPARATE = this._fresnelSeparate;