Forráskód Böngészése

New effects to unlock IE11

David Catuhe 11 éve
szülő
commit
b004e20637

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

@@ -229,10 +229,10 @@ var BABYLON = BABYLON || {};
         if (this._cachedDefines != join) {
             this._cachedDefines = join;
 
-            // IE patch
+            // Legacy browser patch
             var shaderName = "default";
-            if (BABYLON.Tools.isIE()) {
-                shaderName = "iedefault";
+            if (!this._scene.getEngine().getCaps().standardDerivatives) {
+                shaderName = "legacydefault";
             }
 
             this._effect = this._scene.getEngine().createEffect(shaderName,

+ 36 - 58
Babylon/Mesh/babylon.mesh.js

@@ -16,7 +16,9 @@ var BABYLON = BABYLON || {};
 
         this.position = new BABYLON.Vector3(0, 0, 0);
         this.rotation = new BABYLON.Vector3(0, 0, 0);
+        this.worldRotation = new BABYLON.Vector3(0, 0, 0);
         this.rotationQuaternion = null;
+        this.worldRotationQuaternion = null;
         this.scaling = new BABYLON.Vector3(1, 1, 1);
 
         this._pivotMatrix = BABYLON.Matrix.Identity();
@@ -37,10 +39,12 @@ var BABYLON = BABYLON || {};
 
         this._localScaling = BABYLON.Matrix.Zero();
         this._localRotation = BABYLON.Matrix.Zero();
+        this._localWorldRotation = BABYLON.Matrix.Zero();
         this._localTranslation = BABYLON.Matrix.Zero();
         this._localBillboard = BABYLON.Matrix.Zero();
         this._localPivotScaling = BABYLON.Matrix.Zero();
         this._localPivotScalingRotation = BABYLON.Matrix.Zero();
+        this._localPivotScalingRotationWorld = BABYLON.Matrix.Zero();
         this._localWorld = BABYLON.Matrix.Zero();
         this._worldMatrix = BABYLON.Matrix.Zero();
         this._rotateYByPI = BABYLON.Matrix.RotationY(Math.PI);
@@ -124,43 +128,18 @@ var BABYLON = BABYLON || {};
             absolutePositionZ = absolutePosition.z;
         }
 
-        // worldMatrix = pivotMatrix * scalingMatrix * rotationMatrix * translateMatrix * parentWorldMatrix
-        // => translateMatrix = invertRotationMatrix * invertScalingMatrix * invertPivotMatrix * worldMatrix * invertParentWorldMatrix
-
-        // get this matrice before the other ones since
-        // that will update them if they have to be updated
-
-        var worldMatrix = this.getWorldMatrix().clone();
-
-        worldMatrix.m[12] = absolutePositionX;
-        worldMatrix.m[13] = absolutePositionY;
-        worldMatrix.m[14] = absolutePositionZ;
-
-        var invertRotationMatrix = this._localRotation.clone();
-        invertRotationMatrix.invert();
-
-        var invertScalingMatrix = this._localScaling.clone();
-        invertScalingMatrix.invert();
-
-        var invertPivotMatrix = this._pivotMatrix.clone();
-        invertPivotMatrix.invert();
-
-        var translateMatrix = invertRotationMatrix.multiply(invertScalingMatrix);
-
-        translateMatrix.multiplyToRef(invertPivotMatrix, invertScalingMatrix); // reuse matrix
-        invertScalingMatrix.multiplyToRef(worldMatrix, translateMatrix);
-
         if (this.parent) {
             var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
             invertParentWorldMatrix.invert();
 
-            translateMatrix.multiplyToRef(invertParentWorldMatrix, invertScalingMatrix); // reuse matrix
-            translateMatrix = invertScalingMatrix;
-        }
+            var worldPosition = new BABYLON.Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
 
-        this.position.x = translateMatrix.m[12];
-        this.position.y = translateMatrix.m[13];
-        this.position.z = translateMatrix.m[14];
+            this.position = BABYLON.Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
+        } else {
+            this.position.x = absolutePositionX;
+            this.position.y = absolutePositionY;
+            this.position.z = absolutePositionZ;
+        }
     };
 
     BABYLON.Mesh.prototype.getTotalVertices = function () {
@@ -244,6 +223,14 @@ var BABYLON = BABYLON || {};
                 return false;
         }
 
+        if (this.worldRotationQuaternion) {
+            if (!this._cache.worldRotationQuaternion.equals(this.worldRotationQuaternion))
+                return false;
+        } else {
+            if (!this._cache.worldRotation.equals(this.worldRotation))
+                return false;
+        }
+
         if (!this._cache.scaling.equals(this.scaling))
             return false;
 
@@ -269,6 +256,8 @@ var BABYLON = BABYLON || {};
         this._cache.scaling = BABYLON.Vector3.Zero();
         this._cache.rotation = BABYLON.Vector3.Zero();
         this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
