浏览代码

Update IOR to be a mask map

/main
Sebastien Lagarde 6 年前
当前提交
2ad2a458
共有 9 个文件被更改,包括 63 次插入52 次删除
  1. 13
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
  3. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl
  5. 53
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  6. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
  7. 13
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl
  8. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl
  9. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader

13
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs


public static GUIContent thicknessRemapText = new GUIContent("Thickness Remap", "Remaps values of the thickness map from [0, 1] to the specified range.");
// Iridescence
public static GUIContent iorIridescenceText = new GUIContent("Iridescence IOR", "Controls the number of color fringes with increasing angle (view dependent): Smaller mean more fringe. Also modify intensity and saturation of color fringes: Higher value mean more intense and saturate.");
public static GUIContent iridescenceMaskText = new GUIContent("Iridescence Mask", "Control intensity of the iridescence");
public static GUIContent thicknessIridescenceText = new GUIContent("Iridescence Thickness");
public static GUIContent thicknessMapIridescenceText = new GUIContent("Iridescence Thickness map");
public static GUIContent thicknessRemapIridescenceText = new GUIContent("Iridescence Thickness remap");

protected MaterialProperty anisotropyMap = null;
protected const string kAnisotropyMap = "_AnisotropyMap";
protected MaterialProperty iorIridescence = null;
protected const string kIorIridescence = "_IorIridescence";
protected MaterialProperty iridescenceMask = null;
protected const string kIridescenceMask = "_IridescenceMask";
protected MaterialProperty iridescenceMaskMap = null;
protected const string kIridescenceMaskMap = "_IridescenceMaskMap";
protected MaterialProperty thicknessIridescence = null;
protected const string kThicknessIridescence = "_ThicknessIridescence";
protected MaterialProperty thicknessMapIridescence = null;

