浏览代码

Improved reflection shader

David catuhe 10 年之前
父节点
当前提交
2d39b1eff0

文件差异内容过多而无法显示
+ 661 - 656
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 24 - 24
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 40 - 12
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 24 - 24
dist/preview release/babylon.noworker.js


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

@@ -6,6 +6,7 @@
       - New .obj serializer ([BitOfGold](https://github.com/BitOfGold))
     - Sprites now can be [picked](http://www.babylonjs-playground.com/#1XMVZW#3) and can use [actions](http://www.babylonjs-playground.com/#9RUHH#3) ([deltakosh](https://github.com/deltakosh))
   - **Updates**
+    - Improved reflection shader performance ([deltakosh](https://github.com/deltakosh))
     - New `Material.sideOrientation` property to define clockwise or counter-clockwise faces selection. [Demo here](http://www.babylonjs-playground.com/#1TZJQY) ([deltakosh](https://github.com/deltakosh))
     - It is now possible to create a custom loading screen [PR](https://github.com/BabylonJS/Babylon.js/pull/700) ([RaananW](https://github.com/RaananW))
     - Per face color and texture feature in `Mesh.CreateCylinder()` ([jerome](https://github.com/jbousquie))

+ 31 - 6
src/Materials/babylon.standardMaterial.js

@@ -87,6 +87,13 @@ var BABYLON;
             this.EMISSIVEASILLUMINATION = false;
             this.REFLECTIONFRESNELFROMSPECULAR = false;
             this.LIGHTMAP = false;
+            this.REFLECTIONMAP_3D = false;
+            this.REFLECTIONMAP_SPHERICAL = false;
+            this.REFLECTIONMAP_PLANAR = false;
+            this.REFLECTIONMAP_CUBIC = false;
+            this.REFLECTIONMAP_PROJECTION = false;
+            this.REFLECTIONMAP_SKYBOX = false;
+            this.REFLECTIONMAP_EXPLICIT = false;
             this.INVERTCUBICMAP = false;
             this._keys = Object.keys(this);
         }
@@ -239,6 +246,28 @@ var BABYLON;
                         if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
                             this._defines.INVERTCUBICMAP = true;
                         }
+                        this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
+                        switch (this.reflectionTexture.coordinatesMode) {
+                            case BABYLON.Texture.CUBIC_MODE:
+                            case BABYLON.Texture.INVCUBIC_MODE:
+                                this._defines.REFLECTIONMAP_CUBIC = true;
+                                break;
+                            case BABYLON.Texture.EXPLICIT_MODE:
+                                this._defines.REFLECTIONMAP_EXPLICIT = true;
+                                break;
+                            case BABYLON.Texture.PLANAR_MODE:
+                                this._defines.REFLECTIONMAP_PLANAR = true;
+                                break;
+                            case BABYLON.Texture.PROJECTION_MODE:
+                                this._defines.REFLECTIONMAP_PROJECTION = true;
+                                break;
+                            case BABYLON.Texture.SKYBOX_MODE:
+                                this._defines.REFLECTIONMAP_SKYBOX = true;
+                                break;
+                            case BABYLON.Texture.SPHERICAL_MODE:
+                                this._defines.REFLECTIONMAP_SPHERICAL = true;
+                                break;
+                        }
                     }
                 }
                 if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
@@ -522,8 +551,7 @@ var BABYLON;
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix",
                     "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
-                    "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor",
-                    "roughness"
+                    "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor"
                 ], ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler",
                     "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
                 ], join, fallbacks, this.onCompiled, this.onError);
@@ -591,15 +619,12 @@ var BABYLON;
                 if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
                     if (this.reflectionTexture.isCube) {
                         this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
-                        if (this._defines.ROUGHNESS) {
-                            this._effect.setFloat("roughness", this.roughness);
-                        }
                     }
                     else {
                         this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
                     }
                     this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
-                    this._effect.setFloat3("vReflectionInfos", this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE ? BABYLON.Texture.CUBIC_MODE : this.reflectionTexture.coordinatesMode, this.reflectionTexture.level, this.reflectionTexture.isCube ? 1 : 0);
+                    this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
                 }
                 if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
                     this._effect.setTexture("emissiveSampler", this.emissiveTexture);

+ 33 - 6
src/Materials/babylon.standardMaterial.ts

@@ -81,6 +81,13 @@
         public EMISSIVEASILLUMINATION = false;
         public REFLECTIONFRESNELFROMSPECULAR = false;
         public LIGHTMAP = false;
+        public REFLECTIONMAP_3D = false;
+        public REFLECTIONMAP_SPHERICAL = false;
+        public REFLECTIONMAP_PLANAR = false;
+        public REFLECTIONMAP_CUBIC = false;
+        public REFLECTIONMAP_PROJECTION = false;
+        public REFLECTIONMAP_SKYBOX = false;
+        public REFLECTIONMAP_EXPLICIT = false;
         public INVERTCUBICMAP = false;
 
         _keys: string[];
@@ -284,6 +291,30 @@
                         if (this.reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
                             this._defines.INVERTCUBICMAP = true;
                         }
+
+                        this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
+
+                        switch (this.reflectionTexture.coordinatesMode) {
+                            case Texture.CUBIC_MODE:
+                            case Texture.INVCUBIC_MODE:
+                                this._defines.REFLECTIONMAP_CUBIC = true;
+                                break;
+                            case Texture.EXPLICIT_MODE:
+                                this._defines.REFLECTIONMAP_EXPLICIT = true;
+                                break;
+                            case Texture.PLANAR_MODE:
+                                this._defines.REFLECTIONMAP_PLANAR = true;
+                                break;    
+                            case Texture.PROJECTION_MODE:
+                                this._defines.REFLECTIONMAP_PROJECTION = true;
+                                break;  
+                            case Texture.SKYBOX_MODE:
+                                this._defines.REFLECTIONMAP_SKYBOX = true;
+                                break;      
+                            case Texture.SPHERICAL_MODE:
+                                this._defines.REFLECTIONMAP_SPHERICAL = true;
+                                break;  
+                        }
                     }
                 }
 
