浏览代码

Merge pull request #1747 from Unity-Technologies/Decal-compilation

Decal shader stripping and upgrade script + fix
/main
GitHub 7 年前
当前提交
b57e1824
共有 33 个文件被更改,包括 261 次插入344 次删除
  1. 2
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  2. 16
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/BaseShaderPreprocessor.cs
  3. 8
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  4. 12
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs
  5. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/FrameSettingsUI.cs
  6. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs
  7. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs
  8. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs
  9. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs
  10. 278
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs
  11. 7
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset
  12. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs
  13. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs
  14. 67
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl
  15. 21
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.hlsl
  16. 5
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  17. 13
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl
  18. 21
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderVariablesDecal.hlsl
  19. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader
  20. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitData.hlsl
  21. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  22. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader
  23. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitData.hlsl
  24. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader
  25. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Material.hlsl
  26. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  27. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/Unlit.shader
  28. 37
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  29. 2
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  30. 16
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/FrameSettings.cs
  31. 3
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs
  32. 18
      com.unity.render-pipelines.high-definition/HDRP/ShaderVariables.hlsl
  33. 8
      com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering.meta

2
com.unity.render-pipelines.high-definition/CHANGELOG.md


### Changed
- Movde Render Pipeline Debug "Windows from Windows->General-> Render Pipeline debug windows" to "Windows from Windows->Analysis-> Render Pipeline debug windows"
- Update detail map formula for smoothness and albedo, goal it to bright and dark perceptually and scale factor is use to control gradient speed
- Refactor the Upgrade material system. Now a material can be update from older version at any time. Call Edit/Render Pipeline/Upgrade all Materials to newer version
- Change name EnableDBuffer to EnableDecals at several place (shader, hdrp asset...), this require a call to Edit/Render Pipeline/Upgrade all Materials to newer version to have up to date material.
### Added
- Added support for RendererPriority on Renderer. This allow to control order of transparent rendering manually. HDRP have now two stage of sorting for transparent in addition to bact to front. Material have a priority then Renderer have a priority.

16
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/BaseShaderPreprocessor.cs


protected ShaderKeyword m_TileLighting;
protected ShaderKeyword m_ClusterLighting;
protected ShaderKeyword m_LodFadeCrossFade;
protected ShaderKeyword m_Decals3RT;
protected ShaderKeyword m_Decals4RT;
public BaseShaderPreprocessor()
{

m_ClusterLighting = new ShaderKeyword("USE_CLUSTERED_LIGHTLIST");
m_LodFadeCrossFade = new ShaderKeyword("LOD_FADE_CROSSFADE");
m_Decals3RT = new ShaderKeyword("_DECALS_3RT");
m_Decals4RT = new ShaderKeyword("_DECALS_4RT");
}
public virtual void AddStripperFuncs(Dictionary<string, VariantStrippingFunc> stripperFuncs) {}

return true;
if (inputData.shaderKeywordSet.IsEnabled(m_LodFadeCrossFade) && !hdrpAsset.renderPipelineSettings.supportDitheringCrossFade)
return true;
// Decal case
// If no decal, remove decal variant
if ((inputData.shaderKeywordSet.IsEnabled(m_Decals3RT) || inputData.shaderKeywordSet.IsEnabled(m_Decals4RT)) && !hdrpAsset.renderPipelineSettings.supportDecals)
return true;
// If decal but with 4RT remove 3RT variant and vice versa
if (inputData.shaderKeywordSet.IsEnabled(m_Decals3RT) && hdrpAsset.renderPipelineSettings.decalSettings.perChannelMask)
return true;
if (inputData.shaderKeywordSet.IsEnabled(m_Decals4RT) && !hdrpAsset.renderPipelineSettings.decalSettings.perChannelMask)
return true;
return false;

8
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs


if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) && (maskmapSmoothness.floatValue == 0.0f))
maskmapSmoothness.floatValue = 1.0f;
maskBlendFlags = 0; // Re-init the mask
if (maskmapMetal.floatValue == 1.0f)
maskBlendFlags |= Decal.MaskBlendFlags.Metal;
if (maskmapAO.floatValue == 1.0f)

}
else // if perChannelMask is not enabled, force to have smoothness
{
maskBlendFlags = Decal.MaskBlendFlags.Smoothness;
}
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
EditorGUI.indentLevel--;

12
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs


public static GUIContent windShiverDragText = new GUIContent("Shiver Drag");
public static GUIContent windShiverDirectionalityText = new GUIContent("Shiver Directionality");
public static GUIContent supportDBufferText = new GUIContent("Enable Decal", "Allow to specify if the material can receive decal or not");
public static GUIContent supportDecalsText = new GUIContent("Enable Decal", "Allow to specify if the material can receive decal or not");
public static GUIContent enableGeometricSpecularAAText = new GUIContent("Enable geometric specular AA", "This reduce specular aliasing on highly dense mesh (Particularly useful when they don't use normal map)");
public static GUIContent specularAAScreenSpaceVarianceText = new GUIContent("Screen space variance", "Allow to control the strength of the specular AA reduction. Higher mean more blurry result and less aliasing");

protected const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon";
// Decal
protected MaterialProperty supportDBuffer = null;
protected const string kSupportDBuffer = "_SupportDBuffer";
protected MaterialProperty supportDecals = null;
protected const string kSupportDecals = "_SupportDecals";
protected MaterialProperty enableGeometricSpecularAA = null;
protected const string kEnableGeometricSpecularAA = "_EnableGeometricSpecularAA";
protected MaterialProperty specularAAScreenSpaceVariance = null;

windShiverDirectionality = FindProperty(kWindShiverDirectionality, props);
// Decal
supportDBuffer = FindProperty(kSupportDBuffer, props);
supportDecals = FindProperty(kSupportDecals, props);
// specular AA
enableGeometricSpecularAA = FindProperty(kEnableGeometricSpecularAA, props, false);