anisotropyMap = FindProperty(kAnisotropyMap, props);
// Iridescence
iorIridescence = FindProperty(kIorIridescence, props);
iridescenceMask = FindProperty(kIridescenceMask, props);
iridescenceMaskMap = FindProperty(kIridescenceMaskMap, props);
thicknessIridescence = FindProperty(kThicknessIridescence, props);
thicknessMapIridescence = FindProperty(kThicknessMapIridescence, props);
thicknessRemapIridescence = FindProperty(kThicknessRemapIridescence, props);

}
protected void ShaderIridescenceInputGUI()
{
m_MaterialEditor.ShaderProperty(iorIridescence, Styles.iorIridescenceText);
m_MaterialEditor.TexturePropertySingleLine(Styles.iridescenceMaskText, iridescenceMaskMap, iridescenceMask);
m_MaterialEditor.TexturePropertySingleLine(Styles.thicknessMapIridescenceText, thicknessMapIridescence);
if (thicknessMapIridescence.textureValue != null)

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl


surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.coatMask = 0.0;
surfaceData.thicknessIridescence = 0.0;
surfaceData.iorIridescence = 1.0;
surfaceData.iridescenceMask = 0.0;
// Transparency parameters
// Use thickness from SSS

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs


// Iridescence
[SurfaceDataAttributes("Thickness of Iridescence")]
public float thicknessIridescence;
[SurfaceDataAttributes("Index of refraction of Iridescence")]
public float iorIridescence;
[SurfaceDataAttributes("Iridescence Mask")]
public float iridescenceMask;
// Forward property only

// Iridescence
public float thicknessIridescence;
public float iorIridescence;
public float iridescenceMask;
// ClearCoat
public float coatRoughness; // Automatically fill

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl


#define DEBUGVIEW_LIT_SURFACEDATA_TANGENT (1013)
#define DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY (1014)
#define DEBUGVIEW_LIT_SURFACEDATA_THICKNESS_OF_IRIDESCENCE (1015)
#define DEBUGVIEW_LIT_SURFACEDATA_INDEX_OF_REFRACTION_OF_IRIDESCENCE (1016)
#define DEBUGVIEW_LIT_SURFACEDATA_IRIDESCENCE_MASK (1016)
#define DEBUGVIEW_LIT_SURFACEDATA_INDEX_OF_REFRACTION (1017)
#define DEBUGVIEW_LIT_SURFACEDATA_TRANSMITTANCE_COLOR (1018)
#define DEBUGVIEW_LIT_SURFACEDATA_TRANSMITTANCE_ABSORPTION_DISTANCE (1019)

#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B (1046)
#define DEBUGVIEW_LIT_BSDFDATA_ANISOTROPY (1047)
#define DEBUGVIEW_LIT_BSDFDATA_THICKNESS_IRIDESCENCE (1048)
#define DEBUGVIEW_LIT_BSDFDATA_IOR_IRIDESCENCE (1049)
#define DEBUGVIEW_LIT_BSDFDATA_IRIDESCENCE_MASK (1049)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS (1050)
#define DEBUGVIEW_LIT_BSDFDATA_IOR (1051)
#define DEBUGVIEW_LIT_BSDFDATA_ABSORPTION_COEFFICIENT (1052)

float3 tangentWS;
float anisotropy;
float thicknessIridescence;
float iorIridescence;
float iridescenceMask;
float ior;
float3 transmittanceColor;
float atDistance;

float roughnessB;
float anisotropy;
float thicknessIridescence;
float iorIridescence;
float iridescenceMask;
float coatRoughness;
float ior;
float3 absorptionCoefficient;

case DEBUGVIEW_LIT_SURFACEDATA_THICKNESS_OF_IRIDESCENCE:
result = surfacedata.thicknessIridescence.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_INDEX_OF_REFRACTION_OF_IRIDESCENCE:
result = surfacedata.iorIridescence.xxx;
case DEBUGVIEW_LIT_SURFACEDATA_IRIDESCENCE_MASK:
result = surfacedata.iridescenceMask.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_INDEX_OF_REFRACTION:
result = surfacedata.ior.xxx;

case DEBUGVIEW_LIT_BSDFDATA_THICKNESS_IRIDESCENCE:
result = bsdfdata.thicknessIridescence.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_IOR_IRIDESCENCE:
result = bsdfdata.iorIridescence.xxx;
case DEBUGVIEW_LIT_BSDFDATA_IRIDESCENCE_MASK:
result = bsdfdata.iridescenceMask.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS:
result = bsdfdata.coatRoughness.xxx;

53
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


/* 19 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 20 */ LIGHT_FEATURE_MASK_FLAGS_OPAQUE | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
// Standard with clear coat and Iridescence
/* 21 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 22 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_AREA | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 23 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 24 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 25 */ LIGHT_FEATURE_MASK_FLAGS_OPAQUE | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT | MATERIALFEATUREFLAGS_LIT_STANDARD,
// Standard with Iridescence
/* 21 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 22 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_AREA | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 23 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 24 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 25 */ LIGHT_FEATURE_MASK_FLAGS_OPAQUE | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE | MATERIALFEATUREFLAGS_LIT_STANDARD,
/* 26 */ LIGHT_FEATURE_MASK_FLAGS_OPAQUE | MATERIAL_FEATURE_MASK_FLAGS, // Catch all case with MATERIAL_FEATURE_MASK_FLAGS is needed in case we disable material classification
};

// Iridescence
//-----------------------------------------------------------------------------
// Ref: https://belcour.github.io/blog/research/2017/05/01/brdf-thin-film.html
// Evaluation XYZ sensitivity curves in Fourier space
float3 EvalSensitivity(float opd, float shift)
{

float3 EvalIridescence(float eta_1, float cosTheta1, BSDFData bsdfData)
{
// thicknessIridescence unit is micrometer for this equation here. Mean 0.5 is 500nm.
float Dinc = 2.0 * bsdfData.iorIridescence * bsdfData.thicknessIridescence;
float Dinc = 3.0 * bsdfData.thicknessIridescence;
// Note: Unlike the code provide with the paper, here we use schlick approximation
// Schlick is a very poor approximation when dealing with iridescence to the Fresnel
// term and there is no "neutral" value in this unlike in the original paper.
// We use Iridescence mask here to allow to have neutral value
float eta_2 = lerp(eta_1, bsdfData.iorIridescence, smoothstep(0.0, 0.03, Dinc));
float eta2 = lerp(2.0, 1.1, bsdfData.thicknessIridescence);
float eta_2 = lerp(eta_1, eta2, smoothstep(0.0, 0.03, Dinc));
// Evaluate the cosTheta on the base layer (Snell law)
float cosTheta2 = sqrt(1.0 - Sq(eta_1 / eta_2) * (1.0 - Sq(cosTheta1)));

bsdfData.bitangentWS = bitangentWS;
}
void FillMaterialIridescence(float ior, float thickness, inout BSDFData bsdfData)
void FillMaterialIridescence(float mask, float thickness, inout BSDFData bsdfData)
bsdfData.iorIridescence = ior;
bsdfData.iridescenceMask = mask;
bsdfData.thicknessIridescence = thickness;
}