@@ -628,8 +659,7 @@
                         "mBones",
                         "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix",
                         "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
-                        "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor",
-                        "roughness"
+                        "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor"
                     ],
                     ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler",
                         "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
@@ -719,15 +749,12 @@
                 if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
                     if (this.reflectionTexture.isCube) {
                         this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
-                        if (this._defines.ROUGHNESS) {
-                            this._effect.setFloat("roughness", this.roughness);
-                        }
                     } else {
                         this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
                     }
 
                     this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
-                    this._effect.setFloat3("vReflectionInfos", this.reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE ? Texture.CUBIC_MODE : this.reflectionTexture.coordinatesMode, this.reflectionTexture.level, this.reflectionTexture.isCube ? 1 : 0);
+                    this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
                 }
 
                 if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {

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

@@ -2475,3 +2475,4 @@
         }
     }
 }
+

+ 2 - 2
src/Mesh/babylon.mesh.vertexData.js

@@ -618,8 +618,8 @@ var BABYLON;
         // Cylinder and cone 
         VertexData.CreateCylinder = function (options) {
             var height = options.height || 2;
-            var diameterTop = (options.diameterTop === 0) ? 0 : options.diameterTop || 1;
-            var diameterBottom = options.diameterBottom || 1;
+            var diameterTop = (options.diameterTop === 0) ? 0 : options.diameterTop || options.diameter || 1;
+            var diameterBottom = options.diameterBottom || options.diameter || 1;
             var tessellation = options.tessellation || 24;
             var subdivisions = options.subdivisions || 1;
             var arc = (options.arc <= 0) ? 1.0 : options.arc || 1.0;

+ 1 - 0
src/Mesh/babylon.mesh.vertexData.ts

@@ -1537,3 +1537,4 @@
         }
     }
 }
+

+ 22 - 76
src/Shaders/default.fragment.fx

@@ -2,13 +2,6 @@
 precision highp float;
 #endif
 
-#define MAP_EXPLICIT	0.
-#define MAP_SPHERICAL	1.
-#define MAP_PLANAR		2.
-#define MAP_CUBIC		3.
-#define MAP_PROJECTION	4.
-#define MAP_SKYBOX		5.
-
 // Constants
 uniform vec3 vEyePosition;
 uniform vec3 vAmbientColor;
@@ -171,55 +164,14 @@ uniform vec4 emissiveLeftColor;
 uniform vec4 emissiveRightColor;
 #endif
 
-// Reflection
 #ifdef REFLECTION
-varying vec3 vPositionUVW;
+varying vec3 vReflectionUVW;
+#ifdef REFLECTIONMAP_3D
 uniform samplerCube reflectionCubeSampler;
+#else
 uniform sampler2D reflection2DSampler;
-uniform vec3 vReflectionInfos;
-uniform mat4 reflectionMatrix;
-uniform mat4 view;
-
-#ifdef ROUGHNESS
-uniform float roughness;
 #endif
