|
@@ -11,8 +11,10 @@ var BABYLON;
|
|
|
var FresnelParameters = (function () {
|
|
|
function FresnelParameters() {
|
|
|
this.isEnabled = true;
|
|
|
- this.leftColor = BABYLON.Color3.Black();
|
|
|
- this.rightColor = BABYLON.Color3.White();
|
|
|
+ this.leftColor = BABYLON.Color3.White();
|
|
|
+ this.rightColor = BABYLON.Color3.Black();
|
|
|
+ this.bias = 0;
|
|
|
+ this.power = 1;
|
|
|
}
|
|
|
return FresnelParameters;
|
|
|
})();
|
|
@@ -33,7 +35,6 @@ var BABYLON;
|
|
|
this._renderTargets = new BABYLON.SmartArray(16);
|
|
|
this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
|
|
|
this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
|
|
|
- this._baseColor = new BABYLON.Color3();
|
|
|
this._scaledDiffuse = new BABYLON.Color3();
|
|
|
this._scaledSpecular = new BABYLON.Color3();
|
|
|
|
|
@@ -48,7 +49,7 @@ var BABYLON;
|
|
|
};
|
|
|
}
|
|
|
StandardMaterial.prototype.needAlphaBlending = function () {
|
|
|
- return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture();
|
|
|
+ return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
|
|
|
};
|
|
|
|
|
|
StandardMaterial.prototype.needAlphaTesting = function () {
|
|
@@ -261,11 +262,35 @@ var BABYLON;
|
|
|
}
|
|
|
|
|
|
// Fresnel
|
|
|
- if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
|
|
|
+ if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled || this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled || this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
|
|
|
+ var fresnelRank = 1;
|
|
|
+
|
|
|
+ if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
|
|
|
+ defines.push("#define DIFFUSEFRESNEL");
|
|
|
+ fallbacks.addFallback(fresnelRank, "DIFFUSEFRESNEL");
|
|
|
+ fresnelRank++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
|
|
|
+ defines.push("#define OPACITYFRESNEL");
|
|
|
+ fallbacks.addFallback(fresnelRank, "OPACITYFRESNEL");
|
|
|
+ fresnelRank++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
|
|
|
+ defines.push("#define REFLECTIONFRESNEL");
|
|
|
+ fallbacks.addFallback(fresnelRank, "REFLECTIONFRESNEL");
|
|
|
+ fresnelRank++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
|
|
|
+ defines.push("#define EMISSIVEFRESNEL");
|
|
|
+ fallbacks.addFallback(fresnelRank, "EMISSIVEFRESNEL");
|
|
|
+ fresnelRank++;
|
|
|
+ }
|
|
|
+
|
|
|
defines.push("#define FRESNEL");
|
|
|
- defines.push("#define DIFFUSEFRESNEL");
|
|
|
- fallbacks.addFallback(1, "FRESNEL");
|
|
|
- fallbacks.addFallback(1, "DIFFUSEFRESNEL");
|
|
|
+ fallbacks.addFallback(fresnelRank - 1, "FRESNEL");
|
|
|
}
|
|
|
|
|
|
// Attribs
|
|
@@ -324,7 +349,7 @@ var BABYLON;
|
|
|
"mBones",
|
|
|
"vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix",
|
|
|
"darkness0", "darkness1", "darkness2", "darkness3",
|
|
|
- "diffuseLeftColor", "diffuseRightColor"
|
|
|
+ "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor"
|
|
|
], [
|
|
|
"diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler",
|
|
|
"shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
|
|
@@ -351,7 +376,6 @@ var BABYLON;
|
|
|
|
|
|
StandardMaterial.prototype.bind = function (world, mesh) {
|
|
|
var scene = this.getScene();
|
|
|
- this._baseColor.copyFrom(this.diffuseColor);
|
|
|
|
|
|
// Matrices
|
|
|
this.bindOnlyWorldMatrix(world);
|
|
@@ -364,8 +388,22 @@ var BABYLON;
|
|
|
|
|
|
// Fresnel
|
|
|
if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
|
|
|
- this._effect.setColor3("diffuseLeftColor", this.diffuseFresnelParameters.leftColor);
|
|
|
- this._effect.setColor3("diffuseRightColor", this.diffuseFresnelParameters.rightColor);
|
|
|
+ this._effect.setColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
|
|
|
+ this._effect.setColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
|
|
|
+ this._effect.setColor4("opacityParts", new BABYLON.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);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
// Textures
|
|
@@ -374,8 +412,6 @@ var BABYLON;
|
|
|
|
|
|
this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
|
|
|
this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
|
|
|
-
|
|
|
- this._baseColor.copyFromFloats(1, 1, 1);
|
|
|
}
|
|
|
|
|
|
if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
|
|
@@ -429,7 +465,7 @@ var BABYLON;
|
|
|
|
|
|
this._effect.setVector3("vEyePosition", scene.activeCamera.position);
|
|
|
this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
|
|
|
- this._effect.setColor4("vDiffuseColor", this._baseColor, this.alpha * mesh.visibility);
|
|
|
+ this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
|
|
|
this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
|
|
|
this._effect.setColor3("vEmissiveColor", this.emissiveColor);
|
|
|
|