Quellcode durchsuchen

Added material.alphaMode (can be set to BABYLON.Engine.ALPHA_ADD or BABYLON.Engine.ALPHA_COMBINE)

David Catuhe vor 10 Jahren
Ursprung
Commit
a6103f47cd

Datei-Diff unterdrückt, da er zu groß ist
+ 8 - 9
dist/preview release - alpha/babylon.2.2.js


+ 16 - 9
dist/preview release - alpha/babylon.2.2.max.js

@@ -6151,6 +6151,9 @@ var BABYLON;
             this._gl.colorMask(enable, enable, enable, enable);
         };
         Engine.prototype.setAlphaMode = function (mode) {
+            if (this._alphaMode == mode) {
+                return;
+            }
             switch (mode) {
                 case Engine.ALPHA_DISABLE:
                     this.setDepthWrite(true);
@@ -12066,13 +12069,13 @@ var BABYLON;
             var submesh;
             for (subIndex = 0; subIndex < this._opaqueSubMeshes.length; subIndex++) {
                 submesh = this._opaqueSubMeshes.data[subIndex];
-                submesh.render();
+                submesh.render(false);
             }
             // Alpha test
             engine.setAlphaTesting(true);
             for (subIndex = 0; subIndex < this._alphaTestSubMeshes.length; subIndex++) {
                 submesh = this._alphaTestSubMeshes.data[subIndex];
-                submesh.render();
+                submesh.render(false);
             }
             engine.setAlphaTesting(false);
             // Transparent
@@ -12101,11 +12104,10 @@ var BABYLON;
                     }
                     return 0;
                 });
-                // Rendering
-                engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
+                // Rendering                
                 for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {
                     submesh = sortedArray[subIndex];
-                    submesh.render();
+                    submesh.render(true);
                 }
                 engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
             }
@@ -14830,7 +14832,7 @@ var BABYLON;
                 }
             }
         };
