浏览代码

Merge pull request #509 from Unity-Technologies/Add-SSS-support-to-LayeredLit

HDRenderPipeline: Add support of SSS to LayeredLit
/Yibing-Project-2
GitHub 7 年前
当前提交
735db2ae
共有 8 个文件被更改,包括 252 次插入75 次删除
  1. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  2. 48
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  3. 49
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  4. 18
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  5. 69
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  6. 98
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  7. 27
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  8. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl

9
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System.Linq;

SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));
SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));
SetKeyword(material, "_SUBSURFACE_RADIUS_MAP" + i, material.GetTexture(kSubsurfaceRadiusMap + i));
SetKeyword(material, "_THICKNESSMAP" + i, material.GetTexture(kThicknessMap + i));
}
SetKeyword(material, "_INFLUENCEMASK_MAP", material.GetTexture(kLayerInfluenceMaskMap) && material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

useDensityModeEnable |= material.GetFloat(kOpacityAsDensity + i) != 0.0f;
}
SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);
Lit.MaterialId materialId = (Lit.MaterialId)material.GetFloat(kMaterialID);
SetKeyword(material, "_MATID_SSS", materialId == Lit.MaterialId.LitSSS);
//SetKeyword(material, "_MATID_STANDARD", materialId == Lit.MaterialId.LitStandard); // See comment in Lit.shader, it is the default, we don't define it
}
private void DoEmissiveGUI(Material material)
{

48
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace2("NormalMap space", Float) = 0
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace3("NormalMap space", Float) = 0
_SubsurfaceProfile0("Subsurface Profile0", Int) = 0
_SubsurfaceProfile1("Subsurface Profile1", Int) = 0
_SubsurfaceProfile2("Subsurface Profile2", Int) = 0
_SubsurfaceProfile3("Subsurface Profile3", Int) = 0
_SubsurfaceRadius0("Subsurface Radius0", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadius1("Subsurface Radius1", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadius2("Subsurface Radius2", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadius3("Subsurface Radius3", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadiusMap0("Subsurface Radius Map0", 2D) = "white" {}
_SubsurfaceRadiusMap1("Subsurface Radius Map1", 2D) = "white" {}
_SubsurfaceRadiusMap2("Subsurface Radius Map2", 2D) = "white" {}
_SubsurfaceRadiusMap3("Subsurface Radius Map3", 2D) = "white" {}
_Thickness0("Thickness", Range(0.0, 1.0)) = 1.0
_Thickness1("Thickness", Range(0.0, 1.0)) = 1.0
_Thickness2("Thickness", Range(0.0, 1.0)) = 1.0
_Thickness3("Thickness", Range(0.0, 1.0)) = 1.0
_ThicknessMap0("Thickness Map", 2D) = "white" {}
_ThicknessMap1("Thickness Map", 2D) = "white" {}
_ThicknessMap2("Thickness Map", 2D) = "white" {}
_ThicknessMap3("Thickness Map", 2D) = "white" {}
// All the following properties exist only in layered lit material
// Layer blending options

[ToggleOff] _DoubleSidedEnable("Double sided enable", Float) = 0.0
[Enum(None, 0, Mirror, 1, Flip, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1
[HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0)
[Enum(Subsurface Scattering, 0, Standard, 1)] _MaterialID("MaterialId", Int) = 1 // MaterialId.RegularLighting
[Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2)] _DisplacementMode("DisplacementMode", Int) = 0
[ToggleOff] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0

#pragma shader_feature _BENTNORMALMAP3
#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _ENABLESPECULAROCCLUSION
#pragma shader_feature _DETAIL_MAP0
#pragma shader_feature _DETAIL_MAP1
#pragma shader_feature _DETAIL_MAP2
#pragma shader_feature _DETAIL_MAP3
#pragma shader_feature _DETAIL_MAP0
#pragma shader_feature _DETAIL_MAP1
#pragma shader_feature _DETAIL_MAP2
#pragma shader_feature _DETAIL_MAP3
#pragma shader_feature _SUBSURFACE_RADIUS_MAP0
#pragma shader_feature _SUBSURFACE_RADIUS_MAP1
#pragma shader_feature _SUBSURFACE_RADIUS_MAP2
#pragma shader_feature _SUBSURFACE_RADIUS_MAP3
#pragma shader_feature _THICKNESSMAP0
#pragma shader_feature _THICKNESSMAP1
#pragma shader_feature _THICKNESSMAP2
#pragma shader_feature _THICKNESSMAP3
#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _MAIN_LAYER_INFLUENCE_MODE
#pragma shader_feature _INFLUENCEMASK_MAP

#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
#pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING
#pragma shader_feature _ENABLE_FOG_ON_TRANSPARENT
// MaterialId are used as shader feature to allow compiler to optimize properly
// Note _MATID_STANDARD is not define as there is always the default case "_". We assign default as _MATID_STANDARD, so we never test _MATID_STANDARD
#pragma shader_feature _ _MATID_SSS
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

49
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace2("NormalMap space", Float) = 0
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace3("NormalMap space", Float) = 0
_SubsurfaceProfile0("Subsurface Profile0", Int) = 0
_SubsurfaceProfile1("Subsurface Profile1", Int) = 0
_SubsurfaceProfile2("Subsurface Profile2", Int) = 0
_SubsurfaceProfile3("Subsurface Profile3", Int) = 0
_SubsurfaceRadius0("Subsurface Radius0", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadius1("Subsurface Radius1", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadius2("Subsurface Radius2", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadius3("Subsurface Radius3", Range(0.0, 1.0)) = 1.0
_SubsurfaceRadiusMap0("Subsurface Radius Map0", 2D) = "white" {}
_SubsurfaceRadiusMap1("Subsurface Radius Map1", 2D) = "white" {}
_SubsurfaceRadiusMap2("Subsurface Radius Map2", 2D) = "white" {}
_SubsurfaceRadiusMap3("Subsurface Radius Map3", 2D) = "white" {}
_Thickness0("Thickness", Range(0.0, 1.0)) = 1.0
_Thickness1("Thickness", Range(0.0, 1.0)) = 1.0
_Thickness2("Thickness", Range(0.0, 1.0)) = 1.0
_Thickness3("Thickness", Range(0.0, 1.0)) = 1.0
_ThicknessMap0("Thickness Map", 2D) = "white" {}
_ThicknessMap1("Thickness Map", 2D) = "white" {}
_ThicknessMap2("Thickness Map", 2D) = "white" {}
_ThicknessMap3("Thickness Map", 2D) = "white" {}
// All the following properties exist only in layered lit material
// Layer blending options

_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Stencil state
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting (fixed at compile time)
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting
// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0

[Enum(None, 0, Mirror, 1, Flip, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1
[HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0)
[Enum(Subsurface Scattering, 0, Standard, 1)] _MaterialID("MaterialId", Int) = 1 // MaterialId.RegularLighting
[Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2, Tessellation displacement, 3)] _DisplacementMode("DisplacementMode", Int) = 0
[ToggleOff] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0
[ToggleOff] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0

#pragma shader_feature _BENTNORMALMAP3
#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _ENABLESPECULAROCCLUSION
#pragma shader_feature _DETAIL_MAP0
#pragma shader_feature _DETAIL_MAP1
#pragma shader_feature _DETAIL_MAP2
#pragma shader_feature _DETAIL_MAP3
#pragma shader_feature _DETAIL_MAP0
#pragma shader_feature _DETAIL_MAP1
#pragma shader_feature _DETAIL_MAP2
#pragma shader_feature _DETAIL_MAP3
#pragma shader_feature _SUBSURFACE_RADIUS_MAP0
#pragma shader_feature _SUBSURFACE_RADIUS_MAP1
#pragma shader_feature _SUBSURFACE_RADIUS_MAP2
#pragma shader_feature _SUBSURFACE_RADIUS_MAP3
#pragma shader_feature _THICKNESSMAP0
#pragma shader_feature _THICKNESSMAP1
#pragma shader_feature _THICKNESSMAP2
#pragma shader_feature _THICKNESSMAP3
#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _MAIN_LAYER_INFLUENCE_MODE
#pragma shader_feature _INFLUENCEMASK_MAP

#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_MULTIPLY _BLENDMODE_PRE_MULTIPLY
#pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING
#pragma shader_feature _ENABLE_FOG_ON_TRANSPARENT
// MaterialId are used as shader feature to allow compiler to optimize properly
// Note _MATID_STANDARD is not define as there is always the default case "_". We assign default as _MATID_STANDARD, so we never test _MATID_STANDARD
#pragma shader_feature _ _MATID_SSS
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

18
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


// Material ID
public static GUIContent materialIDText = new GUIContent("Material type", "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
// Per pixel displacement
// Per pixel displacement
public static GUIContent ppdMinSamplesText = new GUIContent("Minimum steps", "Minimum steps (texture sample) to use with per pixel displacement mapping");
public static GUIContent ppdMaxSamplesText = new GUIContent("Maximum steps", "Maximum steps (texture sample) to use with per pixel displacement mapping");
public static GUIContent ppdLodThresholdText = new GUIContent("Fading mip level start", "Starting heightmap mipmap lod number where the parallax occlusion mapping effect start to disappear");

depthOffsetEnable = FindProperty(kDepthOffsetEnable, props);
// MaterialID
materialID = FindProperty(kMaterialID, props, false); // LayeredLit is force to be standard for now, so materialID could not exist
materialID = FindProperty(kMaterialID, props);
displacementMode = FindProperty(kDisplacementMode, props);
displacementLockObjectScale = FindProperty(kDisplacementLockObjectScale, props);

ppdLodThreshold = FindProperty(kPpdLodThreshold, props);
ppdPrimitiveLength = FindProperty(kPpdPrimitiveLength, props);
ppdPrimitiveWidth = FindProperty(kPpdPrimitiveWidth, props);
invPrimScale = FindProperty(kInvPrimScale, props);
invPrimScale = FindProperty(kInvPrimScale, props);
// tessellation specific, silent if not found
tessellationMode = FindProperty(kTessellationMode, props, false);

EditorGUI.indentLevel--;
}
if (materialID != null)
m_MaterialEditor.ShaderProperty(materialID, StylesBaseLit.materialIDText);
m_MaterialEditor.ShaderProperty(materialID, StylesBaseLit.materialIDText);
m_MaterialEditor.ShaderProperty(displacementMode, StylesBaseLit.displacementModeText);
if ((DisplacementMode)displacementMode.floatValue != DisplacementMode.None)

// Set the reference value for the stencil test.
int stencilRef = (int)StencilLightingUsage.RegularLighting;
if (material.HasProperty(kMaterialID))
if ((int)material.GetFloat(kMaterialID) == (int)Lit.MaterialId.LitSSS)
if ((int)material.GetFloat(kMaterialID) == (int)UnityEngine.Experimental.Rendering.HDPipeline.Lit.MaterialId.LitSSS)
{
stencilRef = (int)StencilLightingUsage.SplitLighting;
}
stencilRef = (int)StencilLightingUsage.SplitLighting;
}
material.SetInt(kStencilRef, stencilRef);

SetKeyword(material, "_VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE", displacementLockObjectScale && (enableVertexDisplacement || enableTessellationDisplacement));
SetKeyword(material, "_PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE", displacementLockObjectScale && enablePixelDisplacement);
SetKeyword(material, "_DISPLACEMENT_LOCK_TILING_SCALE", displacementLockTilingScale && enableDisplacement);
bool windEnabled = material.GetFloat(kWindEnabled) > 0.0f;
SetKeyword(material, "_VERTEX_WIND", windEnabled);

69
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


protected MaterialProperty[] heightMax = new MaterialProperty[kMaxLayerCount];
protected const string kHeightMax = "_HeightMax";
protected MaterialProperty[] subsurfaceProfileID = new MaterialProperty[kMaxLayerCount];
protected const string kSubsurfaceProfileID = "_SubsurfaceProfile";
protected MaterialProperty[] subsurfaceRadius = new MaterialProperty[kMaxLayerCount];
protected const string kSubsurfaceRadius = "_SubsurfaceRadius";
protected MaterialProperty[] subsurfaceRadiusMap = new MaterialProperty[kMaxLayerCount];
protected const string kSubsurfaceRadiusMap = "_SubsurfaceRadiusMap";
protected MaterialProperty[] thickness = new MaterialProperty[kMaxLayerCount];
protected const string kThickness = "_Thickness";
protected MaterialProperty[] thicknessMap = new MaterialProperty[kMaxLayerCount];
protected const string kThicknessMap = "_ThicknessMap";
protected MaterialProperty[] UVDetail = new MaterialProperty[kMaxLayerCount];
protected const string kUVDetail = "_UVDetail";
protected MaterialProperty[] UVDetailsMappingMask = new MaterialProperty[kMaxLayerCount];

protected MaterialProperty anisotropyMap = null;
protected const string kAnisotropyMap = "_AnisotropyMap";
protected MaterialProperty subsurfaceProfileID = null;
protected const string kSubsurfaceProfileID = "_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";
protected MaterialProperty coatCoverage = null;
protected const string kCoatCoverage = "_CoatCoverage";
protected MaterialProperty coatIOR = null;

heightMax[i] = FindProperty(string.Format("{0}{1}", kHeightMax, m_PropertySuffixes[i]), props);
heightCenter[i] = FindProperty(string.Format("{0}{1}", kHeightCenter, m_PropertySuffixes[i]), props);
// Sub surface
subsurfaceProfileID[i] = FindProperty(string.Format("{0}{1}", kSubsurfaceProfileID, m_PropertySuffixes[i]), props);
subsurfaceRadius[i] = FindProperty(string.Format("{0}{1}", kSubsurfaceRadius, m_PropertySuffixes[i]), props);
subsurfaceRadiusMap[i] = FindProperty(string.Format("{0}{1}", kSubsurfaceRadiusMap, m_PropertySuffixes[i]), props);
thickness[i] = FindProperty(string.Format("{0}{1}", kThickness, m_PropertySuffixes[i]), props);
thicknessMap[i] = FindProperty(string.Format("{0}{1}", kThicknessMap, m_PropertySuffixes[i]), props);
// Details
UVDetail[i] = FindProperty(string.Format("{0}{1}", kUVDetail, m_PropertySuffixes[i]), props);
UVDetailsMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVDetailsMappingMask, m_PropertySuffixes[i]), props);

anisotropy = FindProperty(kAnisotropy, props);
anisotropyMap = FindProperty(kAnisotropyMap, props);
// Sub surface
subsurfaceProfileID = FindProperty(kSubsurfaceProfileID, props);
subsurfaceRadius = FindProperty(kSubsurfaceRadius, props);
subsurfaceRadiusMap = FindProperty(kSubsurfaceRadiusMap, props);
thickness = FindProperty(kThickness, props);
thicknessMap = FindProperty(kThicknessMap, props);
// clear coat
coatCoverage = FindProperty(kCoatCoverage, props);
coatIOR = FindProperty(kCoatIOR, props);

// We reuse thickness from SSS
}
protected void ShaderSSSInputGUI(Material material)
protected void ShaderSSSInputGUI(Material material, int layerIndex)
{
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
var sssSettings = hdPipeline.sssSettings;

using (var scope = new EditorGUI.ChangeCheckScope())
{
int profileID = (int)subsurfaceProfileID.floatValue;
int profileID = (int)subsurfaceProfileID[layerIndex].floatValue;
using (new EditorGUILayout.HorizontalScope())
{

}
if (scope.changed)
subsurfaceProfileID.floatValue = profileID;
subsurfaceProfileID[layerIndex].floatValue = profileID;
m_MaterialEditor.ShaderProperty(subsurfaceRadius, Styles.subsurfaceRadiusText);
m_MaterialEditor.TexturePropertySingleLine(Styles.subsurfaceRadiusMapText, subsurfaceRadiusMap);
m_MaterialEditor.ShaderProperty(thickness, Styles.thicknessText);
m_MaterialEditor.TexturePropertySingleLine(Styles.thicknessMapText, thicknessMap);
m_MaterialEditor.ShaderProperty(subsurfaceRadius[layerIndex], Styles.subsurfaceRadiusText);
m_MaterialEditor.TexturePropertySingleLine(Styles.subsurfaceRadiusMapText, subsurfaceRadiusMap[layerIndex]);
m_MaterialEditor.ShaderProperty(thickness[layerIndex], Styles.thicknessText);
m_MaterialEditor.TexturePropertySingleLine(Styles.thicknessMapText, thicknessMap[layerIndex]);
}
protected void ShaderClearCoatInputGUI()

m_MaterialEditor.TexturePropertySingleLine(refractionEnable ? Styles.baseColorRefractionMaskText : Styles.baseColorText, baseColorMap[layerIndex], baseColor[layerIndex]);
if ( materialID == null || // Will be the case for Layered materials where we only support standard and the parameter does not exist
(Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitStandard || (Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitAniso)
if ((Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitStandard || (Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitAniso)
{
m_MaterialEditor.ShaderProperty(metallic[layerIndex], Styles.metallicText);
}

}
}
m_MaterialEditor.TexturePropertySingleLine((materialID != null && (Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitSpecular) ? Styles.maskMapSpecularText : Styles.maskMapSText, maskMap[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(((Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitSpecular) ? Styles.maskMapSpecularText : Styles.maskMapSText, maskMap[layerIndex]);
m_MaterialEditor.ShaderProperty(normalMapSpace[layerIndex], Styles.normalMapSpaceText);

heightAmplitude[layerIndex].floatValue = (heightMax[layerIndex].floatValue - heightMin[layerIndex].floatValue) * 0.01f; // Conversion centimeters to meters.
}
if (materialID != null)
{
ShaderSSSInputGUI(material);
ShaderSSSInputGUI(material, layerIndex);
// Following mode are not supported by layered lit and will not be call by it
// as the MaterialId enum don't define it
case Lit.MaterialId.LitAniso:
ShaderAnisoInputGUI();
break;

default:
Debug.Assert(false, "Encountered an unsupported MaterialID.");
break;
}
}
EditorGUILayout.Space();

if (mode != Lit.RefractionMode.ThinPlane)
{
if (thicknessMap.textureValue == null)
m_MaterialEditor.ShaderProperty(thickness, Styles.refractionThicknessText);
m_MaterialEditor.TexturePropertySingleLine(Styles.refractionThicknessMapText, thicknessMap);
if (thicknessMap[0].textureValue == null)
m_MaterialEditor.ShaderProperty(thickness[0], Styles.refractionThicknessText);
m_MaterialEditor.TexturePropertySingleLine(Styles.refractionThicknessMapText, thicknessMap[0]);
++EditorGUI.indentLevel;
m_MaterialEditor.ShaderProperty(thicknessMultiplier, Styles.refractionThicknessMultiplierText);

98
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


#define SAMPLER_MASKMAP_IDX sampler_MaskMap
#define SAMPLER_HEIGHTMAP_IDX sampler_HeightMap
#define SAMPLER_SUBSURFACE_RADIUSMAP_IDX sampler_SubsurfaceRadiusMap
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap
// include LitDataInternal to define GetSurfaceData
#define LAYER_INDEX 0
#define ADD_IDX(Name) Name

#endif
#ifdef _DETAIL_MAP
#define _DETAIL_MAP_IDX
#endif
#ifdef _SUBSURFACE_RADIUS_MAP
#define _SUBSURFACE_RADIUS_MAP_IDX
#endif
#ifdef _THICKNESSMAP
#define _THICKNESSMAP_IDX
#endif
#ifdef _MASKMAP
#define _MASKMAP_IDX

#define SAMPLER_HEIGHTMAP_IDX sampler_HeightMap3
#endif
#if defined(_SUBSURFACE_RADIUS_MAP0)
#define _SUBSURFACE_RADIUS_MAP_IDX sampler_SubsurfaceRadiusMap0
#elif defined(_SUBSURFACE_RADIUS_MAP1)
#define _SUBSURFACE_RADIUS_MAP_IDX sampler_SubsurfaceRadiusMap1
#elif defined(_SUBSURFACE_RADIUS_MAP2)
#define _SUBSURFACE_RADIUS_MAP_IDX sampler_SubsurfaceRadiusMap2
#elif defined(_SUBSURFACE_RADIUS_MAP3)
#define _SUBSURFACE_RADIUS_MAP_IDX sampler_SubsurfaceRadiusMap3
#endif
#if defined(_THICKNESSMAP0)
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap0
#elif defined(_THICKNESSMAP1)
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap1
#elif defined(_THICKNESSMAP2)
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap2
#elif defined(_THICKNESSMAP3)
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap3
#endif
// Define a helper macro
#define ADD_ZERO_IDX(Name) Name##0

#ifdef _DETAIL_MAP0
#define _DETAIL_MAP_IDX
#endif
#ifdef _SUBSURFACE_RADIUS_MAP0
#define _SUBSURFACE_RADIUS_MAP_IDX
#endif
#ifdef _THICKNESSMAP0
#define _THICKNESSMAP_IDX
#endif
#ifdef _MASKMAP0
#define _MASKMAP_IDX
#endif

#undef _NORMALMAP_IDX
#undef _NORMALMAP_TANGENT_SPACE_IDX
#undef _DETAIL_MAP_IDX
#undef _SUBSURFACE_RADIUS_MAP_IDX
#undef _THICKNESSMAP_IDX
#undef _MASKMAP_IDX
#undef _BENTNORMALMAP_IDX

#ifdef _DETAIL_MAP1
#define _DETAIL_MAP_IDX
#endif
#ifdef _SUBSURFACE_RADIUS_MAP1
#define _SUBSURFACE_RADIUS_MAP_IDX
#endif
#ifdef _THICKNESSMAP1
#define _THICKNESSMAP_IDX
#endif
#ifdef _MASKMAP1
#define _MASKMAP_IDX
#endif

#undef _NORMALMAP_IDX
#undef _NORMALMAP_TANGENT_SPACE_IDX
#undef _DETAIL_MAP_IDX
#undef _SUBSURFACE_RADIUS_MAP_IDX
#undef _THICKNESSMAP_IDX
#undef _MASKMAP_IDX
#undef _BENTNORMALMAP_IDX

#ifdef _DETAIL_MAP2
#define _DETAIL_MAP_IDX
#endif
#ifdef _SUBSURFACE_RADIUS_MAP2
#define _SUBSURFACE_RADIUS_MAP_IDX
#endif
#ifdef _THICKNESSMAP2
#define _THICKNESSMAP_IDX
#endif
#ifdef _MASKMAP2
#define _MASKMAP_IDX
#endif

#undef _NORMALMAP_IDX
#undef _NORMALMAP_TANGENT_SPACE_IDX
#undef _DETAIL_MAP_IDX
#undef _SUBSURFACE_RADIUS_MAP_IDX
#undef _THICKNESSMAP_IDX
#undef _MASKMAP_IDX
#undef _BENTNORMALMAP_IDX

#ifdef _DETAIL_MAP3
#define _DETAIL_MAP_IDX
#endif
#ifdef _SUBSURFACE_RADIUS_MAP3
#define _SUBSURFACE_RADIUS_MAP_IDX
#endif
#ifdef _THICKNESSMAP3
#define _THICKNESSMAP_IDX
#endif
#ifdef _MASKMAP3
#define _MASKMAP_IDX
#endif

#undef _NORMALMAP_IDX
#undef _NORMALMAP_TANGENT_SPACE_IDX
#undef _DETAIL_MAP_IDX
#undef _SUBSURFACE_RADIUS_MAP_IDX
#undef _THICKNESSMAP_IDX
#undef _MASKMAP_IDX
#undef _BENTNORMALMAP_IDX

return result;
}
// In the case of subsurface profile index, the goal is to take the index with the hights weights.
// Or the last found in case of equality.
float BlendLayeredSSSprofile(float x0, float x1, float x2, float x3, float weight[4])
{
int sssProfileIndex = x0;
float currentMax = weight[0];
sssProfileIndex = currentMax < weight[1] ? x1 : sssProfileIndex;
currentMax = max(currentMax, weight[1]);
#if _LAYER_COUNT >= 3
sssProfileIndex = currentMax < weight[2] ? x2 : sssProfileIndex;
currentMax = max(currentMax, weight[2]);
#endif
#if _LAYER_COUNT >= 4
sssProfileIndex = currentMax < weight[3] ? x3 : sssProfileIndex;
#endif
return sssProfileIndex;
}
#define SURFACEDATA_BLEND_SSS_PROFILE(surfaceData, name, mask) BlendLayeredSSSprofile(MERGE_NAME(surfaceData, 0) MERGE_NAME(., name), MERGE_NAME(surfaceData, 1) MERGE_NAME(., name), MERGE_NAME(surfaceData, 2) MERGE_NAME(., name), MERGE_NAME(surfaceData, 3) MERGE_NAME(., name), mask);
#define PROP_BLEND_SCALAR(name, mask) BlendLayeredScalar(name##0, name##1, name##2, name##3, mask);
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,

surfaceData.ambientOcclusion = SURFACEDATA_BLEND_SCALAR(surfaceData, ambientOcclusion, weights);
surfaceData.metallic = SURFACEDATA_BLEND_SCALAR(surfaceData, metallic, weights);
surfaceData.tangentWS = normalize(input.worldToTangent[0].xyz); // The tangent is not normalize in worldToTangent for mikkt. Tag: SURFACE_GRADIENT
surfaceData.subsurfaceRadius = SURFACEDATA_BLEND_SCALAR(surfaceData, subsurfaceRadius, weights);
surfaceData.thickness = SURFACEDATA_BLEND_SCALAR(surfaceData, thickness, weights);
surfaceData.subsurfaceProfile = SURFACEDATA_BLEND_SSS_PROFILE(surfaceData, subsurfaceProfile, weights);
// Layered shader support either SSS or standard (can't mix them)
#ifdef _MATID_SSS
surfaceData.materialId = MATERIALID_LIT_SSS;
#else // Default
surfaceData.materialId = MATERIALID_LIT_STANDARD;
#endif
surfaceData.materialId = 1; // MaterialId.LitStandard
surfaceData.subsurfaceRadius = 1.0;
surfaceData.thickness = 0.0;
surfaceData.subsurfaceProfile = 0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.coatNormalWS = float3(0.0, 0.0, 0.0);
surfaceData.coatCoverage = 0.0f;

27
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


#endif
surfaceData.metallic *= ADD_IDX(_Metallic);
surfaceData.subsurfaceProfile = ADD_IDX(_SubsurfaceProfile);
surfaceData.subsurfaceRadius = ADD_IDX(_SubsurfaceRadius);
surfaceData.thickness = ADD_IDX(_Thickness);
#ifdef _SUBSURFACE_RADIUS_MAP_IDX
surfaceData.subsurfaceRadius *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_SubsurfaceRadiusMap), SAMPLER_SUBSURFACE_RADIUSMAP_IDX, ADD_IDX(layerTexCoord.base)).r;
#endif
#ifdef _THICKNESSMAP_IDX
surfaceData.thickness *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_ThicknessMap), SAMPLER_THICKNESSMAP_IDX, ADD_IDX(layerTexCoord.base)).r;
#endif
// This part of the code is not used in case of layered shader but we keep the same macro system for simplicity
#if !defined(LAYERED_LIT_SHADER)

#endif
surfaceData.anisotropy *= ADD_IDX(_Anisotropy);
surfaceData.subsurfaceProfile = _SubsurfaceProfile;
surfaceData.subsurfaceRadius = _SubsurfaceRadius;
surfaceData.thickness = _Thickness;
#ifdef _SUBSURFACE_RADIUS_MAP
surfaceData.subsurfaceRadius *= SAMPLE_UVMAPPING_TEXTURE2D(_SubsurfaceRadiusMap, sampler_SubsurfaceRadiusMap, layerTexCoord.base).r;
#endif
#ifdef _THICKNESSMAP
surfaceData.thickness *= SAMPLE_UVMAPPING_TEXTURE2D(_ThicknessMap, sampler_ThicknessMap, layerTexCoord.base).r;
#endif
surfaceData.specularColor = _SpecularColor.rgb;
#ifdef _SPECULARCOLORMAP
surfaceData.specularColor *= SAMPLE_UVMAPPING_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, layerTexCoord.base).rgb;

// Note: any parameters set here must also be set in GetSurfaceAndBuiltinData() layer version
surfaceData.tangentWS = float3(0.0, 0.0, 0.0);
surfaceData.anisotropy = 0.0;
surfaceData.subsurfaceRadius = 0.0;
surfaceData.thickness = 0.0;
surfaceData.subsurfaceProfile = 0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.coatNormalWS = float3(0.0, 0.0, 0.0);
surfaceData.coatCoverage = 0.0f;

9
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl


PROP_DECL_TEX2D(_BentNormalMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL_TEX2D(_NormalMapOS);
PROP_DECL_TEX2D(_DetailMap);
PROP_DECL_TEX2D(_DetailMap);
PROP_DECL_TEX2D(_SubsurfaceRadiusMap);
PROP_DECL_TEX2D(_ThicknessMap);
TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);

PROP_DECL(float, _HeightAmplitude);
PROP_DECL(float, _HeightCenter);
PROP_DECL(int, _SubsurfaceProfile);
PROP_DECL(float, _SubsurfaceRadius);
PROP_DECL(float, _Thickness);
PROP_DECL(float, _OpacityAsDensity);
float _InheritBaseNormal1;

正在加载...
取消
保存