Prechádzať zdrojové kódy

Adding emissiveAsIllumination and reflectionFresnelFromSpecular for StandardMaterial
Adding isEnabled for ProceduralTexture

David catuhe 10 rokov pred
rodič
commit
42d06125d5

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 519 - 516
dist/preview release - beta/babylon.2.2.d.ts


Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 24 - 23
dist/preview release - beta/babylon.2.2.js


Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 17 - 3
dist/preview release - beta/babylon.2.2.max.js


Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 18 - 17
dist/preview release - beta/babylon.2.2.noworker.js


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

@@ -10,6 +10,8 @@
     - 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**
+    - Adding emissiveAsIllumination and reflectionFresnelFromSpecular for StandardMaterial [deltakosh](https://github.com/deltakosh)
+    - Adding isEnabled for ProceduralTexture [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, Sphere, Plane and Ground. See [demo here](http://www.html5gamedevs.com/topic/17044-evolution-for-out-of-the-box-meshes-creation/) [deltakosh](https://github.com/deltakosh)

+ 2 - 0
src/Loading/Plugins/babylon.babylonFileLoader.js

@@ -109,6 +109,8 @@ var BABYLON;
             material.specularColor = BABYLON.Color3.FromArray(parsedMaterial.specular);
             material.specularPower = parsedMaterial.specularPower;
             material.emissiveColor = BABYLON.Color3.FromArray(parsedMaterial.emissive);
+            material.useReflectionFresnelFromSpecular = parsedMaterial.useReflectionFresnelFromSpecular;
+            material.useEmissiveAsIllumination = parsedMaterial.useEmissiveAsIllumination;
             material.alpha = parsedMaterial.alpha;
             material.id = parsedMaterial.id;
             if (parsedMaterial.disableDepthWrite) {

+ 2 - 0
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -128,6 +128,8 @@
         material.specularColor = BABYLON.Color3.FromArray(parsedMaterial.specular);
         material.specularPower = parsedMaterial.specularPower;
         material.emissiveColor = BABYLON.Color3.FromArray(parsedMaterial.emissive);
+        material.useReflectionFresnelFromSpecular = parsedMaterial.useReflectionFresnelFromSpecular;
+        material.useEmissiveAsIllumination = parsedMaterial.useEmissiveAsIllumination;
 
         material.alpha = parsedMaterial.alpha;
 

+ 2 - 1
src/Materials/Textures/Procedurals/babylon.proceduralTexture.js

@@ -11,6 +11,7 @@ var BABYLON;
         function ProceduralTexture(name, size, fragment, scene, fallbackTexture, generateMipMaps) {
             if (generateMipMaps === void 0) { generateMipMaps = true; }
             _super.call(this, null, scene, !generateMipMaps);
+            this.isEnabled = true;
             this._currentRefreshId = -1;
             this._refreshRate = 1;
             this._vertexDeclaration = [2];
@@ -103,7 +104,7 @@ var BABYLON;
             configurable: true
         });
         ProceduralTexture.prototype._shouldRender = function () {
-            if (!this.isReady() || !this._texture) {
+            if (!this.isEnabled || !this.isReady() || !this._texture) {
                 return false;
             }
             if (this._fallbackTextureUsed) {

+ 2 - 1
src/Materials/Textures/Procedurals/babylon.proceduralTexture.ts

@@ -2,6 +2,7 @@
     export class ProceduralTexture extends Texture {
         private _size: number;
         public _generateMipMaps: boolean;
+        public isEnabled = true;
         private _doNotChangeAspectRatio: boolean;
         private _currentRefreshId = -1;
         private _refreshRate = 1;
@@ -133,7 +134,7 @@
         }
 
         public _shouldRender(): boolean {
-            if (!this.isReady() || !this._texture) {
+            if (!this.isEnabled || !this.isReady() || !this._texture) {
                 return false;
             }
 

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

@@ -80,6 +80,8 @@ var BABYLON;
             this.INSTANCES = false;
             this.GLOSSINESS = false;
             this.ROUGHNESS = false;
+            this.EMISSIVEASILLUMINATION = false;
+            this.REFLECTIONFRESNELFROMSPECULAR = false;
             this._keys = Object.keys(this);
         }
         StandardMaterialDefines.prototype.isEqual = function (other) {
@@ -134,6 +136,8 @@ var BABYLON;
             this.specularPower = 64;
             this.emissiveColor = new BABYLON.Color3(0, 0, 0);
             this.useAlphaFromDiffuseTexture = false;
+            this.useEmissiveAsIllumination = false;
+            this.useReflectionFresnelFromSpecular = false;
             this.useSpecularOverAlpha = true;
             this.fogEnabled = true;
             this.roughness = 0;
@@ -267,6 +271,12 @@ var BABYLON;
             if (this._shouldUseAlphaFromDiffuseTexture()) {
                 this._defines.ALPHAFROMDIFFUSE = true;
             }
+            if (this.useEmissiveAsIllumination) {
+                this._defines.EMISSIVEASILLUMINATION = true;
+            }
+            if (this.useReflectionFresnelFromSpecular) {
+                this._defines.REFLECTIONFRESNELFROMSPECULAR = true;
+            }
             // Point size
             if (this.pointsCloud || scene.forcePointsCloud) {
                 this._defines.POINTSIZE = true;

+ 12 - 0
src/Materials/babylon.standardMaterial.ts

@@ -70,6 +70,8 @@
         public INSTANCES = false;
         public GLOSSINESS = false;
         public ROUGHNESS = false;
+        public EMISSIVEASILLUMINATION = false;
+        public REFLECTIONFRESNELFROMSPECULAR = false;
 
         _keys: string[];
 
@@ -144,6 +146,8 @@
         public specularPower = 64;
         public emissiveColor = new Color3(0, 0, 0);
         public useAlphaFromDiffuseTexture = false;
+        public useEmissiveAsIllumination = false;
+        public useReflectionFresnelFromSpecular = false;
         public useSpecularOverAlpha = true;
         public fogEnabled = true;
 
@@ -309,6 +313,14 @@
                 this._defines.ALPHAFROMDIFFUSE = true;
             }
 
+            if (this.useEmissiveAsIllumination) {
+                this._defines.EMISSIVEASILLUMINATION = true;
+            }
+
+            if (this.useReflectionFresnelFromSpecular) {
+                this._defines.REFLECTIONFRESNELFROMSPECULAR = true;
+            }
+
             // Point size
             if (this.pointsCloud || scene.forcePointsCloud) {
                 this._defines.POINTSIZE = true;

+ 0 - 1
src/Mesh/babylon.mesh.js

@@ -1403,7 +1403,6 @@ var BABYLON;
             var lathe = Mesh.ExtrudeShapeCustom(name, shapeLathe, path, scaleFunction, rotateFunction, true, false, Mesh.NO_CAP, scene, updatable, sideOrientation);
             return lathe;
         };
-        // Plane & ground
         Mesh.CreatePlane = function (name, options, scene, updatable, sideOrientation) {
             if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }
             var plane = new Mesh(name, scene);

+ 5 - 1
src/Mesh/babylon.mesh.ts

@@ -1330,6 +1330,7 @@
             return disc;
         }
 
+        public static CreateBox(name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number);
         public static CreateBox(name: string, options: any, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
             // Check parameters
             updatable = updatable || options.updatable;
@@ -1342,6 +1343,7 @@
             return box;
         }
 
+        public static CreateSphere(name: string, segments: number, diameter: number, scene?: Scene, updatable?: boolean, sideOrientation?: number);
         public static CreateSphere(name: string, options: any, diameterOrScene: any, scene?: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
             if (diameterOrScene instanceof Scene) {
                 scene = diameterOrScene;
@@ -1616,6 +1618,7 @@
         }
 
         // Plane & ground
+        public static CreatePlane(name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number);
         public static CreatePlane(name: string, options: any, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
             var plane = new Mesh(name, scene);
 
@@ -1626,7 +1629,8 @@
             return plane;
         }
 
-        public static CreateGround(name: string, options: any, heightOrScene: any, subdivisions: number, scene: Scene, updatable?: boolean): Mesh {
+        public static CreateGround(name: string, width: number, height: number, subdivisions: number, scene: Scene, updatable?: boolean);
+        public static CreateGround(name: string, options: any, heightOrScene: any, subdivisions?: number, scene?: Scene, updatable?: boolean): Mesh {
             if (heightOrScene instanceof Scene) {
                 scene = heightOrScene;
                 updatable = options.updatable;

+ 22 - 3
src/Shaders/default.fragment.fx

@@ -734,9 +734,18 @@ void main(void) {
 #ifdef REFLECTIONFRESNEL
 	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);
 
+#ifdef REFLECTIONFRESNELFROMSPECULAR
+#ifdef SPECULARTERM
+	reflectionColor *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+#else
+	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+#endif
+#else
 	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
 #endif
 #endif
+#endif
+
 
 #ifdef OPACITY
 	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
@@ -763,7 +772,7 @@ void main(void) {
 	// Emissive
 	vec3 emissiveColor = vEmissiveColor;
 #ifdef EMISSIVE
-	emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
+    emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
 #endif
 
 #ifdef EMISSIVEFRESNEL
@@ -780,7 +789,12 @@ void main(void) {
 #endif
 
 	// Composition
-	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
+#ifdef EMISSIVEASILLUMINATION
+	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
+#else
+    vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
+#endif
+
 #ifdef SPECULARTERM
 	vec3 finalSpecular = specularBase * specularColor;
 #else
@@ -791,7 +805,12 @@ void main(void) {
 	alpha = clamp(alpha + dot(finalSpecular, vec3(0.3, 0.59, 0.11)), 0., 1.);
 #endif
 
-	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);
+// Composition
+#ifdef EMISSIVEASILLUMINATION
+    vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + emissiveColor, 0.0, 1.0), alpha);
+#else
+    vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);
+#endif
 
 #ifdef FOG
 	float fog = CalcFogFactor();

+ 2 - 0
src/Tools/babylon.sceneSerializer.js

@@ -206,6 +206,8 @@ var BABYLON;
         serializationObject.specular = material.specularColor.asArray();
         serializationObject.specularPower = material.specularPower;
         serializationObject.emissive = material.emissiveColor.asArray();
+        serializationObject.useReflectionFresnelFromSpecular = serializationObject.useReflectionFresnelFromSpecular;
+        serializationObject.useEmissiveAsIllumination = serializationObject.useEmissiveAsIllumination;
         serializationObject.alpha = material.alpha;
         serializationObject.id = material.id;
         serializationObject.tags = BABYLON.Tags.GetTags(material);

+ 2 - 0
src/Tools/babylon.sceneSerializer.ts

@@ -227,6 +227,8 @@
         serializationObject.specular = material.specularColor.asArray();
         serializationObject.specularPower = material.specularPower;
         serializationObject.emissive = material.emissiveColor.asArray();
+        serializationObject.useReflectionFresnelFromSpecular = serializationObject.useReflectionFresnelFromSpecular;
+        serializationObject.useEmissiveAsIllumination = serializationObject.useEmissiveAsIllumination;
 
         serializationObject.alpha = material.alpha;