-        Mesh.prototype.render = function (subMesh) {
+        Mesh.prototype.render = function (subMesh, enableAlphaMode) {
             var scene = this.getScene();
             // Managing instances
             var batch = this._getInstancesRenderList(subMesh._id);
@@ -14865,6 +14867,10 @@ var BABYLON;
             this._bind(subMesh, effect, fillMode);
             var world = this.getWorldMatrix();
             effectiveMaterial.bind(world, this);
+            // Alpha mode
+            if (enableAlphaMode) {
+                engine.setAlphaMode(effectiveMaterial.alphaMode);
+            }
             // Draw
             this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, function (isInstance, world) {
                 if (isInstance) {
@@ -16022,8 +16028,8 @@ var BABYLON;
         SubMesh.prototype.isInFrustum = function (frustumPlanes) {
             return this._boundingInfo.isInFrustum(frustumPlanes);
         };
-        SubMesh.prototype.render = function () {
-            this._renderingMesh.render(this);
+        SubMesh.prototype.render = function (enableAlphaMode) {
+            this._renderingMesh.render(this, enableAlphaMode);
         };
         SubMesh.prototype.getLinesIndexBuffer = function (indices, engine) {
             if (!this._linesIndexBuffer) {
@@ -17993,6 +17999,7 @@ var BABYLON;
             this.state = "";
             this.alpha = 1.0;
             this.backFaceCulling = true;
+            this.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
             this._wasPreviouslyReady = false;
             this._fillMode = Material.TriangleFillMode;
             this.pointSize = 1.0;
@@ -29553,7 +29560,7 @@ var BABYLON;
                 if (_this._readyToPlayCallback) {
                     _this._readyToPlayCallback();
                 }
-            }, function (error) { BABYLON.Tools.Error("Error while decoding audio data: " + error.err); });
+            }, function () { BABYLON.Tools.Error("Error while decoding audio data for: " + _this.name); });
         };
         Sound.prototype.setAudioBuffer = function (audioBuffer) {
             if (BABYLON.Engine.audioEngine.canUseWebAudio) {

Datei-Diff unterdrückt, da er zu groß ist
+ 8 - 9
dist/preview release - alpha/babylon.2.2.noworker.js


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

@@ -4,6 +4,7 @@
     - HDR Rendering pipeline. See [demo here]() [julien-moreau](https://github.com/julien-moreau)
     - New rewored StandardMaterial.isReady for better memory usage and performance [deltakosh](https://github.com/deltakosh)
   - **Updates**
+    - Added material.alphaMode (can be set to BABYLON.Engine.ALPHA_ADD or  BABYLON.Engine.ALPHA_COMBINE) [deltakosh](https://github.com/deltakosh)
     - Added Animatable.reset() function [deltakosh](https://github.com/deltakosh)
     - New parameter for ArcRotateCamera.zoomOn to preserve maxZ [deltakosh](https://github.com/deltakosh)
     - PickingInfo.getNormal can now use either vertices normals or vertices positions [deltakosh](https://github.com/deltakosh)

+ 1 - 1
src/Audio/babylon.sound.js

@@ -145,7 +145,7 @@ var BABYLON;
                 if (_this._readyToPlayCallback) {
                     _this._readyToPlayCallback();
                 }
-            }, function (error) { BABYLON.Tools.Error("Error while decoding audio data: " + error.err); });
+            }, function () { BABYLON.Tools.Error("Error while decoding audio data for: " + _this.name); });
         };
         Sound.prototype.setAudioBuffer = function (audioBuffer) {
             if (BABYLON.Engine.audioEngine.canUseWebAudio) {

+ 1 - 1
src/Audio/babylon.sound.ts

@@ -157,7 +157,7 @@
                 this._isReadyToPlay = true;
                 if (this.autoplay) { this.play(); }
                 if (this._readyToPlayCallback) { this._readyToPlayCallback(); }
-            }, (error) => { Tools.Error("Error while decoding audio data: " + error.err); });
+            },() => { Tools.Error("Error while decoding audio data for: " + this.name); });
         }
 
         public setAudioBuffer(audioBuffer: AudioBuffer): void {

+ 1 - 0
src/Materials/babylon.material.js

@@ -8,6 +8,7 @@ var BABYLON;
             this.state = "";
             this.alpha = 1.0;
             this.backFaceCulling = true;
+            this.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
             this._wasPreviouslyReady = false;
             this._fillMode = Material.TriangleFillMode;
             this.pointSize = 1.0;

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

@@ -27,6 +27,7 @@
         public onDispose: () => void;
         public onBind: (material: Material, mesh: Mesh) => void;
         public getRenderTargetTextures: () => SmartArray<RenderTargetTexture>;
+        public alphaMode = Engine.ALPHA_COMBINE;
 
         public _effect: Effect;
         public _wasPreviouslyReady = false;

+ 5 - 1
src/Mesh/babylon.mesh.js

@@ -608,7 +608,7 @@ var BABYLON;
                 }
             }
         };
