Pārlūkot izejas kodu

converting shader WIP

Benjamin Guignabert 8 gadi atpakaļ
vecāks
revīzija
3ea383d68b

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1674 - 1671
dist/preview release/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1674 - 1671
dist/preview release/babylon.module.d.ts


+ 8 - 4
index.html

@@ -58,17 +58,21 @@
 						var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
 
 						// Move the sphere upward 1/2 its height
-						// sphere.position.y = 1+i / 500;
+						sphere.position.y = 1+ 2*i;
 						sphere.material = new BABYLON.StandardMaterial("test");
 						sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
-						// window.sphere = sphere;
+						window.sphere = sphere;
 						// sphere.material.diffuseTexture = new BABYLON.Texture("test.jpeg", scene);
 						var t = 0;
 							sphere.material.freeze();
 						scene.registerAfterRender(function() {
-							// sphere.material.specularColor = new BABYLON.Color3(0, 0, Math.sin(t/100));
-							// sphere.material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/50)));
+							sphere.material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/50)));
 							t++;
+							if (t % 120 < 60) {
+								sphere.material.freeze();
+							} else {
+								sphere.material.unfreeze();
+							}
 						})
 					}
 

+ 114 - 73
src/Materials/babylon.standardMaterial.ts

@@ -731,17 +731,41 @@ module BABYLON {
 
         public buildUniformLayout(): void {
             // Order is important !
-            this._uniformBuffer.addUniform("vDiffuseColor", 4);
+            this._uniformBuffer.addUniform("diffuseLeftColor", 4);
+            this._uniformBuffer.addUniform("diffuseRightColor", 4);
+            this._uniformBuffer.addUniform("opacityParts", 4);
+            this._uniformBuffer.addUniform("reflectionLeftColor", 4);
+            this._uniformBuffer.addUniform("reflectionRightColor", 4);
+            this._uniformBuffer.addUniform("refractionLeftColor", 4);
+            this._uniformBuffer.addUniform("refractionRightColor", 4);
+            this._uniformBuffer.addUniform("emissiveLeftColor", 4);
+            this._uniformBuffer.addUniform("emissiveRightColor", 4);
 
             this._uniformBuffer.addUniform("vDiffuseInfos", 2);
-            this._uniformBuffer.addUniform("diffuseMatrix", 16);
-
-            this._uniformBuffer.addUniform("vAmbientColor", 3);
+            this._uniformBuffer.addUniform("vAmbientInfos", 2);
+            this._uniformBuffer.addUniform("vOpacityInfos", 2);
+            this._uniformBuffer.addUniform("vReflectionInfos", 2);
+            this._uniformBuffer.addUniform("vEmissiveInfos", 2);
+            this._uniformBuffer.addUniform("vLightmapInfos", 2);
+            this._uniformBuffer.addUniform("vSpecularInfos", 2);
+            this._uniformBuffer.addUniform("vBumpInfos", 3);
 
+            this._uniformBuffer.addUniform("diffuseMatrix", 16);
+            this._uniformBuffer.addUniform("ambientMatrix", 16);
+            this._uniformBuffer.addUniform("opacityMatrix", 16);
+            this._uniformBuffer.addUniform("reflectionMatrix", 16);
+            this._uniformBuffer.addUniform("emissiveMatrix", 16);
+            this._uniformBuffer.addUniform("lightmapMatrix", 16);
+            this._uniformBuffer.addUniform("specularMatrix", 16);
+            this._uniformBuffer.addUniform("bumpMatrix", 16);
+
+            this._uniformBuffer.addUniform("refractionMatrix", 16);
+            this._uniformBuffer.addUniform("vRefractionInfos", 4);
+            this._uniformBuffer.addUniform("pointSize", 1);
 
             this._uniformBuffer.addUniform("vSpecularColor", 3);
-
             this._uniformBuffer.addUniform("vEmissiveColor", 3);
+            this._uniformBuffer.addUniform("vDiffuseColor", 4);
 
         }
 
@@ -767,7 +791,7 @@ module BABYLON {
             // Matrices        
             this.bindOnlyWorldMatrix(world);
 
-            // Bonesf
+            // Bones
             MaterialHelper.BindBonesParameters(mesh, this._effect);
             
             if (!this.isFrozen || !this._uniformBuffer.isSync) {
@@ -775,53 +799,117 @@ module BABYLON {
                 if (StandardMaterial.FresnelEnabled) {
                     // Fresnel
                     if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
-                        this._effect.setColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
-                        this._effect.setColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
+                        this._uniformBuffer.updateColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
+                        this._uniformBuffer.updateColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
                     }
 
                     if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
-                        this._effect.setColor4("opacityParts", new Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
+                        this._uniformBuffer.updateColor4("opacityParts", new Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
                     }
 
                     if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
-                        this._effect.setColor4("reflectionLeftColor", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);
-                        this._effect.setColor4("reflectionRightColor", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);
+                        this._uniformBuffer.updateColor4("reflectionLeftColor", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);
+                        this._uniformBuffer.updateColor4("reflectionRightColor", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);
                     }
 
                     if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {
-                        this._effect.setColor4("refractionLeftColor", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);
-                        this._effect.setColor4("refractionRightColor", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);
+                        this._uniformBuffer.updateColor4("refractionLeftColor", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);
+                        this._uniformBuffer.updateColor4("refractionRightColor", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);
                     }
 
                     if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
-                        this._effect.setColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
-                        this._effect.setColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
+                        this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
+                        this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
                     }
                 }
 
                 // Textures     
                 if (scene.texturesEnabled) {
                     if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
-                        this._effect.setTexture("diffuseSampler", this.diffuseTexture);
-
-                        // this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
                         this._uniformBuffer.updateFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
-                        // this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
                         this._uniformBuffer.updateMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
                     }
 
                     if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
-                        this._effect.setTexture("ambientSampler", this.ambientTexture);
+                        this._uniformBuffer.updateFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
+                        this._uniformBuffer.updateMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
+                    }
+
+                    if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
+                        this._uniformBuffer.updateFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
+                        this._uniformBuffer.updateMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
+                    }
+
+                    if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                        this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
+                        this._uniformBuffer.updateMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
+                    }
+
+                    if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
+                        this._uniformBuffer.updateFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
+                        this._uniformBuffer.updateMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
+                    }
+
+                    if (this.lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
+                        this._uniformBuffer.updateFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
+                        this._uniformBuffer.updateMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
+                    }
+
+                    if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
+                        this._uniformBuffer.updateFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
+                        this._uniformBuffer.updateMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
+                    }
+
+                    if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
+                        this._uniformBuffer.updateFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
+                        this._uniformBuffer.updateMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
+                    }
+
+                    if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
+                        var depth = 1.0;
+                        if (!this.refractionTexture.isCube) {
+                            this._uniformBuffer.updateMatrix("refractionMatrix", this.refractionTexture.getReflectionTextureMatrix());
+
+                            if ((<any>this.refractionTexture).depth) {
+                                depth = (<any>this.refractionTexture).depth;
+                            }
+                        }
+                        this._uniformBuffer.updateFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
+                    }                    
+                }
+
+                // Point size
+                if (this.pointsCloud) {
+                    this._uniformBuffer.updateFloat("pointSize", this.pointSize);
+                }
+
+                if (this._defines.SPECULARTERM) {
+                    this._uniformBuffer.updateColor4("vSpecularColor", this.specularColor, this.specularPower);
+                }
+                this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
+
+                // Diffuse
+                this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
+            }
+            this._uniformBuffer.update();
+            
+            if (scene.getCachedMaterial() !== this) {
+                this._effect.bindUniformBuffer(this._uniformBuffer.getBuffer());
+
+                this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
+
+                // Textures     
+                if (scene.texturesEnabled) {
+                    if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
+                        this._effect.setTexture("diffuseSampler", this.diffuseTexture);
+                    }
 
-                        this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
-                        this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
+                    if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
+                        this._effect.setTexture("ambientSampler", this.ambientTexture);
                     }
 
                     if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
                         this._effect.setTexture("opacitySampler", this.opacityTexture);
