浏览代码

Enable subsurface radius and thickness parameters

/main
Evgenii Golubev 8 年前
当前提交
8e286ad5
共有 10 个文件被更改,包括 96 次插入57 次删除
  1. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  2. 37
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  3. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  4. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  5. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
  6. 15
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  7. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  8. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  9. 17
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  10. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


public static GUIContent detailMapModeText = new GUIContent("Detail Map with Normal", "Detail Map with AO / Height");
public static GUIContent UVDetailMappingText = new GUIContent("UV set for Detail", "");
public static GUIContent materialIDText = new GUIContent("Material Class", "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
public static GUIContent emissiveColorModeText = new GUIContent("Emissive Color Usage", "Use emissive color or emissive mask");
public static string InputsText = "Inputs";

public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation shape (lerp factor)");
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Tesselation displacement will take into account the object scale - Only work with uniform positive scale");
public static GUIContent materialIDText = new GUIContent("Material Class", "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
public static GUIContent subsurfaceProfileText = new GUIContent("Subsurface scattering profile", "A profile determines the shape of the blur filter.");
public static GUIContent subsurfaceRadiusText = new GUIContent("Subsurface scattering radius", "Determines the range of the blur.");
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface scattering radius map", "Determines the range of the blur.");
public static GUIContent thicknessText = new GUIContent("Thickness", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
public static GUIContent thicknessMapText = new GUIContent("Thickness map", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
}
public enum SurfaceType

37
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


protected const string kUVDetail = "_UVDetail";
protected MaterialProperty UVDetailsMappingMask = null;
protected const string kUVDetailsMappingMask = "_UVDetailsMappingMask";
protected MaterialProperty materialID = null;
protected const string kMaterialID = "_MaterialID";
protected MaterialProperty emissiveColorMode = null;
protected const string kEmissiveColorMode = "_EmissiveColorMode";

protected MaterialProperty detailAOScale = null;
protected const string kDetailAOScale = "_DetailAOScale";
// MaterialProperty subSurfaceRadius = null;
// MaterialProperty subSurfaceRadiusMap = null;
protected MaterialProperty emissiveColor = null;
protected const string kEmissiveColor = "_EmissiveColor";
protected MaterialProperty emissiveColorMap = null;

protected MaterialProperty materialID = null;
protected const string kMaterialID = "_MaterialID";
protected MaterialProperty subsurfaceProfile = null;
protected const string kSubsurfaceProfile = "_SubsurfaceProfile";
protected MaterialProperty subsurfaceRadius = null;
protected const string kSubsurfaceRadius = "_SubsurfaceRadius";
protected MaterialProperty subsurfaceRadiusMap = null;
protected const string kSubsurfaceRadiusMap = "_SubsurfaceRadiusMap";
protected MaterialProperty thickness = null;
protected const string kThickness = "_Thickness";
protected MaterialProperty thicknessMap = null;
protected const string kThicknessMap = "_ThicknessMap";
// These are options that are shared with the LayeredLit shader. Don't put anything that can't be shared here:
// For instance, properties like BaseColor and such don't exist in the LayeredLit so don't put them here.

ppdMinSamples = FindProperty(kPpdMinSamples, props);
ppdMaxSamples = FindProperty(kPpdMaxSamples, props);
detailMapMode = FindProperty(kDetailMapMode, props);
materialID = FindProperty(kMaterialID, props);
emissiveColorMode = FindProperty(kEmissiveColorMode, props);
}

emissiveColor = FindProperty(kEmissiveColor, props);
emissiveColorMap = FindProperty(kEmissiveColorMap, props);
emissiveIntensity = FindProperty(kEmissiveIntensity, props);
materialID = FindProperty(kMaterialID, props);
subsurfaceProfile = FindProperty(kSubsurfaceProfile, props);
subsurfaceRadius = FindProperty(kSubsurfaceRadius, props);
subsurfaceRadiusMap = FindProperty(kSubsurfaceRadiusMap, props);
thickness = FindProperty(kThickness, props);
thicknessMap = FindProperty(kThicknessMap, props);
}
override protected void ShaderInputOptionsGUI()

m_MaterialEditor.ShaderProperty(ppdMinSamples, Styles.ppdMinSamplesText);
m_MaterialEditor.ShaderProperty(ppdMaxSamples, Styles.ppdMaxSamplesText);
ppdMinSamples.floatValue = Mathf.Min(ppdMinSamples.floatValue, ppdMaxSamples.floatValue);
m_MaterialEditor.ShaderProperty(materialID, Styles.materialIDText);
m_MaterialEditor.ShaderProperty(materialID, Styles.materialIDText);
m_MaterialEditor.ShaderProperty(subsurfaceProfile, Styles.subsurfaceProfileText);
m_MaterialEditor.ShaderProperty(subsurfaceRadius, Styles.subsurfaceRadiusText);
m_MaterialEditor.ShaderProperty(subsurfaceRadiusMap, Styles.subsurfaceRadiusMapText);
m_MaterialEditor.ShaderProperty(thickness, Styles.thicknessText);
m_MaterialEditor.ShaderProperty(thicknessMap, Styles.thicknessMapText);
EditorGUI.indentLevel--;
}

SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap));
SetKeyword(material, "_ANISOTROPYMAP", material.GetTexture(kAnisotropyMap));
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap));
SetKeyword(material, "_SUBSURFACE_RADIUS_MAP", material.GetTexture(kSubsurfaceRadiusMap));
SetKeyword(material, "_THICKNESS_MAP", material.GetTexture(kThicknessMap));
bool needUV2 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV2 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0;
bool needUV3 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV3 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0;

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


public float specular; // 0.02, 0.04, 0.16, 0.2
// SSS
[SurfaceDataAttributes("SubSurface Radius")]
public float subSurfaceRadius;
[SurfaceDataAttributes("Subsurface Radius")]
public float subsurfaceRadius;
[SurfaceDataAttributes("SubSurface Profile")]
public int subSurfaceProfile;
[SurfaceDataAttributes("Subsurface Profile")]
public int subsurfaceProfile;
// Clearcoat
[SurfaceDataAttributes("Coat Normal")]

// fold into fresnel0
// SSS
public float subSurfaceRadius;
public float subsurfaceRadius;
public int subSurfaceProfile;
public int subsurfaceProfile;
// Clearcoat
public Vector3 coatNormalWS;

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


float anisotropy;
float metallic;
float specular;
float subSurfaceRadius;
float subsurfaceRadius;
int subSurfaceProfile;
int subsurfaceProfile;
float3 coatNormalWS;
float coatPerceptualSmoothness;
float3 specularColor;

float roughnessT;
float roughnessB;
float anisotropy;
float subSurfaceRadius;
float subsurfaceRadius;
int subSurfaceProfile;
int subsurfaceProfile;
float3 coatNormalWS;
float coatRoughness;
};

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl


else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile
bsdfData.subSurfaceRadius = surfaceData.subSurfaceRadius;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceRadius = surfaceData.subsurfaceRadius;
bsdfData.subSurfaceProfile = surfaceData.subSurfaceProfile;
bsdfData.subsurfaceProfile = surfaceData.subsurfaceProfile;
}
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

}
else if (surfaceData.materialId == MATERIALID_LIT_SSS)
{
outGBuffer2 = float4(surfaceData.subSurfaceRadius, surfaceData.thickness, 0.0, surfaceData.subSurfaceProfile / 8.0); // Number of profile not define yet
outGBuffer2 = float4(surfaceData.subsurfaceRadius, surfaceData.thickness, 0.0, surfaceData.subsurfaceProfile / 8.0); // Number of profile not define yet
}
else if (surfaceData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile
bsdfData.subSurfaceRadius = inGBuffer2.r;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceRadius = inGBuffer2.r;
bsdfData.subSurfaceProfile = inGBuffer2.a * 8.0;
bsdfData.subsurfaceProfile = inGBuffer2.a * 8.0;
}
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

