|
@@ -101,7 +101,8 @@ export class PBRMaterialDefines extends MaterialDefines
|
|
public ROUGHNESSSTOREINMETALMAPGREEN = false;
|
|
public ROUGHNESSSTOREINMETALMAPGREEN = false;
|
|
public METALLNESSSTOREINMETALMAPBLUE = false;
|
|
public METALLNESSSTOREINMETALMAPBLUE = false;
|
|
public AOSTOREINMETALMAPRED = false;
|
|
public AOSTOREINMETALMAPRED = false;
|
|
- public METALLICF0FACTORFROMMETALLICMAP = false;
|
|
|
|
|
|
+ public METALLIC_REFLECTANCE = false;
|
|
|
|
+ public METALLIC_REFLECTANCEDIRECTUV = 0;
|
|
|
|
|
|
public ENVIRONMENTBRDF = false;
|
|
public ENVIRONMENTBRDF = false;
|
|
public ENVIRONMENTBRDF_RGBD = false;
|
|
public ENVIRONMENTBRDF_RGBD = false;
|
|
@@ -406,19 +407,32 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
protected _roughness: Nullable<number> = null;
|
|
protected _roughness: Nullable<number> = null;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Specifies the an F0 factor to help configuring the material F0.
|
|
|
|
- * Instead of the default 4%, 8% * factor will be used. As the factor is defaulting
|
|
|
|
- * to 0.5 the previously hard coded value stays the same.
|
|
|
|
- * Can also be used to scale the F0 values of the metallic texture.
|
|
|
|
|
|
+ * In metallic workflow, specifies an F0 factor to help configuring the material F0.
|
|
|
|
+ * By default the indexOfrefraction is used to compute F0;
|
|
|
|
+ *
|
|
|
|
+ * This is used as a factor against the default reflectance at normal incidence to tweak it.
|
|
|
|
+ *
|
|
|
|
+ * F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor;
|
|
|
|
+ * F90 = metallicReflectanceColor;
|
|
*/
|
|
*/
|
|
- protected _metallicF0Factor = 0.5;
|
|
|
|
|
|
+ protected _metallicF0Factor = 1;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Specifies whether the F0 factor can be fetched from the mettalic texture.
|
|
|
|
- * If set to true, please adapt the metallicF0Factor to ensure it fits with
|
|
|
|
- * your expectation as it multiplies with the texture data.
|
|
|
|
|
|
+ * In metallic workflow, specifies an F90 color to help configuring the material F90.
|
|
|
|
+ * By default the F90 is always 1;
|
|
|
|
+ *
|
|
|
|
+ * Please note that this factor is also used as a factor against the default reflectance at normal incidence.
|
|
|
|
+ *
|
|
|
|
+ * F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor
|
|
|
|
+ * F90 = metallicReflectanceColor;
|
|
*/
|
|
*/
|
|
- protected _useMetallicF0FactorFromMetallicTexture = false;
|
|
|
|
|
|
+ protected _metallicReflectanceColor = Color3.White();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines to store metallicReflectanceColor in RGB and metallicF0Factor in A
|
|
|
|
+ * This is multiply against the scalar values defined in the material.
|
|
|
|
+ */
|
|
|
|
+ protected _metallicReflectanceTexture: Nullable<BaseTexture> = null;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.
|
|
* Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.
|
|
@@ -938,6 +952,12 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this._metallicReflectanceTexture) {
|
|
|
|
+ if (!this._metallicReflectanceTexture.isReadyOrNotBlocking()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._microSurfaceTexture) {
|
|
if (this._microSurfaceTexture) {
|
|
if (!this._microSurfaceTexture.isReadyOrNotBlocking()) {
|
|
if (!this._microSurfaceTexture.isReadyOrNotBlocking()) {
|
|
return false;
|
|
return false;
|
|
@@ -1156,12 +1176,12 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
|
|
|
|
var shaderName = "pbr";
|
|
var shaderName = "pbr";
|
|
|
|
|
|
- var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "visibility", "vReflectionColor",
|
|
|
|
|
|
+ var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vMetallicReflectanceFactors", "vEmissiveColor", "visibility", "vReflectionColor",
|
|
"vFogInfos", "vFogColor", "pointSize",
|
|
"vFogInfos", "vFogColor", "pointSize",
|
|
- "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vReflectionPosition", "vReflectionSize", "vEmissiveInfos", "vReflectivityInfos",
|
|
|
|
|
|
+ "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vReflectionPosition", "vReflectionSize", "vEmissiveInfos", "vReflectivityInfos", "vMetallicReflectanceInfos",
|
|
"vMicroSurfaceSamplerInfos", "vBumpInfos", "vLightmapInfos",
|
|
"vMicroSurfaceSamplerInfos", "vBumpInfos", "vLightmapInfos",
|
|
"mBones",
|
|
"mBones",
|
|
- "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "vClipPlane5", "vClipPlane6", "albedoMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "reflectivityMatrix", "normalMatrix", "microSurfaceSamplerMatrix", "bumpMatrix", "lightmapMatrix",
|
|
|
|
|
|
+ "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "vClipPlane5", "vClipPlane6", "albedoMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "reflectivityMatrix", "normalMatrix", "microSurfaceSamplerMatrix", "bumpMatrix", "lightmapMatrix", "metallicReflectanceMatrix",
|
|
"vLightingIntensity",
|
|
"vLightingIntensity",
|
|
"logarithmicDepthConstant",
|
|
"logarithmicDepthConstant",
|
|
"vSphericalX", "vSphericalY", "vSphericalZ",
|
|
"vSphericalX", "vSphericalY", "vSphericalZ",
|
|
@@ -1178,7 +1198,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
var samplers = ["albedoSampler", "reflectivitySampler", "ambientSampler", "emissiveSampler",
|
|
var samplers = ["albedoSampler", "reflectivitySampler", "ambientSampler", "emissiveSampler",
|
|
"bumpSampler", "lightmapSampler", "opacitySampler",
|
|
"bumpSampler", "lightmapSampler", "opacitySampler",
|
|
"reflectionSampler", "reflectionSamplerLow", "reflectionSamplerHigh", "irradianceSampler",
|
|
"reflectionSampler", "reflectionSamplerLow", "reflectionSamplerHigh", "irradianceSampler",
|
|
- "microSurfaceSampler", "environmentBrdfSampler", "boneSampler"];
|
|
|
|
|
|
+ "microSurfaceSampler", "environmentBrdfSampler", "boneSampler", "metallicReflectanceSampler"];
|
|
|
|
|
|
var uniformBuffers = ["Material", "Scene"];
|
|
var uniformBuffers = ["Material", "Scene"];
|
|
|
|
|
|
@@ -1387,7 +1407,6 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
defines.ROUGHNESSSTOREINMETALMAPGREEN = !this._useRoughnessFromMetallicTextureAlpha && this._useRoughnessFromMetallicTextureGreen;
|
|
defines.ROUGHNESSSTOREINMETALMAPGREEN = !this._useRoughnessFromMetallicTextureAlpha && this._useRoughnessFromMetallicTextureGreen;
|
|
defines.METALLNESSSTOREINMETALMAPBLUE = this._useMetallnessFromMetallicTextureBlue;
|
|
defines.METALLNESSSTOREINMETALMAPBLUE = this._useMetallnessFromMetallicTextureBlue;
|
|
defines.AOSTOREINMETALMAPRED = this._useAmbientOcclusionFromMetallicTextureRed;
|
|
defines.AOSTOREINMETALMAPRED = this._useAmbientOcclusionFromMetallicTextureRed;
|
|
- defines.METALLICF0FACTORFROMMETALLICMAP = this._useMetallicF0FactorFromMetallicTexture;
|
|
|
|
}
|
|
}
|
|
else if (this._reflectivityTexture) {
|
|
else if (this._reflectivityTexture) {
|
|
MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture, defines, "REFLECTIVITY");
|
|
MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture, defines, "REFLECTIVITY");
|
|
@@ -1397,6 +1416,12 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
defines.REFLECTIVITY = false;
|
|
defines.REFLECTIVITY = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this._metallicReflectanceTexture) {
|
|
|
|
+ MaterialHelper.PrepareDefinesForMergedUV(this._metallicReflectanceTexture, defines, "METALLIC_REFLECTANCE");
|
|
|
|
+ } else {
|
|
|
|
+ defines.METALLIC_REFLECTANCE = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._microSurfaceTexture) {
|
|
if (this._microSurfaceTexture) {
|
|
MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture, defines, "MICROSURFACEMAP");
|
|
MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture, defines, "MICROSURFACEMAP");
|
|
} else {
|
|
} else {
|
|
@@ -1572,6 +1597,9 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
ubo.addUniform("vReflectivityColor", 4);
|
|
ubo.addUniform("vReflectivityColor", 4);
|
|
ubo.addUniform("vEmissiveColor", 3);
|
|
ubo.addUniform("vEmissiveColor", 3);
|
|
ubo.addUniform("visibility", 1);
|
|
ubo.addUniform("visibility", 1);
|
|
|
|
+ ubo.addUniform("vMetallicReflectanceFactors", 4);
|
|
|
|
+ ubo.addUniform("vMetallicReflectanceInfos", 2);
|
|
|
|
+ ubo.addUniform("metallicReflectanceMatrix", 16);
|
|
|
|
|
|
PBRClearCoatConfiguration.PrepareUniformBuffer(ubo);
|
|
PBRClearCoatConfiguration.PrepareUniformBuffer(ubo);
|
|
PBRAnisotropicConfiguration.PrepareUniformBuffer(ubo);
|
|
PBRAnisotropicConfiguration.PrepareUniformBuffer(ubo);
|
|
@@ -1740,6 +1768,11 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
MaterialHelper.BindTextureMatrix(this._reflectivityTexture, ubo, "reflectivity");
|
|
MaterialHelper.BindTextureMatrix(this._reflectivityTexture, ubo, "reflectivity");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this._metallicReflectanceTexture) {
|
|
|
|
+ ubo.updateFloat2("vMetallicReflectanceInfos", this._metallicReflectanceTexture.coordinatesIndex, this._metallicReflectanceTexture.level);
|
|
|
|
+ MaterialHelper.BindTextureMatrix(this._metallicReflectanceTexture, ubo, "metallicReflectance");
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._microSurfaceTexture) {
|
|
if (this._microSurfaceTexture) {
|
|
ubo.updateFloat2("vMicroSurfaceSamplerInfos", this._microSurfaceTexture.coordinatesIndex, this._microSurfaceTexture.level);
|
|
ubo.updateFloat2("vMicroSurfaceSamplerInfos", this._microSurfaceTexture.coordinatesIndex, this._microSurfaceTexture.level);
|
|
MaterialHelper.BindTextureMatrix(this._microSurfaceTexture, ubo, "microSurfaceSampler");
|
|
MaterialHelper.BindTextureMatrix(this._microSurfaceTexture, ubo, "microSurfaceSampler");
|
|
@@ -1767,13 +1800,21 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
if (defines.METALLICWORKFLOW) {
|
|
if (defines.METALLICWORKFLOW) {
|
|
TmpColors.Color3[0].r = (this._metallic === undefined || this._metallic === null) ? 1 : this._metallic;
|
|
TmpColors.Color3[0].r = (this._metallic === undefined || this._metallic === null) ? 1 : this._metallic;
|
|
TmpColors.Color3[0].g = (this._roughness === undefined || this._roughness === null) ? 1 : this._roughness;
|
|
TmpColors.Color3[0].g = (this._roughness === undefined || this._roughness === null) ? 1 : this._roughness;
|
|
|
|
+ ubo.updateColor4("vReflectivityColor", TmpColors.Color3[0], 1);
|
|
|
|
+
|
|
|
|
+ const ior = this.subSurface.indexOfRefraction;
|
|
|
|
+ const outside_ior = 1; // consider air as clear coat and other layaers would remap in the shader.
|
|
|
|
|
|
// We are here deriving our default reflectance from a common value for none metallic surface.
|
|
// We are here deriving our default reflectance from a common value for none metallic surface.
|
|
- // Default specular reflectance at normal incidence.
|
|
|
|
- // 4% corresponds to index of refraction (IOR) of 1.50, approximately equal to glass.
|
|
|
|
- // We then use 8% combined with a factor of 0.5 to allow some variations around the 0.04 default value.
|
|
|
|
- const metallicF0 = 0.08 * this._metallicF0Factor;
|
|
|
|
- ubo.updateColor4("vReflectivityColor", TmpColors.Color3[0], metallicF0);
|
|
|
|
|
|
+ // Based of the schlick fresnel approximation model
|
|
|
|
+ // for dielectrics.
|
|
|
|
+ const f0 = Math.pow((ior - outside_ior) / (ior + outside_ior), 2);
|
|
|
|
+
|
|
|
|
+ // Tweak the default F0 and F90 based on our given setup
|
|
|
|
+ this._metallicReflectanceColor.scaleToRef(f0 * this._metallicF0Factor, TmpColors.Color3[0]);
|
|
|
|
+ const metallicF90 = this._metallicF0Factor;
|
|
|
|
+
|
|
|
|
+ ubo.updateColor4("vMetallicReflectanceFactors", TmpColors.Color3[0], metallicF90);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
ubo.updateColor4("vReflectivityColor", this._reflectivityColor, this._microSurface);
|
|
ubo.updateColor4("vReflectivityColor", this._reflectivityColor, this._microSurface);
|
|
@@ -1849,6 +1890,10 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
ubo.setTexture("reflectivitySampler", this._reflectivityTexture);
|
|
ubo.setTexture("reflectivitySampler", this._reflectivityTexture);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this._metallicReflectanceTexture) {
|
|
|
|
+ ubo.setTexture("metallicReflectanceSampler", this._metallicReflectanceTexture);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._microSurfaceTexture) {
|
|
if (this._microSurfaceTexture) {
|
|
ubo.setTexture("microSurfaceSampler", this._microSurfaceTexture);
|
|
ubo.setTexture("microSurfaceSampler", this._microSurfaceTexture);
|
|
}
|
|
}
|
|
@@ -2010,6 +2055,10 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
activeTextures.push(this._metallicTexture);
|
|
activeTextures.push(this._metallicTexture);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this._metallicReflectanceTexture) {
|
|
|
|
+ activeTextures.push(this._metallicReflectanceTexture);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._microSurfaceTexture) {
|
|
if (this._microSurfaceTexture) {
|
|
activeTextures.push(this._microSurfaceTexture);
|
|
activeTextures.push(this._microSurfaceTexture);
|
|
}
|
|
}
|
|
@@ -2064,6 +2113,10 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this._metallicReflectanceTexture === texture) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._microSurfaceTexture === texture) {
|
|
if (this._microSurfaceTexture === texture) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -2089,45 +2142,21 @@ export abstract class PBRBaseMaterial extends PushMaterial {
|
|
*/
|
|
*/
|
|
public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean): void {
|
|
public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean): void {
|
|
if (forceDisposeTextures) {
|
|
if (forceDisposeTextures) {
|
|
- if (this._albedoTexture) {
|
|
|
|
- this._albedoTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._ambientTexture) {
|
|
|
|
- this._ambientTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._opacityTexture) {
|
|
|
|
- this._opacityTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._reflectionTexture) {
|
|
|
|
- this._reflectionTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (this._environmentBRDFTexture && this.getScene().environmentBRDFTexture !== this._environmentBRDFTexture) {
|
|
if (this._environmentBRDFTexture && this.getScene().environmentBRDFTexture !== this._environmentBRDFTexture) {
|
|
this._environmentBRDFTexture.dispose();
|
|
this._environmentBRDFTexture.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
- if (this._emissiveTexture) {
|
|
|
|
- this._emissiveTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._metallicTexture) {
|
|
|
|
- this._metallicTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._reflectivityTexture) {
|
|
|
|
- this._reflectivityTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._bumpTexture) {
|
|
|
|
- this._bumpTexture.dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._lightmapTexture) {
|
|
|
|
- this._lightmapTexture.dispose();
|
|
|
|
- }
|
|
|
|
|
|
+ this._albedoTexture?.dispose();
|
|
|
|
+ this._ambientTexture?.dispose();
|
|
|
|
+ this._opacityTexture?.dispose();
|
|
|
|
+ this._reflectionTexture?.dispose();
|
|
|
|
+ this._emissiveTexture?.dispose();
|
|
|
|
+ this._metallicTexture?.dispose();
|
|
|
|
+ this._reflectivityTexture?.dispose();
|
|
|
|
+ this._bumpTexture?.dispose();
|
|
|
|
+ this._lightmapTexture?.dispose();
|
|
|
|
+ this._metallicReflectanceTexture?.dispose();
|
|
|
|
+ this._microSurfaceTexture?.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
this.subSurface.dispose(forceDisposeTextures);
|
|
this.subSurface.dispose(forceDisposeTextures);
|