EditorGUI.indentLevel--;
}
m_MaterialEditor.ShaderProperty(supportDBuffer, StylesBaseLit.supportDBufferText);
m_MaterialEditor.ShaderProperty(supportDecals, StylesBaseLit.supportDecalsText);
m_MaterialEditor.ShaderProperty(enableGeometricSpecularAA, StylesBaseLit.enableGeometricSpecularAAText);

SetupMainTexForAlphaTestGI("_BaseColorMap", "_BaseColor", material);
// Use negation so we don't create keyword by default
CoreUtils.SetKeyword(material, "_DISABLE_DBUFFER", material.GetFloat(kSupportDBuffer) == 0.0);
CoreUtils.SetKeyword(material, "_DISABLE_DECALS", material.GetFloat(kSupportDecals) == 0.0);
CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.GetFloat(kEnableGeometricSpecularAA) == 1.0);
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/FrameSettingsUI.cs


EditorGUILayout.PropertyField(p.enableTransparentPostpass, _.GetContent("Enable Transparent Postpass"));
EditorGUILayout.PropertyField(p.enableMotionVectors, _.GetContent("Enable Motion Vectors"));
EditorGUILayout.PropertyField(p.enableObjectMotionVectors, _.GetContent("Enable Object Motion Vectors"));
EditorGUILayout.PropertyField(p.enableDBuffer, _.GetContent("Enable DBuffer"));
EditorGUILayout.PropertyField(p.enableDecals, _.GetContent("Enable DBuffer"));
EditorGUILayout.PropertyField(p.enableRoughRefraction, _.GetContent("Enable Rough Refraction"));
EditorGUILayout.PropertyField(p.enableDistortion, _.GetContent("Enable Distortion"));
EditorGUILayout.PropertyField(p.enablePostprocess, _.GetContent("Enable Postprocess"));

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs


EditorGUILayout.PropertyField(d.supportShadowMask, _.GetContent("Support Shadow Mask|Enable memory (Extra Gbuffer in deferred) and shader variant for shadow mask."));
EditorGUILayout.PropertyField(d.supportSSR, _.GetContent("Support SSR|Enable memory use by SSR effect."));
EditorGUILayout.PropertyField(d.supportSSAO, _.GetContent("Support SSAO|Enable memory use by SSAO effect."));
EditorGUILayout.PropertyField(d.supportDBuffer, _.GetContent("Support Decal Buffer|Enable memory and variant of decal buffer."));
EditorGUILayout.PropertyField(d.supportDecals, _.GetContent("Support Decals|Enable memory and variant for decals buffer and cluster decals"));
// TODO: Implement MSAA - Hide for now as it doesn't work
//EditorGUILayout.PropertyField(d.supportMSAA, _.GetContent("Support Multi Sampling Anti-Aliasing|This feature doesn't work currently."));
//EditorGUILayout.PropertyField(d.MSAASampleCount, _.GetContent("MSAA Sample Count|Allow to select the level of MSAA."));

4
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs


public SerializedProperty enableTransparentPrepass;
public SerializedProperty enableMotionVectors;
public SerializedProperty enableObjectMotionVectors;
public SerializedProperty enableDBuffer;
public SerializedProperty enableDecals;
public SerializedProperty enableRoughRefraction;
public SerializedProperty enableTransparentPostpass;
public SerializedProperty enableDistortion;

enableTransparentPrepass = root.Find((FrameSettings d) => d.enableTransparentPrepass);
enableMotionVectors = root.Find((FrameSettings d) => d.enableMotionVectors);
enableObjectMotionVectors = root.Find((FrameSettings d) => d.enableObjectMotionVectors);
enableDBuffer = root.Find((FrameSettings d) => d.enableDBuffer);
enableDecals = root.Find((FrameSettings d) => d.enableDecals);
enableRoughRefraction = root.Find((FrameSettings d) => d.enableRoughRefraction);
enableTransparentPostpass = root.Find((FrameSettings d) => d.enableTransparentPostpass);
enableDistortion = root.Find((FrameSettings d) => d.enableDistortion);

4
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs


public SerializedProperty supportShadowMask;
public SerializedProperty supportSSR;
public SerializedProperty supportSSAO;
public SerializedProperty supportDBuffer;
public SerializedProperty supportDecals;
public SerializedProperty supportMSAA;
public SerializedProperty MSAASampleCount;
public SerializedProperty supportSubsurfaceScattering;

supportShadowMask = root.Find((RenderPipelineSettings s) => s.supportShadowMask);
supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR);
supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO);
supportDBuffer = root.Find((RenderPipelineSettings s) => s.supportDBuffer);
supportDecals = root.Find((RenderPipelineSettings s) => s.supportDecals);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering);

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs


[InitializeOnLoad]
public class HDRPVersion
{
// 1 changed emissive color
// 2 add decal mode in decal material
static public int hdrpVersion = 2;
static public int hdrpVersion = 1;
static public int GetCurrentHDRPProjectVersion()
{

278
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs


{
public class UpgradeMenuItems
{
// Remove a set of variables from the text file target by path
static void UpdateMaterialFile_RemoveLines(string path, string[] variableNames)
{
string[] readText = File.ReadAllLines(path);
List<string> writeText = new List<string>();
//[MenuItem("Internal/HDRenderPipeline/Update/Update material for subsurface")]
static void UpdateMaterialForSubsurface()
{
try
foreach (string line in readText)
var matIds = AssetDatabase.FindAssets("t:Material");
bool found = false;
for (int i = 0, length = matIds.Length; i < length; i++)
foreach (string str in variableNames)
var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
var mat = AssetDatabase.LoadAssetAtPath<Material>(path);
EditorUtility.DisplayProgressBar(
"Setup materials Keywords...",
string.Format("{0} / {1} materials subsurface updated.", i, length),
i / (float)(length - 1));
bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);
if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
mat.shader.name == "HDRenderPipeline/Lit" ||
mat.shader.name == "HDRenderPipeline/LayeredLit" ||
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
if (line.Contains(str))
float materialID = mat.GetInt("_MaterialID");
if (materialID != 0.0)
continue;
if (mat.HasProperty("_SSSAndTransmissionType"))
{
CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
found = true;
}
}
int materialSSSAndTransmissionID = mat.GetInt("_SSSAndTransmissionType");
if (!found)
writeText.Add(line);
}
// Both;, SSS only, Transmission only
if (materialSSSAndTransmissionID == 2.0)
{
mat.SetInt("_MaterialID", 5);
}
else
{
if (materialSSSAndTransmissionID == 0.0)
mat.SetFloat("_TransmissionEnable", 1.0f);
else
mat.SetFloat("_TransmissionEnable", 0.0f);
}
File.WriteAllLines(path, writeText.ToArray());
EditorUtility.SetDirty(mat);
}
}
}
}
finally
{
EditorUtility.ClearProgressBar();
}
return;
//[MenuItem("Internal/HDRenderPipeline/Update/Update Height Maps parametrization")]
static void UpdateHeightMapParametrization()
// It is a pity but if we call mat.GetFloat("_hdrpVersion"), this return the default value
// if the _hdrpVersion was not written. So older material that haven't been updated can't be detected.
// so for now we must check for _hdrpVersion in the .txt
// maybe in a far future we can rely on just mat.GetFloat("_hdrpVersion")
static float UpdateMaterial_GetVersion(string path, Material mat)
try
{
var matIds = AssetDatabase.FindAssets("t:Material");
// Find the missing property in the file and update EmissiveColor
string[] readText = File.ReadAllLines(path);
for (int i = 0, length = matIds.Length; i < length; i++)
foreach (string line in readText)
{
if (line.Contains("_HdrpVersion:"))
var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
var mat = AssetDatabase.LoadAssetAtPath<Material>(path);
EditorUtility.DisplayProgressBar(
"Updating Materials...",
string.Format("{0} / {1} materials updated.", i, length),
i / (float)(length - 1));
bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);
if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
mat.shader.name == "HDRenderPipeline/Lit")
{
// Need only test one of the new properties
if (mat.HasProperty("_HeightPoMAmplitude"))
{
CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
float valueMax = mat.GetFloat("_HeightMax");
float valueMin = mat.GetFloat("_HeightMin");
float center = mat.GetFloat("_HeightCenter");
float amplitude = valueMax - valueMin;
mat.SetInt("_HeightMapParametrization", 1);
mat.SetFloat("_HeightPoMAmplitude", amplitude);
mat.SetFloat("_HeightTessAmplitude", amplitude);
mat.SetFloat("_HeightOffset", 0.0f);
mat.SetFloat("_HeightTessCenter", center);
BaseLitGUI.DisplacementMode displaceMode = (BaseLitGUI.DisplacementMode)mat.GetInt("_DisplacementMode");
if (displaceMode == BaseLitGUI.DisplacementMode.Pixel)
{
mat.SetFloat("_HeightCenter", 1.0f); // With PoM this is always 1.0f. We set it here to avoid having to open the UI to update it.
}
EditorUtility.SetDirty(mat);
}
}
else if (mat.shader.name == "HDRenderPipeline/LayeredLit" ||
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
{
int numLayer = (int)mat.GetFloat("_LayerCount");
if (mat.HasProperty("_HeightPoMAmplitude0"))
{
CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
for (int x = 0; x < numLayer; ++x)
{
float valueMax = mat.GetFloat("_HeightMax" + x);
float valueMin = mat.GetFloat("_HeightMin" + x);
float center = mat.GetFloat("_HeightCenter" + x);
float amplitude = valueMax - valueMin;
mat.SetInt("_HeightMapParametrization" + x, 1);
mat.SetFloat("_HeightPoMAmplitude" + x, amplitude);
mat.SetFloat("_HeightTessAmplitude" + x, amplitude);
mat.SetFloat("_HeightOffset" + x, 0.0f);
mat.SetFloat("_HeightTessCenter" + x, center);
int startPos = line.IndexOf(":") + 1;
string sub = line.Substring(startPos);
return float.Parse(sub);
}
}
BaseLitGUI.DisplacementMode displaceMode = (BaseLitGUI.DisplacementMode)mat.GetInt("_DisplacementMode");
if (displaceMode == BaseLitGUI.DisplacementMode.Pixel)
{
mat.SetFloat("_HeightCenter" + x, 1.0f); // With PoM this is always 1.0f. We set it here to avoid having to open the UI to update it.
}
}
// When _HdrpVersion don't exist we MUST create it, otherwise next call to
// mat.SetFloat("_HdrpVersion", value) will just put the default value instead of the value we pass!
// a call to GetFloat("_HdrpVersion") solve this.
float useless = mat.GetFloat("_HdrpVersion");
EditorUtility.SetDirty(mat);
}
}
}
}
finally
{
EditorUtility.ClearProgressBar();
}
return 0.0f;
// Version 1
static bool UpdateMaterial_EmissiveColor(string path, Material mat)
static bool UpdateMaterial_EmissiveColor_1(string path, Material mat)
{
// Find the missing property in the file and update EmissiveColor
string[] readText = File.ReadAllLines(path);

return false;
}
static void UpdateMaterialFile_EmissiveColor(string path)
static void UpdateMaterialFile_EmissiveColor_1(string path)
string[] readText = File.ReadAllLines(path);
foreach (string line in readText)
{
if (line.Contains("_EmissiveIntensity:"))
{
// Remove emissive intensity line
string[] writeText = readText.Where(l => l != line).ToArray();
File.WriteAllLines(path, writeText);
return;
}
}
return;
string[] variablesNames = new string[1];
variablesNames[0] = "_EmissiveIntensity:";
UpdateMaterialFile_RemoveLines(path, variablesNames);
// Version 2
static bool UpdateMaterial_DecalBlendMode(string path, Material mat)
// Also we have rename _SupportDBuffer to _SupportDecals
static bool UpdateMaterial_Decals_2(string path, Material mat)
bool dirty = false;
if (mat.shader.name == "HDRenderPipeline/Decal")
{
float maskBlendMode = mat.GetFloat("_MaskBlendMode");

mat.SetFloat("_MaskBlendMode", (float)Decal.MaskBlendFlags.Smoothness);
return true;
dirty = true;
}
}
else
{
// Find the missing property in the file and update EmissiveColor
string[] readText = File.ReadAllLines(path);
foreach (string line in readText)
{
if (line.Contains("_SupportDBuffer:"))
{
int startPos = line.IndexOf(":") + 1;
string sub = line.Substring(startPos);
float enableDecal = float.Parse(sub);
mat.SetFloat("_SupportDecals", enableDecal);
// Decal need to also update keywords _DISABLE_DECALS
HDEditorUtils.ResetMaterialKeywords(mat);
dirty = true;
}
return false;
return dirty;
}
static void UpdateMaterialFile_Decals_2(string path)
{
string[] variablesNames = new string[1];
variablesNames[0] = "_SupportDBuffer:";
UpdateMaterialFile_RemoveLines(path, variablesNames);
static void UpdateMaterialToNewerVersion(string caption, UpdateMaterial updateMaterial, UpdateMaterialFile updateMaterialFile = null)
static void UpdateMaterialToNewerVersion(string caption, float scriptVersion, UpdateMaterial updateMaterial, UpdateMaterialFile updateMaterialFile = null)
{
bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);
var matIds = AssetDatabase.FindAssets("t:Material");

mat.shader.name == "HDRenderPipeline/Decal"
)
{
// Need to be processed in order - All function here should be re-entrant (i.e after upgrade it can be recall)
bool dirty = updateMaterial(path, mat);
// Get current version
float materialVersion = UpdateMaterial_GetVersion(path, mat);
if (dirty)
if (materialVersion < scriptVersion)
updateMaterial(path, mat);
// Update version number to script number (so next script can upgrade correctly)
mat.SetFloat("_HdrpVersion", scriptVersion);
// Checkout the file and tag it as dirty
CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
EditorUtility.SetDirty(mat);

}
}
[MenuItem("Edit/Render Pipeline/Single step upgrade script/Upgrade all Materials EmissionColor", priority = CoreUtils.editMenuPriority3)]
static public void UpdateMaterialToNewerVersionEmissiveColor()
[MenuItem("Edit/Render Pipeline/Upgrade all Materials to newer version", priority = CoreUtils.editMenuPriority3)]
static public void UpdateMaterialToNewerVersion()
UpdateMaterialToNewerVersion("(EmissiveColor)", UpdateMaterial_EmissiveColor, UpdateMaterialFile_EmissiveColor);
}
// TODO: We need to handle material that are embed inside scene!
[MenuItem("Edit/Render Pipeline/Single step upgrade script/Upgrade all DecalMaterial MaskBlendMode", priority = CoreUtils.editMenuPriority3)]
static public void UpdateMaterialToNewerVersionDecalMaterialMaskBlendMode()
{
UpdateMaterialToNewerVersion("(DecalMaterial)", UpdateMaterial_DecalBlendMode);
}
[MenuItem("Edit/Render Pipeline/Upgrade all Materials to latest version", priority = CoreUtils.editMenuPriority3)]
static public void UpdateMaterialToNewerVersion()
{
// Add here all the material upgrade function supported in this version
// Caution: All the functions here MUST be re-entrant (call multiple time) without failing.
// Add here all the material upgrade functions
// Note: This is a slow path as we go through all files for each script + update the version number after each script execution,
// but it is the safest way to do it currently for incremental upgrade
// Caution: When calling SaveAsset, Unity will update the material with latest addition at the same time, so for example
// unity can add a supportDecal when executing script for version 1 whereas they only appear in version 2 because it is now part
// of the shader. Most of the time this have no consequence, but we never know.
UpdateMaterialToNewerVersion("(EmissiveColor_1)", 1.0f, UpdateMaterial_EmissiveColor_1, UpdateMaterialFile_EmissiveColor_1);
UpdateMaterialToNewerVersion("(Decals_2)", 2.0f, UpdateMaterial_Decals_2, UpdateMaterialFile_Decals_2);
int currentVersion = HDRPVersion.GetCurrentHDRPProjectVersion();
if (currentVersion < 1)
{
// Appear in hdrp version 1.0
UpdateMaterialToNewerVersion("(EmissiveColor)", UpdateMaterial_EmissiveColor, UpdateMaterialFile_EmissiveColor);
}
if (currentVersion < 2)
{
// Appear in hdrp version 2.0
UpdateMaterialToNewerVersion("(DecalMaterial)", UpdateMaterial_DecalBlendMode);
}
// Caution: Version of latest script and default version in all HDRP shader must match
}
}
}

