ソースを参照

Merge pull request #9082 from metaobjects/master

Fix alphatest transparency so it no-longer requires a diffuse/albedo texture if an opacityTexture is present
David Catuhe 4 年 前
コミット
969c293934

+ 1 - 0
dist/preview release/what's new.md

@@ -173,6 +173,7 @@
 - Added support for lightmaps in unlit PBR materials ([Popov72](https://github.com/Popov72))
 - Added `muted` setting to `VideoTexture`, fix autoplay in Chrome ([simonihmig](https://github.com/simonihmig))
 - Added `waveCount` to `WaterMaterial` used to adjust waves count according to the ground's size where the material is applied on ([julien-moreau](https://github.com/julien-moreau))
+- Alpha test `transparencyMode` no-longer requires a diffuse/albedo texture if `opacityTexture` is present ([metaobjects](https://github.com/metaobjects))
 
 ### Meshes
 

+ 8 - 1
src/Materials/PBR/pbrBaseMaterial.ts

@@ -939,7 +939,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
             return false;
         }
 
-        return this._albedoTexture != null && this._albedoTexture.hasAlpha && (this._transparencyMode == null || this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST);
+        return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST);
     }
 
     /**
@@ -950,6 +950,13 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     }
 
     /**
+     * Specifies whether or not there is a usable alpha channel for transparency.
+     */
+    protected _hasAlphaChannel(): boolean {
+        return (this._albedoTexture != null && this._albedoTexture.hasAlpha) || this._opacityTexture != null;
+    }
+
+    /**
      * Gets the texture used for the alpha test.
      */
     public getAlphaTestTexture(): Nullable<BaseTexture> {

+ 15 - 4
src/Materials/standardMaterial.ts

@@ -804,14 +804,24 @@ export class StandardMaterial extends PushMaterial {
             return true;
         }
 
-        return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST);
+        return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST);
     }
 
+    /**
+     * Specifies 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;
     }
 
     /**
+     * Specifies whether or not there is a usable alpha channel for transparency.
+     */
+    protected _hasAlphaChannel(): boolean {
+        return (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._opacityTexture != null;
+    }
+
+    /**
      * Get the texture used for alpha test purpose.
      * @returns the diffuse texture in case of the standard material.
      */
@@ -1432,9 +1442,6 @@ export class StandardMaterial extends PushMaterial {
                         ubo.updateFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                         MaterialHelper.BindTextureMatrix(this._diffuseTexture, ubo, "diffuse");
 
-                        if (this._diffuseTexture.hasAlpha) {
-                            effect.setFloat("alphaCutOff", this.alphaCutOff);
-                        }
                     }
 
                     if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {
@@ -1447,6 +1454,10 @@ export class StandardMaterial extends PushMaterial {
                         MaterialHelper.BindTextureMatrix(this._opacityTexture, ubo, "opacity");
                     }
 
+                    if (this._hasAlphaChannel()) {
+                        effect.setFloat("alphaCutOff", this.alphaCutOff);
+                    }
+
                     if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
                         ubo.updateFloat2("vReflectionInfos", this._reflectionTexture.level, this.roughness);
                         ubo.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());