if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
{
FillMaterialIridescence(surfaceData.iorIridescence, surfaceData.thicknessIridescence, bsdfData);
FillMaterialIridescence(surfaceData.iridescenceMask, surfaceData.thicknessIridescence, bsdfData);
}
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))

{
materialFeatureId = GBUFFER_LIT_IRIDESCENCE;
// Range of IOR is 1..2.5, so remap to 0..1
outGBuffer2.rgb = float3(RemapIor25to01(surfaceData.iorIridescence), surfaceData.thicknessIridescence,
outGBuffer2.rgb = float3(surfaceData.iridescenceMask, surfaceData.thicknessIridescence,
PackFloatInt8bit(surfaceData.metallic, 0, 8));
}
else // Standard

FillMaterialAnisotropy(anisotropy, frame[0], frame[1], bsdfData);
}
// The neutral value of iridescenceMask is 0 (handled by ZERO_INITIALIZE).
// Range of IOR is 1..2.5
FillMaterialIridescence(RemapIor01to25(inGBuffer2.r), inGBuffer2.g, bsdfData);
FillMaterialIridescence(inGBuffer2.r, inGBuffer2.g, bsdfData);
}
// The neutral value of coatMask is 0 (handled by ZERO_INITIALIZE).

case DEBUGVIEW_LIT_SURFACEDATA_MATERIAL_FEATURES:
result = (surfaceData.materialFeatures.xxx) / 255.0; // Aloow to read with color picker debug mode
break;
case DEBUGVIEW_LIT_SURFACEDATA_INDEX_OF_REFRACTION_OF_IRIDESCENCE:
result = RemapIor25to01(surfaceData.iorIridescence).xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_INDEX_OF_REFRACTION:
result = RemapIor25to01(surfaceData.ior).xxx;
break;

case DEBUGVIEW_LIT_BSDFDATA_MATERIAL_FEATURES:
result = (bsdfData.materialFeatures.xxx) / 255.0; // Aloow to read with color picker debug mode
break;
case DEBUGVIEW_LIT_BSDFDATA_IOR_IRIDESCENCE:
result = RemapIor25to01(bsdfData.iorIridescence).xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_IOR:
result = RemapIor25to01(bsdfData.ior).xxx;
break;

float NdotV = ClampNdotV(preLightData.NdotV);
// We modify the bsdfData.fresnel0 here for iridescence
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
{
float viewAngle = NdotV;

viewAngle = sqrt(1.0 + Sq(1.0 / topIor) * (Sq(dot(bsdfData.normalWS, V)) - 1.0));
}
// TEMP
if (bsdfData.thicknessIridescence != 0.0)
if (bsdfData.iridescenceMask > 0.0)
bsdfData.fresnel0 = EvalIridescence(topIor, viewAngle, bsdfData);
bsdfData.fresnel0 = lerp(bsdfData.fresnel0, EvalIridescence(topIor, viewAngle, bsdfData), bsdfData.iridescenceMask);
// We modify the bsdfData.fresnel0 here for clearCoat
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
// Fresnel0 is deduced from interface between air and material (Assume to be 1.5 in Unity, or a metal).

