|
@@ -23,7 +23,7 @@ export interface IMaterialSubSurfaceDefines {
|
|
|
|
|
|
SS_REFRACTION: boolean;
|
|
SS_REFRACTION: boolean;
|
|
SS_TRANSLUCENCY: boolean;
|
|
SS_TRANSLUCENCY: boolean;
|
|
- SS_SCATERRING: boolean;
|
|
|
|
|
|
+ SS_SCATTERING: boolean;
|
|
|
|
|
|
SS_THICKNESSANDMASK_TEXTURE: boolean;
|
|
SS_THICKNESSANDMASK_TEXTURE: boolean;
|
|
SS_THICKNESSANDMASK_TEXTUREDIRECTUV: number;
|
|
SS_THICKNESSANDMASK_TEXTUREDIRECTUV: number;
|
|
@@ -35,6 +35,7 @@ export interface IMaterialSubSurfaceDefines {
|
|
SS_RGBDREFRACTION: boolean;
|
|
SS_RGBDREFRACTION: boolean;
|
|
SS_LINEARSPECULARREFRACTION: boolean;
|
|
SS_LINEARSPECULARREFRACTION: boolean;
|
|
SS_LINKREFRACTIONTOTRANSPARENCY: boolean;
|
|
SS_LINKREFRACTIONTOTRANSPARENCY: boolean;
|
|
|
|
+ SS_ALBEDOFORREFRACTIONTINT: boolean;
|
|
|
|
|
|
SS_MASK_FROM_THICKNESS_TEXTURE: boolean;
|
|
SS_MASK_FROM_THICKNESS_TEXTURE: boolean;
|
|
|
|
|
|
@@ -94,6 +95,12 @@ export class PBRSubSurfaceConfiguration {
|
|
@serialize()
|
|
@serialize()
|
|
public scatteringIntensity: number = 1;
|
|
public scatteringIntensity: number = 1;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * When enabled, transparent surfaces will be tinted with the albedo colour (independent of thickness)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public useAlbedoToTintRefraction: boolean = false;
|
|
|
|
+
|
|
private _thicknessTexture: Nullable<BaseTexture> = null;
|
|
private _thicknessTexture: Nullable<BaseTexture> = null;
|
|
/**
|
|
/**
|
|
* Stores the average thickness of a mesh in a texture (The texture is holding the values linearly).
|
|
* Stores the average thickness of a mesh in a texture (The texture is holding the values linearly).
|
|
@@ -127,6 +134,31 @@ export class PBRSubSurfaceConfiguration {
|
|
@expandToProperty("_markAllSubMeshesAsTexturesDirty")
|
|
@expandToProperty("_markAllSubMeshesAsTexturesDirty")
|
|
public indexOfRefraction = 1.5;
|
|
public indexOfRefraction = 1.5;
|
|
|
|
|
|
|
|
+ private _volumeIndexOfRefraction = -1.0;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Index of refraction of the material's volume.
|
|
|
|
+ * https://en.wikipedia.org/wiki/List_of_refractive_indices
|
|
|
|
+ *
|
|
|
|
+ * This ONLY impacts refraction. If not provided or given a non-valid value,
|
|
|
|
+ * the volume will use the same IOR as the surface.
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ @expandToProperty("_markAllSubMeshesAsTexturesDirty")
|
|
|
|
+ public get volumeIndexOfRefraction(): number {
|
|
|
|
+ if (this._volumeIndexOfRefraction >= 1.0) {
|
|
|
|
+ return this._volumeIndexOfRefraction;
|
|
|
|
+ }
|
|
|
|
+ return this._indexOfRefraction;
|
|
|
|
+ }
|
|
|
|
+ public set volumeIndexOfRefraction(value: number) {
|
|
|
|
+ if (value >= 1.0) {
|
|
|
|
+ this._volumeIndexOfRefraction = value;
|
|
|
|
+ } else {
|
|
|
|
+ this._volumeIndexOfRefraction = -1.0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private _invertRefractionY = false;
|
|
private _invertRefractionY = false;
|
|
/**
|
|
/**
|
|
* Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.
|
|
* Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.
|
|
@@ -242,7 +274,7 @@ export class PBRSubSurfaceConfiguration {
|
|
defines.SUBSURFACE = false;
|
|
defines.SUBSURFACE = false;
|
|
|
|
|
|
defines.SS_TRANSLUCENCY = this._isTranslucencyEnabled;
|
|
defines.SS_TRANSLUCENCY = this._isTranslucencyEnabled;
|
|
- defines.SS_SCATERRING = this._isScatteringEnabled;
|
|
|
|
|
|
+ defines.SS_SCATTERING = this._isScatteringEnabled;
|
|
defines.SS_THICKNESSANDMASK_TEXTURE = false;
|
|
defines.SS_THICKNESSANDMASK_TEXTURE = false;
|
|
defines.SS_MASK_FROM_THICKNESS_TEXTURE = false;
|
|
defines.SS_MASK_FROM_THICKNESS_TEXTURE = false;
|
|
defines.SS_REFRACTION = false;
|
|
defines.SS_REFRACTION = false;
|
|
@@ -253,6 +285,7 @@ export class PBRSubSurfaceConfiguration {
|
|
defines.SS_REFRACTIONMAP_OPPOSITEZ = false;
|
|
defines.SS_REFRACTIONMAP_OPPOSITEZ = false;
|
|
defines.SS_LODINREFRACTIONALPHA = false;
|
|
defines.SS_LODINREFRACTIONALPHA = false;
|
|
defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;
|
|
defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;
|
|
|
|
+ defines.SS_ALBEDOFORREFRACTIONTINT = false;
|
|
|
|
|
|
if (this._isRefractionEnabled || this._isTranslucencyEnabled || this._isScatteringEnabled) {
|
|
if (this._isRefractionEnabled || this._isTranslucencyEnabled || this._isScatteringEnabled) {
|
|
defines.SUBSURFACE = true;
|
|
defines.SUBSURFACE = true;
|
|
@@ -280,6 +313,7 @@ export class PBRSubSurfaceConfiguration {
|
|
defines.SS_REFRACTIONMAP_OPPOSITEZ = refractionTexture.invertZ;
|
|
defines.SS_REFRACTIONMAP_OPPOSITEZ = refractionTexture.invertZ;
|
|
defines.SS_LODINREFRACTIONALPHA = refractionTexture.lodLevelInAlpha;
|
|
defines.SS_LODINREFRACTIONALPHA = refractionTexture.lodLevelInAlpha;
|
|
defines.SS_LINKREFRACTIONTOTRANSPARENCY = this._linkRefractionWithTransparency;
|
|
defines.SS_LINKREFRACTIONTOTRANSPARENCY = this._linkRefractionWithTransparency;
|
|
|
|
+ defines.SS_ALBEDOFORREFRACTIONTINT = this.useAlbedoToTintRefraction;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -317,8 +351,8 @@ export class PBRSubSurfaceConfiguration {
|
|
}
|
|
}
|
|
|
|
|
|
var width = refractionTexture.getSize().width;
|
|
var width = refractionTexture.getSize().width;
|
|
-
|
|
|
|
- uniformBuffer.updateFloat4("vRefractionInfos", refractionTexture.level, 1 / this._indexOfRefraction, depth, this._invertRefractionY ? -1 : 1);
|
|
|
|
|
|
+ var refractionIor = this.volumeIndexOfRefraction;
|
|
|
|
+ uniformBuffer.updateFloat4("vRefractionInfos", refractionTexture.level, 1 / refractionIor, depth, this._invertRefractionY ? -1 : 1);
|
|
uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",
|
|
uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",
|
|
width,
|
|
width,
|
|
refractionTexture.lodGenerationScale,
|
|
refractionTexture.lodGenerationScale,
|
|
@@ -496,8 +530,8 @@ export class PBRSubSurfaceConfiguration {
|
|
* @returns the new fallback rank.
|
|
* @returns the new fallback rank.
|
|
*/
|
|
*/
|
|
public static AddFallbacks(defines: IMaterialSubSurfaceDefines, fallbacks: EffectFallbacks, currentRank: number): number {
|
|
public static AddFallbacks(defines: IMaterialSubSurfaceDefines, fallbacks: EffectFallbacks, currentRank: number): number {
|
|
- if (defines.SS_SCATERRING) {
|
|
|
|
- fallbacks.addFallback(currentRank++, "SS_SCATERRING");
|
|
|
|
|
|
+ if (defines.SS_SCATTERING) {
|
|
|
|
+ fallbacks.addFallback(currentRank++, "SS_SCATTERING");
|
|
}
|
|
}
|
|
if (defines.SS_TRANSLUCENCY) {
|
|
if (defines.SS_TRANSLUCENCY) {
|
|
fallbacks.addFallback(currentRank++, "SS_TRANSLUCENCY");
|
|
fallbacks.addFallback(currentRank++, "SS_TRANSLUCENCY");
|