-        Mesh.prototype.render = function (subMesh) {
+        Mesh.prototype.render = function (subMesh, enableAlphaMode) {
             var scene = this.getScene();
             // Managing instances
             var batch = this._getInstancesRenderList(subMesh._id);
@@ -643,6 +643,10 @@ var BABYLON;
             this._bind(subMesh, effect, fillMode);
             var world = this.getWorldMatrix();
             effectiveMaterial.bind(world, this);
+            // Alpha mode
+            if (enableAlphaMode) {
+                engine.setAlphaMode(effectiveMaterial.alphaMode);
+            }
             // Draw
             this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, function (isInstance, world) {
                 if (isInstance) {

+ 6 - 1
src/Mesh/babylon.mesh.ts

@@ -688,7 +688,7 @@
             }
         }
 
-        public render(subMesh: SubMesh): void {
+        public render(subMesh: SubMesh, enableAlphaMode: boolean): void {
             var scene = this.getScene();
 
             // Managing instances
@@ -736,6 +736,11 @@
 
             effectiveMaterial.bind(world, this);
 
+            // Alpha mode
+            if (enableAlphaMode) {
+                engine.setAlphaMode(effectiveMaterial.alphaMode);
+            }
+
             // Draw
             this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering,
                 (isInstance, world) => {

+ 2 - 2
src/Mesh/babylon.subMesh.js

@@ -68,8 +68,8 @@ var BABYLON;
         SubMesh.prototype.isInFrustum = function (frustumPlanes) {
             return this._boundingInfo.isInFrustum(frustumPlanes);
         };
-        SubMesh.prototype.render = function () {
-            this._renderingMesh.render(this);
+        SubMesh.prototype.render = function (enableAlphaMode) {
+            this._renderingMesh.render(this, enableAlphaMode);
         };
         SubMesh.prototype.getLinesIndexBuffer = function (indices, engine) {
             if (!this._linesIndexBuffer) {

+ 2 - 2
src/Mesh/babylon.subMesh.ts

@@ -92,8 +92,8 @@
             return this._boundingInfo.isInFrustum(frustumPlanes);
         }
 
-        public render(): void {
-            this._renderingMesh.render(this);
+        public render(enableAlphaMode: boolean): void {
+            this._renderingMesh.render(this, enableAlphaMode);
         }
 
         public getLinesIndexBuffer(indices: number[], engine): WebGLBuffer {

+ 4 - 5
src/Rendering/babylon.renderingGroup.js

@@ -22,13 +22,13 @@ var BABYLON;
             var submesh;
             for (subIndex = 0; subIndex < this._opaqueSubMeshes.length; subIndex++) {
                 submesh = this._opaqueSubMeshes.data[subIndex];
-                submesh.render();
+                submesh.render(false);
             }
             // Alpha test
             engine.setAlphaTesting(true);
             for (subIndex = 0; subIndex < this._alphaTestSubMeshes.length; subIndex++) {
                 submesh = this._alphaTestSubMeshes.data[subIndex];
-                submesh.render();
+                submesh.render(false);
             }
             engine.setAlphaTesting(false);
             // Transparent
@@ -57,11 +57,10 @@ var BABYLON;
                     }
                     return 0;
                 });
-                // Rendering
-                engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
+                // Rendering                
                 for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {
                     submesh = sortedArray[subIndex];
-                    submesh.render();
+                    submesh.render(true);
                 }
                 engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
             }

+ 4 - 5
src/Rendering/babylon.renderingGroup.ts

@@ -27,7 +27,7 @@
             for (subIndex = 0; subIndex < this._opaqueSubMeshes.length; subIndex++) {
                 submesh = this._opaqueSubMeshes.data[subIndex];
 
-                submesh.render();
+                submesh.render(false);
             }
 
             // Alpha test
@@ -35,7 +35,7 @@
             for (subIndex = 0; subIndex < this._alphaTestSubMeshes.length; subIndex++) {
                 submesh = this._alphaTestSubMeshes.data[subIndex];
 
-                submesh.render();
+                submesh.render(false);
             }
             engine.setAlphaTesting(false);
 
@@ -70,12 +70,11 @@
                     return 0;
                 });
 
-                // Rendering
-                engine.setAlphaMode(Engine.ALPHA_COMBINE);
+                // Rendering                
                 for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {
                     submesh = sortedArray[subIndex];
 
-                    submesh.render();
+                    submesh.render(true);
                 }
                 engine.setAlphaMode(Engine.ALPHA_DISABLE);
             }

+ 3 - 0
src/babylon.engine.js

@@ -1190,6 +1190,9 @@ var BABYLON;
             this._gl.colorMask(enable, enable, enable, enable);
         };
         Engine.prototype.setAlphaMode = function (mode) {
+            if (this._alphaMode == mode) {
+                return;
+            }
             switch (mode) {
                 case Engine.ALPHA_DISABLE:
                     this.setDepthWrite(true);

+ 4 - 0
src/babylon.engine.ts

@@ -1425,6 +1425,10 @@
         }
 
         public setAlphaMode(mode: number): void {
+            if (this._alphaMode == mode) {
+                return;
+            }
+
             switch (mode) {
                 case Engine.ALPHA_DISABLE:
                     this.setDepthWrite(true);