Sfoglia il codice sorgente

Materials Library:

- Improved fire material (alpha and texture coords)
- Improved water material (added waves, test with the ground mesh)
- Added ground mesh in controls
luaacro 9 anni fa
parent
commit
a73e4f5b02

File diff suppressed because it is too large
+ 9 - 173
materialsLibrary/dist/babylon.fireMaterial.js


File diff suppressed because it is too large
+ 22 - 11
materialsLibrary/dist/babylon.waterMaterial.js


+ 14 - 199
materialsLibrary/materials/fire/babylon.fireMaterial.ts

@@ -9,38 +9,8 @@ module BABYLON {
         public ALPHATEST = false;
         public POINTSIZE = false;
         public FOG = false;
-        public LIGHT0 = false;
-        public LIGHT1 = false;
-        public LIGHT2 = false;
-        public LIGHT3 = false;
-        public SPOTLIGHT0 = false;
-        public SPOTLIGHT1 = false;
-        public SPOTLIGHT2 = false;
-        public SPOTLIGHT3 = false;
-        public HEMILIGHT0 = false;
-        public HEMILIGHT1 = false;
-        public HEMILIGHT2 = false;
-        public HEMILIGHT3 = false;
-        public POINTDIRLIGHT0 = false;
-        public POINTDIRLIGHT1 = false;
-        public POINTDIRLIGHT2 = false;
-        public POINTDIRLIGHT3 = false;
-        public SHADOW0 = false;
-        public SHADOW1 = false;
-        public SHADOW2 = false;
-        public SHADOW3 = false;
-        public SHADOWS = false;
-        public SHADOWVSM0 = false;
-        public SHADOWVSM1 = false;
-        public SHADOWVSM2 = false;
-        public SHADOWVSM3 = false;
-        public SHADOWPCF0 = false;
-        public SHADOWPCF1 = false;
-        public SHADOWPCF2 = false;
-        public SHADOWPCF3 = false;
-        public NORMAL = false;
         public UV1 = false;
-        public UV2 = false;
+        public NORMAL = false;
         public VERTEXCOLOR = false;
         public VERTEXALPHA = false;
         public BONES = false;
@@ -62,6 +32,8 @@ module BABYLON {
         public diffuseColor = new Color3(1, 1, 1);
         public disableLighting = false;
         
+        public speed = 1.0;
+        
         private _scaledDiffuse = new Color3();
         private _renderId: number;
 
@@ -144,10 +116,8 @@ module BABYLON {
             if (scene.clipPlane) {
                 this._defines.CLIPPLANE = true;
             }
-
-            if (engine.getAlphaTesting()) {
-                this._defines.ALPHATEST = true;
-            }
+            
+            this._defines.ALPHATEST = true;
 
             // Point size
             if (this.pointsCloud || scene.forcePointsCloud) {
@@ -158,83 +128,7 @@ module BABYLON {
             if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {
                 this._defines.FOG = true;
             }
-
-            var lightIndex = 0;
-            if (scene.lightsEnabled && !this.disableLighting) {
-                for (var index = 0; index < scene.lights.length; index++) {
-                    var light = scene.lights[index];
-
-                    if (!light.isEnabled()) {
-                        continue;
-                    }
-
-                    // Excluded check
-                    if (light._excludedMeshesIds.length > 0) {
-                        for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
-                            var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
-
-                            if (excludedMesh) {
-                                light.excludedMeshes.push(excludedMesh);
-                            }
-                        }
-
-                        light._excludedMeshesIds = [];
-                    }
-
-                    // Included check
-                    if (light._includedOnlyMeshesIds.length > 0) {
-                        for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
-                            var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
-
-                            if (includedOnlyMesh) {
-                                light.includedOnlyMeshes.push(includedOnlyMesh);
-                            }
-                        }
-
-                        light._includedOnlyMeshesIds = [];
-                    }
-
-                    if (!light.canAffectMesh(mesh)) {
-                        continue;
-                    }
-                    needNormals = true;
-                    this._defines["LIGHT" + lightIndex] = true;
-
-                    var type;
-                    if (light instanceof SpotLight) {
-                        type = "SPOTLIGHT" + lightIndex;
-                    } else if (light instanceof HemisphericLight) {
-                        type = "HEMILIGHT" + lightIndex;
-                    } else {
-                        type = "POINTDIRLIGHT" + lightIndex;
-                    }
-
-                    this._defines[type] = true;
-
-                    // Shadows
-                    if (scene.shadowsEnabled) {
-                        var shadowGenerator = light.getShadowGenerator();
-                        if (mesh && mesh.receiveShadows && shadowGenerator) {
-                            this._defines["SHADOW" + lightIndex] = true;
-
-                            this._defines.SHADOWS = true;
-
-                            if (shadowGenerator.useVarianceShadowMap || shadowGenerator.useBlurVarianceShadowMap) {
-                                this._defines["SHADOWVSM" + lightIndex] = true;
-                            }
-
-                            if (shadowGenerator.usePoissonSampling) {
-                                this._defines["SHADOWPCF" + lightIndex] = true;
-                            }
-                        }
-                    }
-
-                    lightIndex++;
-                    if (lightIndex === maxSimultaneousLights)
-                        break;
-                }
-            }
-
+            
             // Attribs
             if (mesh) {
                 if (needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
@@ -244,9 +138,6 @@ module BABYLON {
                     if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
                         this._defines.UV1 = true;
                     }
-                    if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
-                        this._defines.UV2 = true;
-                    }
                 }
                 if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {
                     this._defines.VERTEXCOLOR = true;
@@ -278,28 +169,6 @@ module BABYLON {
                 if (this._defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                 }
-
-                for (lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
-                    if (!this._defines["LIGHT" + lightIndex]) {
-                        continue;
-                    }
-
-                    if (lightIndex > 0) {
-                        fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
-                    }
-
-                    if (this._defines["SHADOW" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOW" + lightIndex);
-                    }
-
-                    if (this._defines["SHADOWPCF" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
-                    }
-
-                    if (this._defines["SHADOWVSM" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
-                    }
-                }
              
                 if (this._defines.BONES4) {
                     fallbacks.addFallback(0, "BONES4");
@@ -316,10 +185,6 @@ module BABYLON {
                     attribs.push(VertexBuffer.UVKind);
                 }
 
-                if (this._defines.UV2) {
-                    attribs.push(VertexBuffer.UV2Kind);
-                }
-
                 if (this._defines.VERTEXCOLOR) {
                     attribs.push(VertexBuffer.ColorKind);
                 }
@@ -342,26 +207,21 @@ module BABYLON {
                 var join = this._defines.toString();
                 this._effect = scene.getEngine().createEffect(shaderName,
                     attribs,
-                    ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                        "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                        "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                        "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                        "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                    ["world", "view", "viewProjection", "vEyePosition",
                         "vFogInfos", "vFogColor", "pointSize",
                         "vDiffuseInfos", 
                         "mBones",
                         "vClipPlane", "diffuseMatrix",
-                        "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
                         // Fire
-                        "time"
+                        "time", "speed"
                     ],
                     ["diffuseSampler",
-                        "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3",
                         // Fire
                         "distortionSampler", "opacitySampler"
                     ],
                     join, fallbacks, this.onCompiled, this.onError);
             }
+            
             if (!this._effect.isReady()) {
                 return false;
             }
@@ -403,8 +263,7 @@ module BABYLON {
 
                     this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
                     this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
-                }
-                if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
+                    
                     this._effect.setTexture("distortionSampler", this.distortionTexture);
                     this._effect.setTexture("opacitySampler", this.opacityTexture);
                 }
@@ -425,58 +284,11 @@ module BABYLON {
 
             this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
 
-            if (scene.lightsEnabled && !this.disableLighting) {
-                var lightIndex = 0;
-                for (var index = 0; index < scene.lights.length; index++) {
-                    var light = scene.lights[index];
-
-                    if (!light.isEnabled()) {
-                        continue;
-                    }
-
-                    if (!light.canAffectMesh(mesh)) {
-                        continue;
-                    }
-
-                    if (light instanceof PointLight) {
-                        // Point Light
-                        light.transferToEffect(this._effect, "vLightData" + lightIndex);
-                    } else if (light instanceof DirectionalLight) {
-                        // Directional Light
-                        light.transferToEffect(this._effect, "vLightData" + lightIndex);
-                    } else if (light instanceof SpotLight) {
-                        // Spot Light
-                        light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
-                    } else if (light instanceof HemisphericLight) {
-                        // Hemispheric Light
-                        light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
-                    }
-
-                    light.diffuse.scaleToRef(light.intensity, this._scaledDiffuse);
-                    this._effect.setColor4("vLightDiffuse" + lightIndex, this._scaledDiffuse, light.range);
-
-                    // Shadows
-                    if (scene.shadowsEnabled) {
-                        var shadowGenerator = light.getShadowGenerator();
-                        if (mesh.receiveShadows && shadowGenerator) {
-                            this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
-                            this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                            this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
-                        }
-                    }
-
-                    lightIndex++;
-
-                    if (lightIndex === maxSimultaneousLights)
-                        break;
-                }
-            }
-
             // View
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
                 this._effect.setMatrix("view", scene.getViewMatrix());
             }
-
+            
             // Fog
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
                 this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
@@ -486,6 +298,9 @@ module BABYLON {
             // Time
             this._lastTime += scene.getEngine().getDeltaTime();
             this._effect.setFloat("time", this._lastTime);
+            
+            // Speed
+            this._effect.setFloat("speed", this.speed);
 
             super.bind(world, mesh);
         }

+ 11 - 347
materialsLibrary/materials/fire/fire.fragment.fx

@@ -2,7 +2,6 @@ precision highp float;
 
 // Constants
 uniform vec3 vEyePosition;
-uniform vec4 vDiffuseColor;
 
 // Input
 varying vec3 vPositionW;
@@ -15,71 +14,6 @@ varying vec3 vNormalW;
 varying vec4 vColor;
 #endif
 
-// Lights
-#ifdef LIGHT0
-uniform vec4 vLightData0;
-uniform vec4 vLightDiffuse0;
-#ifdef SHADOW0
-varying vec4 vPositionFromLight0;
-uniform sampler2D shadowSampler0;
-uniform vec3 shadowsInfo0;
-#endif
-#ifdef SPOTLIGHT0
-uniform vec4 vLightDirection0;
-#endif
-#ifdef HEMILIGHT0
-uniform vec3 vLightGround0;
-#endif
-#endif
-
-#ifdef LIGHT1
-uniform vec4 vLightData1;
-uniform vec4 vLightDiffuse1;
-#ifdef SHADOW1
-varying vec4 vPositionFromLight1;
-uniform sampler2D shadowSampler1;
-uniform vec3 shadowsInfo1;
-#endif
-#ifdef SPOTLIGHT1
-uniform vec4 vLightDirection1;
-#endif
-#ifdef HEMILIGHT1
-uniform vec3 vLightGround1;
-#endif
-#endif
-
-#ifdef LIGHT2
-uniform vec4 vLightData2;
-uniform vec4 vLightDiffuse2;
-#ifdef SHADOW2
-varying vec4 vPositionFromLight2;
-uniform sampler2D shadowSampler2;
-uniform vec3 shadowsInfo2;
-#endif
-#ifdef SPOTLIGHT2
-uniform vec4 vLightDirection2;
-#endif
-#ifdef HEMILIGHT2
-uniform vec3 vLightGround2;
-#endif
-#endif
-
-#ifdef LIGHT3
-uniform vec4 vLightData3;
-uniform vec4 vLightDiffuse3;
-#ifdef SHADOW3
-varying vec4 vPositionFromLight3;
-uniform sampler2D shadowSampler3;
-uniform vec3 shadowsInfo3;
-#endif
-#ifdef SPOTLIGHT3
-uniform vec4 vLightDirection3;
-#endif
-#ifdef HEMILIGHT3
-uniform vec3 vLightGround3;
-#endif
-#endif
-
 // Samplers
 #ifdef DIFFUSE
 varying vec2 vDiffuseUV;
@@ -95,103 +29,6 @@ varying vec2 vDistortionCoords1;
 varying vec2 vDistortionCoords2;
 varying vec2 vDistortionCoords3;
 
-// Shadows
-#ifdef SHADOWS
-
-float unpack(vec4 color)
-{
-	const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);
-	return dot(color, bit_shift);
-}
-
-float unpackHalf(vec2 color)
-{
-	return color.x + (color.y / 255.0);
-}
-
-float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)
-{
-	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
-	depth = 0.5 * depth + vec3(0.5);
-	vec2 uv = depth.xy;
-
-	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
-	{
-		return 1.0;
-	}
-
-	float shadow = unpack(texture2D(shadowSampler, uv)) + bias;
-
-	if (depth.z > shadow)
-	{
-		return darkness;
-	}
-	return 1.;
-}
-
-float computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias, float darkness)
-{
-	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
-	depth = 0.5 * depth + vec3(0.5);
-	vec2 uv = depth.xy;
-
-	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
-	{
-		return 1.0;
-	}
-
-	float visibility = 1.;
-
-	vec2 poissonDisk[4];
-	poissonDisk[0] = vec2(-0.94201624, -0.39906216);
-	poissonDisk[1] = vec2(0.94558609, -0.76890725);
-	poissonDisk[2] = vec2(-0.094184101, -0.92938870);
-	poissonDisk[3] = vec2(0.34495938, 0.29387760);
-
-	// Poisson Sampling
-	float biasedDepth = depth.z - bias;
-
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / mapSize)) < biasedDepth) visibility -= 0.25;
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / mapSize)) < biasedDepth) visibility -= 0.25;
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / mapSize)) < biasedDepth) visibility -= 0.25;
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / mapSize)) < biasedDepth) visibility -= 0.25;
-
-	return  min(1.0, visibility + darkness);
-}
-
-// Thanks to http://devmaster.net/
-float linstep(float low, float high, float v) {
-	return clamp((v - low) / (high - low), 0.0, 1.0);
-}
-
-float ChebychevInequality(vec2 moments, float compare, float bias)
-{
-	float p = smoothstep(compare - bias, compare, moments.x);
-	float variance = max(moments.y - moments.x * moments.x, 0.02);
-	float d = compare - moments.x;
-	float p_max = linstep(0.2, 1.0, variance / (variance + d * d));
-
-	return clamp(max(p, p_max), 0.0, 1.0);
-}
-
-float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)
-{
-	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
-	depth = 0.5 * depth + vec3(0.5);
-	vec2 uv = depth.xy;
-
-	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)
-	{
-		return 1.0;
-	}
-
-	vec4 texel = texture2D(shadowSampler, uv);
-
-	vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));
-	return min(1.0, 1.0 - ChebychevInequality(moments, depth.z, bias) + darkness);
-}
-#endif
-
 #ifdef CLIPPLANE
 varying float fClipDistance;
 #endif