+        this._cache.worldRotation = BABYLON.Vector3.Zero();
+        this._cache.worldRotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
     };
 
     BABYLON.Mesh.prototype.markAsDirty = function (property) {
@@ -336,6 +325,15 @@ var BABYLON = BABYLON || {};
             this._cache.rotation.copyFrom(this.rotation);
         }
 
+        // World rotation
+        if (this.worldRotationQuaternion) {
+            this.worldRotationQuaternion.toRotationMatrix(this._localWorldRotation);
+            this._cache.worldRotationQuaternion.copyFrom(this.worldRotationQuaternion);
+        } else {
+            BABYLON.Matrix.RotationYawPitchRollToRef(this.worldRotation.y, this.worldRotation.x, this.worldRotation.z, this._localWorldRotation);
+            this._cache.worldRotation.copyFrom(this.worldRotation);
+        }
+
         // Translation
         if (this.infiniteDistance) {
             var camera = this._scene.activeCamera;
@@ -347,6 +345,7 @@ var BABYLON = BABYLON || {};
         // Composing transformations
         this._pivotMatrix.multiplyToRef(this._localScaling, this._localPivotScaling);
         this._localPivotScaling.multiplyToRef(this._localRotation, this._localPivotScalingRotation);
+        this._localPivotScalingRotation.multiplyToRef(this._localWorldRotation, this._localPivotScalingRotationWorld);
 
         // Billboarding
         if (this.billboardMode !== BABYLON.Mesh.BILLBOARDMODE_NONE) {
@@ -374,18 +373,18 @@ var BABYLON = BABYLON || {};
 
             this._localBillboard.invert();
 
-            this._localPivotScalingRotation.multiplyToRef(this._localBillboard, this._localWorld);
-            this._rotateYByPI.multiplyToRef(this._localWorld, this._localPivotScalingRotation);
+            this._localPivotScalingRotationWorld.multiplyToRef(this._localBillboard, this._localWorld);
+            this._rotateYByPI.multiplyToRef(this._localWorld, this._localPivotScalingRotationWorld);
         }
 
         // Local world
-        this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._localWorld);
+        this._localPivotScalingRotationWorld.multiplyToRef(this._localTranslation, this._localWorld);
 
         // Parent
         if (this.parent && this.parent.getWorldMatrix && this.billboardMode === BABYLON.Mesh.BILLBOARDMODE_NONE) {
             this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
         } else {
-            this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._worldMatrix);
+            this._localPivotScalingRotationWorld.multiplyToRef(this._localTranslation, this._worldMatrix);
         }
 
         // Bounding info
@@ -616,27 +615,6 @@ var BABYLON = BABYLON || {};
     };
 
     // Geometry
-    // Deprecated: use setPositionWithLocalVector instead 
-    BABYLON.Mesh.prototype.setLocalTranslation = function (vector3) {
-        console.warn("deprecated: use setPositionWithLocalVector instead");
-        this.computeWorldMatrix();
-        var worldMatrix = this._worldMatrix.clone();
-        worldMatrix.setTranslation(BABYLON.Vector3.Zero());
-
-        this.position = BABYLON.Vector3.TransformCoordinates(vector3, worldMatrix);
-    };
-
-    // Deprecated: use getPositionExpressedInLocalSpace instead 
-    BABYLON.Mesh.prototype.getLocalTranslation = function () {
-        console.warn("deprecated: use getPositionExpressedInLocalSpace instead");
-        this.computeWorldMatrix();
-        var invWorldMatrix = this._worldMatrix.clone();
-        invWorldMatrix.setTranslation(BABYLON.Vector3.Zero());
-        invWorldMatrix.invert();
-
-        return BABYLON.Vector3.TransformCoordinates(this.position, invWorldMatrix);
-    };
-
     BABYLON.Mesh.prototype.setPositionWithLocalVector = function (vector3) {
         this.computeWorldMatrix();
 
@@ -1011,7 +989,7 @@ var BABYLON = BABYLON || {};
     };
 
     // Geometric tools
