|
@@ -123,6 +123,7 @@ var BABYLON;
|
|
|
this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
|
|
|
this.INVERTCUBICMAP = false;
|
|
|
this.LOGARITHMICDEPTH = false;
|
|
|
+ this.REFRACTION = false;
|
|
|
this._keys = Object.keys(this);
|
|
|
}
|
|
|
return StandardMaterialDefines;
|
|
@@ -144,6 +145,7 @@ var BABYLON;
|
|
|
this.useSpecularOverAlpha = false;
|
|
|
this.disableLighting = false;
|
|
|
this.roughness = 0;
|
|
|
+ this.indexOfRefraction = 1.05;
|
|
|
this.useLightmapAsShadowmap = false;
|
|
|
this.useGlossinessFromSpecularMapAlpha = false;
|
|
|
this._renderTargets = new BABYLON.SmartArray(16);
|
|
@@ -157,6 +159,9 @@ var BABYLON;
|
|
|
if (_this.reflectionTexture && _this.reflectionTexture.isRenderTarget) {
|
|
|
_this._renderTargets.push(_this.reflectionTexture);
|
|
|
}
|
|
|
+ if (_this.refractionTexture && _this.refractionTexture.isRenderTarget) {
|
|
|
+ _this._renderTargets.push(_this.refractionTexture);
|
|
|
+ }
|
|
|
return _this._renderTargets;
|
|
|
};
|
|
|
}
|
|
@@ -443,14 +448,23 @@ var BABYLON;
|
|
|
this._defines.GLOSSINESS = this.useGlossinessFromSpecularMapAlpha;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
|
|
|
- if (!this.bumpTexture.isReady()) {
|
|
|
- return false;
|
|
|
+ if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
|
|
|
+ if (!this.bumpTexture.isReady()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ needUVs = true;
|
|
|
+ this._defines.BUMP = true;
|
|
|
+ }
|
|
|
}
|
|
|
- else {
|
|
|
- needUVs = true;
|
|
|
- this._defines.BUMP = true;
|
|
|
+ if (this.refractionTexture && StandardMaterial.ReflectionTextureEnabled) {
|
|
|
+ if (!this.refractionTexture.isReady()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ needUVs = true;
|
|
|
+ this._defines.REFRACTION = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// Effect
|
|
@@ -644,13 +658,13 @@ var BABYLON;
|
|
|
"vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
|
|
|
"vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
|
|
|
"vFogInfos", "vFogColor", "pointSize",
|
|
|
- "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos",
|
|
|
+ "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
|
|
|
"mBones",
|
|
|
"vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix",
|
|
|
"shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
|
|
|
"diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor",
|
|
|
"logarithmicDepthConstant"
|
|
|
- ], ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler",
|
|
|
+ ], ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionSampler",
|
|
|
"shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
|
|
|
], join, fallbacks, this.onCompiled, this.onError);
|
|
|
}
|
|
@@ -751,6 +765,10 @@ var BABYLON;
|
|
|
this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
|
|
|
this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
|
|
|
}
|
|
|
+ if (this.refractionTexture && StandardMaterial.RefractionEnabled) {
|
|
|
+ this._effect.setTexture("refractionSampler", this.refractionTexture);
|
|
|
+ this._effect.setFloat2("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction);
|
|
|
+ }
|
|
|
}
|
|
|
// Clip plane
|
|
|
if (scene.clipPlane) {
|
|
@@ -816,6 +834,12 @@ var BABYLON;
|
|
|
if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
|
|
|
results.push(this.bumpTexture);
|
|
|
}
|
|
|
+ if (this.lightmapTexture && this.lightmapTexture.animations && this.lightmapTexture.animations.length > 0) {
|
|
|
+ results.push(this.lightmapTexture);
|
|
|
+ }
|
|
|
+ if (this.refractionTexture && this.refractionTexture.animations && this.refractionTexture.animations.length > 0) {
|
|
|
+ results.push(this.refractionTexture);
|
|
|
+ }
|
|
|
return results;
|
|
|
};
|
|
|
StandardMaterial.prototype.dispose = function (forceDisposeEffect) {
|
|
@@ -840,6 +864,12 @@ var BABYLON;
|
|
|
if (this.bumpTexture) {
|
|
|
this.bumpTexture.dispose();
|
|
|
}
|
|
|
+ if (this.lightmapTexture) {
|
|
|
+ this.lightmapTexture.dispose();
|
|
|
+ }
|
|
|
+ if (this.refractionTexture) {
|
|
|
+ this.refractionTexture.dispose();
|
|
|
+ }
|
|
|
_super.prototype.dispose.call(this, forceDisposeEffect);
|
|
|
};
|
|
|
StandardMaterial.prototype.clone = function (name) {
|
|
@@ -872,6 +902,9 @@ var BABYLON;
|
|
|
newStandardMaterial.lightmapTexture = this.lightmapTexture.clone();
|
|
|
newStandardMaterial.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
|
|
|
}
|
|
|
+ if (this.refractionTexture && this.refractionTexture.clone) {
|
|
|
+ newStandardMaterial.refractionTexture = this.refractionTexture.clone();
|
|
|
+ }
|
|
|
newStandardMaterial.ambientColor = this.ambientColor.clone();
|
|
|
newStandardMaterial.diffuseColor = this.diffuseColor.clone();
|
|
|
newStandardMaterial.specularColor = this.specularColor.clone();
|
|
@@ -943,6 +976,9 @@ var BABYLON;
|
|
|
if (this.bumpTexture) {
|
|
|
serializationObject.bumpTexture = this.bumpTexture.serialize();
|
|
|
}
|
|
|
+ if (this.refractionTexture) {
|
|
|
+ serializationObject.refractionTexture = this.refractionTexture.serialize();
|
|
|
+ }
|
|
|
return serializationObject;
|
|
|
};
|
|
|
StandardMaterial.Parse = function (source, scene, rootUrl) {
|
|
@@ -999,6 +1035,9 @@ var BABYLON;
|
|
|
if (source.bumpTexture) {
|
|
|
material.bumpTexture = BABYLON.Texture.Parse(source.bumpTexture, scene, rootUrl);
|
|
|
}
|
|
|
+ if (source.refractionTexture) {
|
|
|
+ material.refractionTexture = BABYLON.Texture.Parse(source.refractionTexture, scene, rootUrl);
|
|
|
+ }
|
|
|
if (source.checkReadyOnlyOnce) {
|
|
|
material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
|
|
|
}
|
|
@@ -1017,6 +1056,7 @@ var BABYLON;
|
|
|
StandardMaterial.BumpTextureEnabled = true;
|
|
|
StandardMaterial.FresnelEnabled = true;
|
|
|
StandardMaterial.LightmapEnabled = true;
|
|
|
+ StandardMaterial.RefractionEnabled = true;
|
|
|
return StandardMaterial;
|
|
|
})(BABYLON.Material);
|
|
|
BABYLON.StandardMaterial = StandardMaterial;
|