@@ -233,72 +70,9 @@ float CalcFogFactor()
 }
 #endif
 
-// Light Computing
-struct lightingInfo
+vec4 bx2(vec4 x)
 {
-	vec3 diffuse;
-};
-
-lightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, float range) {
-	lightingInfo result;
-
-	vec3 lightVectorW;
-	float attenuation = 1.0;
-	if (lightData.w == 0.)
-	{
-		vec3 direction = lightData.xyz - vPositionW;
-
-		attenuation = max(0., 1.0 - length(direction) / range);
-		lightVectorW = normalize(direction);
-	}
-	else
-	{
-		lightVectorW = normalize(-lightData.xyz);
-	}
-
-	// diffuse
-	float ndl = max(0., dot(vNormal, lightVectorW));
-	result.diffuse = ndl * diffuseColor * attenuation;
-
-	return result;
-}
-
-lightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, float range) {
-	lightingInfo result;
-
-	vec3 direction = lightData.xyz - vPositionW;
-	vec3 lightVectorW = normalize(direction);
-	float attenuation = max(0., 1.0 - length(direction) / range);
-
-	// 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 = clamp((cosAngle - lightDirection.w) / (1. - cosAngle), 0.0, 1.0);
-
-		// Diffuse
-		float ndl = max(0., dot(vNormal, -lightDirection.xyz));
-		result.diffuse = ndl * spotAtten * diffuseColor * attenuation;
-
-		return result;
-	}
-
-	result.diffuse = vec3(0.);
-
-	return result;
-}
-
-lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 groundColor) {
-	lightingInfo result;
-
-	// Diffuse
-	float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;
-	result.diffuse = mix(groundColor, diffuseColor, ndl);
-
-	return result;
+   return vec4(2.0) * x - vec4(1.0);
 }
 
 void main(void) {
@@ -312,10 +86,9 @@ void main(void) {
 
 	// Base color
 	vec4 baseColor = vec4(1., 1., 1., 1.);
-	vec3 diffuseColor = vDiffuseColor.rgb;
 
 	// Alpha
-	float alpha = vDiffuseColor.a;
+	float alpha = 1.0;
 
 #ifdef DIFFUSE
 	// Fire
@@ -329,15 +102,17 @@ void main(void) {
 	vec4 noise1 = texture2D(distortionSampler, vDistortionCoords2);
 	vec4 noise2 = texture2D(distortionSampler, vDistortionCoords3);
 	
-	vec4 noiseSum = (noise0 * 2.0 - 1.0) * distortionAmount0 + (noise1 * 2.0 - 1.0) * distortionAmount1 + (noise2 * 2.0 - 1.0) * distortionAmount2;
+	vec4 noiseSum = bx2(noise0) * distortionAmount0 + bx2(noise1) * distortionAmount1 + bx2(noise2) * distortionAmount2;
+	
+	vec4 perturbedBaseCoords = vec4(vDiffuseUV, 0.0, 1.0) + noiseSum * (vDiffuseUV.y * heightAttenuation.x + heightAttenuation.y);
 	
-	vec4 perturbedBaseCoords = noiseSum + vec4(vDiffuseUV, 0.0, 1.0) * (vDiffuseUV.y * heightAttenuation.x + heightAttenuation.y);
+	vec4 opacityColor = texture2D(opacitySampler, perturbedBaseCoords.xy);
 	
 	baseColor = texture2D(diffuseSampler, perturbedBaseCoords.xy) * 2.0;
-	baseColor *= texture2D(opacitySampler, perturbedBaseCoords.xy);
+	baseColor *= opacityColor;
 
 #ifdef ALPHATEST
-	if (baseColor.a < 0.4)
+	if (opacityColor.r < 0.1)
 		discard;
 #endif
 
@@ -356,125 +131,14 @@ void main(void) {
 #endif
 
 	// Lighting
-	vec3 diffuseBase = vec3(0., 0., 0.);
-	float shadow = 1.;
-
-#ifdef LIGHT0
-#ifdef SPOTLIGHT0
-	lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightDiffuse0.a);
-#endif
-#ifdef HEMILIGHT0
-	lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightGround0);
-#endif
-#ifdef POINTDIRLIGHT0
-	lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightDiffuse0.a);
-#endif
-#ifdef SHADOW0
-#ifdef SHADOWVSM0
-	shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);
-#else
-#ifdef SHADOWPCF0
-	shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);
-#else
-	shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);
-#endif
-#endif
-#else
-	shadow = 1.;
-#endif
-	diffuseBase += info.diffuse * shadow;
-#endif
-
-#ifdef LIGHT1
-
-#ifdef SPOTLIGHT1
-	info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightDiffuse1.a);
-#endif
-#ifdef HEMILIGHT1
-	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightGround1);
-#endif
-#ifdef POINTDIRLIGHT1
-	info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightDiffuse1.a);
-#endif
-#ifdef SHADOW1
-#ifdef SHADOWVSM1
-	shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);
-#else
-#ifdef SHADOWPCF1
-	shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);
-#else
-	shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);
-#endif
-#endif
-#else
-	shadow = 1.;
-#endif
-	diffuseBase += info.diffuse * shadow;
-
-#endif
-
-#ifdef LIGHT2
-#ifdef SPOTLIGHT2
-	info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightDiffuse2.a);
-#endif
-#ifdef HEMILIGHT2
-	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightGround2);
-#endif
-#ifdef POINTDIRLIGHT2
-	info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightDiffuse2.a);
-#endif
-#ifdef SHADOW2
-#ifdef SHADOWVSM2
-	shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);
-#else
-#ifdef SHADOWPCF2
-	shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);
-#else
-	shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);
-#endif	
-#endif	
-#else
-	shadow = 1.;
-#endif
-	diffuseBase += info.diffuse * shadow;
-
-#endif
-
-#ifdef LIGHT3
-
-#ifdef SPOTLIGHT3
-	info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightDiffuse3.a);
-#endif
-#ifdef HEMILIGHT3
-	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightGround3);
-#endif
-#ifdef POINTDIRLIGHT3
-	info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightDiffuse3.a);
-#endif
-#ifdef SHADOW3
-#ifdef SHADOWVSM3
-	shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);
-#else
-#ifdef SHADOWPCF3
-	shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);
-#else
-	shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);
-#endif	
-#endif	
-#else
-	shadow = 1.;
-#endif
-	diffuseBase += info.diffuse * shadow;
-#endif
+	vec3 diffuseBase = vec3(1.0, 1.0, 1.0);
 
 #ifdef VERTEXALPHA
 	alpha *= vColor.a;
 #endif
 