-    BABYLON.Mesh.prototype.convertToFlatShadedMesh = function() {
+    BABYLON.Mesh.prototype.convertToFlatShadedMesh = function () {
         /// <summary>Update normals and vertices to get a flat shading rendering.</summary>
         /// <summary>Warning: This may imply adding vertices to the mesh in order to get exactly 3 vertices per face</summary>
 

+ 2 - 0
Babylon/Physics/babylon.physicsEngine.js

@@ -17,6 +17,8 @@ var BABYLON = BABYLON || {};
     BABYLON.PhysicsEngine.prototype._runOneStep = function (delta) {
         if (delta > 0.1) {
             delta = 0.1;
+        } else if (delta <= 0) {
+            delta = 1.0 / 60.0;
         }
 
         this._world.step(delta);

+ 505 - 0
Babylon/Shaders/legacydefault.fragment.fx

@@ -0,0 +1,505 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+#define MAP_PROJECTION	4.
+
+// Constants
+uniform vec3 vEyePosition;
+uniform vec3 vAmbientColor;
+uniform vec4 vDiffuseColor;
+uniform vec4 vSpecularColor;
+uniform vec3 vEmissiveColor;
+
+// Input
+varying vec3 vPositionW;
+varying vec3 vNormalW;
+
+#ifdef VERTEXCOLOR
+varying vec3 vColor;
+#endif
+
+// Lights
+#ifdef LIGHT0
+uniform vec4 vLightData0;
+uniform vec3 vLightDiffuse0;
+uniform vec3 vLightSpecular0;
+#ifdef SHADOW0
+varying vec4 vPositionFromLight0;
+uniform sampler2D shadowSampler0;
+#endif
+#ifdef SPOTLIGHT0
+uniform vec4 vLightDirection0;
+#endif
+#ifdef HEMILIGHT0
+uniform vec3 vLightGround0;
+#endif
+#endif
+
+#ifdef LIGHT1
+uniform vec4 vLightData1;
+uniform vec3 vLightDiffuse1;
+uniform vec3 vLightSpecular1;
+#ifdef SHADOW1
+varying vec4 vPositionFromLight1;
+uniform sampler2D shadowSampler1;
+#endif
+#ifdef SPOTLIGHT1
+uniform vec4 vLightDirection1;
+#endif
+#ifdef HEMILIGHT1
+uniform vec3 vLightGround1;
+#endif
+#endif
+
+#ifdef LIGHT2
+uniform vec4 vLightData2;
+uniform vec3 vLightDiffuse2;
+uniform vec3 vLightSpecular2;
+#ifdef SHADOW2
+varying vec4 vPositionFromLight2;
+uniform sampler2D shadowSampler2;
+#endif
+#ifdef SPOTLIGHT2
+uniform vec4 vLightDirection2;
+#endif
+#ifdef HEMILIGHT2
+uniform vec3 vLightGround2;
+#endif
+#endif
+
+#ifdef LIGHT3
+uniform vec4 vLightData3;
+uniform vec3 vLightDiffuse3;
+uniform vec3 vLightSpecular3;
+#ifdef SHADOW3
+varying vec4 vPositionFromLight3;
+uniform sampler2D shadowSampler3;
+#endif
+#ifdef SPOTLIGHT3
+uniform vec4 vLightDirection3;
+#endif
+#ifdef HEMILIGHT3
+uniform vec3 vLightGround3;
+#endif
+#endif
+
+// Samplers
+#ifdef DIFFUSE
+varying vec2 vDiffuseUV;
+uniform sampler2D diffuseSampler;
+uniform vec2 vDiffuseInfos;
+#endif
+
+#ifdef AMBIENT
+varying vec2 vAmbientUV;
+uniform sampler2D ambientSampler;
+uniform vec2 vAmbientInfos;
+#endif
+
+#ifdef OPACITY	
+varying vec2 vOpacityUV;
+uniform sampler2D opacitySampler;
+uniform vec2 vOpacityInfos;
+#endif
+
+#ifdef REFLECTION
+varying vec3 vReflectionUVW;
+uniform samplerCube reflectionCubeSampler;
+uniform sampler2D reflection2DSampler;
+uniform vec3 vReflectionInfos;
+#endif
+
+#ifdef EMISSIVE
+varying vec2 vEmissiveUV;
+uniform vec2 vEmissiveInfos;
+uniform sampler2D emissiveSampler;
+#endif
+
+#ifdef SPECULAR
+varying vec2 vSpecularUV;
+uniform vec2 vSpecularInfos;
+uniform sampler2D specularSampler;
+#endif
+
+// Shadows
+#ifdef SHADOWS
+
+float unpack(vec4 color)
+{
+	const vec4 bitShift = vec4(1. / (255. * 255. * 255.), 1. / (255. * 255.), 1. / 255., 1.);
+	return dot(color, bitShift);
+}
+
+float unpackHalf(vec2 color)
+{
+	return color.x + (color.y / 255.0);
+}
+
+float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler)
+{
+	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
+	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);
+
+	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
+	{
+		return 1.0;
+	}
+
+	float shadow = unpack(texture2D(shadowSampler, uv));
+
+	if (depth.z > shadow)
+	{
+		return 0.;
+	}
+	return 1.;
+}
+
+// Thanks to http://devmaster.net/
+float ChebychevInequality(vec2 moments, float t)
+{
+	if (t <= moments.x)
+	{
+		return 1.0;
+	}
+
+	float variance = moments.y - (moments.x * moments.x);
+	variance = max(variance, 0.);
+
+	float d = t - moments.x;
+	return variance / (variance + d * d);
+}
+
+float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)
+{
+	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
+	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);
+
+	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
+	{
+		return 1.0;
+	}
+
+	vec4 texel = texture2D(shadowSampler, uv);
+
+	vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));
+	return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);
+}
+#endif
+
+#ifdef CLIPPLANE
+varying float fClipDistance;
+#endif
+
+// Fog
+#ifdef FOG
+
+#define FOGMODE_NONE    0.
+#define FOGMODE_EXP     1.
+#define FOGMODE_EXP2    2.
+#define FOGMODE_LINEAR  3.
+#define E 2.71828
+
+uniform vec4 vFogInfos;
+uniform vec3 vFogColor;
+varying float fFogDistance;
+
+float CalcFogFactor()
+{
+	float fogCoeff = 1.0;
+	float fogStart = vFogInfos.y;
+	float fogEnd = vFogInfos.z;
+	float fogDensity = vFogInfos.w;
+
+	if (FOGMODE_LINEAR == vFogInfos.x)
+	{
+		fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);
+	}
+	else if (FOGMODE_EXP == vFogInfos.x)
+	{
+		fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);
+	}
+	else if (FOGMODE_EXP2 == vFogInfos.x)
+	{
+		fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);
+	}
+
+	return clamp(fogCoeff, 0.0, 1.0);
+}
+#endif
+
+// Light Computing
+mat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor) {
+	mat3 result;
+
+	vec3 lightVectorW;
+	if (lightData.w == 0.)
+	{
+		lightVectorW = normalize(lightData.xyz - vPositionW);
+	}
+	else
+	{
+		lightVectorW = normalize(-lightData.xyz);
+	}
+
+	// diffuse
+	float ndl = max(0., dot(vNormal, lightVectorW));
+
+	// Specular
+	vec3 angleW = normalize(viewDirectionW + lightVectorW);
+	float specComp = max(0., dot(vNormal, angleW));
+	specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));
+
+	result[0] = ndl * diffuseColor;
+	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 result;
+
+	vec3 lightVectorW = normalize(lightData.xyz - vPositionW);
+
+	// diffuse
+	float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));
+	float spotAtten = 0.0;
+
+	if (cosAngle >= lightDirection.w)
+	{
+		cosAngle = max(0., pow(cosAngle, lightData.w));
+		spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));
+
+		// Diffuse
+		float ndl = max(0., dot(vNormal, -lightDirection.xyz));
+
+		// Specular
+		vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);
+		float specComp = max(0., dot(vNormal, angleW));
+		specComp = pow(specComp, vSpecularColor.a);
+
+		result[0] = ndl * spotAtten * diffuseColor;
+		result[1] = specComp * specularColor * spotAtten;
+		result[2] = vec3(0.);
+
+		return result;
+	}
+
+	result[0] = vec3(0.);
+	result[1] = vec3(0.);
+	result[2] = vec3(0.);
+
+	return result;
+}
+
+mat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {
+	mat3 result;
+
+	// Diffuse
+	float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;
+
+	// Specular
+	vec3 angleW = normalize(viewDirectionW + lightData.xyz);
+	float specComp = max(0., dot(vNormal, angleW));
+	specComp = pow(specComp, vSpecularColor.a);
+
+	result[0] = mix(groundColor, diffuseColor, ndl);
+	result[1] = specComp * specularColor;
+	result[2] = vec3(0.);
+
+	return result;
+}
+
+void main(void) {
+	// Clip plane
+#ifdef CLIPPLANE
+	if (fClipDistance > 0.0)
+		discard;
+#endif
+
+	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
+
+	// Base color
+	vec4 baseColor = vec4(1., 1., 1., 1.);
+	vec3 diffuseColor = vDiffuseColor.rgb;
+
+#ifdef VERTEXCOLOR
+	diffuseColor *= vColor;
+#endif
+
+#ifdef DIFFUSE
+	baseColor = texture2D(diffuseSampler, vDiffuseUV);
+
+#ifdef ALPHATEST
+	if (baseColor.a < 0.4)
+		discard;
+#endif
+
+	baseColor.rgb *= vDiffuseInfos.y;
+#endif
+
+	// Bump
+	vec3 normalW = vNormalW;
+
+	// Ambient color
+	vec3 baseAmbientColor = vec3(1., 1., 1.);
+
+#ifdef AMBIENT
+	baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;
+#endif
+
+	// Lighting
+	vec3 diffuseBase = vec3(0., 0., 0.);
+	vec3 specularBase = vec3(0., 0., 0.);
+	float shadow = 1.;
+
+#ifdef LIGHT0
+#ifdef SPOTLIGHT0
+	mat3 info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);
+#endif
+#ifdef HEMILIGHT0
+	mat3 info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);
+#endif
+#ifdef POINTDIRLIGHT0
+	mat3 info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);
+#endif
+#ifdef SHADOW0
+#ifdef SHADOWVSM0
+	shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);
+#else
+	shadow = computeShadow(vPositionFromLight0, shadowSampler0);
+#endif
+#else
+	shadow = 1.;
+#endif
+	diffuseBase += info[0] * shadow;
+	specularBase += info[1] * shadow;
+#endif
+
+#ifdef LIGHT1
+#ifdef SPOTLIGHT1
+	info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);
+#endif
+#ifdef HEMILIGHT1
+	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);
+#endif
+#ifdef POINTDIRLIGHT1
+	info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);
+#endif
+#ifdef SHADOW1
+#ifdef SHADOWVSM1
+	shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);
+#else
+	shadow = computeShadow(vPositionFromLight1, shadowSampler1);
+#endif
+#else
+	shadow = 1.;
+#endif
+	diffuseBase += info[0] * shadow;
+	specularBase += info[1] * shadow;
+#endif
+
+#ifdef LIGHT2
+#ifdef SPOTLIGHT2
+	info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);
+#endif
+#ifdef HEMILIGHT2
+	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);
+#endif
+#ifdef POINTDIRLIGHT2
+	info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);
+#endif
+#ifdef SHADOW2
+#ifdef SHADOWVSM2
+	shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);
+#else
+	shadow = computeShadow(vPositionFromLight2, shadowSampler2);
+#endif	
+#else
+	shadow = 1.;
+#endif
+	diffuseBase += info[0] * shadow;
+	specularBase += info[1] * shadow;
+#endif
+
+#ifdef LIGHT3
+#ifdef SPOTLIGHT3
+	info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);
+#endif
+#ifdef HEMILIGHT3
+	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);
+#endif
+#ifdef POINTDIRLIGHT3
+	info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);
+#endif
+#ifdef SHADOW3
+#ifdef SHADOWVSM3
+	shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);
+#else
+	shadow = computeShadow(vPositionFromLight3, shadowSampler3);
+#endif	
+#else
+	shadow = 1.;
+#endif
+	diffuseBase += info[0] * shadow;
+	specularBase += info[1] * shadow;
+#endif
+
+	// Reflection
+	vec3 reflectionColor = vec3(0., 0., 0.);
+
+#ifdef REFLECTION
+	if (vReflectionInfos.z != 0.0)
+	{
+		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;
+	}
+	else
+	{
+		vec2 coords = vReflectionUVW.xy;
+
+		if (vReflectionInfos.x == MAP_PROJECTION)
+		{
+			coords /= vReflectionUVW.z;
+		}
+
+		coords.y = 1.0 - coords.y;
+
+		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;
+	}
+#endif
+
+	// Alpha
+	float alpha = vDiffuseColor.a;
+
+#ifdef OPACITY
+	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
+	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11) * opacityMap.a;
+	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;
+#endif
+
+	// Emissive
+	vec3 emissiveColor = vEmissiveColor;
+#ifdef EMISSIVE
+	emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
+#endif
+
+	// Specular map
+	vec3 specularColor = vSpecularColor.rgb;
+#ifdef SPECULAR
+	specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;
+#endif
+
+	// Composition
+	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
+	vec3 finalSpecular = specularBase * specularColor;
+
+	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);
+
+#ifdef FOG
+	float fog = CalcFogFactor();
+	color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;
+#endif
+
+	gl_FragColor = color;
+}