-
-vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
-{
-	if (mode == MAP_SPHERICAL)
-	{
-		vec3 coords = vec3(view * vec4(worldNormal, 0.0));
-
-		return vec3(reflectionMatrix * vec4(coords, 1.0));
-	}
-	else if (mode == MAP_PLANAR)
-	{
-		vec3 viewDir = worldPos.xyz - vEyePosition;
-		vec3 coords = normalize(reflect(viewDir, worldNormal));
-
-		return vec3(reflectionMatrix * vec4(coords, 1));
-	}
-	else if (mode == MAP_CUBIC)
-	{
-		vec3 viewDir = worldPos.xyz - vEyePosition;
-		vec3 coords = reflect(viewDir, worldNormal);
-#ifdef INVERTCUBICMAP
-		coords.y = 1.0 - coords.y;
-#endif
-
-		return vec3(reflectionMatrix * vec4(coords, 0));
-	}
-	else if (mode == MAP_PROJECTION)
-	{
-		return vec3(reflectionMatrix * (view * worldPos));
-	}
-	else if (mode == MAP_SKYBOX)
-	{
-		return vPositionUVW;
-	}
-
-	return vec3(0, 0, 0);
-}
+uniform vec2 vReflectionInfos;
 #endif
 
 // Shadows
@@ -706,39 +658,33 @@ void main(void) {
 	vec3 reflectionColor = vec3(0., 0., 0.);
 
 #ifdef REFLECTION
-	vec3 vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), normalW);
-
-	if (vReflectionInfos.z != 0.0)
-	{
-		float bias = 0.;
+	#ifdef REFLECTIONMAP_3D
+			float bias = 0.;
 
-#ifdef ROUGHNESS
-		bias = roughness;
-#endif
+		#ifdef ROUGHNESS
+				bias = vReflectionInfos.y;
+		#endif
 
-#ifdef SPECULARTERM
-#ifdef SPECULAR
-#ifdef GLOSSINESS
-		bias *= (1.0 - specularMapColor.a);
-#endif
-#endif
-#endif
+		#ifdef SPECULARTERM
+			#ifdef SPECULAR
+				#ifdef GLOSSINESS
+						bias *= (1.0 - specularMapColor.a);
+				#endif
+			#endif
+		#endif
 
-		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.y * shadow;
-	}
-	else
-	{
+		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x * shadow;
+	#else
 		vec2 coords = vReflectionUVW.xy;
 
-		if (vReflectionInfos.x == MAP_PROJECTION)
-		{
+		#ifdef REFLECTIONMAP_PROJECTION
 			coords /= vReflectionUVW.z;
-		}
+		#endif
 
 		coords.y = 1.0 - coords.y;
 
-		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y * shadow;
-	}
+		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x * shadow;
+#endif	
 
 #ifdef REFLECTIONFRESNEL
 	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);

+ 44 - 5
src/Shaders/default.vertex.fx

@@ -124,16 +124,51 @@ varying vec4 vPositionFromLight3;
 #endif
 
 #ifdef REFLECTION
