Bladeren bron

Fix needAlphaBlending bug

Gary Hsu 7 jaren geleden
bovenliggende
commit
4e0bd79472

+ 16 - 13
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -516,35 +516,38 @@
         }
 
         /**
-         * Specifies whether or not the meshes using this material should be rendered in alpha blend mode.
+         * Returns true if alpha blending should be disabled.
+         */
+        private get _disableAlphaBlending(): boolean {
+            return (this._linkRefractionWithTransparency ||
+                this._transparencyMode === PBRMaterial.PBRMATERIAL_OPAQUE ||
+                this._transparencyMode === PBRMaterial.PBRMATERIAL_ALPHATEST);
+        }
+
+        /**
+         * Specifies whether or not this material should be rendered in alpha blend mode.
          */
         public needAlphaBlending(): boolean {
-            if (this._transparencyMode === PBRMaterial.PBRMATERIAL_OPAQUE ||
-                this._transparencyMode === PBRMaterial.PBRMATERIAL_ALPHATEST) {
+            if (this._disableAlphaBlending) {
                 return false;
             }
 
-            return super.needAlphaBlending();
+            return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromAlbedoTexture();
         }
 
         /**
-         * Specifies whether or not the meshes using this material should be rendered in alpha blend mode.
+         * Specifies whether or not this material should be rendered in alpha blend mode for the given mesh.
          */
         public needAlphaBlendingForMesh(mesh: AbstractMesh): boolean {
-            if (this._linkRefractionWithTransparency) {
-                return false;
-            }
-
-            if (this._transparencyMode === PBRMaterial.PBRMATERIAL_OPAQUE ||
-                this._transparencyMode === PBRMaterial.PBRMATERIAL_ALPHATEST) {
+            if (this._disableAlphaBlending) {
                 return false;
             }
 
-            return super.needAlphaBlendingForMesh(mesh) || (this._opacityTexture != null) || this._shouldUseAlphaFromAlbedoTexture();
+            return super.needAlphaBlendingForMesh(mesh);
         }
 
         /**
-         * Specifies whether or not the meshes using this material should be rendered in alpha test mode.
+         * Specifies whether or not this material should be rendered in alpha test mode.
          */
         public needAlphaTesting(): boolean {
             if (this._forceAlphaTest) {

+ 1 - 1
src/Materials/babylon.material.ts

@@ -451,7 +451,7 @@
         }
 
         public needAlphaBlendingForMesh(mesh: AbstractMesh): boolean {
-            return (mesh.visibility < 1.0) || mesh.hasVertexAlpha;
+            return this.needAlphaBlending() || (mesh.visibility < 1.0) || mesh.hasVertexAlpha;
         }
 
         public needAlphaTesting(): boolean {

+ 1 - 1
src/Rendering/babylon.renderingGroup.ts

@@ -324,7 +324,7 @@
                 return;
             }
 
-            if (material.needAlphaBlending() || material.needAlphaBlendingForMesh(mesh)) { // Transparent
+            if (material.needAlphaBlendingForMesh(mesh)) { // Transparent
                 this._transparentSubMeshes.push(subMesh);
             } else if (material.needAlphaTesting()) { // Alpha test
                 if (material.needDepthPrePass) {