+ 286 - 0
Babylon/Shaders/legacydefault.vertex.fx

@@ -0,0 +1,286 @@
+#ifdef GL_ES
+precision mediump 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;
+#ifdef UV1
+attribute vec2 uv;
+#endif
+#ifdef UV2
+attribute vec2 uv2;
+#endif
+#ifdef VERTEXCOLOR
+attribute vec3 color;
+#endif
+#ifdef BONES
+attribute vec4 matricesIndices;
+attribute vec4 matricesWeights;
+#endif
+
+// Uniforms
+uniform mat4 world;
+uniform mat4 view;
+uniform mat4 viewProjection;
+
+#ifdef DIFFUSE
+varying vec2 vDiffuseUV;
+uniform mat4 diffuseMatrix;
+uniform vec2 vDiffuseInfos;
+#endif
+
+#ifdef AMBIENT
+varying vec2 vAmbientUV;
+uniform mat4 ambientMatrix;
+uniform vec2 vAmbientInfos;
+#endif
+
+#ifdef OPACITY
+varying vec2 vOpacityUV;
+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;
+uniform mat4 emissiveMatrix;
+#endif
+
+#ifdef SPECULAR
+varying vec2 vSpecularUV;
+uniform vec2 vSpecularInfos;
+uniform mat4 specularMatrix;
+#endif
+
+#ifdef BUMP
+varying vec2 vBumpUV;
+uniform vec2 vBumpInfos;
+uniform mat4 bumpMatrix;
+#endif
+
+#ifdef BONES
+uniform mat4 mBones[BonesPerMesh];
+#endif
+
+// Output
+varying vec3 vPositionW;
+varying vec3 vNormalW;
+
+#ifdef VERTEXCOLOR
+varying vec3 vColor;
+#endif
+
+#ifdef CLIPPLANE
+uniform vec4 vClipPlane;
+varying float fClipDistance;
+#endif
+
+#ifdef FOG
+varying float fFogDistance;
+#endif
+
+#ifdef SHADOWS
+#ifdef LIGHT0
+uniform mat4 lightMatrix0;
+varying vec4 vPositionFromLight0;
+#endif
+#ifdef LIGHT1
+uniform mat4 lightMatrix1;
+varying vec4 vPositionFromLight1;
+#endif
+#ifdef LIGHT2
+uniform mat4 lightMatrix2;
+varying vec4 vPositionFromLight2;
+#endif
+#ifdef LIGHT3
+uniform mat4 lightMatrix3;
+varying vec4 vPositionFromLight3;
+#endif
+#endif
+
+#ifdef REFLECTION
+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);
+
+		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(0, 0, 0);
+}
+#endif
+
+void main(void) {
+	mat4 finalWorld;
+
+#ifdef BONES
+	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
+	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
+	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
+
+#ifdef BONES4
+	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
+	finalWorld = world * (m0 + m1 + m2 + m3);
+#else
+	finalWorld = world * (m0 + m1 + m2);
+#endif 
+
+#else
+	finalWorld = world;
+#endif
+
+	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
+
+	vec4 worldPos = finalWorld * vec4(position, 1.0);
+	vPositionW = vec3(worldPos);
+	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
+
+	// Texture coordinates
+#ifndef UV1
+	vec2 uv = vec2(0., 0.);
+#endif
+#ifndef UV2
+	vec2 uv2 = vec2(0., 0.);
+#endif
+
+#ifdef DIFFUSE
+	if (vDiffuseInfos.x == 0.)
+	{
+		vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+	}
+	else
+	{
+		vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
+#ifdef AMBIENT
+	if (vAmbientInfos.x == 0.)
+	{
+		vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
+	}
+	else
+	{
+		vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
+#ifdef OPACITY
+	if (vOpacityInfos.x == 0.)
+	{
+		vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
+	}
+	else
+	{
+		vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
+#ifdef REFLECTION
+	vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);
+#endif
+
+#ifdef EMISSIVE
+	if (vEmissiveInfos.x == 0.)
+	{
+		vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
+	}
+	else
+	{
+		vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
+#ifdef SPECULAR
+	if (vSpecularInfos.x == 0.)
+	{
+		vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));
+	}
+	else
+	{
+		vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
+#ifdef BUMP
+	if (vBumpInfos.x == 0.)
+	{
+		vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));
+	}
+	else
+	{
+		vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));
+	}
+#endif
+
+	// Clip plane
+#ifdef CLIPPLANE
+	fClipDistance = dot(worldPos, vClipPlane);
+#endif
+
+	// Fog
+#ifdef FOG
+	fFogDistance = (view * worldPos).z;
+#endif
+
+	// Shadows
+#ifdef SHADOWS
+#ifdef LIGHT0
+	vPositionFromLight0 = lightMatrix0 * vec4(position, 1.0);
+#endif
+#ifdef LIGHT1
+	vPositionFromLight1 = lightMatrix1 * vec4(position, 1.0);
+#endif
+#ifdef LIGHT2
+	vPositionFromLight2 = lightMatrix2 * vec4(position, 1.0);
+#endif
+#ifdef LIGHT3
+	vPositionFromLight3 = lightMatrix3 * vec4(position, 1.0);
+#endif
+#endif
+
+	// Vertex color
+#ifdef VERTEXCOLOR
+	vColor = color;
+#endif
+}