if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
{
// Only lighting, not BSDF
lighting.diffuse = color * intensity * lightData.diffuseScale;;
lighting.diffuse = color * intensity * lightData.diffuseScale;
}
#endif

if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
{
// Only lighting, not BSDF
lighting.diffuse = color * intensity * lightData.diffuseScale;;
lighting.diffuse = color * intensity * lightData.diffuseScale;
}
#endif

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader


_ThicknessIridescence("Thickness sridescence", Range(0.0, 1.0)) = 1.0
_ThicknessMapIridescence("Thickness Map Iridescence", 2D) = "white" {}
_ThicknessRemapIridescence("Thickness Remap Iridescence", Vector) = (0, 1, 0, 0)
_IorIridescence("Indice Of Refraction Iridescence", Range(1.0, 2.5)) = 1.0
_IridescenceMask("Iridescence Mask", Range(0.0, 1.0)) = 1.0
_IridescenceMaskMap("Iridescence Mask Map", 2D) = "white" {}
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0
_CoatMaskMap("CoatMaskMap", 2D) = "white" {}

13
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl


#ifdef _MATERIAL_FEATURE_IRIDESCENCE
#ifdef _THICKNESSMAP_IRIDESCENCE
surfaceData.thicknessIridescence = SAMPLE_UVMAPPING_TEXTURE2D(_ThicknessMapIridescence, sampler_ThicknessMapIridescence, ADD_IDX(layerTexCoord.base)).r;
surfaceData.thicknessIridescence = ADD_IDX(_ThicknessRemapIridescence).x + ADD_IDX(_ThicknessRemapIridescence).y * surfaceData.thicknessIridescence;
surfaceData.thicknessIridescence = SAMPLE_UVMAPPING_TEXTURE2D(_ThicknessMapIridescence, sampler_ThicknessMapIridescence, layerTexCoord.base).r;
surfaceData.thicknessIridescence = _ThicknessRemapIridescence.x + _ThicknessRemapIridescence.y * surfaceData.thicknessIridescence;
surfaceData.thicknessIridescence = ADD_IDX(_ThicknessIridescence);
surfaceData.thicknessIridescence = _ThicknessIridescence;
surfaceData.iorIridescence = ADD_IDX(_IorIridescence);
surfaceData.iridescenceMask = _IridescenceMask;
surfaceData.iridescenceMask *= SAMPLE_UVMAPPING_TEXTURE2D(_IridescenceMaskMap, sampler_IridescenceMaskMap, layerTexCoord.base).r;
surfaceData.iorIridescence = 1.0;
surfaceData.iridescenceMask = 0.0;
#endif
#else // #if !defined(LAYERED_LIT_SHADER)

surfaceData.anisotropy = 0.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.thicknessIridescence = 0.0;
surfaceData.iorIridescence = 0.0;
surfaceData.iridescenceMask = 0.0;
surfaceData.coatMask = 0.0;
// Transparency

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl


TEXTURE2D(_ThicknessMapIridescence);
SAMPLER(sampler_ThicknessMapIridescence);
TEXTURE2D(_IridescenceMaskMap);
SAMPLER(sampler_IridescenceMaskMap);
TEXTURE2D(_SpecularColorMap);
SAMPLER(sampler_SpecularColorMap);

float _ThicknessIridescence;
float4 _ThicknessRemapIridescence;
float _IorIridescence;
float _IridescenceMask;
float _CoatMask;

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader


_ThicknessIridescence("Thickness sridescence", Range(0.0, 1.0)) = 1.0
_ThicknessMapIridescence("Thickness Map Iridescence", 2D) = "white" {}
_ThicknessRemapIridescence("Thickness Remap Iridescence", Vector) = (0, 1, 0, 0)
_IorIridescence("Indice Of Refraction Iridescence", Range(1.0, 2.5)) = 1.0
_IridescenceMask("Iridescence Mask", Range(0.0, 1.0)) = 1.0
_IridescenceMaskMap("Iridescence Mask Map", 2D) = "white" {}
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0
_CoatMaskMap("CoatMaskMap", 2D) = "white" {}

正在加载...
取消
保存