From b5c52bc80ec56088523a3e3144d4d125c20e2b68 Mon Sep 17 00:00:00 2001 From: Popov72 Date: Tue, 4 Feb 2025 17:03:22 +0100 Subject: [PATCH 1/3] Fix alpha support --- .../dev/core/src/Layers/thinEffectLayer.ts | 4 +-- .../src/Lights/Shadows/shadowGenerator.ts | 4 +-- .../Background/backgroundMaterial.ts | 2 +- .../core/src/Materials/PBR/pbrBaseMaterial.ts | 10 ++++++- packages/dev/core/src/Materials/material.ts | 30 ++++++++++++++++++- .../dev/core/src/Materials/shaderMaterial.ts | 2 +- .../core/src/Materials/standardMaterial.ts | 10 ++++++- .../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 +- .../tests/test/visualization/config.json | 6 ++-- 24 files changed, 76 insertions(+), 32 deletions(-) diff --git a/packages/dev/core/src/Layers/thinEffectLayer.ts b/packages/dev/core/src/Layers/thinEffectLayer.ts index 3238d2e49f9..f3c1a193e81 100644 --- a/packages/dev/core/src/Layers/thinEffectLayer.ts +++ b/packages/dev/core/src/Layers/thinEffectLayer.ts @@ -547,7 +547,7 @@ export class ThinEffectLayer { // Diffuse if (material) { - const needAlphaTest = material.needAlphaTesting(); + const needAlphaTest = material.needAlphaTestingForMesh(mesh); const diffuseTexture = material.getAlphaTestTexture(); const needAlphaBlendFromDiffuse = @@ -941,7 +941,7 @@ export class ThinEffectLayer { } 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 c7d6efc4b31..6a1db7c28ef 100644 --- a/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts +++ b/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts @@ -1608,9 +1608,9 @@ export class ShadowGenerator implements IShadowGenerator { } // Alpha test - const needAlphaTesting = material.needAlphaTesting(); + const needAlphaTesting = material.needAlphaTestingForMesh(mesh); - if (needAlphaTesting || material.needAlphaBlending()) { + if (needAlphaTesting || material.needAlphaBlendingForMesh(mesh)) { if (this.useOpacityTextureForTransparentShadow) { this._opacityTexture = (material as any).opacityTexture; } else { 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 6fe28007c3e..aa349653aad 100644 --- a/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts +++ b/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts @@ -1040,6 +1040,10 @@ export abstract class PBRBaseMaterial extends PushMaterial { * @returns whether or not this material should be rendered in alpha blend mode. */ public override needAlphaBlending(): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; + } + if (this._disableAlphaBlending) { return false; } @@ -1051,6 +1055,10 @@ export abstract class PBRBaseMaterial extends PushMaterial { * @returns whether or not this material should be rendered in alpha test mode. */ public override needAlphaTesting(): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; + } + if (this._forceAlphaTest) { return true; } @@ -1951,7 +1959,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, - this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, + this.needAlphaTestingForMesh(mesh) || this.needAlphaTesting(), defines, this._applyDecalMapAfterDetailMap ); diff --git a/packages/dev/core/src/Materials/material.ts b/packages/dev/core/src/Materials/material.ts index f1d622caee6..cd2af7f8c56 100644 --- a/packages/dev/core/src/Materials/material.ts +++ b/packages/dev/core/src/Materials/material.ts @@ -1132,6 +1132,18 @@ export class Material implements IAnimatable, IClipPlanesHolder { this._markAllSubMeshesAsTexturesAndMiscDirty(); } + 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; + } + /** * Returns true if alpha blending should be disabled. */ @@ -1144,6 +1156,10 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @returns a boolean specifying if alpha blending is needed */ public needAlphaBlending(): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; + } + if (this._disableAlphaBlending) { return false; } @@ -1157,6 +1173,10 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @returns a boolean specifying if alpha blending is needed for the mesh */ public needAlphaBlendingForMesh(mesh: AbstractMesh): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; + } + if (mesh.visibility < 1.0) { return true; } @@ -1173,6 +1193,10 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @returns a boolean specifying if an alpha test is needed. */ public needAlphaTesting(): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; + } + if (this._forceAlphaTest) { return true; } @@ -1185,7 +1209,11 @@ export class Material implements IAnimatable, IClipPlanesHolder { * @param mesh defines the mesh to check * @returns a boolean specifying if alpha testing should be turned on for the mesh */ - protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean { + public needAlphaTestingForMesh(mesh: AbstractMesh): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; + } + return !this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting(); } diff --git a/packages/dev/core/src/Materials/shaderMaterial.ts b/packages/dev/core/src/Materials/shaderMaterial.ts index 03676efb631..183c084f9b6 100644 --- a/packages/dev/core/src/Materials/shaderMaterial.ts +++ b/packages/dev/core/src/Materials/shaderMaterial.ts @@ -839,7 +839,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 a1ecdb764bc..7d1cf81ebb5 100644 --- a/packages/dev/core/src/Materials/standardMaterial.ts +++ b/packages/dev/core/src/Materials/standardMaterial.ts @@ -878,6 +878,10 @@ export class StandardMaterial extends PushMaterial { * @returns a boolean specifying if alpha blending is needed */ public override needAlphaBlending(): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsBlend; + } + if (this._disableAlphaBlending) { return false; } @@ -895,6 +899,10 @@ export class StandardMaterial extends PushMaterial { * @returns a boolean specifying if an alpha test is needed. */ public override needAlphaTesting(): boolean { + if (this._hasTransparencyMode) { + return this._transparencyModeIsTest; + } + if (this._forceAlphaTest) { return true; } @@ -1237,7 +1245,7 @@ export class StandardMaterial extends PushMaterial { this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, - this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, + this.needAlphaTestingForMesh(mesh) || this.needAlphaTesting(), defines, this._applyDecalMapAfterDetailMap ); diff --git a/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts b/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts index 3def9231993..ff743ba7e63 100644 --- a/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts +++ b/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts @@ -215,7 +215,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess { // Alpha test if (material) { - const needAlphaTesting = material.needAlphaTesting(); + const needAlphaTesting = material.needAlphaTestingForMesh(mesh); if (needAlphaTesting) { defines.push("#define ALPHATEST"); } @@ -466,7 +466,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 ce782231e38..5b6733a532e 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) { @@ -407,7 +407,7 @@ export class DepthRenderer { let uv2 = false; // 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 1c94276a8e1..f0f96348722 100644 --- a/packages/dev/core/src/Rendering/geometryBufferRenderer.ts +++ b/packages/dev/core/src/Rendering/geometryBufferRenderer.ts @@ -560,7 +560,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; @@ -1099,7 +1099,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 466e0202c2b..13b3dc721c0 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); @@ -291,7 +291,7 @@ export class OutlineRenderer implements ISceneComponent { let uv2 = false; // 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 1bd1dab6a32..40513e39a49 100644 --- a/packages/dev/materials/src/cell/cellMaterial.ts +++ b/packages/dev/materials/src/cell/cellMaterial.ts @@ -154,7 +154,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 3d12ff78579..645c13b07bd 100644 --- a/packages/dev/materials/src/fur/furMaterial.ts +++ b/packages/dev/materials/src/fur/furMaterial.ts @@ -230,7 +230,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 2d7ce2def24..86d2d3982dd 100644 --- a/packages/dev/materials/src/gradient/gradientMaterial.ts +++ b/packages/dev/materials/src/gradient/gradientMaterial.ts @@ -144,7 +144,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 38927c2e968..5afd30fc73d 100644 --- a/packages/dev/materials/src/lava/lavaMaterial.ts +++ b/packages/dev/materials/src/lava/lavaMaterial.ts @@ -212,7 +212,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 9bb1dec5ce1..849bed67db6 100644 --- a/packages/dev/materials/src/normal/normalMaterial.ts +++ b/packages/dev/materials/src/normal/normalMaterial.ts @@ -187,7 +187,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 c2766e899cc..cdc91414def 100644 --- a/packages/dev/materials/src/simple/simpleMaterial.ts +++ b/packages/dev/materials/src/simple/simpleMaterial.ts @@ -143,7 +143,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 d2434319321..de1fb8602aa 100644 --- a/packages/dev/materials/src/terrain/terrainMaterial.ts +++ b/packages/dev/materials/src/terrain/terrainMaterial.ts @@ -205,7 +205,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 de9ab373ada..dab6b1ed075 100644 --- a/packages/dev/materials/src/triPlanar/triPlanarMaterial.ts +++ b/packages/dev/materials/src/triPlanar/triPlanarMaterial.ts @@ -207,7 +207,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; diff --git a/packages/tools/tests/test/visualization/config.json b/packages/tools/tests/test/visualization/config.json index 91ca3200429..88b5c0bb359 100644 --- a/packages/tools/tests/test/visualization/config.json +++ b/packages/tools/tests/test/visualization/config.json @@ -52,7 +52,7 @@ }, { "title": "NME Loop Block", - "playgroundId": "#D8AK3Z#109", + "playgroundId": "#D8AK3Z#115", "referenceImage": "nme-loop.png", "excludedEngines": ["webgl1"] }, @@ -1302,7 +1302,7 @@ }, { "title": "Visibility", - "playgroundId": "#PXC9CF#2", + "playgroundId": "#PXC9CF#6", "referenceImage": "visibility.png" }, { @@ -1606,7 +1606,7 @@ { "title": "Prepass SSAO + visibility", "renderCount": 30, - "playgroundId": "#PXC9CF#4", + "playgroundId": "#PXC9CF#7", "excludedEngines": ["webgl1"], "referenceImage": "prepass-ssao-visibility.png" }, From 52a2bee0c4b88508606afabe371fcdd29ef343b1 Mon Sep 17 00:00:00 2001 From: Popov72 Date: Tue, 4 Feb 2025 19:45:09 +0100 Subject: [PATCH 2/3] Remove the _forceAlphaTest property --- .../dev/core/src/Materials/PBR/pbrBaseMaterial.ts | 12 +----------- packages/dev/core/src/Materials/material.ts | 11 ----------- packages/dev/core/src/Materials/standardMaterial.ts | 6 +----- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts b/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts index aa349653aad..276445b4dee 100644 --- a/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts +++ b/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts @@ -749,12 +749,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) @@ -1059,10 +1053,6 @@ export abstract class PBRBaseMaterial extends PushMaterial { return this._transparencyModeIsTest; } - if (this._forceAlphaTest) { - return true; - } - if (this.subSurface?.disableAlphaBlending) { return false; } @@ -1959,7 +1949,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, - this.needAlphaTestingForMesh(mesh) || this.needAlphaTesting(), + 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 cd2af7f8c56..4ee79b9bf16 100644 --- a/packages/dev/core/src/Materials/material.ts +++ b/packages/dev/core/src/Materials/material.ts @@ -1091,11 +1091,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. */ @@ -1127,8 +1122,6 @@ export class Material implements IAnimatable, IClipPlanesHolder { this._transparencyMode = value; - this._forceAlphaTest = value === Material.MATERIAL_ALPHATESTANDBLEND; - this._markAllSubMeshesAsTexturesAndMiscDirty(); } @@ -1197,10 +1190,6 @@ export class Material implements IAnimatable, IClipPlanesHolder { return this._transparencyModeIsTest; } - if (this._forceAlphaTest) { - return true; - } - return false; } diff --git a/packages/dev/core/src/Materials/standardMaterial.ts b/packages/dev/core/src/Materials/standardMaterial.ts index 7d1cf81ebb5..9d92f888a15 100644 --- a/packages/dev/core/src/Materials/standardMaterial.ts +++ b/packages/dev/core/src/Materials/standardMaterial.ts @@ -903,10 +903,6 @@ export class StandardMaterial extends PushMaterial { return this._transparencyModeIsTest; } - if (this._forceAlphaTest) { - return true; - } - return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST); } @@ -1245,7 +1241,7 @@ export class StandardMaterial extends PushMaterial { this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, - this.needAlphaTestingForMesh(mesh) || this.needAlphaTesting(), + this.needAlphaTestingForMesh(mesh), defines, this._applyDecalMapAfterDetailMap ); From 9a7d5d86da15c11ae95d038059718573cd9b4563 Mon Sep 17 00:00:00 2001 From: Popov72 Date: Wed, 5 Feb 2025 18:50:36 +0100 Subject: [PATCH 3/3] Deprecate needAlphaTesting and needAlphaBlending --- packages/dev/core/src/Materials/material.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/dev/core/src/Materials/material.ts b/packages/dev/core/src/Materials/material.ts index 4ee79b9bf16..05319bf2b32 100644 --- a/packages/dev/core/src/Materials/material.ts +++ b/packages/dev/core/src/Materials/material.ts @@ -1147,6 +1147,7 @@ export class Material implements IAnimatable, IClipPlanesHolder { /** * Specifies whether or not this material should be rendered in alpha blend mode. * @returns a boolean specifying if alpha blending is needed + * @deprecated Please use needAlphaBlendingForMesh instead */ public needAlphaBlending(): boolean { if (this._hasTransparencyMode) { @@ -1184,6 +1185,7 @@ export class Material implements IAnimatable, IClipPlanesHolder { /** * Specifies whether or not this material should be rendered in alpha test mode. * @returns a boolean specifying if an alpha test is needed. + * @deprecated Please use needAlphaTestingForMesh instead */ public needAlphaTesting(): boolean { if (this._hasTransparencyMode) {