-varying vec3 vPositionUVW;
+uniform vec3 vEyePosition;
+varying vec3 vReflectionUVW;
+uniform mat4 reflectionMatrix;
+
+vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
+{
+#ifdef REFLECTIONMAP_SPHERICAL
+	vec3 coords = vec3(view * vec4(worldNormal, 0.0));
+
+	return vec3(reflectionMatrix * vec4(coords, 1.0));
+#endif
+
+#ifdef REFLECTIONMAP_PLANAR
+	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 coords = normalize(reflect(viewDir, worldNormal));
+
+	return vec3(reflectionMatrix * vec4(coords, 1));
+#endif
+
+#ifdef REFLECTIONMAP_CUBIC
+	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 coords = reflect(viewDir, worldNormal);
+#ifdef INVERTCUBICMAP
+	coords.y = 1.0 - coords.y;
+#endif
+	return vec3(reflectionMatrix * vec4(coords, 0));
+#endif
+
+#ifdef REFLECTIONMAP_PROJECTION
+	return vec3(reflectionMatrix * (view * worldPos));
+#endif
+
+#ifdef REFLECTIONMAP_SKYBOX
+	return position;
+#endif
+
+#ifdef REFLECTIONMAP_EXPLICIT
+	return vec3(0, 0, 0);
+#endif
+}
 #endif
 
 void main(void) {
 	mat4 finalWorld;
 
-#ifdef REFLECTION
-	vPositionUVW = position;
-#endif 
-
 #ifdef INSTANCES
 	finalWorld = mat4(world0, world1, world2, world3);
 #else
@@ -203,6 +238,10 @@ void main(void) {
 	}
 #endif
 
+#ifdef REFLECTION
+	vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), vNormalW);
+#endif
+
 #ifdef EMISSIVE
 	if (vEmissiveInfos.x == 0.)
 	{

+ 12 - 13
src/Shaders/legacydefault.fragment.fx

@@ -115,9 +115,12 @@ uniform vec2 vOpacityInfos;
 
 #ifdef REFLECTION
 varying vec3 vReflectionUVW;
+#ifdef REFLECTIONMAP_3D
 uniform samplerCube reflectionCubeSampler;
+#else
 uniform sampler2D reflection2DSampler;
-uniform vec3 vReflectionInfos;
+#endif
+uniform vec2 vReflectionInfos;
 #endif
 
 #ifdef EMISSIVE
@@ -522,23 +525,19 @@ void main(void) {
 	vec3 reflectionColor = vec3(0., 0., 0.);
 
 #ifdef REFLECTION
-	if (vReflectionInfos.z != 0.0)
-	{
-		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;
-	}
-	else
-	{
+#ifdef REFLECTIONMAP_3D
+		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.x;
+#else
 		vec2 coords = vReflectionUVW.xy;
 
-		if (vReflectionInfos.x == MAP_PROJECTION)
-		{
-			coords /= vReflectionUVW.z;
-		}
+#ifdef REFLECTIONMAP_PROJECTION
+		coords /= vReflectionUVW.z;
+#endif
 
 		coords.y = 1.0 - coords.y;
 
-		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;
-	}
+		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x;
+#endif
 
 #ifdef REFLECTIONFRESNEL
 	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);

+ 35 - 42
src/Shaders/legacydefault.vertex.fx

@@ -2,13 +2,6 @@
 precision highp float;
 #endif
 
-#define MAP_EXPLICIT	0.
-#define MAP_SPHERICAL	1.
-#define MAP_PLANAR		2.
-#define MAP_CUBIC		3.
-#define MAP_PROJECTION	4.
-#define MAP_SKYBOX		5.
-
 // Attributes
 attribute vec3 position;
 attribute vec3 normal;
@@ -49,13 +42,6 @@ uniform mat4 opacityMatrix;
 uniform vec2 vOpacityInfos;
 #endif
 
-#ifdef REFLECTION
-uniform vec3 vEyePosition;
-varying vec3 vReflectionUVW;
-uniform vec3 vReflectionInfos;
-uniform mat4 reflectionMatrix;
-#endif
-
 #ifdef EMISSIVE
 varying vec2 vEmissiveUV;
 uniform vec2 vEmissiveInfos;
@@ -115,38 +101,45 @@ varying vec4 vPositionFromLight3;
 #endif
 
 #ifdef REFLECTION
-vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
+uniform vec3 vEyePosition;
+varying vec3 vReflectionUVW;
+uniform mat4 reflectionMatrix;
+
+vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
 {
-	if (mode == MAP_SPHERICAL)
-	{
-		vec3 coords = vec3(view * vec4(worldNormal, 0.0));
+#ifdef REFLECTIONMAP_SPHERICAL
+	vec3 coords = vec3(view * vec4(worldNormal, 0.0));
 
-		return vec3(reflectionMatrix * vec4(coords, 1.0));
-	}
-	else if (mode == MAP_PLANAR)
-	{
-		vec3 viewDir = worldPos.xyz - vEyePosition;
-		vec3 coords = normalize(reflect(viewDir, worldNormal));
+	return vec3(reflectionMatrix * vec4(coords, 1.0));
+#endif
 
-		return vec3(reflectionMatrix * vec4(coords, 1));
-	}
-	else if (mode == MAP_CUBIC)
-	{
-		vec3 viewDir = worldPos.xyz - vEyePosition;
-		vec3 coords = reflect(viewDir, worldNormal);
+#ifdef REFLECTIONMAP_PLANAR
+	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 coords = normalize(reflect(viewDir, worldNormal));
 
-		return vec3(reflectionMatrix * vec4(coords, 0));
-	}
-	else if (mode == MAP_PROJECTION)
-	{
-		return vec3(reflectionMatrix * (view * worldPos));
-	}
-	else if (mode == MAP_SKYBOX)
-	{
-		return position;
-	}
+	return vec3(reflectionMatrix * vec4(coords, 1));
+#endif
+
+#ifdef REFLECTIONMAP_CUBIC
+	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 coords = reflect(viewDir, worldNormal);
+#ifdef INVERTCUBICMAP
+	coords.y = 1.0 - coords.y;
+#endif
+	return vec3(reflectionMatrix * vec4(coords, 0));
+#endif
+
+#ifdef REFLECTIONMAP_PROJECTION
+	return vec3(reflectionMatrix * (view * worldPos));
+#endif
 
+#ifdef REFLECTIONMAP_SKYBOX
+	return position;
+#endif
+
+#ifdef REFLECTIONMAP_EXPLICIT
 	return vec3(0, 0, 0);
+#endif
 }
 #endif
 
@@ -215,9 +208,9 @@ void main(void) {
 		vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
 	}
 #endif
-
+	
 #ifdef REFLECTION
-	vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);
+	vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), vNormalW);
 #endif
 
 #ifdef EMISSIVE

