Browse Source

Adding new property for texture: texture.getAlphaFromRGB

David Catuhe 11 năm trước cách đây
mục cha
commit
63b3ddcbe4

+ 1 - 0
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -38,6 +38,7 @@ var BABYLON = BABYLON || {};
 
         texture.name = parsedTexture.name;
         texture.hasAlpha = parsedTexture.hasAlpha;
+        texture.getAlphaFromRGB = parsedTexture.getAlphaFromRGB;
         texture.level = parsedTexture.level;
 
         texture.coordinatesIndex = parsedTexture.coordinatesIndex;

+ 5 - 1
Babylon/Materials/babylon.standardMaterial.js

@@ -42,7 +42,7 @@ var BABYLON;
         };
 
         StandardMaterial.prototype.needAlphaTesting = function () {
-            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha;
+            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && !this.diffuseTexture.getAlphaFromRGB;
         };
 
         StandardMaterial.prototype._shouldUseAlphaFromDiffuseTexture = function () {
@@ -96,6 +96,10 @@ var BABYLON;
                         return false;
                     } else {
                         defines.push("#define OPACITY");
+
+                        if (this.opacityTexture.getAlphaFromRGB) {
+                            defines.push("#define OPACITYRGB");
+                        }
                     }
                 }
 

+ 5 - 1
Babylon/Materials/babylon.standardMaterial.ts

@@ -45,7 +45,7 @@
         }
 
         public needAlphaTesting(): boolean {
-            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha;
+            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && !this.diffuseTexture.getAlphaFromRGB;
         }
 
         private _shouldUseAlphaFromDiffuseTexture(): boolean {
@@ -99,6 +99,10 @@
                         return false;
                     } else {
                         defines.push("#define OPACITY");
+
+                        if (this.opacityTexture.getAlphaFromRGB) {
+                            defines.push("#define OPACITYRGB");
+                        }
                     }
                 }
 

+ 1 - 0
Babylon/Materials/textures/babylon.baseTexture.js

@@ -4,6 +4,7 @@
         function BaseTexture(scene) {
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this.hasAlpha = false;
+            this.getAlphaFromRGB = false;
             this.level = 1;
             this.isCube = false;
             this.isRenderTarget = false;

+ 1 - 0
Babylon/Materials/textures/babylon.baseTexture.ts

@@ -3,6 +3,7 @@
         public name: string;
         public delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
         public hasAlpha = false;
+        public getAlphaFromRGB = false;
         public level = 1;
         public isCube = false
         public isRenderTarget = false;

+ 8 - 1
Babylon/Shaders/default.fragment.fx

@@ -574,8 +574,15 @@ void main(void) {
 
 #ifdef OPACITY
 	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
-	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11) * opacityMap.a;
+
+#ifdef OPACITYRGB
+	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
 	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;
+#else
+	alpha *= opacityMap.a * vOpacityInfos.y;
+#endif
+
+
 #endif
 
 	// Emissive

+ 5 - 1
Babylon/Shaders/legacydefault.fragment.fx

@@ -474,8 +474,12 @@ void main(void) {
 
 #ifdef OPACITY
 	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
-	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11) * opacityMap.a;
+#ifdef OPACITYRGB
+	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
 	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;
+#else
+	alpha *= opacityMap.a * vOpacityInfos.y;
+#endif
 #endif
 
 	// Emissive

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 6 - 6
babylon.1.12-beta.js