-
-                        this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
-                        this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
                     }
 
                     if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
@@ -830,37 +918,22 @@ module BABYLON {
                         } else {
                             this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
                         }
-
-                        this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
-                        this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
                     }
 
                     if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
                         this._effect.setTexture("emissiveSampler", this.emissiveTexture);
-
-                        this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
-                        this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
                     }
 
                     if (this.lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
                         this._effect.setTexture("lightmapSampler", this.lightmapTexture);
-
-                        this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
-                        this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
                     }
 
                     if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
                         this._effect.setTexture("specularSampler", this.specularTexture);
-
-                        this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
-                        this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
                     }
 
                     if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
                         this._effect.setTexture("bumpSampler", this.bumpTexture);
-
-                        this._effect.setFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
-                        this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                     }
 
                     if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
@@ -869,13 +942,7 @@ module BABYLON {
                             this._effect.setTexture("refractionCubeSampler", this.refractionTexture);
                         } else {
                             this._effect.setTexture("refraction2DSampler", this.refractionTexture);
-                            this._effect.setMatrix("refractionMatrix", this.refractionTexture.getReflectionTextureMatrix());
-
-                            if ((<any>this.refractionTexture).depth) {
-                                depth = (<any>this.refractionTexture).depth;
-                            }
                         }
-                        this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
                     }
                     
                     if (this.cameraColorGradingTexture && StandardMaterial.ColorGradingTextureEnabled) {
@@ -886,30 +953,11 @@ module BABYLON {
                 // Clip plane
                 MaterialHelper.BindClipPlane(this._effect, scene);
 
-                // Point size
-                if (this.pointsCloud) {
-                    this._effect.setFloat("pointSize", this.pointSize);
-                }
-
                 // Colors
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
 
                 this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
-                // this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
-                this._uniformBuffer.updateColor3("vAmbientColor", this._globalAmbientColor);
-
-                if (this._defines.SPECULARTERM) {
-                    // this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
-                    this._uniformBuffer.updateColor4("vSpecularColor", this.specularColor, this.specularPower);
-                }
-                // this._effect.setColor3("vEmissiveColor", this.emissiveColor);
-                this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
-
-                // TODO : this depends on mesh
-
-                // Diffuse
-                // this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
-                this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
+                this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
 
                 // Lights
                 if (scene.lightsEnabled && !this.disableLighting) {
@@ -933,13 +981,6 @@ module BABYLON {
                 }
 
             }
-            this._uniformBuffer.update();
-            
-            if (scene.getCachedMaterial() !== this) {
-                this._effect.bindUniformBuffer(this._uniformBuffer.getBuffer());
-
-                this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
-            }
 
             super.bind(world, mesh);
         }

+ 17 - 1
src/Materials/babylon.uniformBuffer.ts

@@ -25,7 +25,7 @@ module BABYLON {
         }
 
         public get isSync(): boolean {
-            return this._needSync;
+            return !this._needSync;
         }
 
         // Properties
@@ -174,10 +174,26 @@ module BABYLON {
             this._needSync = this._needSync || changed;
         }
 
+        public updateFloat(name: string, x: number) {
+            var temp = [x];
+            this.updateUniform(name, temp);
+        }
+
         public updateFloat2(name: string, x: number, y: number) {
             var temp = [x, y];
             this.updateUniform(name, temp);
         }
+
+        public updateFloat3(name: string, x: number, y: number, z: number) {
+            var temp = [x, y, z];
+            this.updateUniform(name, temp);
+        }
+
+        public updateFloat4(name: string, x: number, y: number, z: number, w: number) {
+            var temp = [x, y, z, w];
+            this.updateUniform(name, temp);
+        }
+
         public updateMatrix(name: string, mat: Matrix) {
             this.updateUniform(name, mat.toArray());
         }

+ 52 - 65
src/Shaders/default.fragment.fx

@@ -1,22 +1,39 @@
 layout(std140, column_major) uniform;
 
-struct Camera {
-	vec3 vEyePosition;
-};
-
 uniform Material
 {
+	vec4 diffuseLeftColor;
+	vec4 diffuseRightColor;
+	vec4 opacityParts;
+	vec4 reflectionLeftColor;
+	vec4 reflectionRightColor;
+	vec4 refractionLeftColor;
+	vec4 refractionRightColor;
+	vec4 emissiveLeftColor;
+	vec4 emissiveRightColor;
+	vec2 vDiffuseInfos;
+	vec2 vAmbientInfos;
+	vec2 vOpacityInfos;
+	vec2 vReflectionInfos;
+	vec2 vEmissiveInfos;
+	vec2 vLightmapInfos;
+	vec2 vSpecularInfos;
+	
+	vec3 vBumpInfos;
+	mat4 diffuseMatrix;
+	mat4 ambientMatrix;
+	mat4 opacityMatrix;
+	mat4 reflectionMatrix;
+	mat4 emissiveMatrix;
+	mat4 lightmapMatrix;
+	mat4 specularMatrix;
+	mat4 bumpMatrix;
+	mat4 refractionMatrix;
+	vec4 vRefractionInfos;
+	float pointSize;
+	vec3 vSpecularColor;
+	vec3 vEmissiveColor;
 	vec4 vDiffuseColor;
-
-  	vec2 vDiffuseInfos;
-  	mat4 diffuseMatrix;
-
-  	vec3 vAmbientColor;
-
-  	vec4 vSpecularColor;
-
-  	vec3 vEmissiveColor;
-
 } uMaterial;
 
 uniform vec3 vEyePosition;
@@ -61,24 +78,20 @@ uniform sampler2D diffuseSampler;
 #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 EMISSIVE
 varying vec2 vEmissiveUV;
-uniform vec2 vEmissiveInfos;
 uniform sampler2D emissiveSampler;
 #endif
 
 #ifdef LIGHTMAP
 varying vec2 vLightmapUV;
-uniform vec2 vLightmapInfos;
 uniform sampler2D lightmapSampler;
 #endif
 
@@ -96,39 +109,18 @@ uniform sampler2D refraction2DSampler;
 uniform mat4 refractionMatrix;
 #endif
 
-#ifdef REFRACTIONFRESNEL
-uniform vec4 refractionLeftColor;
-uniform vec4 refractionRightColor;
-#endif
 #endif
 
 #if defined(SPECULAR) && defined(SPECULARTERM)
 varying vec2 vSpecularUV;
-uniform vec2 vSpecularInfos;
 uniform sampler2D specularSampler;
 #endif
 
 // Fresnel
 #include<fresnelFunction>
 
-#ifdef DIFFUSEFRESNEL
-uniform vec4 diffuseLeftColor;
-uniform vec4 diffuseRightColor;
-#endif
-
-#ifdef OPACITYFRESNEL
-uniform vec4 opacityParts;
-#endif
-
-#ifdef EMISSIVEFRESNEL
-uniform vec4 emissiveLeftColor;
-uniform vec4 emissiveRightColor;
-#endif
-
 // Reflection
 #ifdef REFLECTION
-uniform vec2 vReflectionInfos;
-
 #ifdef REFLECTIONMAP_3D
 uniform samplerCube reflectionCubeSampler;
 #else
@@ -149,11 +141,6 @@ uniform mat4 reflectionMatrix;
 
 #include<reflectionFunction>
 
-#ifdef REFLECTIONFRESNEL
-uniform vec4 reflectionLeftColor;
-uniform vec4 reflectionRightColor;
-#endif
-
 #endif
 
 #ifdef CAMERACOLORGRADING
@@ -219,7 +206,7 @@ void main(void) {
 	vec3 baseAmbientColor = vec3(1., 1., 1.);
 
 #ifdef AMBIENT
-	baseAmbientColor = texture2D(ambientSampler, vAmbientUV + uvOffset).rgb * vAmbientInfos.y;
+	baseAmbientColor = texture2D(ambientSampler, vAmbientUV + uvOffset).rgb * uMaterial.vAmbientInfos.y;
 #endif
 
 	// Specular map
@@ -247,7 +234,7 @@ void main(void) {
 	float shadow = 1.;
 
 #ifdef LIGHTMAP
-	vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset).rgb * vLightmapInfos.y;
+	vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset).rgb * uMaterial.vLightmapInfos.y;
 #endif
 
 #include<lightFragment>[0..maxSimultaneousLights]
@@ -284,7 +271,7 @@ void main(void) {
 
 #ifdef REFLECTIONMAP_3D
 #ifdef ROUGHNESS
-	float bias = vReflectionInfos.y;
+	float bias = uMaterial.vReflectionInfos.y;
 
 #ifdef SPECULARTERM
 	#ifdef SPECULAR
@@ -294,9 +281,9 @@ void main(void) {
 	#endif
 #endif
 
-	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x;
+	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * uMaterial.vReflectionInfos.x;
 #else
-	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.x;
+	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * uMaterial.vReflectionInfos.x;
 #endif
 
 #else
@@ -308,28 +295,28 @@ void main(void) {
 
 	coords.y = 1.0 - coords.y;
 
-	reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x;
+	reflectionColor = texture2D(reflection2DSampler, coords).rgb * uMaterial.vReflectionInfos.x;
 #endif
 
 #ifdef REFLECTIONFRESNEL
-	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);
+	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, uMaterial.reflectionRightColor.a, uMaterial.reflectionLeftColor.a);
 
 #ifdef REFLECTIONFRESNELFROMSPECULAR
 #ifdef SPECULARTERM
-	reflectionColor *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+	reflectionColor *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * uMaterial.reflectionRightColor.rgb;
 #else
-	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+	reflectionColor *= uMaterial.reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * uMaterial.reflectionRightColor.rgb;
 #endif
 #else
-	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+	reflectionColor *= uMaterial.reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * uMaterial.reflectionRightColor.rgb;
 #endif
 #endif
 #endif
 
 #ifdef REFRACTIONFRESNEL
-	float refractionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, refractionRightColor.a, refractionLeftColor.a);
+	float refractionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, uMaterial.refractionRightColor.a, uMaterial.refractionLeftColor.a);
 