-	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
-
 	// Composition
-	vec4 color = vec4(finalDiffuse, alpha);
+	vec4 color = vec4(baseColor.rgb, alpha);
 
 #ifdef FOG
 	float fog = CalcFogFactor();

+ 4 - 53
materialsLibrary/materials/fire/fire.vertex.fx

@@ -35,8 +35,6 @@ uniform mat4 viewProjection;
 
 #ifdef DIFFUSE
 varying vec2 vDiffuseUV;
-uniform mat4 diffuseMatrix;
-uniform vec2 vDiffuseInfos;
 #endif
 
 #ifdef BONES
@@ -66,27 +64,9 @@ varying float fClipDistance;
 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
-
 // Fire
 uniform float time;
+uniform float speed;
 
 varying vec2 vDistortionCoords1;
 varying vec2 vDistortionCoords2;
@@ -124,22 +104,9 @@ void main(void) {
 #endif
 
 	// 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));
-	}
+	vDiffuseUV = uv;
+	vDiffuseUV.y -= 0.2;
 #endif
 
 	// Clip plane
@@ -152,22 +119,6 @@ void main(void) {
 	fFogDistance = (view * worldPos).z;
 #endif
 
-	// Shadows
-#ifdef SHADOWS
-#ifdef LIGHT0
-	vPositionFromLight0 = lightMatrix0 * worldPos;
-#endif
-#ifdef LIGHT1
-	vPositionFromLight1 = lightMatrix1 * worldPos;
-#endif
-#ifdef LIGHT2
-	vPositionFromLight2 = lightMatrix2 * worldPos;
-#endif
-#ifdef LIGHT3
-	vPositionFromLight3 = lightMatrix3 * worldPos;
-#endif
-#endif
-
 	// Vertex color
 #ifdef VERTEXCOLOR
 	vColor = color;
@@ -179,7 +130,7 @@ void main(void) {
 #endif
 
 	// Fire
-	vec3 layerSpeed = vec3(0.2, 0.52, 0.1);
+	vec3 layerSpeed = vec3(-0.2, -0.52, -0.1) * speed;
 	
 	vDistortionCoords1.x = uv.x;
 	vDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;

+ 24 - 12
materialsLibrary/materials/water/babylon.waterMaterial.ts

@@ -5,7 +5,8 @@ module BABYLON {
 	var maxSimultaneousLights = 4;
 
     class WaterMaterialDefines extends MaterialDefines {
-        public DIFFUSE = false;
+        public BUMP = false;
+        public REFLECTION = false;
         public CLIPPLANE = false;
         public ALPHATEST = false;
         public POINTSIZE = false;
@@ -72,9 +73,13 @@ module BABYLON {
         */
 		public windDirection: Vector2 = new Vector2(0, 1);
         /**
-        * @param {number}: Wave height, represents the bump height related to the bump map
+        * @param {number}: Wave height, represents the height of the waves
         */
-		public waveHeight: number = 0.3;
+		public waveHeight: number = 0.4;
+        /**
+        * @param {number}: Bump height, represents the bump height related to the bump map
+        */
+		public bumpHeight: number = 0.4;
         /**
         * @param {number}: The water color blended with the reflection and refraction samplers
         */
@@ -138,6 +143,11 @@ module BABYLON {
         }
 		
         // Methods
+        public addToRenderList(node: any): void {
+            this._refractionRTT.renderList.push(node);
+            this._reflectionRTT.renderList.push(node);
+        }
+        
         public enableRenderTargets(enable: boolean): void {
             var refreshRate = enable ? 1 : 0;
             
@@ -198,14 +208,18 @@ module BABYLON {
 
             // Textures
             if (scene.texturesEnabled) {
-                if (this.bumpTexture && StandardMaterial.DiffuseTextureEnabled) {
+                if (this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
                     if (!this.bumpTexture.isReady()) {
                         return false;
                     } else {
                         needUVs = true;
-                        this._defines.DIFFUSE = true;
+                        this._defines.BUMP = true;
                     }
                 }
+                
+                if (StandardMaterial.ReflectionTextureEnabled) {
+                    this._defines.REFLECTION = true;
+                }
             }
 
             // Effect
@@ -422,7 +436,7 @@ module BABYLON {
                         "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
 						// Water
 						"worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
-						"cameraPosition", "waveHeight", "waterColor", "colorBlendFactor"
+						"cameraPosition", "bumpHeight", "waveHeight", "waterColor", "colorBlendFactor"
                     ],
                     ["normalSampler",
                         "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3",
@@ -549,8 +563,8 @@ module BABYLON {
             
             // Water
             if (StandardMaterial.ReflectionTextureEnabled) {
-			 this._effect.setTexture("refractionSampler", this._refractionRTT);
-			 this._effect.setTexture("reflectionSampler", this._reflectionRTT);
+                this._effect.setTexture("refractionSampler", this._refractionRTT);
+                this._effect.setTexture("reflectionSampler", this._reflectionRTT);
             }
             
 			var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
@@ -562,6 +576,7 @@ module BABYLON {
 			this._effect.setFloat("time", this._lastTime / 100000);
 			this._effect.setFloat("windForce", this.windForce);
 			this._effect.setFloat("waveHeight", this.waveHeight);
+            this._effect.setFloat("bumpHeight", this.bumpHeight);
 			this._effect.setColor4("waterColor", this.waterColor, 1.0);
 			this._effect.setFloat("colorBlendFactor", this.colorBlendFactor);
 
@@ -576,9 +591,6 @@ module BABYLON {
 			scene.customRenderTargets.push(this._refractionRTT);
 			scene.customRenderTargets.push(this._reflectionRTT);
 			
-			this._refractionRTT.renderList = scene.meshes;
-			this._reflectionRTT.renderList = scene.meshes;
-			
 			var isVisible: boolean;
 			var clipPlane = null;
 			var savedViewMatrix;
@@ -590,7 +602,7 @@ module BABYLON {
 				
 				// Clip plane
 				clipPlane = scene.clipPlane;
-				scene.clipPlane = Plane.FromPositionAndNormal(new Vector3(0, this._mesh.position.y, 0), new Vector3(0, 1, 0));
+				//scene.clipPlane = Plane.FromPositionAndNormal(new Vector3(0, this._mesh.position.y, 0), new Vector3(0, 1, 0));
 			};
 			
 			this._refractionRTT.onAfterRender = () => {

+ 4 - 2
materialsLibrary/materials/water/water.fragment.fx

@@ -81,7 +81,7 @@ uniform vec3 vLightGround3;
 #endif
 
 // Samplers
-#ifdef DIFFUSE
+#ifdef BUMP
 varying vec2 vNormalUV;
 uniform sampler2D normalSampler;
 uniform vec2 vNormalInfos;
@@ -326,7 +326,7 @@ void main(void) {
 	// Alpha
 	float alpha = vDiffuseColor.a;
 
-#ifdef DIFFUSE
+#ifdef BUMP
 	baseColor = texture2D(normalSampler, vNormalUV);
 
 #ifdef ALPHATEST
@@ -341,6 +341,7 @@ void main(void) {
 	baseColor.rgb *= vColor.rgb;
 #endif
 
+#ifdef REFLECTION
 	// Water
 	vec2 perturbation = vWaveHeight * (baseColor.rg - 0.5);
 	
@@ -358,6 +359,7 @@ void main(void) {
 	vec4 combinedColor = refractiveColor * fresnelTerm + reflectiveColor * (1.0 - fresnelTerm);
 	
 	baseColor = colorBlendFactor * waterColor + (1.0 - colorBlendFactor) * combinedColor;
+#endif
 
 	// Bump
 #ifdef NORMAL

+ 9 - 4
materialsLibrary/materials/water/water.vertex.fx

@@ -33,7 +33,7 @@ uniform mat4 world;
 uniform mat4 view;
 uniform mat4 viewProjection;
 
-#ifdef DIFFUSE
+#ifdef BUMP
 varying vec2 vNormalUV;
 uniform mat4 normalMatrix;
 uniform vec2 vNormalInfos;
@@ -91,6 +91,7 @@ uniform vec2 windDirection;
 uniform float waveLength;
 uniform float time;
 uniform float windForce;
+uniform float bumpHeight;
 uniform float waveHeight;
 
 // Water varyings
@@ -137,7 +138,7 @@ void main(void) {
 	vec2 uv2 = vec2(0., 0.);
 #endif
 
-#ifdef DIFFUSE
+#ifdef BUMP
 	if (vNormalInfos.x == 0.)
 	{
 		vNormalUV = vec2(normalMatrix * vec4((uv * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));
@@ -184,11 +185,15 @@ void main(void) {
 	gl_PointSize = pointSize;
 #endif
 
+	vec3 p = position;
+	p.y += (sin(((p.x / 0.05) + time * 100.0)) * waveHeight * 5.0) + (cos(((p.z / 0.05) + time * 100.0)) * waveHeight * 5.0);
+	
+	gl_Position = viewProjection * finalWorld * vec4(p, 1.0);;
+
 	worldPos = viewProjection * finalWorld * vec4(position, 1.0);
-	gl_Position = worldPos;
 
 	// Water
-	vWaveHeight = waveHeight;
+	vWaveHeight = bumpHeight;
 	vPosition = position;
 	
 	vRefractionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);

+ 16 - 2
materialsLibrary/test/index.html

@@ -63,9 +63,13 @@
 			// Create meshes
 			var sphere = BABYLON.Mesh.CreateSphere("sphere", 32, 30.0, scene);
 			
-			var plane = BABYLON.MeshBuilder.CreateBox("plane", { width: 30, height: 0.1, depth:30 }, scene);
+			var plane = BABYLON.MeshBuilder.CreateBox("plane", { width: 30, height: 1, depth:30 }, scene);
 			plane.setEnabled(false);
 			
+			var ground = BABYLON.Mesh.CreateGround("ground", 512, 512, 32, scene, false);
+			ground.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1);
+			ground.setEnabled(false);
+			
 			var knot = BABYLON.Mesh.CreateTorusKnot("knot", 10, 3, 128, 64, 2, 3, scene);
 			knot.setEnabled(false);
 			
@@ -141,8 +145,14 @@
 				simple.diffuseTexture.vScale = 5;
 				
 				var water = new BABYLON.WaterMaterial("water", scene, currentMesh);
+				water.backFaceCulling = false;
 				water.enableRenderTargets(false);
 				water.bumpTexture = new BABYLON.Texture("textures/waterbump.png", scene);
+				water.windForce = -45;
+				water.waveHeight = 1.3;
+				water.addToRenderList(skybox);
+				water.addToRenderList(shadowCaster);
+				water.addToRenderList(shadowCaster2);
 				
 				var fire = new BABYLON.FireMaterial("fire", scene);
 				fire.diffuseTexture = new BABYLON.Texture("textures/fire/diffuse.png", scene);
@@ -178,6 +188,7 @@
 						case "water":
 							currentMaterial = water;
 							water.enableRenderTargets(true);
+							skybox.setEnabled(true);
 							break;
 						case "fire":
 							currentMaterial = fire;
@@ -190,7 +201,7 @@
 					currentMesh.material = currentMaterial;
 				});
 
-				gui.add(options, 'mesh', ['sphere', 'knot', 'plane', 'rabbit']).onFinishChange(function () {
+				gui.add(options, 'mesh', ['sphere', 'knot', 'plane', 'ground', 'rabbit']).onFinishChange(function () {
 					currentMesh.setEnabled(false);
 					switch (options.mesh) {
 						case "sphere":
@@ -202,6 +213,9 @@
 						case "plane":
 							currentMesh = plane;
 							break;
+						case "ground":
+							currentMesh = ground;
+							break;
 						case "rabbit":
 							currentMesh = rabbit;
 							break;