7
com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset


m_Script: {fileID: 11500000, guid: 0cf1dab834d4ec34195b920ea7bbf9ec, type: 3}
m_Name: HDRenderPipelineAsset
m_EditorClassIdentifier:
version: 1
m_Version: 1
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7, type: 2}
m_FrameSettings:
enableShadow: 1

enableTransparentPrepass: 1
enableMotionVectors: 1
enableObjectMotionVectors: 1
enableDBuffer: 1
enableDecals: 1
enableRoughRefraction: 1
enableTransparentPostpass: 1
enableDistortion: 1

increaseResolutionOfVolumetrics: 0
supportRuntimeDebugDisplay: 1
supportDitheringCrossFade: 1
supportDBuffer: 1
supportDecals: 1
supportMSAA: 0
msaaSampleCount: 1
supportMotionVectors: 1

drawDistance: 1000
atlasWidth: 4096
atlasHeight: 4096
perChannelMask: 0
allowShaderVariantStripping: 1
diffusionProfileSettings: {fileID: 11400000, guid: 404820c4cf36ad944862fa59c56064f0, type: 2}

8
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs


{
public class DBufferManager : MRTBufferManager
{
public bool EnableDBUffer { get; set; }
public bool enableDecals { get; set; }
RTHandleSystem.RTHandle m_HTile;

public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd)
{
if (hdCamera.frameSettings.enableDBuffer)
if (hdCamera.frameSettings.enableDecals)
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, EnableDBUffer ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._EnableDecals, enableDecals ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, 0);
cmd.SetGlobalInt(HDShaderIDs._EnableDecals, 0);
// We still bind black textures to make sure that something is bound (can be a problem on some platforms)
for (int i = 0; i < m_BufferCount; ++i)
{

2
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs


public partial class Decal
{
// Main structure that store the user data (i.e user input of master node in material graph)
[GenerateHLSL(PackingRules.Exact, false, true, 200)]
[GenerateHLSL(PackingRules.Exact, false)]
public struct DecalSurfaceData
{
[SurfaceDataAttributes("Base Color", false, true)]

67
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl


#ifndef DECAL_CS_HLSL
#define DECAL_CS_HLSL
//
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DecalSurfaceData: static fields
//
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_BASE_COLOR (200)
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_NORMAL (201)
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_MASK (202)
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_AOSBLEND (203)
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_HTILE_MASK (204)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DBufferMaterial: static fields
//
#define DBUFFERMATERIAL_COUNT (4)

float4 baseColor;
float3 blendParams;
};
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DecalData
//
float4x4 GetWorldToDecal(DecalData value)
{
return value.worldToDecal;
}
float4x4 GetNormalToWorld(DecalData value)
{
return value.normalToWorld;
}
float4 GetDiffuseScaleBias(DecalData value)
{
return value.diffuseScaleBias;
}
float4 GetNormalScaleBias(DecalData value)
{
return value.normalScaleBias;
}
float4 GetMaskScaleBias(DecalData value)
{
return value.maskScaleBias;
}
float4 GetBaseColor(DecalData value)
{
return value.baseColor;
}
float3 GetBlendParams(DecalData value)
{
return value.blendParams;
}
//
// Debug functions
//
void GetGeneratedDecalSurfaceDataDebug(uint paramId, DecalSurfaceData decalsurfacedata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_DECAL_DECALSURFACEDATA_BASE_COLOR:
result = decalsurfacedata.baseColor.xyz;
needLinearToSRGB = true;
break;
case DEBUGVIEW_DECAL_DECALSURFACEDATA_NORMAL:
result = decalsurfacedata.normalWS.xyz;
break;
case DEBUGVIEW_DECAL_DECALSURFACEDATA_MASK:
result = decalsurfacedata.mask.xyz;
break;
case DEBUGVIEW_DECAL_DECALSURFACEDATA_AOSBLEND:
result = float3(decalsurfacedata.MAOSBlend, 0.0);
break;
case DEBUGVIEW_DECAL_DECALSURFACEDATA_HTILE_MASK:
result = GetIndexColor(decalsurfacedata.HTileMask);
break;
}
}
#endif

21
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.hlsl


#include "CoreRP/ShaderLibrary/Debug.hlsl"
#include "Decal.cs.hlsl"
#define DBufferType0 float4
#define DBufferType1 float4
#define DBufferType2 float4

#endif
UNITY_INSTANCING_BUFFER_START(Decal)
UNITY_DEFINE_INSTANCED_PROP(float4x4, _NormalToWorld)
UNITY_INSTANCING_BUFFER_END(matrix)
RW_TEXTURE2D(float, _DecalHTile); // DXGI_FORMAT_R8_UINT is not supported by Unity
TEXTURE2D(_DecalHTileTexture);
uint _DecalCount;
StructuredBuffer<DecalData> _DecalDatas;
TEXTURE2D_ARRAY(_DecalAtlas);
SAMPLER(sampler_DecalAtlas);
TEXTURE2D(_DecalAtlas2D);
SAMPLER(_trilinear_clamp_sampler_DecalAtlas2D);
// Must be in sync with RT declared in HDRenderPipeline.cs ::Rebuild
void EncodeIntoDBuffer( DecalSurfaceData surfaceData
, out DBufferType0 outDBuffer0

{
ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
surfaceData.baseColor = inDBuffer0;
surfaceData.normalWS.xyz = inDBuffer1.xyz * 2.0f - 1.0f;
surfaceData.normalWS.xyz = inDBuffer1.xyz * 2.0 - 1.0;
surfaceData.normalWS.w = inDBuffer1.w;
surfaceData.mask = inDBuffer2;
#ifdef _DECALS_4RT

5
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
_BaseColor("_BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map

Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
ColorMask BA 2 // smoothness/smoothness alpha
ColorMask 0 3 // Caution: We need to setup the mask to 0 in case perChannelMAsk is enabled as 4 RT are bind
HLSLPROGRAM

Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
ColorMask BA 2 // smoothness/smoothness alpha
ColorMask 0 3 // Caution: We need to setup the mask to 0 in case perChannelMAsk is enabled as 4 RT are bind
HLSLPROGRAM

13
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl


void ApplyBlendDiffuse(inout float4 dst, inout int matMask, float2 texCoords, float4 src, int mapMask, inout float blend, float lod, int diffuseTextureBound)
{
if(diffuseTextureBound)
if (diffuseTextureBound)
{
src *= SAMPLE_TEXTURE2D_LOD(_DecalAtlas2D, _trilinear_clamp_sampler_DecalAtlas2D, texCoords, lod);
}

void AddDecalContribution(PositionInputs posInput, inout SurfaceData surfaceData, inout float alpha)
{
if(_EnableDBuffer)
if (_EnableDecals)
DecalSurfaceData decalSurfaceData;
int mask = 0;
// the code in the macros, gets moved inside the conditionals by the compiler
FETCH_DBUFFER(DBuffer, _DBufferTexture, posInput.positionSS);

#else
mask = UnpackByte(LOAD_TEXTURE2D(_DecalHTileTexture, posInput.positionSS / 8).r);
#endif
DecalSurfaceData decalSurfaceData;
if(mask & DBUFFERHTILEBIT_DIFFUSE)
if (mask & DBUFFERHTILEBIT_DIFFUSE)
if(mask & DBUFFERHTILEBIT_NORMAL)
if (mask & DBUFFERHTILEBIT_NORMAL)
if(mask & DBUFFERHTILEBIT_MASK)
if (mask & DBUFFERHTILEBIT_MASK)
{
#ifdef _DECALS_4RT // only smoothness in 3RT mode
surfaceData.metallic = surfaceData.metallic * decalSurfaceData.MAOSBlend.x + decalSurfaceData.mask.x;

21
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderVariablesDecal.hlsl


#ifdef SHADER_VARIABLES_INCLUDE_CB
uint _EnableDBuffer;
uint _EnableDecals;
uint _DecalCount;
#include "HDRP/Material/Decal//Decal.cs.hlsl"
StructuredBuffer<DecalData> _DecalDatas;
TEXTURE2D_ARRAY(_DecalAtlas);
SAMPLER(sampler_DecalAtlas);
TEXTURE2D(_DecalAtlas2D);
SAMPLER(_trilinear_clamp_sampler_DecalAtlas2D);
RW_TEXTURE2D(float, _DecalHTile); // DXGI_FORMAT_R8_UINT is not supported by Unity
TEXTURE2D(_DecalHTileTexture);
UNITY_INSTANCING_BUFFER_START(Decal)
UNITY_DEFINE_INSTANCED_PROP(float4x4, _NormalToWorld)
UNITY_INSTANCING_BUFFER_END(matrix)
#endif

8
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader


Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

_Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleUI] _SupportDBuffer("Support DBuffer", Float) = 1.0
[ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
}
HLSLINCLUDE

#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _DISABLE_DECALS
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent

#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_4RT
#pragma multi_compile _ _DECALS_3RT _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

2
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitData.hlsl


surfaceData.specularOcclusion = 1.0;
#endif
#ifndef _DISABLE_DBUFFER
#if HAVE_DECALS
AddDecalContribution(posInput, surfaceData, alpha);
#endif

8
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader


Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

_Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleUI] _SupportDBuffer("Support DBuffer", Float) = 1.0
[ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
}
HLSLINCLUDE

#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _DISABLE_DECALS
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent

#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_4RT
#pragma multi_compile _ _DECALS_3RT _DECALS_4RT
// enable GPU instancing
#pragma multi_compile_instancing

8
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader


Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

_Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleUI] _SupportDBuffer("Support DBuffer", Float) = 1.0
[ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
}
HLSLINCLUDE

#pragma shader_feature _SPECULARCOLORMAP
#pragma shader_feature _TRANSMITTANCECOLORMAP
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _DISABLE_DECALS
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent

#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_4RT
#pragma multi_compile _ _DECALS_3RT _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

2
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitData.hlsl


// This is use with anisotropic material
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
#ifndef _DISABLE_DBUFFER
#if HAVE_DECALS
AddDecalContribution(posInput, surfaceData, alpha);
#endif

8
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader


Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

_Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleUI] _SupportDBuffer("Support DBuffer", Float) = 1.0
[ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
}
HLSLINCLUDE

#pragma shader_feature _SPECULARCOLORMAP
#pragma shader_feature _TRANSMITTANCECOLORMAP
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _DISABLE_DECALS
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent

#pragma multi_compile _ LOD_FADE_CROSSFADE
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_4RT
#pragma multi_compile _ _DECALS_3RT _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

3
com.unity.render-pipelines.high-definition/HDRP/Material/Material.hlsl


// - _BLENDMODE_ALPHA, _BLENDMODE_ADD, _BLENDMODE_PRE_MULTIPLY for blend mode
// - _BLENDMODE_PRESERVE_SPECULAR_LIGHTING for correct lighting when blend mode are use with a Lit material
// - _ENABLE_FOG_ON_TRANSPARENT if fog is enable on transparent surface
// - _DISABLE_DECALS if the material don't support decals
#define HAVE_DECALS ( (defined(_DECALS_3RT) || defined(_DECALS_4RT)) && !defined(_DISABLE_DECALS) )
//-----------------------------------------------------------------------------
// ApplyBlendMode function

4
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader


Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

#pragma shader_feature _STACKLIT_DEBUG
// decal 3RT or 4RT toggle
#pragma multi_compile _ _DECALS_4RT
#pragma multi_compile _ _DECALS_3RT _DECALS_4RT
//enable GPU instancing support
#pragma multi_compile_instancing

2
com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/Unlit.shader


Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 2
// Be careful, do not change the name here to _Color. It will conflict with the "fake" parameters (see end of properties) required for GI.
_UnlitColor("Color", Color) = (1,1,1,1)

37
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs


if (!m_Asset.renderPipelineSettings.supportOnlyForward)
m_GbufferManager.CreateBuffers();
if (m_Asset.renderPipelineSettings.supportDBuffer)
if (m_Asset.renderPipelineSettings.supportDecals)
m_DbufferManager.CreateBuffers();
m_SSSBufferManager.InitSSSBuffers(m_GbufferManager, m_Asset.renderPipelineSettings);

m_currentDebugViewMaterialGBuffer = enableBakeShadowMask ? m_DebugViewMaterialGBufferShadowMask : m_DebugViewMaterialGBuffer;
}
public void ConfigureForDecal(CommandBuffer cmd)
{
if (m_Asset.renderPipelineSettings.supportDecals)
{
CoreUtils.SetKeyword(cmd, "_DECALS_3RT", !m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask);
CoreUtils.SetKeyword(cmd, "_DECALS_4RT", m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask);
}
else
{
CoreUtils.SetKeyword(cmd, "_DECALS_3RT", false);
CoreUtils.SetKeyword(cmd, "_DECALS_4RT", false);
}
}
CullResults m_CullResults;
ReflectionProbeCullResults m_ReflectionProbeCullResults;
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)

}
#endif
if (hdCamera.frameSettings.enableDBuffer)
if (hdCamera.frameSettings.enableDecals)
{
// decal system needs to be updated with current camera, it needs it to set up culling and light list generation parameters
DecalSystem.instance.CurrentCamera = camera;

m_ReflectionProbeCullResults.Cull();
m_DbufferManager.EnableDBUffer = false;
using (new ProfilingSample(cmd, "DBufferPrepareDrawData", CustomSamplerId.DBufferPrepareDrawData.GetSampler()))
m_DbufferManager.enableDecals = false;
if (hdCamera.frameSettings.enableDecals)
if (hdCamera.frameSettings.enableDBuffer)
using (new ProfilingSample(cmd, "DBufferPrepareDrawData", CustomSamplerId.DBufferPrepareDrawData.GetSampler()))
m_DbufferManager.EnableDBUffer = true; // mesh decals are renderers managed by c++ runtime and we have no way to query if any are visible, so set to true
m_DbufferManager.enableDecals = true; // mesh decals are renderers managed by c++ runtime and we have no way to query if any are visible, so set to true
DecalSystem.instance.UpdateCachedMaterialData(); // textures, alpha or fade distances could've changed
DecalSystem.instance.CreateDrawData(); // prepare data is separate from draw
DecalSystem.instance.UpdateTextureAtlas(cmd); // as this is only used for transparent pass, would've been nice not to have to do this if no transparent renderers are visible, needs to happen after CreateDrawData

enableBakeShadowMask = m_LightLoop.PrepareLightsForGPU(cmd, hdCamera, m_ShadowSettings, m_CullResults, m_ReflectionProbeCullResults, densityVolumes);
}
ConfigureForShadowMask(enableBakeShadowMask, cmd);
ConfigureForDecal(cmd);
StartStereoRendering(renderContext, hdCamera);

}
}
// If we enable DBuffer, we need a full depth prepass
else if (hdCamera.frameSettings.enableDepthPrepassWithDeferredRendering || m_DbufferManager.EnableDBUffer)
else if (hdCamera.frameSettings.enableDepthPrepassWithDeferredRendering || m_DbufferManager.enableDecals)
using (new ProfilingSample(cmd, m_DbufferManager.EnableDBUffer ? "Depth Prepass (deferred) force by DBuffer" : "Depth Prepass (deferred)", CustomSamplerId.DepthPrepass.GetSampler()))
using (new ProfilingSample(cmd, m_DbufferManager.enableDecals ? "Depth Prepass (deferred) force by Decals" : "Depth Prepass (deferred)", CustomSamplerId.DepthPrepass.GetSampler()))
{
cmd.DisableShaderKeyword("WRITE_NORMAL_BUFFER"); // Note: This only disable the output of normal buffer for Lit shader, not the other shader that don't use multicompile

void RenderDBuffer(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, CullResults cullResults)
{
if (!hdCamera.frameSettings.enableDBuffer)
if (!hdCamera.frameSettings.enableDecals)
return;
using (new ProfilingSample(cmd, "DBufferRender", CustomSamplerId.DBufferRender.GetSampler()))

{
renderQueueRange = HDRenderQueue.k_RenderQueue_AllOpaque
};
CoreUtils.SetKeyword(cmd, "_DECALS_4RT", m_Asset.GetRenderPipelineSettings().decalSettings.perChannelMask);
renderContext.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, filterRenderersSettings);
DecalSystem.instance.RenderIntoDBuffer(cmd);

else
{
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraColorBuffer, m_CameraDepthStencilBuffer);
if ((hdCamera.frameSettings.enableDBuffer) && (DecalSystem.m_DecalDatasCount > 0)) // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered
if ((hdCamera.frameSettings.enableDecals) && (DecalSystem.m_DecalDatasCount > 0)) // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered
// decal datas count is 0 if no decals affect transparency
{
DecalSystem.instance.SetAtlas(cmd); // for clustered decals

2
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _CameraFilteringBuffer = Shader.PropertyToID("_CameraFilteringTexture");
public static readonly int _IrradianceSource = Shader.PropertyToID("_IrradianceSource");
public static readonly int _EnableDBuffer = Shader.PropertyToID("_EnableDBuffer");
public static readonly int _EnableDecals = Shader.PropertyToID("_EnableDecals");
public static readonly int _DecalAtlasResolution = Shader.PropertyToID("_DecalAtlasResolution");
public static readonly int[] _GBufferTexture =

16
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/FrameSettings.cs


using System;
using System.Collections.Generic;
using UnityEngine.XR;
using UnityEngine.Serialization;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public bool enableTransparentPrepass = true;
public bool enableMotionVectors = true; // Enable/disable whole motion vectors pass (Camera + Object).
public bool enableObjectMotionVectors = true;
public bool enableDBuffer = true;
[FormerlySerializedAs("enableDBuffer")]
public bool enableDecals = true;
public bool enableRoughRefraction = true; // Depends on DepthPyramid - If not enable, just do a copy of the scene color (?) - how to disable rough refraction ?
public bool enableTransparentPostpass = true;
public bool enableDistortion = true;

frameSettings.enableTransparentPrepass = this.enableTransparentPrepass;
frameSettings.enableMotionVectors = this.enableMotionVectors;
frameSettings.enableObjectMotionVectors = this.enableObjectMotionVectors;
frameSettings.enableDBuffer = this.enableDBuffer;
frameSettings.enableDecals = this.enableDecals;
frameSettings.enableRoughRefraction = this.enableRoughRefraction;
frameSettings.enableTransparentPostpass = this.enableTransparentPostpass;
frameSettings.enableDistortion = this.enableDistortion;

aggregate.enableTransparentPrepass = srcFrameSettings.enableTransparentPrepass;
aggregate.enableMotionVectors = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableMotionVectors && renderPipelineSettings.supportMotionVectors;
aggregate.enableObjectMotionVectors = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableObjectMotionVectors && renderPipelineSettings.supportMotionVectors;
aggregate.enableDBuffer = srcFrameSettings.enableDBuffer && renderPipelineSettings.supportDBuffer;
aggregate.enableDecals = srcFrameSettings.enableDecals && renderPipelineSettings.supportDecals;
aggregate.enableRoughRefraction = srcFrameSettings.enableRoughRefraction;
aggregate.enableTransparentPostpass = srcFrameSettings.enableTransparentPostpass;
aggregate.enableDistortion = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableDistortion;

aggregate.enableTransparentPrepass = false;
aggregate.enableMotionVectors = false;
aggregate.enableObjectMotionVectors = false;
aggregate.enableDBuffer = false;
aggregate.enableDecals = false;
aggregate.enableTransparentPostpass = false;
aggregate.enableDistortion = false;
aggregate.enablePostprocess = false;

enableMotionVectors = false;
// TODO: The work will be implemented piecemeal to support all passes
enableDBuffer = false; // no decals
enableDecals = false; // no decals
enableDistortion = false; // no gaussian final color
enablePostprocess = false;
enableRoughRefraction = false; // no gaussian pre-refraction

// TODO: The work will be implemented piecemeal to support all passes
enableMotionVectors = false;
enableDBuffer = false;
enableDecals = false;
enableDistortion = false;
enablePostprocess = false;
enableRoughRefraction = false;

new DebugUI.BoolField { displayName = "Enable Transparent Postpass", getter = () => frameSettings.enableTransparentPostpass, setter = value => frameSettings.enableTransparentPostpass = value },
new DebugUI.BoolField { displayName = "Enable Motion Vectors", getter = () => frameSettings.enableMotionVectors, setter = value => frameSettings.enableMotionVectors = value },
new DebugUI.BoolField { displayName = "Enable Object Motion Vectors", getter = () => frameSettings.enableObjectMotionVectors, setter = value => frameSettings.enableObjectMotionVectors = value },
new DebugUI.BoolField { displayName = "Enable DBuffer", getter = () => frameSettings.enableDBuffer, setter = value => frameSettings.enableDBuffer = value },
new DebugUI.BoolField { displayName = "Enable DBuffer", getter = () => frameSettings.enableDecals, setter = value => frameSettings.enableDecals = value },
new DebugUI.BoolField { displayName = "Enable Rough Refraction", getter = () => frameSettings.enableRoughRefraction, setter = value => frameSettings.enableRoughRefraction = value },
new DebugUI.BoolField { displayName = "Enable Distortion", getter = () => frameSettings.enableDistortion, setter = value => frameSettings.enableDistortion = value },
new DebugUI.BoolField { displayName = "Enable Postprocess", getter = () => frameSettings.enablePostprocess, setter = value => frameSettings.enablePostprocess = value },

3
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs


public bool supportDitheringCrossFade = true;
// Engine
public bool supportDBuffer = false;
[FormerlySerializedAs("supportDBuffer")]
public bool supportDecals = true;
public bool supportMSAA = false;
public MSAASamples msaaSampleCount = MSAASamples.None;
public bool supportMotionVectors = true;

18
com.unity.render-pipelines.high-definition/HDRP/ShaderVariables.hlsl


CBUFFER_END
// Undef in order to include all textures and buffers declarations
#undef SHADER_VARIABLES_INCLUDE_CB
#include "Lighting/LightLoop/ShaderVariablesLightLoop.hlsl"
#include "Lighting/AtmosphericScattering/ShaderVariablesAtmosphericScattering.hlsl"
#include "Lighting/ScreenSpaceLighting/ShaderVariablesScreenSpaceLighting.hlsl"
#include "Material/Decal/ShaderVariablesDecal.hlsl"
#include "Material/SubsurfaceScattering/ShaderVariablesSubsurfaceScattering.hlsl"
// Custom generated by HDRP, not from Unity Engine (passed in via HDCamera)
#if defined(USING_STEREO_MATRICES)

// This define allow to tell to unity instancing that we will use our camera relative functions (ApplyCameraTranslationToMatrix and ApplyCameraTranslationToInverseMatrix) for the model view matrix
#define MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING
#include "CoreRP/ShaderLibrary/UnityInstancing.hlsl"
// This is located after the include of UnityInstancing.hlsl so it can be used for declaration
// Undef in order to include all textures and buffers declarations
#undef SHADER_VARIABLES_INCLUDE_CB
#include "Lighting/LightLoop/ShaderVariablesLightLoop.hlsl"
#include "Lighting/AtmosphericScattering/ShaderVariablesAtmosphericScattering.hlsl"
#include "Lighting/ScreenSpaceLighting/ShaderVariablesScreenSpaceLighting.hlsl"
#include "Material/Decal/ShaderVariablesDecal.hlsl"
#include "Material/SubsurfaceScattering/ShaderVariablesSubsurfaceScattering.hlsl"
#include "ShaderVariablesFunctions.hlsl"
#endif // UNITY_SHADER_VARIABLES_INCLUDED

8
com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering.meta


fileFormatVersion: 2
guid: d522828bc0314e14cb6faa4291bb64da
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存