فهرست منبع

Merge remote-tracking branch 'remotes/BabylonJS/master' into ScreenShotFeatureTS

Conflicts:
	Babylon/Tools/babylon.tools.js
	Babylon/Tools/babylon.tools.ts
	Babylon/babylon.engine.js
	Babylon/babylon.engine.ts
Nicolas Obré 11 سال پیش
والد
کامیت
20b16f87cf

+ 4 - 3
Babylon/Materials/babylon.standardMaterial.js

@@ -232,10 +232,11 @@ var BABYLON;
 
                 // Legacy browser patch
                 var shaderName = "default";
-                if (!scene.getEngine().getCaps().standardDerivatives) {
-                    shaderName = "legacydefault";
-                }
 
+                //     if (!scene.getEngine().getCaps().standardDerivatives) {
+                shaderName = "legacydefault";
+
+                //   }
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, [
                     "world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
                     "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",

+ 2 - 2
Babylon/Materials/babylon.standardMaterial.ts

@@ -235,9 +235,9 @@
 
                 // Legacy browser patch
                 var shaderName = "default";
-                if (!scene.getEngine().getCaps().standardDerivatives) {
+           //     if (!scene.getEngine().getCaps().standardDerivatives) {
                     shaderName = "legacydefault";
-                }
+             //   }
 
                 this._effect = scene.getEngine().createEffect(shaderName,
                     attribs,

+ 49 - 50
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPass.js

@@ -1,50 +1,49 @@
-"use strict";
-
-var BABYLON = BABYLON || {};
-
-(function () {
-	BABYLON.PostProcessRenderPass = function PostProcessRenderPass(scene, name, size, renderList, beforeRender, afterRender) {
-		this._name = name;
-		this._enabled = true;
-
-		this._renderList = renderList;
-
-		this._renderTexture = new BABYLON.RenderTargetTexture(name, size, scene);
-		this.setRenderList(renderList);
-
-		this._renderTexture.onBeforeRender = beforeRender;
-		this._renderTexture.onAfterRender = afterRender;
-
-		this._scene = scene;
-
-		this._refCount = 0;
-	};
-
-	BABYLON.PostProcessRenderPass.prototype.incRefCount = function () {
-	    if (this._refCount == 0) {
-	        this._scene.customRenderTargets.push(this._renderTexture);
-	    }
-
-	    this._refCount++;
-	};
-
-	BABYLON.PostProcessRenderPass.prototype.decRefCount = function () {
-	    this._refCount--;
-
-	    if (this._refCount <= 0) {
-	        this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture), 1);
-	    }
-	};
-
-	BABYLON.PostProcessRenderPass.prototype.setRenderList = function (renderList) {
-		this._renderTexture.renderList = renderList;
-	};
-
-	BABYLON.PostProcessRenderPass.prototype.getRenderTexture = function () {
-		return this._renderTexture;
-	};
-
-	BABYLON.PostProcessRenderPass.prototype._update = function () {
-		this.setRenderList(this._renderList);
-	};
-})();
+var BABYLON;
+(function (BABYLON) {
+    var PostProcessRenderPass = (function () {
+        function PostProcessRenderPass(scene, name, size, renderList, beforeRender, afterRender) {
+            this.name = name;
+            this._enabled = true;
+            this._refCount = 0;
+            this._renderTexture = new BABYLON.RenderTargetTexture(name, size, scene);
+            this.setRenderList(renderList);
+
+            this._renderTexture.onBeforeRender = beforeRender;
+            this._renderTexture.onAfterRender = afterRender;
+
+            this._scene = scene;
+        }
+        PostProcessRenderPass.prototype.incRefCount = function () {
+            if (this._refCount == 0) {
+                this._scene.customRenderTargets.push(this._renderTexture);
+            }
+
+            return ++this._refCount;
+        };
+
+        PostProcessRenderPass.prototype.decRefCount = function () {
+            this._refCount--;
+
+            if (this._refCount <= 0) {
+                this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture), 1);
+            }
+
+            return this._refCount;
+        };
+
+        PostProcessRenderPass.prototype.setRenderList = function (renderList) {
+            this._renderTexture.renderList = renderList;
+        };
+
+        PostProcessRenderPass.prototype.getRenderTexture = function () {
+            return this._renderTexture;
+        };
+
+        PostProcessRenderPass.prototype._update = function () {
+            this.setRenderList(this._renderList);
+        };
+        return PostProcessRenderPass;
+    })();
+    BABYLON.PostProcessRenderPass = PostProcessRenderPass;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.postProcessRenderPass.js.map

