Browse Source

Adding support for StandardMaterial.roughness

David catuhe 10 years ago
parent
commit
cbed4b10c8

File diff suppressed because it is too large
+ 553 - 552
dist/preview release - beta/babylon.2.2.d.ts


File diff suppressed because it is too large
+ 17 - 13
dist/preview release - beta/babylon.2.2.js


File diff suppressed because it is too large
+ 11 - 2
dist/preview release - beta/babylon.2.2.max.js


File diff suppressed because it is too large
+ 17 - 13
dist/preview release - beta/babylon.2.2.noworker.js


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

@@ -9,6 +9,7 @@
     - OBJ loader. See [demo here](http://www.babylonjs-playground.com/#28YUR5) [Temechon](https://github.com/Temechon)
     - EdgesRenderer. See [demo here](http://www.babylonjs-playground.com/#TYAHX#10) [deltakosh](https://github.com/deltakosh)
   - **Updates**
+    - Added support for StandardMaterial.roughness. See [demo here](http://www.babylonjs-playground.com/#RNBKQ#8) [deltakosh](https://github.com/deltakosh)
     - Compression supported for raw textures [deltakosh](https://github.com/deltakosh)
     - New TonemapPostProcess. See [demo here](http://www.babylonjs-playground.com/#ELTGD) [deltakosh](https://github.com/deltakosh)
     - New options parameters for Box and Sphere. See [demo here](http://www.html5gamedevs.com/topic/17044-evolution-for-out-of-the-box-meshes-creation/) [deltakosh](https://github.com/deltakosh)

+ 10 - 1
src/Materials/babylon.standardMaterial.js

@@ -79,6 +79,7 @@ var BABYLON;
             this.BonesPerMesh = 0;
             this.INSTANCES = false;
             this.GLOSSINESS = false;
+            this.ROUGHNESS = false;
             this._keys = Object.keys(this);
         }
         StandardMaterialDefines.prototype.isEqual = function (other) {
@@ -135,6 +136,7 @@ var BABYLON;
             this.useAlphaFromDiffuseTexture = false;
             this.useSpecularOverAlpha = true;
             this.fogEnabled = true;
+            this.roughness = 0;
             this.useGlossinessFromSpecularMapAlpha = false;
             this._renderTargets = new BABYLON.SmartArray(16);
             this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
@@ -221,6 +223,9 @@ var BABYLON;
                         needNormals = true;
                         needUVs = true;
                         this._defines.REFLECTION = true;
+                        if (this.roughness > 0) {
+                            this._defines.ROUGHNESS = true;
+                        }
                     }
                 }
                 if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
@@ -489,7 +494,8 @@ var BABYLON;
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix",
                     "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
-                    "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor"
+                    "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor",
+                    "roughness"
                 ], ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler",
                     "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
                 ], join, fallbacks, this.onCompiled, this.onError);
@@ -557,6 +563,9 @@ var BABYLON;
                 if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
                     if (this.reflectionTexture.isCube) {
                         this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                        if (this._defines.ROUGHNESS) {
+                            this._effect.setFloat("roughness", this.roughness);
+                        }
                     }
                     else {
                         this._effect.setTexture("reflection2DSampler", this.reflectionTexture);

+ 13 - 2
src/Materials/babylon.standardMaterial.ts

@@ -69,6 +69,7 @@
         public BonesPerMesh = 0;
         public INSTANCES = false;
         public GLOSSINESS = false;
+        public ROUGHNESS = false;
 
         _keys: string[];
 
@@ -144,7 +145,9 @@
         public emissiveColor = new Color3(0, 0, 0);
         public useAlphaFromDiffuseTexture = false;
         public useSpecularOverAlpha = true;
-		public fogEnabled = true;
+        public fogEnabled = true;
+
+        public roughness = 0;
 
         public diffuseFresnelParameters: FresnelParameters;
         public opacityFresnelParameters: FresnelParameters;
@@ -257,6 +260,10 @@
                         needNormals = true;
                         needUVs = true;
                         this._defines.REFLECTION = true;
+
+                        if (this.roughness > 0) {
+                            this._defines.ROUGHNESS = true;
+                        }
                     }
                 }
 
@@ -584,7 +591,8 @@
                         "mBones",
                         "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix",
                         "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
-                        "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor"
+                        "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor",
+                        "roughness"
                     ],
                     ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler",
                         "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
@@ -674,6 +682,9 @@
                 if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
                     if (this.reflectionTexture.isCube) {
                         this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                        if (this._defines.ROUGHNESS) {
+                            this._effect.setFloat("roughness", this.roughness);
+                        }
                     } else {
                         this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
                     }

+ 19 - 1
src/Shaders/default.fragment.fx

@@ -174,6 +174,10 @@ uniform vec3 vReflectionInfos;
 uniform mat4 reflectionMatrix;
 uniform mat4 view;
 
+#ifdef ROUGHNESS
+uniform float roughness;
+#endif
+
 vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
 {
 	if (mode == MAP_SPHERICAL)
@@ -697,7 +701,21 @@ void main(void) {
 
 	if (vReflectionInfos.z != 0.0)
 	{
-		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y * shadow;
+		float bias = 0.;
+
+#ifdef ROUGHNESS
+		bias = roughness;
+#endif
+
+#ifdef SPECULARTERM
+#ifdef SPECULAR
+#ifdef GLOSSINESS
+		bias *= (1.0 - specularMapColor.a);
+#endif
+#endif
+#endif
+
+		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.y * shadow;
 	}
 	else
 	{