Browse Source

Adding `StandardMaterial.linkEmissiveWithDiffuse` to, well, link emissive with diffuse value

David catuhe 9 years ago
parent
commit
4a7b142a1e

File diff suppressed because it is too large
+ 8 - 8
dist/preview release/babylon.core.js


File diff suppressed because it is too large
+ 585 - 584
dist/preview release/babylon.d.ts


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


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


File diff suppressed because it is too large
+ 14 - 14
dist/preview release/babylon.noworker.js


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

@@ -11,6 +11,7 @@
     - New `Mesh.CreatePolygon()` method ([jerome](https://github.com/jbousquie))
     - New `Mesh.CreatePolygon()` method ([jerome](https://github.com/jbousquie))
     - Introducing [babylon.core.js](http://doc.babylonjs.com/generals/Framework_versions) ([deltakosh](https://github.com/deltakosh))
     - Introducing [babylon.core.js](http://doc.babylonjs.com/generals/Framework_versions) ([deltakosh](https://github.com/deltakosh))
   - **Updates**
   - **Updates**
+    - Adding `StandardMaterial.linkEmissiveWithDiffuse` to, well, link emissive with diffuse value. (With)[http://www.babylonjs-playground.com/#2FPUCS#2] and (without)[http://www.babylonjs-playground.com/#2FPUCS#1] ([deltakosh](https://github.com/deltakosh))
     - Adding support for equi-rectangular mapping. See [demo here](http://www.babylonjs-playground.com/#27FN5R#8) ([deltakosh](https://github.com/deltakosh))
     - Adding support for equi-rectangular mapping. See [demo here](http://www.babylonjs-playground.com/#27FN5R#8) ([deltakosh](https://github.com/deltakosh))
     - Sprites and particles scheduler updated to be resolved before transparent objects ([deltakosh](https://github.com/deltakosh))
     - Sprites and particles scheduler updated to be resolved before transparent objects ([deltakosh](https://github.com/deltakosh))
     - Added `DirectionalLight.autoUpdateExtends` to prevent directional lights to adapt to scene extends ([deltakosh](https://github.com/deltakosh))
     - Added `DirectionalLight.autoUpdateExtends` to prevent directional lights to adapt to scene extends ([deltakosh](https://github.com/deltakosh))

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

@@ -87,6 +87,7 @@ var BABYLON;
             this.GLOSSINESS = false;
             this.GLOSSINESS = false;
             this.ROUGHNESS = false;
             this.ROUGHNESS = false;
             this.EMISSIVEASILLUMINATION = false;
             this.EMISSIVEASILLUMINATION = false;
+            this.LINKEMISSIVEWITHDIFFUSE = false;
             this.REFLECTIONFRESNELFROMSPECULAR = false;
             this.REFLECTIONFRESNELFROMSPECULAR = false;
             this.LIGHTMAP = false;
             this.LIGHTMAP = false;
             this.USELIGHTMAPASSHADOWMAP = false;
             this.USELIGHTMAPASSHADOWMAP = false;
@@ -115,6 +116,7 @@ var BABYLON;
             this.emissiveColor = new BABYLON.Color3(0, 0, 0);
             this.emissiveColor = new BABYLON.Color3(0, 0, 0);
             this.useAlphaFromDiffuseTexture = false;
             this.useAlphaFromDiffuseTexture = false;
             this.useEmissiveAsIllumination = false;
             this.useEmissiveAsIllumination = false;
+            this.linkEmissiveWithDiffuse = false;
             this.useReflectionFresnelFromSpecular = false;
             this.useReflectionFresnelFromSpecular = false;
             this.useSpecularOverAlpha = true;
             this.useSpecularOverAlpha = true;
             this.disableLighting = false;
             this.disableLighting = false;
@@ -304,6 +306,9 @@ var BABYLON;
             if (this.useEmissiveAsIllumination) {
             if (this.useEmissiveAsIllumination) {
                 this._defines.EMISSIVEASILLUMINATION = true;
                 this._defines.EMISSIVEASILLUMINATION = true;
             }
             }
+            if (this.linkEmissiveWithDiffuse) {
+                this._defines.LINKEMISSIVEWITHDIFFUSE = true;
+            }
             if (this.useReflectionFresnelFromSpecular) {
             if (this.useReflectionFresnelFromSpecular) {
                 this._defines.REFLECTIONFRESNELFROMSPECULAR = true;
                 this._defines.REFLECTIONFRESNELFROMSPECULAR = true;
             }
             }
@@ -646,22 +651,16 @@ var BABYLON;
                 }
                 }
                 // Colors
                 // Colors
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
-                // Scaling down color according to emissive
-                this._scaledSpecular.r = this.specularColor.r * BABYLON.Tools.Clamp(1.0 - this.emissiveColor.r);
-                this._scaledSpecular.g = this.specularColor.g * BABYLON.Tools.Clamp(1.0 - this.emissiveColor.g);
-                this._scaledSpecular.b = this.specularColor.b * BABYLON.Tools.Clamp(1.0 - this.emissiveColor.b);
                 this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
                 this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
                 this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 if (this._defines.SPECULARTERM) {
                 if (this._defines.SPECULARTERM) {
-                    this._effect.setColor4("vSpecularColor", this._scaledSpecular, this.specularPower);
+                    this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
                 }
                 }
                 this._effect.setColor3("vEmissiveColor", this.emissiveColor);
                 this._effect.setColor3("vEmissiveColor", this.emissiveColor);
             }
             }
-            // Scaling down color according to emissive
-            this._scaledDiffuse.r = this.diffuseColor.r * BABYLON.Tools.Clamp(1.0 - this.emissiveColor.r);
-            this._scaledDiffuse.g = this.diffuseColor.g * BABYLON.Tools.Clamp(1.0 - this.emissiveColor.g);
-            this._scaledDiffuse.b = this.diffuseColor.b * BABYLON.Tools.Clamp(1.0 - this.emissiveColor.b);
-            this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
+            // Diffuse
+            this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
+            // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
             if (scene.lightsEnabled && !this.disableLighting) {
                 var lightIndex = 0;
                 var lightIndex = 0;
                 for (var index = 0; index < scene.lights.length; index++) {
                 for (var index = 0; index < scene.lights.length; index++) {

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

@@ -79,6 +79,7 @@
         public GLOSSINESS = false;
         public GLOSSINESS = false;
         public ROUGHNESS = false;
         public ROUGHNESS = false;
         public EMISSIVEASILLUMINATION = false;
         public EMISSIVEASILLUMINATION = false;
+        public LINKEMISSIVEWITHDIFFUSE = false;
         public REFLECTIONFRESNELFROMSPECULAR = false;
         public REFLECTIONFRESNELFROMSPECULAR = false;
         public LIGHTMAP = false;
         public LIGHTMAP = false;
         public USELIGHTMAPASSHADOWMAP = false;
         public USELIGHTMAPASSHADOWMAP = false;
@@ -115,6 +116,7 @@
         public emissiveColor = new Color3(0, 0, 0);
         public emissiveColor = new Color3(0, 0, 0);
         public useAlphaFromDiffuseTexture = false;
         public useAlphaFromDiffuseTexture = false;
         public useEmissiveAsIllumination = false;
         public useEmissiveAsIllumination = false;
+        public linkEmissiveWithDiffuse = false;
         public useReflectionFresnelFromSpecular = false;
         public useReflectionFresnelFromSpecular = false;
         public useSpecularOverAlpha = true;
         public useSpecularOverAlpha = true;
         public disableLighting = false;
         public disableLighting = false;
@@ -345,6 +347,10 @@
                 this._defines.EMISSIVEASILLUMINATION = true;
                 this._defines.EMISSIVEASILLUMINATION = true;
             }
             }
 
 
+            if (this.linkEmissiveWithDiffuse) {
+                this._defines.LINKEMISSIVEWITHDIFFUSE = true;
+            }
+
             if (this.useReflectionFresnelFromSpecular) {
             if (this.useReflectionFresnelFromSpecular) {
                 this._defines.REFLECTIONFRESNELFROMSPECULAR = true;
                 this._defines.REFLECTIONFRESNELFROMSPECULAR = true;
             }
             }
@@ -780,27 +786,19 @@
                 // Colors
                 // Colors
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
 
 
-                // Scaling down color according to emissive
-                this._scaledSpecular.r = this.specularColor.r * Tools.Clamp(1.0 - this.emissiveColor.r);
-                this._scaledSpecular.g = this.specularColor.g * Tools.Clamp(1.0 - this.emissiveColor.g);
-                this._scaledSpecular.b = this.specularColor.b * Tools.Clamp(1.0 - this.emissiveColor.b);
-
                 this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
                 this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
                 this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
 
 
                 if (this._defines.SPECULARTERM) {
                 if (this._defines.SPECULARTERM) {
-                    this._effect.setColor4("vSpecularColor", this._scaledSpecular, this.specularPower);
+                    this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
                 }
                 }
                 this._effect.setColor3("vEmissiveColor", this.emissiveColor);
                 this._effect.setColor3("vEmissiveColor", this.emissiveColor);
             }
             }
+            
+            // Diffuse
+            this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
 
 
-            // Scaling down color according to emissive
-            this._scaledDiffuse.r = this.diffuseColor.r * Tools.Clamp(1.0 - this.emissiveColor.r);
-            this._scaledDiffuse.g = this.diffuseColor.g * Tools.Clamp(1.0 - this.emissiveColor.g);
-            this._scaledDiffuse.b = this.diffuseColor.b * Tools.Clamp(1.0 - this.emissiveColor.b);
-
-            this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
-
+            // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
             if (scene.lightsEnabled && !this.disableLighting) {
                 var lightIndex = 0;
                 var lightIndex = 0;
                 for (var index = 0; index < scene.lights.length; index++) {
                 for (var index = 0; index < scene.lights.length; index++) {

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

@@ -819,8 +819,12 @@ void main(void) {
 #ifdef EMISSIVEASILLUMINATION
 #ifdef EMISSIVEASILLUMINATION
 	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
 	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
 #else
 #else
+	#ifdef LINKEMISSIVEWITHDIFFUSE
+	vec3 finalDiffuse = clamp((diffuseBase + emissiveColor) * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
+	#else
 	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
 	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
 #endif
 #endif
+#endif
 
 
 #ifdef SPECULARTERM
 #ifdef SPECULARTERM
 	vec3 finalSpecular = specularBase * specularColor;
 	vec3 finalSpecular = specularBase * specularColor;