result = surfaceData.specular.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_RADIUS:
result = surfaceData.subSurfaceRadius.xxx;
result = surfaceData.subsurfaceRadius.xxx;
result = GetIndexColor(surfaceData.subSurfaceProfile);
result = GetIndexColor(surfaceData.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS:
result = surfaceData.coatNormalWS * 0.5 + 0.5;

result = bsdfData.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_RADIUS:
result = bsdfData.subSurfaceRadius.xxx;
result = bsdfData.subsurfaceRadius.xxx;
result = GetIndexColor(bsdfData.subSurfaceProfile);
result = GetIndexColor(bsdfData.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS:
result = bsdfData.coatNormalWS * 0.5 + 0.5;

15
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader


_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1
[Enum(Standard, 0, Subsurface Scattering, 1, Clear Coat, 2)] _MaterialID("Material Class", Int) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
_SubsurfaceProfile("Subsurface Profile", Int) = 0
_SubsurfaceRadius("Subsurface Radius", Range(0.0, 1.0)) = 0
_SubsurfaceRadiusMap("Subsurface Radius Map", 2D) = "white" {}
_Thickness("Thickness", Range(0.0, 1.0)) = 0
_ThicknessMap("Thickness Map", 2D) = "white" {}
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}

[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_HorizonFade("Horizon fade", Range(0.0, 5.0)) = 1.0

#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _TANGENTMAP
#pragma shader_feature _ANISOTROPYMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl


surfaceData.materialId = 0;
surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.subsurfaceRadius = 1.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.subsurfaceProfile = 0;
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);

18
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.thickness = 0.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.subsurfaceProfile = _SubsurfaceProfile;
#ifdef _Subsurface_RADIUS_MAP
surfaceData.subsurfaceProfile = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_SubsurfaceRadiusMap), ADD_ZERO_IDX(sampler_SubsurfaceRadiusMap), ADD_IDX(layerTexCoord.base)).r;
#else
surfaceData.subsurfaceRadius = _SubsurfaceRadius;
#endif
#ifdef _THICKNESS_MAP
surfaceData.thickness = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_ThicknessMap), ADD_ZERO_IDX(sampler_ThicknessMap), ADD_IDX(layerTexCoord.base)).r;
#else
surfaceData.thickness = _Thickness;
#endif
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;

surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.subsurfaceRadius = 1.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.subsurfaceProfile = 0;
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;

17
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl


TEXTURE2D(_AnisotropyMap);
SAMPLER2D(sampler_AnisotropyMap);
float _MaterialID;
//float _SubSurfaceRadius;
//TEXTURE2D(_SubSurfaceRadiusMap);
//SAMPLER2D(sampler_SubSurfaceRadiusMap);
// float _Thickness;
//TEXTURE2D(_ThicknessMap);
//SAMPLER2D(sampler_ThicknessMap);
int _MaterialID;
int _SubsurfaceProfile;
float _SubsurfaceRadius;
float _Thickness;
TEXTURE2D(_SubsurfaceRadiusMap);
SAMPLER2D(sampler_SubsurfaceRadiusMap);
TEXTURE2D(_ThicknessMap);
SAMPLER2D(sampler_ThicknessMap);
// float _CoatCoverage;
//TEXTURE2D(_CoatCoverageMap);

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader


_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1
[Enum(Standard, 0, Subsurface Scattering, 1, Clear Coat, 2)] _MaterialID("Material Class", Int) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
_SubsurfaceProfile("Subsurface Profile", Int) = 0
_SubsurfaceRadius("Subsurface Radius", Range(0.0, 1.0)) = 0
_SubsurfaceRadiusMap("Subsurface Radius Map", 2D) = "white" {}
_Thickness("Thickness", Range(0.0, 1.0)) = 0
_ThicknessMap("Thickness Map", 2D) = "white" {}
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}

#pragma shader_feature _TANGENTMAP
#pragma shader_feature _ANISOTROPYMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

正在加载...
取消
保存