+ 1 - 1
Babylon/Rendering/babylon.renderingManager.js

@@ -58,7 +58,7 @@
         RenderingManager.prototype.render = function (customRenderFunction, activeMeshes, renderParticles, renderSprites) {
             var _this = this;
             for (var index = 0; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
-                this._depthBufferAlreadyCleaned = index == 0;
+                this._depthBufferAlreadyCleaned = false;
                 var renderingGroup = this._renderingGroups[index];
 
                 if (renderingGroup) {

+ 1 - 1
Babylon/Rendering/babylon.renderingManager.ts

@@ -63,7 +63,7 @@
         public render(customRenderFunction: (opaqueSubMeshes: SmartArray, transparentSubMeshes: SmartArray, alphaTestSubMeshes: SmartArray, beforeTransparents: () => void) => void,
             activeMeshes: Mesh[], renderParticles: boolean, renderSprites: boolean): void {
             for (var index = 0; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
-                this._depthBufferAlreadyCleaned = index == 0;
+                this._depthBufferAlreadyCleaned = false;
                 var renderingGroup = this._renderingGroups[index];
 
                 if (renderingGroup) {

+ 10 - 10
Babylon/Shaders/legacydefault.fragment.fx

@@ -22,7 +22,7 @@ varying vec3 vColor;
 // Lights
 #ifdef LIGHT0
 uniform vec4 vLightData0;
-uniform vec3 vLightDiffuse0;
+uniform vec4 vLightDiffuse0;
 uniform vec3 vLightSpecular0;
 #ifdef SHADOW0
 varying vec4 vPositionFromLight0;
@@ -38,7 +38,7 @@ uniform vec3 vLightGround0;
 
 #ifdef LIGHT1
 uniform vec4 vLightData1;
-uniform vec3 vLightDiffuse1;
+uniform vec4 vLightDiffuse1;
 uniform vec3 vLightSpecular1;
 #ifdef SHADOW1
 varying vec4 vPositionFromLight1;
@@ -54,7 +54,7 @@ uniform vec3 vLightGround1;
 
 #ifdef LIGHT2
 uniform vec4 vLightData2;
-uniform vec3 vLightDiffuse2;
+uniform vec4 vLightDiffuse2;
 uniform vec3 vLightSpecular2;
 #ifdef SHADOW2
 varying vec4 vPositionFromLight2;
@@ -70,7 +70,7 @@ uniform vec3 vLightGround2;
 
 #ifdef LIGHT3
 uniform vec4 vLightData3;
-uniform vec3 vLightDiffuse3;
+uniform vec4 vLightDiffuse3;
 uniform vec3 vLightSpecular3;
 #ifdef SHADOW3
 varying vec4 vPositionFromLight3;
@@ -229,7 +229,7 @@ float CalcFogFactor()
 #endif
 
 // Light Computing
-mat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor) {
+mat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor) {
 	mat3 result;
 
 	vec3 lightVectorW;
@@ -250,14 +250,14 @@ mat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 dif
 	float specComp = max(0., dot(vNormal, angleW));
 	specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));
 
-	result[0] = ndl * diffuseColor;
+	result[0] = ndl * diffuseColor.rgb;
 	result[1] = specComp * specularColor;
 	result[2] = vec3(0.);
 
 	return result;
 }
 
-mat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor) {
+mat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec4 diffuseColor, vec3 specularColor) {
 	mat3 result;
 
 	vec3 lightVectorW = normalize(lightData.xyz - vPositionW);
@@ -279,7 +279,7 @@ mat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4
 		float specComp = max(0., dot(vNormal, angleW));
 		specComp = pow(specComp, vSpecularColor.a);
 
-		result[0] = ndl * spotAtten * diffuseColor;
+		result[0] = ndl * spotAtten * diffuseColor.rgb;
 		result[1] = specComp * specularColor * spotAtten;
 		result[2] = vec3(0.);
 
@@ -293,7 +293,7 @@ mat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4
 	return result;
 }
 
-mat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {
+mat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor, vec3 groundColor) {
 	mat3 result;
 
 	// Diffuse
@@ -304,7 +304,7 @@ mat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightDat
 	float specComp = max(0., dot(vNormal, angleW));
 	specComp = pow(specComp, vSpecularColor.a);
 
-	result[0] = mix(groundColor, diffuseColor, ndl);
+	result[0] = mix(groundColor, diffuseColor.rgb, ndl);
 	result[1] = specComp * specularColor;
 	result[2] = vec3(0.);
 

+ 10 - 8
Babylon/Tools/babylon.tools.js

@@ -1,5 +1,8 @@
 var BABYLON;
 (function (BABYLON) {
+    // Screenshots
+    var screenshotCanvas;
+
     // FPS
     var fpsRange = 60;
     var previousFramesDuration = [];
@@ -349,7 +352,7 @@
                 var halfHeight = height / 2;
 
                 //Reading datas from WebGL
-                var data = engine.ReadPixels(0, 0, width, height);
+                var data = engine.readPixels(0, 0, width, height);
 
                 for (var i = 0; i < halfHeight; i++) {
                     for (var j = 0; j < numberOfChannelsByLine; j++) {
@@ -365,19 +368,19 @@
                 }
 
                 // Create a 2D canvas to store the result
-                if (!Tools._ScreenshotCanvas) {
-                    Tools._ScreenshotCanvas = document.createElement('canvas');
+                if (!screenshotCanvas) {
+                    screenshotCanvas = document.createElement('canvas');
                 }
-                Tools._ScreenshotCanvas.width = width;
-                Tools._ScreenshotCanvas.height = height;
-                var context = Tools._ScreenshotCanvas.getContext('2d');
+                screenshotCanvas.width = width;
+                screenshotCanvas.height = height;
+                var context = screenshotCanvas.getContext('2d');
 
                 // Copy the pixels to a 2D canvas
                 var imageData = context.createImageData(width, height);
                 imageData.data.set(data);
                 context.putImageData(imageData, 0, 0);
 
-                var base64Image = Tools._ScreenshotCanvas.toDataURL();
+                var base64Image = screenshotCanvas.toDataURL();
 
                 //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.
                 if (("download" in document.createElement("a"))) {
@@ -403,7 +406,6 @@
             };
 
             texture.render();
-
             texture.dispose();
         };
         Tools.BaseUrl = "";

+ 13 - 12
Babylon/Tools/babylon.tools.ts

@@ -11,6 +11,9 @@
         height: number;
     }
 
+    // Screenshots
+    var screenshotCanvas: HTMLCanvasElement;
+
     // FPS
     var fpsRange = 60;
     var previousFramesDuration = [];
@@ -35,7 +38,6 @@
 
     export class Tools {
         public static BaseUrl = "";
-        private static _ScreenshotCanvas: HTMLCanvasElement;
 
         public static GetFilename(path: string): string {
             var index = path.lastIndexOf("/");
@@ -84,7 +86,7 @@
             };
         }
 
-        public static MakeArray(obj, allowsNullUndefined?: boolean): Array<any> {
+        public static MakeArray(obj, allowsNullUndefined: boolean): Array<any> {
             if (allowsNullUndefined !== true && (obj === undefined || obj == null))
                 return undefined;
 
@@ -373,13 +375,13 @@
             var texture = new RenderTargetTexture("screenShot", size, engine.scenes[0]);
             texture.renderList = engine.scenes[0].meshes;
 
-            texture.onAfterRender = function () {
+            texture.onAfterRender = () => {
                 // Read the contents of the framebuffer
                 var numberOfChannelsByLine = width * 4;
                 var halfHeight = height / 2;
 
                 //Reading datas from WebGL
-                var data = engine.ReadPixels(0, 0, width, height);
+                var data = engine.readPixels(0, 0, width, height);
 
 
                 //To flip image on Y axis.
@@ -396,19 +398,19 @@
                 }
 
                 // Create a 2D canvas to store the result
-                if (!Tools._ScreenshotCanvas) {
-                    Tools._ScreenshotCanvas = document.createElement('canvas');
+                if (!screenshotCanvas) {
+                    screenshotCanvas = document.createElement('canvas');
                 }
-                Tools._ScreenshotCanvas.width = width;
-                Tools._ScreenshotCanvas.height = height;
-                var context = Tools._ScreenshotCanvas.getContext('2d');
+                screenshotCanvas.width = width;
+                screenshotCanvas.height = height;
+                var context = screenshotCanvas.getContext('2d');
 
                 // Copy the pixels to a 2D canvas
                 var imageData = context.createImageData(width, height);
                 imageData.data.set(data);
                 context.putImageData(imageData, 0, 0);
 
-                var base64Image = Tools._ScreenshotCanvas.toDataURL();
+                var base64Image = screenshotCanvas.toDataURL();
 
                 //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.
                 if (("download" in document.createElement("a"))) {
@@ -420,7 +422,7 @@
 
                     window.document.body.appendChild(a);
 
-                    a.addEventListener("click", function () {
+                    a.addEventListener("click", () => {
                         a.parentElement.removeChild(a);
                     });
                     a.click();
@@ -436,7 +438,6 @@
             };
 
             texture.render();
-
             texture.dispose();
         }
     }

+ 1 - 1
Babylon/babylon.engine.js

@@ -1121,7 +1121,7 @@
             }
         };
 
-        Engine.prototype.ReadPixels = function (x, y, width, height) {
+        Engine.prototype.readPixels = function (x, y, width, height) {
             var data = new Uint8Array(height * width * 4);
             this._gl.readPixels(0, 0, width, height, this._gl.RGBA, this._gl.UNSIGNED_BYTE, data);
             return data;

+ 4 - 3
Babylon/babylon.engine.ts

@@ -134,7 +134,7 @@
         private _renderFunction: () => void;
 
         // Cache
-        private _loadedTexturesCache = new Array <WebGLTexture>();
+        private _loadedTexturesCache = new Array<WebGLTexture>();
         public _activeTexturesCache = new Array<Texture>();
         private _currentEffect: Effect;
         private _cullingState: boolean;
@@ -286,7 +286,7 @@
             return this._hardwareScalingLevel;
         }
 
-        public getLoadedTexturesCache():  WebGLTexture[] {
+        public getLoadedTexturesCache(): WebGLTexture[] {
             return this._loadedTexturesCache;
         }
 
@@ -1176,11 +1176,12 @@
             }
         }
 
-        public ReadPixels(x: number, y: number, width: number, height: number) : Uint8Array {
+        public readPixels(x: number, y: number, width: number, height: number): Uint8Array {
             var data = new Uint8Array(height * width * 4);
             this._gl.readPixels(0, 0, width, height, this._gl.RGBA, this._gl.UNSIGNED_BYTE, data);
             return data;
         }
+
         // Dispose
         public dispose(): void {
             // Release scenes

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 3 - 3
babylon.1.12-beta.js