+ 12 - 0
Babylon/Tools/babylon.math.js

@@ -922,6 +922,10 @@ var BABYLON = BABYLON || {};
         return "{X: " + this.x + " Y:" + this.y + " Z:" + this.z + " W:" + this.w + "}";
     };
 
+    BABYLON.Quaternion.prototype.asArray = function () {
+        return [this.x, this.y, this.z, this.w];
+    };
+
     BABYLON.Quaternion.prototype.equals = function (otherQuaternion) {
         return otherQuaternion && this.x === otherQuaternion.x && this.y === otherQuaternion.y && this.z === otherQuaternion.z && this.w === otherQuaternion.w;
     };
@@ -1131,6 +1135,10 @@ var BABYLON = BABYLON || {};
         return this.m;
     };
 
+    BABYLON.Matrix.prototype.asArray = function () {
+        return this.toArray();
+    };
+
     BABYLON.Matrix.prototype.invert = function () {
         this.invertToRef(this);
     };
@@ -1753,6 +1761,10 @@ var BABYLON = BABYLON || {};
         this.d = d;
     };
 
+    BABYLON.Plane.prototype.asArray = function () {
+        return [this.normal.x, this.normal.y, this.normal.z, this.d];
+    };
+
     // Methods
     BABYLON.Plane.prototype.normalize = function () {
         var norm = (Math.sqrt((this.normal.x * this.normal.x) + (this.normal.y * this.normal.y) + (this.normal.z * this.normal.z)));

+ 229 - 20
Babylon/Tools/babylon.sceneSerializer.js

@@ -4,36 +4,227 @@ var BABYLON = BABYLON || {};
 
 (function () {
 
-    var serializeLight = function (light, serializationObject) {
+    var serializeLight = function (light) {
+        var serializationObject = {};
         serializationObject.name = light.name;
+        serializationObject.id = light.id;
 
         if (light instanceof BABYLON.PointLight) {
             serializationObject.type = 0;
             serializationObject.position = light.position.asArray();
+        } else if (light instanceof BABYLON.DirectionalLight) {
+            serializationObject.type = 1;
+            serializationObject.position = light.position.asArray();
+            serializationObject.direction = light.position.asArray();
+        } else if (light instanceof BABYLON.SpotLight) {
+            serializationObject.type = 2;
+            serializationObject.position = light.position.asArray();
+            serializationObject.direction = light.position.asArray();
+            serializationObject.angle = light.angle;
+            serializationObject.exponent = light.exponent;
+        } else if (light instanceof BABYLON.HemisphericLight) {
+            serializationObject.type = 2;
+            serializationObject.groundColor = light.groundColor.asArray();
         }
-        //switch (light.type) {
-        //    case 1:
-        //        light = new BABYLON.DirectionalLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
-        //        light.position = BABYLON.Vector3.FromArray(parsedLight.position);
-        //        break;
-        //    case 2:
-        //        light = new BABYLON.SpotLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), BABYLON.Vector3.FromArray(parsedLight.direction), parsedLight.angle, parsedLight.exponent, scene);
-        //        break;
-        //    case 3:
-        //        light = new BABYLON.HemisphericLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
-        //        light.groundColor = BABYLON.Color3.FromArray(parsedLight.groundColor);
-        //        break;
-        //}
-
-        serializationObject.id = light.id;
 
         if (light.intensity) {
             serializationObject.intensity = light.intensity;
         }
         serializationObject.diffuse = light.diffuse.asArray();
         serializationObject.specular = light.specular.asArray();
+
+        return serializationObject;
+    };
+
+    var serializeCamera = function (camera) {
+        var serializationObject = {};
+        serializationObject.name = camera.name;
+        serializationObject.id = camera.id;
+        serializationObject.position = camera.position.asArray();
+
+        // Parent
+        if (camera.parent) {
+            serializationObject.parentId = camera.parent.id;
+        }
+
+        // Target
+        serializationObject.rotation = camera.rotation.asArray();
+
+        // Locked target
+        if (camera.lockedTarget && camera.lockedTarget.id) {
+            serializationObject.lockedTargetId = camera.lockedTarget.id;
+        }
+
+        serializationObject.fov = camera.fov;
+        serializationObject.minZ = camera.minZ;
+        serializationObject.maxZ = camera.maxZ;
+
+        serializationObject.speed = camera.speed;
+        serializationObject.inertia = camera.inertia;
+
+        serializationObject.checkCollisions = camera.checkCollisions;
+        serializationObject.applyGravity = camera.applyGravity;
+
+        if (camera.ellipsoid) {
+            serializationObject.ellipsoid = camera.ellipsoid.asArray();
+        }
+
+        // Animations
+        appendAnimations(camera, serializationObject);
+
+        return serializationObject;
+    };
+
+    var appendAnimations = function(source, destination) {
+        if (source.animations) {
+            destination.animations = [];
+            for (var animationIndex = 0; animationIndex < source.animations.length; animationIndex++) {
+                var animation = source.animations[animationIndex];
+
+                destination.animations.push(serializeAnimation(animation));
+            }
+        }
     };
 
+    var serializeAnimation = function (animation) {
+        var serializationObject = {};
+
+        serializationObject.name = animation.name;
+        serializationObject.property = animation.targetProperty;
+        serializationObject.framePerSecond = animation.framePerSecond;
+        serializationObject.dataType = animation.dataType;
+        serializationObject.loopBehavior = animation.loopBehavior;
+
+        var dataType = animation.dataType;
+        serializationObject.keys = [];
+        for (var index = 0; index < animation.keys.length; index++) {
+            var animationKey = animation.keys[index];
+
+            var key = {};
+            key.frame = animationKey.frame;
+
+            switch (dataType) {
+                case BABYLON.Animation.ANIMATIONTYPE_FLOAT:
+                    key.values = [animationKey.value];
+                    break;
+                case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:
+                case BABYLON.Animation.ANIMATIONTYPE_MATRIX:
+                case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:
+                    key.values = animationKey.value.asArray();
+                    break;
+            }
+
+            serializationObject.keys.push(key);
+        }
+
+        return serializationObject;
+    };
+
+    var serializeMaterial = function (material) {
+        var serializationObject = {};
+
+        serializationObject.name = material.name;
+
+        serializationObject.ambient = material.ambientColor.asArray();
+        serializationObject.diffuse = material.diffuseColor.asArray();
+        serializationObject.specular = material.specularColor.asArray();
+        serializationObject.specularPower = material.specularPower;
+        serializationObject.emissive = material.emissiveColor.asArray();
+
+        serializationObject.alpha = material.alpha;
+
+        serializationObject.id = material.id;
+        serializationObject.backFaceCulling = material.backFaceCulling;
+
+        if (material.diffuseTexture) {
+            serializationObject.diffuseTexture = serializeTexture(material.diffuseTexture);
+        }
+
+        if (material.ambientTexture) {
+            serializationObject.ambientTexture = serializeTexture(material.ambientTexture);
+        }
+
+        if (material.opacityTexture) {
+            serializationObject.opacityTexture = serializeTexture(material.opacityTexture);
+        }
+
+        if (material.reflectionTexture) {
+            serializationObject.reflectionTexture = serializeTexture(material.reflectionTexture);
+        }
+
+        if (material.emissiveTexture) {
+            serializationObject.emissiveTexture = serializeTexture(material.emissiveTexture);
+        }
+
+        if (material.specularTexture) {
+            serializationObject.specularTexture = serializeTexture(material.specularTexture);
+        }
+
+        if (material.bumpTexture) {
+            serializationObject.bumpTexture = serializeTexture(material.bumpTexture);
+        }
+
+        return serializationObject;
+    };
+
+    var serializeTexture = function (texture) {
+        var serializationObject = {};
+
+        if (!texture.name) {
+            return null;
+        }
+
+        if (texture instanceof BABYLON.CubeTexture) {
+            serializationObject.name = texture.name;
+            serializationObject.hasAlpha = texture.hasAlpha;
+            serializationObject.level = texture.level;
+            serializationObject.coordinatesMode = texture.coordinatesMode;
+
+            return serializationObject;
+        }
+
+        if (texture instanceof BABYLON.MirrorTexture) {
+            serializationObject.renderTargetSize = texture.renderTargetSize;
+            serializationObject.renderList = [];
+
+            for (var index = 0; index < texture.renderList.length; index++) {
+                serializationObject.renderList.push(texture.renderList[index].id);
+            }
+
+            serializationObject.mirrorPlane = texture.mirrorPlane.asArray();
+        } else if (texture instanceof BABYLON.RenderTargetTexture) {
+            serializationObject.renderTargetSize = texture.renderTargetSize;
+            serializationObject.renderList = [];
+
+            for (var index = 0; index < texture.renderList.length; index++) {
+                serializationObject.renderList.push(texture.renderList[index].id);
+            }
+        }
+
+        serializationObject.name = texture.name;
+        serializationObject.hasAlpha = texture.hasAlpha;
+        serializationObject.level = texture.level;
+
+        serializationObject.coordinatesIndex = texture.coordinatesIndex;
+        serializationObject.coordinatesMode = texture.coordinatesMode;
+        serializationObject.uOffset = texture.uOffset;
+        serializationObject.vOffset = texture.vOffset;
+        serializationObject.uScale = texture.uScale;
+        serializationObject.vScale = texture.vScale;
+        serializationObject.uAng = texture.uAng;
+        serializationObject.vAng = texture.vAng;
+        serializationObject.wAng = texture.wAng;
+
+        serializationObject.wrapU = texture.wrapU;
+        serializationObject.wrapV = texture.wrapV;
+
+        // Animations
+        appendAnimations(texture, serializationObject);
+
+        return serializationObject;
+    };
+
+
     BABYLON.SceneSerializer = {
         Serialize: function (scene) {
             var serializationObject = {};
@@ -59,13 +250,31 @@ var BABYLON = BABYLON || {};
             for (var index = 0; index < scene.lights.length; index++) {
                 var light = scene.lights[index];
                 
-                var serializedLight = {};
-                serializationObject.lights.push(serializedLight);
+                serializationObject.lights.push(serializeLight(light));
+            }
+
+            // Cameras
+            serializationObject.cameras = [];
+            for (var index = 0; index < scene.cameras.length; index++) {
+                var camera = scene.cameras[index];
+
+                serializationObject.cameras.push(serializeCamera(camera));
+            }
+            if (scene.activecamera) {
+                serializationObject.activeCameraID = scene.activeCamera.id;
+            }
+
+            // Materials
+            serializationObject.materials = [];
+            for (var index = 0; index < scene.materials.length; index++) {
+                var material = scene.materials[index];
+
+                serializationObject.materials.push(serializeMaterial(material));
 
-                serializeLight(light, serializedLight);
+                ;
             }
 
-            return JSON.stringify(serializationObject);
+            return serializationObject;
         }
     };
 })();

+ 1 - 5
Babylon/Tools/babylon.tools.js

@@ -243,11 +243,7 @@ var BABYLON = BABYLON || {};
         reader.readAsText(fileToLoad);
     };
 
-    // Misc.    
-    BABYLON.Tools.isIE = function () {
-        return window.ActiveXObject !== undefined;
-    };
-    
+    // Misc.        
     BABYLON.Tools.WithinEpsilon = function (a, b) {
         var num = a - b;
         return -1.401298E-45 <= num && num <= 1.401298E-45;

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 4 - 4
babylon.1.8.5.js