瀏覽代碼

Updated Water Material to unlimited number of lights
Fixed simple material

Julien Moreau-Mathis 9 年之前
父節點
當前提交
a428bef12e

+ 3 - 5
materialsLibrary/dist/babylon.simpleMaterial.js

@@ -112,7 +112,6 @@ var BABYLON;
             if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
                 this._defines.FOG = true;
             }
-            var lightIndex = 0;
             if (scene.lightsEnabled && !this.disableLighting) {
                 needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
             }
@@ -181,10 +180,9 @@ var BABYLON;
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "depthValues"
                 ];
-                BABYLON.MaterialHelper.PrepareUniformsListForList(uniforms, this._defines, this.maxSimultaneousLights);
-                this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, ["diffuseSampler",
-                    "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
-                ], join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
+                var samplers = ["diffuseSampler"];
+                BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
+                this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
             }
             if (!this._effect.isReady()) {
                 return false;

File diff suppressed because it is too large
+ 1 - 1
materialsLibrary/dist/babylon.simpleMaterial.min.js


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


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


+ 0 - 2
materialsLibrary/dist/dts/babylon.waterMaterial.d.ts

@@ -47,8 +47,6 @@ declare module BABYLON {
         private _material;
         private _reflectionTransform;
         private _lastTime;
-        private _scaledDiffuse;
-        private _scaledSpecular;
         private _renderId;
         private _defines;
         private _cachedDefines;

+ 8 - 10
materialsLibrary/materials/simple/babylon.simpleMaterial.ts

@@ -211,19 +211,17 @@ module BABYLON {
                 var shaderName = "simple";
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                        "vFogInfos", "vFogColor", "pointSize",
-                        "vDiffuseInfos", 
-                        "mBones",
-                        "vClipPlane", "diffuseMatrix", "depthValues"
-                    ];
+                                "vFogInfos", "vFogColor", "pointSize",
+                                "vDiffuseInfos", 
+                                "mBones",
+                                "vClipPlane", "diffuseMatrix", "depthValues"
+                ];
+                var samplers = ["diffuseSampler"];
                     
-                MaterialHelper.PrepareUniformsListForList(uniforms, this._defines, this.maxSimultaneousLights);
+                MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 
                 this._effect = scene.getEngine().createEffect(shaderName,
-                    attribs, uniforms,
-                    ["diffuseSampler",
-                        "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
-                    ],
+                    attribs, uniforms, samplers,
                     join, fallbacks, this.onCompiled, this.onError, {maxSimultaneousLights: this.maxSimultaneousLights});
             }
             if (!this._effect.isReady()) {

+ 7 - 10
materialsLibrary/materials/water/babylon.waterMaterial.ts

@@ -104,8 +104,6 @@ module BABYLON {
 		private _reflectionTransform: Matrix = Matrix.Zero();
 		private _lastTime: number = 0;
         
-        private _scaledDiffuse = new Color3();
-        private _scaledSpecular = new Color3();
         private _renderId: number;
 
         private _defines = new WaterMaterialDefines();
@@ -319,16 +317,15 @@ module BABYLON {
                     "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
                     "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "colorBlendFactor", "waveSpeed"
                 ]
+                var samplers = ["normalSampler",
+                    // Water
+                    "refractionSampler", "reflectionSampler"
+                ];
                 
-                MaterialHelper.PrepareUniformsListForList(uniforms, this._defines, this.maxSimultaneousLights);
+                MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 
                 this._effect = scene.getEngine().createEffect(shaderName,
-                    attribs, uniforms,
-                    ["normalSampler",
-                        "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3",
-						// Water
-						"refractionSampler", "reflectionSampler"
-                    ],
+                    attribs, uniforms, samplers,
                     join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
             }
             if (!this._effect.isReady()) {
@@ -382,7 +379,7 @@ module BABYLON {
                 this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
             }
 
-            this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
+            this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             
             if (this._defines.SPECULARTERM) {
                 this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);

+ 3 - 1
materialsLibrary/materials/water/water.fragment.fx

@@ -118,11 +118,13 @@ void main(void) {
 	vec3 diffuseBase = vec3(0., 0., 0.);
     lightingInfo info;
 	float shadow = 1.;
-    float glossiness = 0.;
     
 #ifdef SPECULARTERM
+	float glossiness = vSpecularColor.a;
 	vec3 specularBase = vec3(0., 0., 0.);
     vec3 specularColor = vSpecularColor.rgb;
+#else
+	float glossiness = 0.;
 #endif
     
 #include<lightFragment>[0..maxSimultaneousLights]