-	refractionColor *= refractionLeftColor.rgb * (1.0 - refractionFresnelTerm) + refractionFresnelTerm * refractionRightColor.rgb;
+	refractionColor *= uMaterial.refractionLeftColor.rgb * (1.0 - refractionFresnelTerm) + refractionFresnelTerm * uMaterial.refractionRightColor.rgb;
 #endif
 
 #ifdef OPACITY
@@ -337,9 +324,9 @@ void main(void) {
 
 #ifdef OPACITYRGB
 	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
-	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;
+	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* uMaterial.vOpacityInfos.y;
 #else
-	alpha *= opacityMap.a * vOpacityInfos.y;
+	alpha *= opacityMap.a * uMaterial.vOpacityInfos.y;
 #endif
 
 #endif
@@ -349,28 +336,28 @@ void main(void) {
 #endif
 
 #ifdef OPACITYFRESNEL
-	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);
+	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, uMaterial.opacityParts.z, uMaterial.opacityParts.w);
 
-	alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;
+	alpha += uMaterial.opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * uMaterial.opacityParts.y;
 #endif
 
 	// Emissive
 	vec3 emissiveColor = uMaterial.vEmissiveColor;
 #ifdef EMISSIVE
-	emissiveColor += texture2D(emissiveSampler, vEmissiveUV + uvOffset).rgb * vEmissiveInfos.y;
+	emissiveColor += texture2D(emissiveSampler, vEmissiveUV + uvOffset).rgb * uMaterial.vEmissiveInfos.y;
 #endif
 
 #ifdef EMISSIVEFRESNEL
-	float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);
+	float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, uMaterial.emissiveRightColor.a, uMaterial.emissiveLeftColor.a);
 
-	emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;
+	emissiveColor *= uMaterial.emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * uMaterial.emissiveRightColor.rgb;
 #endif
 
 	// Fresnel
 #ifdef DIFFUSEFRESNEL
-	float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);
+	float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, uMaterial.diffuseRightColor.a, uMaterial.diffuseLeftColor.a);
 
-	diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;
+	diffuseBase *= uMaterial.diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * uMaterial.diffuseRightColor.rgb;
 #endif
 
 	// Composition

+ 0 - 4
src/Shaders/default.vertex.fx

@@ -1,9 +1,5 @@
 layout(std140, column_major) uniform;
 
-struct Camera {
-	vec3 vEyePosition;
-};
-
 uniform Material
 {
 	vec4 vDiffuseColor;