+ 3 - 1
src/Tools/babylon.filesInput.js

@@ -76,7 +76,9 @@ var BABYLON;
                             FilesInput.FilesToLoad[this._filesToLoad[i].name] = this._filesToLoad[i];
                             break;
                         default:
-                            if (this._filesToLoad[i].name.indexOf(".babylon") !== -1 && this._filesToLoad[i].name.indexOf(".manifest") === -1
+                            if ((this._filesToLoad[i].name.indexOf(".babylon") !== -1 || this._filesToLoad[i].name.indexOf(".stl") !== -1 ||
+                                this._filesToLoad[i].name.indexOf(".obj") !== -1 || this._filesToLoad[i].name.indexOf(".mtl") !== -1)
+                                && this._filesToLoad[i].name.indexOf(".manifest") === -1
                                 && this._filesToLoad[i].name.indexOf(".incremental") === -1 && this._filesToLoad[i].name.indexOf(".babylonmeshdata") === -1
                                 && this._filesToLoad[i].name.indexOf(".babylongeometrydata") === -1 && this._filesToLoad[i].name.indexOf(".babylonbinarymeshdata") === -1 &&
                                 this._filesToLoad[i].name.indexOf(".binary.babylon") === -1) {

+ 5 - 1
src/Tools/babylon.filesInput.ts

@@ -100,7 +100,11 @@
                             FilesInput.FilesToLoad[this._filesToLoad[i].name] = this._filesToLoad[i];
                             break;
                         default:
-                            if (this._filesToLoad[i].name.indexOf(".babylon") !== -1 && this._filesToLoad[i].name.indexOf(".manifest") === -1
+                            if ((
+                                this._filesToLoad[i].name.indexOf(".babylon") !== -1 || this._filesToLoad[i].name.indexOf(".stl") !== -1 ||
+                                this._filesToLoad[i].name.indexOf(".obj") !== -1 || this._filesToLoad[i].name.indexOf(".mtl") !== -1
+                                )   
+                                && this._filesToLoad[i].name.indexOf(".manifest") === -1
                                 && this._filesToLoad[i].name.indexOf(".incremental") === -1 && this._filesToLoad[i].name.indexOf(".babylonmeshdata") === -1
                                 && this._filesToLoad[i].name.indexOf(".babylongeometrydata") === -1 && this._filesToLoad[i].name.indexOf(".babylonbinarymeshdata") === -1 && 
                                 this._filesToLoad[i].name.indexOf(".binary.babylon") === -1) {

+ 3 - 2
src/babylon.engine.js

@@ -352,8 +352,9 @@ var BABYLON;
          * @param {boolean} [antialias] - enable antialias
          * @param options - further options to be sent to the getContext function
          */
-        function Engine(canvas, antialias, options) {
+        function Engine(canvas, antialias, options, adaptToDeviceRatio) {
             var _this = this;
+            if (adaptToDeviceRatio === void 0) { adaptToDeviceRatio = true; }
             // Public members
             this.isFullscreen = false;
             this.isPointerLock = false;
@@ -405,7 +406,7 @@ var BABYLON;
             window.addEventListener("blur", this._onBlur);
             window.addEventListener("focus", this._onFocus);
             // Viewport
-            this._hardwareScalingLevel = 1.0 / (window.devicePixelRatio || 1.0);
+            this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / (window.devicePixelRatio || 1.0) : 1.0;
             this.resize();
             // Caps
             this._caps = new EngineCapabilities();

+ 2 - 2
src/babylon.engine.ts

@@ -562,7 +562,7 @@
          * @param {boolean} [antialias] - enable antialias
          * @param options - further options to be sent to the getContext function
          */
-        constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?) {
+        constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?: { antialias?: boolean, preserveDrawingBuffer?: boolean}, adaptToDeviceRatio = true) {
             this._renderingCanvas = canvas;
 
             options = options || {};
@@ -596,7 +596,7 @@
             window.addEventListener("focus", this._onFocus);
 
             // Viewport
-            this._hardwareScalingLevel = 1.0 / (window.devicePixelRatio || 1.0);
+            this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / (window.devicePixelRatio || 1.0) : 1.0;
             this.resize();
 
             // Caps