浏览代码

Merge branch 'master' into prototype/decals_gpu_optimization

# Conflicts:
#	ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
#	ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
/main
Paul Melamed 7 年前
当前提交
3441b497
共有 49 个文件被更改,包括 1988 次插入186 次删除
  1. 16
      ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs
  2. 34
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
  3. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  4. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl
  6. 45
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineMenuItems.cs
  7. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDReflectionProbeUI.Drawers.cs
  8. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/DiffusionProfile/DiffusionProfileSettingsEditor.Styles.cs
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/DiffusionProfile/DiffusionProfileSettingsEditor.cs
  10. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/LayeredLit/LayeredLitUI.cs
  11. 35
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/BaseLitUI.cs
  12. 78
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
  13. 39
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  14. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset
  15. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  16. 46
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  17. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  18. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopSettings.cs
  19. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/PlanarReflectionProbe.cs
  20. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  21. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VBuffer.hlsl
  22. 34
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  23. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/DiffusionProfile/DiffusionProfileSettings.cs
  24. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/DiffusionProfile/DiffusionProfileSettings.cs.hlsl
  25. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLit.shader
  26. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
  27. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  28. 20
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  29. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
  30. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl
  31. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl
  32. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader
  33. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl
  34. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
  35. 29
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs
  36. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl
  37. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.hlsl
  38. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  39. 57
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2103_BakeMixed.unity
  40. 1
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/CommonAssets/Cornell Box.fbx.meta
  41. 1
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/040_UpgradeScene/Models/Environment/Floor.fbx.meta
  42. 338
      ImageTemplates/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity.png
  43. 83
      ImageTemplates/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity.png.meta
  44. 87
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/3DObjects/CornelBox/Cornell Box.prefab
  45. 8
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/3DObjects/CornelBox/Cornell Box.prefab.meta
  46. 8
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.meta
  47. 1001
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity
  48. 7
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity.meta
  49. 8
      SampleScenes/HDTest/PlanarReflectionTests.meta

16
ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs


baseDesc.depthBufferBits = depthBufferBits;
baseDesc.colorFormat = format;
baseDesc.sRGB = (readWrite != RenderTextureReadWrite.Linear);
// TODO: Explicit MSAA support will come in later
// Depth-only needs bindMS in order to use with CopyTexture
if ((format == RenderTextureFormat.Depth) && (baseDesc.msaaSamples > 1))
baseDesc.bindMS = true;
return new RenderTexture(baseDesc);
}

RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int msaaSamples = 1, bool enableRandomWrite = false)
RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int msaaSamplesOverride = 0, bool enableRandomWrite = false)
UpdateRenderTextureDescriptor(ref baseDesc, depthBufferBits, format, readWrite, msaaSamples, enableRandomWrite);
if (msaaSamplesOverride > 0)
UpdateRenderTextureDescriptor(ref baseDesc, depthBufferBits, format, readWrite, msaaSamplesOverride, enableRandomWrite);
else
UpdateRenderTextureDescriptor(ref baseDesc, depthBufferBits, format, readWrite, baseDesc.msaaSamples, enableRandomWrite);
cmd.GetTemporaryRT(nameID, baseDesc, filter);
}

baseDesc.depthBufferBits = depthBufferBits;
baseDesc.colorFormat = format;
baseDesc.sRGB = (readWrite != RenderTextureReadWrite.Linear);
Debug.Assert(!enableRandomWrite || (msaaSamples == 1));
baseDesc.msaaSamples = msaaSamples;
baseDesc.enableRandomWrite = enableRandomWrite;
}

// We use 8x8 tiles in order to match the native GCN HTile as closely as possible.
desc.width = (desc.width + 7) / 8;
desc.height = (desc.height + 7) / 8;
// TODO: This fails allocation with MSAA enabled?
hTile = CreateRenderTexture(desc, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear); // DXGI_FORMAT_R8_UINT is not supported by Unity
hTile.filterMode = FilterMode.Point;
hTile.enableRandomWrite = true;

34
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl


return mul(viewProjMatrix, float4(positionWS, 1.0)).w;
}
// 'z' is the view space Z position (linear depth).
// saturate(z) the output of the function to clamp them to the [0, 1] range.
// d = log2(c * (z - n) + 1) / log2(c * (f - n) + 1)
// = log2(c * (z - n + 1/c)) / log2(c * (f - n) + 1)
// = log2(c) / log2(c * (f - n) + 1) + log2(z - (n - 1/c)) / log2(c * (f - n) + 1)
// = E + F * log2(z - G)
// encodingParams = { E, F, G, 0 }
float EncodeLogarithmicDepthGeneralized(float z, float4 encodingParams)
{
// Use max() to avoid NaNs.
return encodingParams.x + encodingParams.y * log2(max(0, z - encodingParams.z));
}
// 'd' is the logarithmically encoded depth value.
// saturate(d) to clamp the output of the function to the [n, f] range.
// z = 1/c * (pow(c * (f - n) + 1, d) - 1) + n
// = 1/c * pow(c * (f - n) + 1, d) + n - 1/c
// = L * pow(M, d) + N
// decodingParams = { L, M, N, 0 }
// Graph: https://www.desmos.com/calculator/qrtatrlrba
float DecodeLogarithmicDepthGeneralized(float d, float4 decodingParams)
{
// Use abs() to avoid the compiler warning.
return decodingParams.x * pow(abs(decodingParams.y), d) + decodingParams.z;
}
// saturate() the output of the function to clamp them to the [0, 1] range.
// saturate(z) the output of the function to clamp them to the [0, 1] range.
// TODO: plot and modify the distribution to be a little more linear.
// This is an optimized version of EncodeLogarithmicDepthGeneralized() for (c = 2).
// Use max() to avoid NaNs.
return log2(max(0, z * encodingParams.z)) * encodingParams.w;
}

// TODO: plot and modify the distribution to be a little more linear.
// This is an optimized version of DecodeLogarithmicDepthGeneralized() for (c = 2).
// Graph: https://www.desmos.com/calculator/qrtatrlrba
float DecodeLogarithmicDepth(float d, float4 encodingParams)
{
return encodingParams.x * exp2(d * encodingParams.y);

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs


tempDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
}
tempDesc.msaaSamples = 1; // will be updated later, deferred will always set to 1
if (frameSettings.enableMSAA)
{
// this is already pre-validated to be a valid sample count by InitializeFrameSettings
var sampleCount = QualitySettings.antiAliasing;
tempDesc.msaaSamples = sampleCount;
}
else
{
tempDesc.msaaSamples = 1;
}
tempDesc.depthBufferBits = 0;
tempDesc.autoGenerateMips = false;
tempDesc.useMipMap = false;

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs


IndirectSpecularOcclusionFromSsao,
IndirectSpecularGtaoFromSsao,
EnvironmentProxyVolume,
EnvironmentSampleCoordinates,
}
public enum ShadowMapDebugMode

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl


#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_OCCLUSION_FROM_SSAO (7)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_GTAO_FROM_SSAO (8)
#define DEBUGLIGHTINGMODE_ENVIRONMENT_PROXY_VOLUME (9)
#define DEBUGLIGHTINGMODE_ENVIRONMENT_SAMPLE_COORDINATES (10)
#endif

45
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineMenuItems.cs


}
}
[MenuItem("Internal/HDRenderPipeline/Update/Update SSS profile indices")]
static void UpdateSSSProfileIndices()
[MenuItem("Internal/HDRenderPipeline/Update/Update diffusion profile")]
static void UpdateDiffusionProfile()
{
var matIds = AssetDatabase.FindAssets("t:DiffusionProfileSettings");
for (int i = 0, length = matIds.Length; i < length; i++)
{
var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
var diffusionProfileSettings = AssetDatabase.LoadAssetAtPath<DiffusionProfileSettings>(path);
bool VSCEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);
CheckOutFile(VSCEnabled, diffusionProfileSettings);
var profiles = diffusionProfileSettings.profiles;
for (int j = 0; j < profiles.Length; j++)
{
if ((uint)profiles[j].transmissionMode == 2)
{
profiles[j].transmissionMode = (DiffusionProfile.TransmissionMode)0;
}
}
EditorUtility.SetDirty(diffusionProfileSettings);
}
}
[MenuItem("Internal/HDRenderPipeline/Update/Update material for clear coat")]
static void UpdateMaterialForClearCoat()
{
try
{

EditorUtility.DisplayProgressBar(
"Setup materials Keywords...",
string.Format("{0} / {1} materials SSS updated.", i, length),
string.Format("{0} / {1} materials clearcoat updated.", i, length),
i / (float)(length - 1));
bool VSCEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);

{
if (mat.HasProperty("_SubsurfaceProfile"))
if (mat.HasProperty("_CoatMask"))
// 3 is Old value for clear coat
float materialID = mat.GetInt("_MaterialID");
if (materialID == 3.0)
continue;
//float value = mat.GetInt("_DiffusionProfile");
//mat.SetInt("_DiffusionProfile", 0);
mat.SetInt("_CoatMask", 0);
EditorUtility.SetDirty(mat);
}

{
/*
bool hasSubsurfaceProfile = false;
int numLayer = (int)mat.GetFloat("_LayerCount");

EditorUtility.SetDirty(mat);
}
*/
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDReflectionProbeUI.Drawers.cs


}
EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius"));
EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Sphere Offset|The center of the sphere in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));
EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Sphere Projection|Sphere projection causes reflections to appear to change based on the object's position within the probe's sphere, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting sphere projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));
}
#endregion

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/DiffusionProfile/DiffusionProfileSettingsEditor.Styles.cs


new GUIContent("Post-scatter", "Texturing is performed only during the SSS pass. Effectively preserves the sharpness of the diffuse texture. Choose this mode if your diffuse texture already contains SSS lighting (e.g. a photo of skin).")
};
public readonly GUIContent profileTransmissionMode = new GUIContent("Transmission Mode", "Configures the simulation of light passing through thin objects. Depends on the thickness value (which is applied in the normal direction).");
public readonly GUIContent[] transmissionModeOptions = new GUIContent[3]
public readonly GUIContent[] transmissionModeOptions = new GUIContent[2]
new GUIContent("None", "Disables transmission. Choose this mode for completely opaque, or very thick translucent objects."),
new GUIContent("Thin Object", "Choose this mode for thin objects, such as paper or leaves. Transmitted light reuses the shadowing state of the surface."),
new GUIContent("Regular", "Choose this mode for moderately thick objects. For performance reasons, transmitted light ignores occlusion (shadows).")
new GUIContent("Regular", "Choose this mode for moderately thick objects. For performance reasons, transmitted light ignores occlusion (shadows)."),
new GUIContent("Thin Object", "Choose this mode for thin objects, such as paper or leaves. Transmitted light reuses the shadowing state of the surface.")
};
public readonly GUIContent profileMinMaxThickness = new GUIContent("Min-Max Thickness (mm)", "Shows the values of the thickness remap below (in millimeters).");
public readonly GUIContent profileThicknessRemap = new GUIContent("Thickness Remap (mm)", "Remaps the thickness parameter from [0, 1] to the desired range (in millimeters).");

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/DiffusionProfile/DiffusionProfileSettingsEditor.cs


var S = obj.shapeParam;
var T = (Vector4)profile.transmissionTint.colorValue;
var R = profile.thicknessRemap.vector2Value;
bool transmissionEnabled = profile.transmissionMode.intValue != (int)DiffusionProfile.TransmissionMode.None;
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, r);
m_ProfileMaterial.SetVector(HDShaderIDs._ShapeParam, S);

// <<< Old SSS Model
m_TransmittanceMaterial.SetVector(HDShaderIDs._ShapeParam, S);
m_TransmittanceMaterial.SetVector(HDShaderIDs._TransmissionTint, transmissionEnabled ? T : Vector4.zero);
m_TransmittanceMaterial.SetVector(HDShaderIDs._TransmissionTint, T);
m_TransmittanceMaterial.SetVector(HDShaderIDs._ThicknessRemap, R);
// Draw the transmittance graph.

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/LayeredLit/LayeredLitUI.cs


EditorGUI.indentLevel--;
EditorGUILayout.Space();
DoLayerGUI(material, layerIndex);
DoLayerGUI(material, layerIndex, true);
if (layerIndex == 0)
EditorGUILayout.Space();

CoreUtils.SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);
BaseLitGUI.MaterialId materialId = (BaseLitGUI.MaterialId)material.GetFloat(kMaterialID);
BaseLitGUI.SSSAndTransmissionType sssAndTransmissionType = (BaseLitGUI.SSSAndTransmissionType)material.GetFloat(kSSSAndTransmissionType);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", materialId == BaseLitGUI.MaterialId.LitSSS);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", materialId == BaseLitGUI.MaterialId.LitSSS);
if (materialId == BaseLitGUI.MaterialId.LitSSSAndTransmission)
{
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission || sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitSSSOnly);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission || sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitTransmissionOnly);
}
else
{
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", false);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", false);
}
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)

35
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/BaseLitUI.cs


public static GUIContent enableMotionVectorForVertexAnimationText = new GUIContent("Enable MotionVector For Vertex Animation", "This will enable an object motion vector pass for this material. Useful if wind animation is enabled or if displacement map is animated");
// 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.");
public static GUIContent materialIDText = new GUIContent("Material type", "Select a material feature to enable on top of regular material");
public static GUIContent SSSAndTransmissionTypeText = new GUIContent("SSS and Transmission type", "Subsurface Scattering for translucent materials such as skin, vegetation, fruit, marble, wax and milk., Transmission for back lighting");
// Per pixel displacement
public static GUIContent ppdMinSamplesText = new GUIContent("Minimum steps", "Minimum steps (texture sample) to use with per pixel displacement mapping");

public enum MaterialId
{
LitSSS = 0,
LitSSSAndTransmission = 0,
LitClearCoat = 3,
LitSpecular = 4,
LitIridescence = 5,
LitIridescence = 3,
LitSpecular = 4
};
public enum SSSAndTransmissionType
{
LitSSSAndTransmission = 0,
LitSSSOnly = 1,
LitTransmissionOnly = 2,
};
public enum HeightmapParametrization

// Properties
// Material ID
protected MaterialProperty materialID = null;
protected const string kMaterialID = "_MaterialID";
protected const string kMaterialID = "_MaterialID";
protected MaterialProperty sssAndTransmissionType = null;
protected const string kSSSAndTransmissionType = "_SSSAndTransmissionType";
protected const string kStencilRef = "_StencilRef";
protected const string kStencilWriteMask = "_StencilWriteMask";

// MaterialID
materialID = FindProperty(kMaterialID, props);
sssAndTransmissionType = FindProperty(kSSSAndTransmissionType, props);
displacementMode = FindProperty(kDisplacementMode, props);
displacementLockObjectScale = FindProperty(kDisplacementLockObjectScale, props);

}
m_MaterialEditor.ShaderProperty(materialID, StylesBaseLit.materialIDText);
if ((int)materialID.floatValue == (int)BaseLitGUI.MaterialId.LitSSSAndTransmission)
{
m_MaterialEditor.ShaderProperty(sssAndTransmissionType, StylesBaseLit.SSSAndTransmissionTypeText);
}
m_MaterialEditor.ShaderProperty(supportDBuffer, StylesBaseLit.supportDBufferText);

// Set the reference value for the stencil test.
int stencilRef = (int)StencilLightingUsage.RegularLighting;
if ((int)material.GetFloat(kMaterialID) == (int)BaseLitGUI.MaterialId.LitSSS)
if ((int)material.GetFloat(kMaterialID) == (int)BaseLitGUI.MaterialId.LitSSSAndTransmission)
stencilRef = (int)StencilLightingUsage.SplitLighting;
if ((int)material.GetFloat(kSSSAndTransmissionType) == (int)BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission ||
(int)material.GetFloat(kSSSAndTransmissionType) == (int)BaseLitGUI.SSSAndTransmissionType.LitSSSOnly)
{
stencilRef = (int)StencilLightingUsage.SplitLighting;
}
}
// As we tag both during velocity pass and Gbuffer pass we need a separate state and we need to use the write mask
material.SetInt(kStencilRef, stencilRef);

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


protected MaterialProperty coatMask = null;
protected const string kCoatMask = "_CoatMask";
protected MaterialProperty coatMaskMap = null;
protected const string kCoatMaskMap = "_CoatMaskMap";
protected MaterialProperty emissiveColorMode = null;
protected const string kEmissiveColorMode = "_EmissiveColorMode";

// clear coat
coatMask = FindProperty(kCoatMask, props);
coatMaskMap = FindProperty(kCoatMaskMap, props);
// Transparency
refractionMode = FindProperty(kRefractionMode, props, false);

EditorGUI.indentLevel--;
}
protected void ShaderSSSInputGUI(Material material, int layerIndex)
protected void ShaderSSSAndTransmissionInputGUI(Material material, int layerIndex)
{
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
var diffusionProfileSettings = hdPipeline.diffusionProfileSettings;

diffusionProfileID[layerIndex].floatValue = profileID;
}
m_MaterialEditor.ShaderProperty(subsurfaceMask[layerIndex], Styles.subsurfaceMaskText);
m_MaterialEditor.TexturePropertySingleLine(Styles.subsurfaceMaskMapText, subsurfaceMaskMap[layerIndex]);
m_MaterialEditor.TexturePropertySingleLine(Styles.thicknessMapText, thicknessMap[layerIndex]);
if (thicknessMap[layerIndex].textureValue != null)
if ((int)sssAndTransmissionType.floatValue == (int)BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission || (int)sssAndTransmissionType.floatValue == (int)BaseLitGUI.SSSAndTransmissionType.LitSSSOnly)
// Display the remap of texture values.
Vector2 remap = thicknessRemap[layerIndex].vectorValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.MinMaxSlider(Styles.thicknessRemapText, ref remap.x, ref remap.y, 0.0f, 1.0f);
if (EditorGUI.EndChangeCheck())
{
thicknessRemap[layerIndex].vectorValue = remap;
}
m_MaterialEditor.ShaderProperty(subsurfaceMask[layerIndex], Styles.subsurfaceMaskText);
m_MaterialEditor.TexturePropertySingleLine(Styles.subsurfaceMaskMapText, subsurfaceMaskMap[layerIndex]);
else
if ((int)sssAndTransmissionType.floatValue == (int)BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission || (int)sssAndTransmissionType.floatValue == (int)BaseLitGUI.SSSAndTransmissionType.LitTransmissionOnly)
// Allow the user to set the constant value of thickness if no thickness map is provided.
m_MaterialEditor.ShaderProperty(thickness[layerIndex], Styles.thicknessText);
m_MaterialEditor.TexturePropertySingleLine(Styles.thicknessMapText, thicknessMap[layerIndex]);
if (thicknessMap[layerIndex].textureValue != null)
{
// Display the remap of texture values.
Vector2 remap = thicknessRemap[layerIndex].vectorValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.MinMaxSlider(Styles.thicknessRemapText, ref remap.x, ref remap.y, 0.0f, 1.0f);
if (EditorGUI.EndChangeCheck())
{
thicknessRemap[layerIndex].vectorValue = remap;
}
}
else
{
// Allow the user to set the constant value of thickness if no thickness map is provided.
m_MaterialEditor.ShaderProperty(thickness[layerIndex], Styles.thicknessText);
}
m_MaterialEditor.ShaderProperty(coatMask, Styles.coatMaskText);
m_MaterialEditor.TexturePropertySingleLine(Styles.coatMaskText, coatMaskMap, coatMask);
}
protected void ShaderAnisoInputGUI()

}
}
protected void DoLayerGUI(Material material, int layerIndex)
protected void DoLayerGUI(Material material, int layerIndex, bool isLayeredLit)
{
EditorGUILayout.LabelField(Styles.InputsText, EditorStyles.boldLabel);

switch ((BaseLitGUI.MaterialId)materialID.floatValue)
{
case BaseLitGUI.MaterialId.LitSSS:
ShaderSSSInputGUI(material, layerIndex);
case BaseLitGUI.MaterialId.LitSSSAndTransmission:
ShaderSSSAndTransmissionInputGUI(material, layerIndex);
break;
case BaseLitGUI.MaterialId.LitStandard:
// Nothing

case BaseLitGUI.MaterialId.LitSpecular:
ShaderSpecularColorInputGUI(material);
break;
case BaseLitGUI.MaterialId.LitClearCoat:
ShaderClearCoatInputGUI();
break;
if (!isLayeredLit)
{
ShaderClearCoatInputGUI();
}
EditorGUILayout.Space();

protected override void MaterialPropertiesGUI(Material material)
{
DoLayerGUI(material, 0);
DoLayerGUI(material, 0, false);
DoEmissiveGUI(material);
// The parent Base.ShaderPropertiesGUI will call DoEmissionArea
}

}
BaseLitGUI.MaterialId materialId = (BaseLitGUI.MaterialId)material.GetFloat(kMaterialID);
BaseLitGUI.SSSAndTransmissionType sssAndTransmissionType = (BaseLitGUI.SSSAndTransmissionType)material.GetFloat(kSSSAndTransmissionType);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", materialId == BaseLitGUI.MaterialId.LitSSS);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", materialId == BaseLitGUI.MaterialId.LitSSS);
if (materialId == BaseLitGUI.MaterialId.LitSSSAndTransmission)
{
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission || sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitSSSOnly);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitSSSAndTransmission || sssAndTransmissionType == BaseLitGUI.SSSAndTransmissionType.LitTransmissionOnly);
}
else
{
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", false);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", false);
}
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_CLEAR_COAT", materialId == BaseLitGUI.MaterialId.LitClearCoat);
// No material Id for clear coat, just test the attribute
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_CLEAR_COAT", material.GetFloat(kCoatMask) > 0.0 || material.GetTexture(kCoatMaskMap));
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_IRIDESCENCE", materialId == BaseLitGUI.MaterialId.LitIridescence);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SPECULAR_COLOR", materialId == BaseLitGUI.MaterialId.LitSpecular);

39
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


// Detect when windows size is changing
int m_CurrentWidth;
int m_CurrentHeight;
int m_CurrentMSAASampleCount;
// Use to detect frame changes
int m_FrameCount;

if (m_CameraStencilBufferCopy != null)
m_CameraStencilBufferCopy.Release();
// TODO: This might fail allocation with MSAA
m_CameraStencilBufferCopy = CoreUtils.CreateRenderTexture(hdCamera.renderTextureDesc, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear); // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy.filterMode = FilterMode.Point;
m_CameraStencilBufferCopy.Create();

var desc = hdCamera.renderTextureDesc;
var texWidth = desc.width;
var texHeight = desc.height;
var sampleCount = desc.msaaSamples;
bool resolutionChanged = (texWidth != m_CurrentWidth) || (texHeight != m_CurrentHeight);
bool resolutionChanged = (texWidth != m_CurrentWidth) ||
(texHeight != m_CurrentHeight) ||
(sampleCount != m_CurrentMSAASampleCount);
m_SSSBufferManager.Resize(hdCamera);
m_DbufferManager.Resize(hdCamera);
if (m_FrameSettings.enableDBuffer)
{
m_DbufferManager.Resize(hdCamera);
}
if (m_FrameSettings.enableSubsurfaceScattering)
{
// TODO: The R8 target doesn't allocate with MSAA support...
m_SSSBufferManager.Resize(hdCamera);
}
}
if (resolutionChanged || m_LightLoop.NeedResize())

// update recorded window resolution
m_CurrentWidth = texWidth;
m_CurrentHeight = texHeight;
m_CurrentMSAASampleCount = sampleCount;
}
public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, DiffusionProfileSettings sssParameters)

using (new ProfilingSample(cmd, "Deferred directional shadows", CustomSamplerId.RenderDeferredDirectionalShadow.GetSampler()))
{
cmd.ReleaseTemporaryRT(m_DeferredShadowBuffer);
// TODO: For MSAA, we are overriding to 1x, but we'll need to add a Draw path in order to support MSAA properly
CoreUtils.CreateCmdTemporaryRT(cmd, m_DeferredShadowBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, true);
m_LightLoop.RenderDeferredDirectionalShadow(hdCamera, m_DeferredShadowBufferRT, GetDepthTexture(), cmd);
PushFullScreenDebugTexture(cmd, m_DeferredShadowBuffer, hdCamera, FullScreenDebugMode.DeferredShadows);

if (settings.IsEnabledAndSupported(null))
{
cmd.ReleaseTemporaryRT(HDShaderIDs._AmbientOcclusionTexture);
CoreUtils.CreateCmdTemporaryRT(cmd, HDShaderIDs._AmbientOcclusionTexture, hdCamera.renderTextureDesc, 0, FilterMode.Bilinear, RenderTextureFormat.R8, RenderTextureReadWrite.Linear, msaaSamples: 1, enableRandomWrite: true);
CoreUtils.CreateCmdTemporaryRT(cmd, HDShaderIDs._AmbientOcclusionTexture, hdCamera.renderTextureDesc, 0, FilterMode.Bilinear, RenderTextureFormat.R8, RenderTextureReadWrite.Linear, msaaSamplesOverride: 1, enableRandomWrite: true);
postProcessLayer.BakeMSVOMap(cmd, camera, HDShaderIDs._AmbientOcclusionTexture, GetDepthTexture(), true);
cmd.SetGlobalVector(HDShaderIDs._AmbientOcclusionParam, new Vector4(settings.color.value.r, settings.color.value.g, settings.color.value.b, settings.directLightingStrength.value));
PushFullScreenDebugTexture(cmd, HDShaderIDs._AmbientOcclusionTexture, hdCamera, FullScreenDebugMode.SSAO);

cmd.ReleaseTemporaryRT(m_CameraColorBuffer);
cmd.ReleaseTemporaryRT(m_CameraSssDiffuseLightingBuffer);
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraColorBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraSssDiffuseLightingBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
if (m_FrameSettings.enableMSAA)
{
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraColorBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraSssDiffuseLightingBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear);
}
else
{
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraColorBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraSssDiffuseLightingBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
}
// Color and depth pyramids
m_GaussianPyramidColorBufferDesc = BuildPyramidDescriptor(hdCamera, PyramidType.Color, m_FrameSettings.enableStereo);

desc.depthBufferBits = 0;
desc.useMipMap = true;
desc.autoGenerateMips = false;
desc.msaaSamples = 1; // These are approximation textures, they don't need MSAA
var pyramidSize = CalculatePyramidSize((int)hdCamera.screenSize.x, (int)hdCamera.screenSize.y);

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset


cubeCookieTexArraySize: 16
reflectionProbeCacheSize: 128
planarReflectionProbeCacheSize: 128
reflectionCubemapSize: 512
planarReflectionTextureSize: 512
reflectionCubemapSize: 128
planarReflectionTextureSize: 128
reflectionCacheCompressed: 0
planarReflectionCacheCompressed: 0
maxPlanarReflectionProbes: 128

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _VBufferResolution = Shader.PropertyToID("_VBufferResolution");
public static readonly int _VBufferScaleAndSliceCount = Shader.PropertyToID("_VBufferScaleAndSliceCount");
public static readonly int _VBufferDepthEncodingParams = Shader.PropertyToID("_VBufferDepthEncodingParams");
public static readonly int _VBufferDepthDecodingParams = Shader.PropertyToID("_VBufferDepthDecodingParams");
public static readonly int _VBufferCoordToViewDirWS = Shader.PropertyToID("_VBufferCoordToViewDirWS");
public static readonly int _VBufferDensity = Shader.PropertyToID("_VBufferDensity");
public static readonly int _VBufferLighting = Shader.PropertyToID("_VBufferLighting");

46
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


static ComputeBuffer s_PerVoxelOffset = null;
static ComputeBuffer s_PerTileLogBaseTweak = null;
static ComputeBuffer s_GlobalLightListAtomic = null;
public enum ClusterPrepassSource : int
{
None = 0,
BigTile = 1,
Count = 2,
}
public enum ClusterDepthSource : int
{
NoDepth = 0,
Depth = 1,
MSAA_Depth = 2,
Count = 3,
}
static string[,] s_ClusterKernelNames = new string[(int)ClusterPrepassSource.Count, (int)ClusterDepthSource.Count]
{
{ "TileLightListGen_NoDepthRT", "TileLightListGen_DepthRT", "TileLightListGen_DepthRT_MSAA" },
{ "TileLightListGen_NoDepthRT_SrcBigTile", "TileLightListGen_DepthRT_SrcBigTile", "TileLightListGen_DepthRT_MSAA_SrcBigTile" }
};
// clustered light list specific buffers and data end
static int[] s_TempIntArray = new int[2]; // Used to avoid GC stress when calling SetComputeIntParams

m_lightList = new LightList();
m_lightList.Allocate();
m_Env2DCaptureVP.Clear();
for (int i = 0, c = Mathf.Max(1, hdAsset.renderPipelineSettings.lightLoopSettings.maxPlanarReflectionProbes); i < c; ++i)
m_Env2DCaptureVP.Add(Matrix4x4.identity);
s_DirectionalLightDatas = new ComputeBuffer(k_MaxDirectionalLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));
s_LightDatas = new ComputeBuffer(k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));

// Cluster
{
var kernelName = m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? (k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile") : (k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT");
var clustPrepassSourceIdx = m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? ClusterPrepassSource.BigTile : ClusterPrepassSource.None;
var clustDepthSourceIdx = ClusterDepthSource.NoDepth;
if (k_UseDepthBuffer)
{
if (m_FrameSettings.enableMSAA)
clustDepthSourceIdx = ClusterDepthSource.MSAA_Depth;
else
clustDepthSourceIdx = ClusterDepthSource.Depth;
}
var kernelName = s_ClusterKernelNames[(int)clustPrepassSourceIdx, (int)clustDepthSourceIdx];
s_GenListPerVoxelKernel = buildPerVoxelLightListShader.FindKernel(kernelName);
}

var envIndex = -1;
if (probe.planarReflectionProbe != null)
{
envIndex = m_ReflectionPlanarProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Texture2D;
var fetchIndex = m_ReflectionPlanarProbeCache.FetchSlice(cmd, probe.texture);
envIndex = (fetchIndex << 1) | (int)EnvCacheType.Texture2D;
float nearClipPlane, farClipPlane, aspect, fov;
Color backgroundColor;

// We transform it to object space by translating the capturePosition
var vp = gpuProj * gpuView * Matrix4x4.Translate(capturePosition);
m_Env2DCaptureVP.Add(vp);
m_Env2DCaptureVP[fetchIndex] = vp;
sampleDirectionDiscardWS = captureRotation * Vector3.forward;
}
else if (probe.reflectionProbe != null)

// If any light require it, we need to enabled bake shadow mask feature
m_enableBakeShadowMask = false;
m_Env2DCaptureVP.Clear();
m_lightList.Clear();
Vector3 camPosWS = camera.transform.position;

cmd.SetGlobalTexture(HDShaderIDs._CookieCubeTextures, m_CubeCookieTexArray.GetTexCache());
cmd.SetGlobalTexture(HDShaderIDs._EnvCubemapTextures, m_ReflectionProbeCache.GetTexCache());
cmd.SetGlobalTexture(HDShaderIDs._Env2DTextures, m_ReflectionPlanarProbeCache.GetTexCache());
if (m_Env2DCaptureVP.Count > 0)
cmd.SetGlobalMatrixArray(HDShaderIDs._Env2DCaptureVP, m_Env2DCaptureVP);
cmd.SetGlobalMatrixArray(HDShaderIDs._Env2DCaptureVP, m_Env2DCaptureVP);
cmd.SetGlobalBuffer(HDShaderIDs._DirectionalLightDatas, s_DirectionalLightDatas);
cmd.SetGlobalInt(HDShaderIDs._DirectionalLightCount, m_lightList.directionalLights.Count);

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


float4 color = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc.xy, index, 0);
color.a = any(ndc.xyz < 0) || any(ndc.xyz > 1) ? 0 : 1;
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_ENVIRONMENT_SAMPLE_COORDINATES)
return float4(ndc.xy, 0, color.a);
#endif
return color;
}
else if (cacheType == ENVCACHETYPE_CUBEMAP)

#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_ENVIRONMENT_SAMPLE_COORDINATES)
return float4(texCoord.xyz * 0.5 + 0.5, color.a);
#endif
return color;
}
return float4(0, 0, 0, 0);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopSettings.cs


// Deferred opaque are always using Fptl. Forward opaque can use Fptl or Cluster, transparent use cluster.
// When MSAA is enabled we disable Fptl as it become expensive compare to cluster
// In HD, MSAA is only supported for forward only rendering, no MSAA in deferred mode (for code complexity reasons)
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && aggregateFrameSettings.enableMSAA;
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && !aggregateFrameSettings.enableMSAA;
// If Deferred, enable Fptl. If we are forward renderer only and not using Fptl for forward opaque, disable Fptl
aggregate.isFptlEnabled = !aggregateFrameSettings.enableForwardRenderingOnly || aggregate.enableFptlForForwardOpaque;
}

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/PlanarReflectionProbe.cs


[SerializeField]
Texture m_BakedTexture;
[SerializeField]
RenderTexture m_RealtimeTexture;
[SerializeField]
FrameSettings m_FrameSettings;
[SerializeField]
float m_CaptureNearPlane = 1;

[SerializeField]
[Range(0, 180)]
float m_FieldOfViewOverride = 90;
RenderTexture m_RealtimeTexture;
public bool overrideFieldOfView { get { return m_OverrideFieldOfView; } }
public float fieldOfViewOverride { get { return m_FieldOfViewOverride; } }

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/Resources/VolumetricLighting.compute


void FillVolumetricLightingBuffer(LightLoopContext context, uint featureFlags,
PositionInputs posInput, DualRay ray)
{
float z0 = _VBufferDepthEncodingParams.x; // Start integration from the near plane
float t0 = ray.strataDirInvViewZ * z0; // Convert view space Z to distance along the stratified ray
float de = rcp(VBUFFER_SLICE_COUNT); // Log-encoded distance between slices
float n = _VBufferDepthDecodingParams.x + _VBufferDepthDecodingParams.z;
float z0 = n; // Start integration from the near plane
float t0 = ray.strataDirInvViewZ * z0; // Convert view space Z to distance along the stratified ray
float de = rcp(VBUFFER_SLICE_COUNT); // Log-encoded distance between slices
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.x); // Prevent unrolling...
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.w); // Prevent unrolling...
#ifdef LIGHTLOOP_TILE_PASS
// Our voxel is not necessarily completely inside a single light cluster.

for (uint slice = 0; slice < sliceCountHack; slice++)
{
float e1 = slice * de + de; // (slice + 1) / sliceCount
float z1 = DecodeLogarithmicDepth(e1, _VBufferDepthEncodingParams);
float z1 = DecodeLogarithmicDepthGeneralized(e1, _VBufferDepthDecodingParams);
float t1 = ray.strataDirInvViewZ * z1; // Convert view space Z to distance along the stratified ray
float dt = t1 - t0;

float4 reprojValue = SampleVBuffer(TEXTURE3D_PARAM(_VBufferLightingHistory, s_trilinear_clamp_sampler),
false, reprojPosNDC, reprojZ,
_VBufferScaleAndSliceCount,
_VBufferDepthEncodingParams);
_VBufferDepthEncodingParams,
_VBufferDepthDecodingParams);
// Compute the exponential moving average over 'n' frames:
// X = (1 - a) * ValueAtFrame[n] + a * AverageOverPreviousFrames.

24
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VBuffer.hlsl


// which allows us to perform HW interpolation which is linear in the view space.
float ComputeLerpPositionForLogEncoding(float linearDepth, float logEncodedDepth,
float4 VBufferScaleAndSliceCount,
float4 VBufferDepthEncodingParams)
float4 VBufferDepthDecodingParams)
{
float z = linearDepth;
float d = logEncodedDepth;

float s1 = ceil(d * numSlices - 0.5);
float d0 = saturate(s0 * rcpNumSlices + (0.5 * rcpNumSlices));
float d1 = saturate(s1 * rcpNumSlices + (0.5 * rcpNumSlices));
float z0 = DecodeLogarithmicDepth(d0, VBufferDepthEncodingParams);
float z1 = DecodeLogarithmicDepth(d1, VBufferDepthEncodingParams);
float z0 = DecodeLogarithmicDepthGeneralized(d0, VBufferDepthDecodingParams);
float z1 = DecodeLogarithmicDepthGeneralized(d1, VBufferDepthDecodingParams);
// Compute the linear interpolation weight.
float t = saturate((z - z0) / (z1 - z0));

float4 SampleVBuffer(TEXTURE3D_ARGS(VBufferLighting, trilinearSampler), bool clampToEdge,
float2 positionNDC, float linearDepth,
float4 VBufferScaleAndSliceCount,
float4 VBufferDepthEncodingParams)
float4 VBufferDepthEncodingParams,
float4 VBufferDepthDecodingParams)
{
float numSlices = VBufferScaleAndSliceCount.z;
float rcpNumSlices = VBufferScaleAndSliceCount.w;

// The distance between slices is log-encoded.
float z = linearDepth;
float d = EncodeLogarithmicDepth(z, VBufferDepthEncodingParams);
float d = EncodeLogarithmicDepthGeneralized(z, VBufferDepthEncodingParams);
// Unity doesn't support samplers clamping to border, so we have to do it ourselves.
// TODO: add the proper sampler support.

float w = d;
#else
// Adjust the texture coordinate for HW trilinear sampling.
float w = ComputeLerpPositionForLogEncoding(z, d, VBufferScaleAndSliceCount, VBufferDepthEncodingParams);
float w = ComputeLerpPositionForLogEncoding(z, d, VBufferScaleAndSliceCount, VBufferDepthDecodingParams);
#endif
return SAMPLE_TEXTURE3D_LOD(VBufferLighting, trilinearSampler, float3(uv, w), 0);

float2 positionNDC, float linearDepth,
float4 VBufferResolution,
float4 VBufferScaleAndSliceCount,
float4 VBufferDepthEncodingParams)
float4 VBufferDepthEncodingParams,
float4 VBufferDepthDecodingParams)
VBufferScaleAndSliceCount, VBufferDepthEncodingParams);
VBufferScaleAndSliceCount,
VBufferDepthEncodingParams,
VBufferDepthDecodingParams);
#else
// Perform biquadratic reconstruction in XY, linear in Z, using 4x trilinear taps.

// The distance between slices is log-encoded.
float z = linearDepth;
float d = EncodeLogarithmicDepth(z, VBufferDepthEncodingParams);
float d = EncodeLogarithmicDepthGeneralized(z, VBufferDepthEncodingParams);
float w = ComputeLerpPositionForLogEncoding(z, d, VBufferScaleAndSliceCount, VBufferDepthEncodingParams);
float w = ComputeLerpPositionForLogEncoding(z, d, VBufferScaleAndSliceCount, VBufferDepthDecodingParams);
float2 weights[2], offsets[2];
BiquadraticFilter(1 - fc, weights, offsets); // Inverse-translate the filter centered around 0.5

34
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


List<VBuffer> m_VBuffers = null;
float m_VBufferNearPlane = 0.5f; // Distance in meters; dynamic modifications not handled by reprojection
float m_VBufferFarPlane = 64.0f; // Distance in meters; dynamic modifications not handled by reprojection
const float k_LogScale = 0.5f;
public void Build(HDRenderPipelineAsset asset)
{

return new Vector2((float)screenWidth / (float)(w * t), (float)screenHeight / (float)(h * t));
}
// Uses a logarithmic depth encoding.
// Near plane: depth = 0; far plane: depth = 1.
// x = n, y = log2(f/n), z = 1/n, w = 1/log2(f/n).
static Vector4 ComputeLogarithmicDepthEncodingParams(float nearPlane, float farPlane)
// See EncodeLogarithmicDepthGeneralized().
static Vector4 ComputeLogarithmicDepthEncodingParams(float nearPlane, float farPlane, float c)
{
Vector4 depthParams = new Vector4();
float n = nearPlane;
float f = farPlane;
depthParams.x = Mathf.Log(c, 2) * (1.0f / Mathf.Log(c * (f - n) + 1, 2));
depthParams.y = 1.0f / Mathf.Log(c * (f - n) + 1, 2);
depthParams.z = n - 1.0f / c; // Same
depthParams.w = 0.0f;
return depthParams;
}
// See DecodeLogarithmicDepthGeneralized().
static Vector4 ComputeLogarithmicDepthDecodingParams(float nearPlane, float farPlane, float c)
{
Vector4 depthParams = new Vector4();

depthParams.x = n;
depthParams.y = Mathf.Log(f / n, 2);
depthParams.z = 1.0f / depthParams.x;
depthParams.w = 1.0f / depthParams.y;
depthParams.x = 1.0f / c;
depthParams.y = c * (f - n) + 1;
depthParams.z = n - 1.0f / c; // Same
depthParams.w = 0.0f;
return depthParams;
}

cmd.SetGlobalVector( HDShaderIDs._VBufferResolution, new Vector4(w, h, 1.0f / w, 1.0f / h));
cmd.SetGlobalVector( HDShaderIDs._VBufferScaleAndSliceCount, new Vector4(scale.x, scale.y, d, 1.0f / d));
cmd.SetGlobalVector( HDShaderIDs._VBufferDepthEncodingParams, ComputeLogarithmicDepthEncodingParams(m_VBufferNearPlane, m_VBufferFarPlane));
cmd.SetGlobalVector( HDShaderIDs._VBufferDepthEncodingParams, ComputeLogarithmicDepthEncodingParams(m_VBufferNearPlane, m_VBufferFarPlane, k_LogScale));
cmd.SetGlobalVector( HDShaderIDs._VBufferDepthDecodingParams, ComputeLogarithmicDepthDecodingParams(m_VBufferNearPlane, m_VBufferFarPlane, k_LogScale));
cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, vBuffer.GetLightingIntegralBuffer());
}

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/DiffusionProfile/DiffusionProfileSettings.cs


public const int SSS_N_SAMPLES_NEAR_FIELD = 55; // Used for extreme close ups; must be a Fibonacci number
public const int SSS_N_SAMPLES_FAR_FIELD = 21; // Used at a regular distance; must be a Fibonacci number
public const int SSS_LOD_THRESHOLD = 4; // The LoD threshold of the near-field kernel (in pixels)
public const int TRANSMISSION_MODE_NONE = 0;
public const int TRANSMISSION_MODE_THIN = 1;
// Old SSS Model >>>
public const int SSS_BASIC_N_SAMPLES = 11; // Must be an odd number
public const int SSS_BASIC_DISTANCE_SCALE = 3; // SSS distance units per centimeter

public enum TransmissionMode : uint
{
None = DiffusionProfileConstants.TRANSMISSION_MODE_NONE,
ThinObject = DiffusionProfileConstants.TRANSMISSION_MODE_THIN,
Regular
Regular = 0,
ThinObject = 1
}
public string name;

scatteringDistance = Color.grey;
transmissionTint = Color.white;
texturingMode = TexturingMode.PreAndPostScatter;
transmissionMode = TransmissionMode.None;
transmissionMode = TransmissionMode.ThinObject;
thicknessRemap = new Vector2(0f, 5f);
worldScale = 1f;
ior = 1.4f; // TYpical value for skin specular reflectance

ValidateArray(ref halfRcpVariancesAndWeights, DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 2);
ValidateArray(ref filterKernelsBasic, DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * DiffusionProfileConstants.SSS_BASIC_N_SAMPLES);
Debug.Assert(DiffusionProfileConstants.DIFFUSION_PROFILE_NEUTRAL_ID <= 16, "Transmission flags (32-bit integer) cannot support more than 16 profiles (2 bits per profile).");
Debug.Assert(DiffusionProfileConstants.DIFFUSION_PROFILE_NEUTRAL_ID <= 32, "Transmission and Texture flags (32-bit integer) cannot support more than 32 profiles.");
UpdateCache();
}

// Erase previous value (This need to be done here individually as in the SSS editor we edit individual component)
uint mask = 1u << i;
texturingModeFlags &= ~mask;
mask = 3u << i * 2;
mask = 1u << i;
transmissionFlags |= (uint)profiles[p].transmissionMode << i * 2;
transmissionFlags |= (uint)profiles[p].transmissionMode << i;
thicknessRemaps[i] = new Vector4(profiles[p].thicknessRemap.x, profiles[p].thicknessRemap.y - profiles[p].thicknessRemap.x, 0f, 0f);
worldScales[i] = new Vector4(profiles[p].worldScale, 1.0f / profiles[p].worldScale, 0f, 0f);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/DiffusionProfile/DiffusionProfileSettings.cs.hlsl


#define SSS_N_SAMPLES_NEAR_FIELD (55)
#define SSS_N_SAMPLES_FAR_FIELD (21)
#define SSS_LOD_THRESHOLD (4)
#define TRANSMISSION_MODE_NONE (0)
#define TRANSMISSION_MODE_THIN (1)
#define SSS_BASIC_N_SAMPLES (11)
#define SSS_BASIC_DISTANCE_SCALE (3)

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLit.shader


[Enum(Flip, 0, Mirror, 1)] _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
// For layering, due to combinatorial explosion, we only support SSS/Transmission and Standard. We let other case for the shader graph
[Enum(Subsurface Scattering and Transmissison, 0, Standard, 1)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard
[Enum(Both, 0, SSS only, 1, Transmission only, 2)] _SSSAndTransmissionType("SSSandTransmissionType", Int) = 0 // SSSandTransmissionType.Both
[Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2)] _DisplacementMode("DisplacementMode", Int) = 0
[ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0

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


surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
#endif
#ifdef _MATERIAL_FEATURE_TRANSMISSION
// TEMP: The UI must control if we have transmission or not.
// Currently until we update the UI, this is control in the diffusion profile
uint transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u * surfaceData.diffusionProfile, 2u);
// Caution: Because of this dynamic test we don't know anymore statically if we have transmission, which mess with performance.
// in deferred case as we still have both sss and transmission until we update the UI it should be the same perf
if (transmissionMode != TRANSMISSION_MODE_NONE)
{
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
}
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
#endif
// Init other parameters

#else
surfaceData.specularOcclusion = 1.0;
#endif
AddDecalContribution(posInput.positionSS, surfaceData);
AddDecalContribution(posInput.positionSS, surfaceData);
#endif
#if defined(DEBUG_DISPLAY)

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitTessellation.shader


[Enum(Flip, 0, Mirror, 1)] _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
// For layering, due to combinatorial explosion, we only support SSS/Transmission and Standard. We let other case for the shader graph
[Enum(Subsurface Scattering and Transmissison, 0, Standard, 1)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard
[Enum(Both, 0, SSS only, 1, Transmission only, 2)] _SSSAndTransmissionType("SSSandTransmissionType", Int) = 0 // SSSandTransmissionType.Both
[Enum(None, 0, Tessellation displacement, 3)] _DisplacementMode("DisplacementMode", Int) = 3
[ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0
[ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0

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


bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[diffusionProfile].a;
bsdfData.thickness = _ThicknessRemaps[diffusionProfile].x + _ThicknessRemaps[diffusionProfile].y * thickness;
uint transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u * diffusionProfile, 2u);
#if SHADEROPTIONS_USE_DISNEY_SSS
bsdfData.transmittance = ComputeTransmittanceDisney( _ShapeParams[diffusionProfile].rgb,
_TransmissionTintsAndFresnel0[diffusionProfile].rgb,

bsdfData.thickness);
#endif
// Apply the transmission mode. Only the thick object mode performs the thickness displacement.
bsdfData.useThickObjectMode = transmissionMode != TRANSMISSION_MODE_THIN;
bsdfData.useThickObjectMode = !IsBitSet(asuint(_TransmissionFlags), diffusionProfile);
if (bsdfData.useThickObjectMode)
{

// Fresnel0 is deduced from interface between air and material (Assume to be 1.5 in Unity, or a metal).
// but here we go from clear coat (1.5) to material, we need to update fresnel0
// Note: Schlick is a poor approximation of Fresnel when ieta is 1 (1.5 / 1.5), schlick target 1.4 to 2.2 IOR.
bsdfData.fresnel0 = ConvertF0ForAirInterfaceToF0ForClearCoat15(bsdfData.fresnel0);
bsdfData.fresnel0 = lerp(bsdfData.fresnel0, ConvertF0ForAirInterfaceToF0ForClearCoat15(bsdfData.fresnel0), coatMask);
}
void FillMaterialTransparencyData(float3 baseColor, float metallic, float ior, float3 transmittanceColor, float atDistance, float thickness, float transmittanceMask, inout BSDFData bsdfData)

bool pixelHasTransmission = materialFeatureId == GBUFFER_LIT_TRANSMISSION_SSS || materialFeatureId == GBUFFER_LIT_TRANSMISSION;
bool pixelHasAnisotropy = materialFeatureId == GBUFFER_LIT_ANISOTROPIC;
bool pixelHasIridescence = materialFeatureId == GBUFFER_LIT_IRIDESCENCE;
bool pixelHasClearCoat = coatMask > 0;
bool pixelHasClearCoat = coatMask > 0.0;
// Disable pixel features disabled by the tile.
pixelFeatureFlags |= tileFeatureFlags & (pixelHasSubsurface ? MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING : 0);

bool PixelHasSubsurfaceScattering(BSDFData bsdfData)
{
return bsdfData.diffusionProfile != DIFFUSION_PROFILE_NEUTRAL_ID && bsdfData.subsurfaceMask != 0 && HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING);
// bsdfData.subsurfaceMask != 0 allow if sss is enabled for this pixels (i.e like per pixels feature) as in deferred case MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING alone is not sufficient
// but keep testing MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING for forward case
return bsdfData.diffusionProfile != DIFFUSION_PROFILE_NEUTRAL_ID && bsdfData.subsurfaceMask != 0 && HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING);
}
//-----------------------------------------------------------------------------

// Note: The modification of the base roughness and fresnel0 by the clear coat is already handled in FillMaterialClearCoatData
// Very coarse attempt at doing energy conservation for the diffuse layer based on NdotL. No science.
diffuseLighting *= lerp(1, F_Schlick(CLEAR_COAT_F0, NdotL), bsdfData.coatMask);
diffuseLighting *= lerp(1, 1.0 - coatF, bsdfData.coatMask);
}
}

#endif
float3 modifiedDiffuseColor;
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
// bsdfData.subsurfaceMask != 0 allow if sss is enabled for this pixels (i.e like per pixels feature) as in deferred case MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING alone is not sufficient
// but keep testing MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING for forward case
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING) && bsdfData.subsurfaceMask != 0)
modifiedDiffuseColor = ApplySubsurfaceScatteringTexturingMode(bsdfData.diffuseColor, bsdfData.diffusionProfile);
else
modifiedDiffuseColor = bsdfData.diffuseColor;

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


_ThicknessMap("Thickness Map", 2D) = "white" {}
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 1.0
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0
_CoatMaskMap("CoatMaskMap", 2D) = "white" {}
[ToggleUI] _EnergyConservingSpecularColor("_EnergyConservingSpecularColor", Float) = 1.0
_SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)

[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0
[Enum(Subsurface Scattering, 0, Standard, 1, Anisotropy, 2, ClearCoat, 3, Specular Color, 4)] _MaterialID("MaterialId", Int) = 1 // MaterialId.RegularLighting
// Following enum should be material feature flags (i.e bitfield), however due to Gbuffer encoding constrain many combination exclude each other
// so we use this enum as "material ID" which can be interpreted as preset of bitfield of material feature
// The only material feature flag that can be added in all cases is clear coat
[Enum(Subsurface Scattering and Transmissison, 0, Standard, 1, Anisotropy, 2, Iridescence, 3, Specular Color, 4)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard
[Enum(Both, 0, SSS only, 1, Transmission only, 2)] _SSSAndTransmissionType("SSSandTransmissionType", Int) = 0 // SSSandTransmissionType.Both
[Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2)] _DisplacementMode("DisplacementMode", Int) = 0
[ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0

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


surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
#endif
#ifdef _MATERIAL_FEATURE_TRANSMISSION
// TEMP: The UI must control if we have transmission or not.
// Currently until we update the UI, this is control in the diffusion profile
uint transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u * surfaceData.diffusionProfile, 2u);
// Caution: Because of this dynamic test we don't know anymore statically if we have transmission, which mess with performance.
// in deferred case as we still have both sss and transmission until we update the UI it should be the same perf
if (transmissionMode != TRANSMISSION_MODE_NONE)
{
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
}
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
#endif
#ifdef _MATERIAL_FEATURE_ANISOTROPY
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;

surfaceData.transmittanceMask = 0.0;
#endif
#ifdef _MATERIAL_FEATURE_CLEAR_COAT
// To shader feature for keyword to limit the variant
surfaceData.coatMask *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_CoatMaskMap), ADD_ZERO_IDX(sampler_CoatMaskMap), ADD_IDX(layerTexCoord.base)).r;
#else
surfaceData.coatMask = 0.0;
#endif
surfaceData.thicknessIrid = 0.0;

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


TEXTURE2D(_TransmittanceColorMap);
SAMPLER(sampler_TransmittanceColorMap);
TEXTURE2D(_CoatMaskMap);
SAMPLER(sampler_CoatMaskMap);
#else
// Set of users variables

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


_ThicknessMap("Thickness Map", 2D) = "white" {}
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 1.0
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0
_CoatMaskMap("CoatMaskMap", 2D) = "white" {}
[ToggleUI] _EnergyConservingSpecularColor("_EnergyConservingSpecularColor", Float) = 1.0
_SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)

[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0
[Enum(Subsurface Scattering, 0, Standard, 1, Anisotropy, 2, ClearCoat, 3, Specular Color, 4)] _MaterialID("MaterialId", Int) = 1 // MaterialId.RegularLighting
// Following enum should be material feature flags (i.e bitfield), however due to Gbuffer encoding constrain many combination exclude each other
// so we use this enum as "material ID" which can be interpreted as preset of bitfield of material feature
// The only material feature flag that can be added in all cases is clear coat
[Enum(Subsurface Scattering and Transmissison, 0, Standard, 1, Anisotropy, 2, Iridescence, 3, Specular Color, 4)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard
[Enum(Both, 0, SSS only, 1, Transmission only, 2)] _SSSAndTransmissionType("SSSandTransmissionType", Int) = 0 // SSSandTransmissionType.Both
[Enum(None, 0, Tessellation displacement, 3)] _DisplacementMode("DisplacementMode", Int) = 3
[ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl


// Therefore, we bitcast uint to float in C#, and bitcast back to uint in the shader.
uint _EnableSubsurfaceScattering; // Globally toggles subsurface and transmission scattering on/off
float _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
float _TransmissionFlags; // 2 bit/profile; 0 = inf. thick, 1 = thin, 2 = regular
float _TransmissionFlags; // 1 bit/profile; 0 = regular, 1 = thin
// Old SSS Model >>>
float4 _HalfRcpVariancesAndWeights[DIFFUSION_PROFILE_COUNT][2]; // 2x Gaussians in RGB, A is interpolation weights
// <<< Old SSS Model

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs


if (sssParameters == null || !frameSettings.enableSubsurfaceScattering)
return;
// TODO: For MSAA, at least initially, we can only support Jimenez, because we can't
// create MSAA + UAV render targets.
using (new ProfilingSample(cmd, "Subsurface Scattering", CustomSamplerId.SubsurfaceScattering.GetSampler()))
{
// For Jimenez we always need an extra buffer, for Disney it depends on platform

cmd.ReleaseTemporaryRT(m_CameraFilteringBuffer);
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraFilteringBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
if (frameSettings.enableMSAA)
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraFilteringBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear); // no UAV
else
CoreUtils.CreateCmdTemporaryRT(cmd, m_CameraFilteringBuffer, hdCamera.renderTextureDesc, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
// Clear the SSS filtering target
using (new ProfilingSample(cmd, "Clear SSS filtering target", CustomSamplerId.ClearSSSFilteringTarget.GetSampler()))

29
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs


aggregate.enableTransparentObjects = srcFrameSettings.enableTransparentObjects;
aggregate.enableMSAA = srcFrameSettings.enableMSAA && renderPipelineSettings.supportMSAA;
if (QualitySettings.antiAliasing < 1)
aggregate.enableMSAA = false;
aggregate.ConfigureMSAADependentSettings();
}
public void ConfigureMSAADependentSettings()
{
if (enableMSAA)
{
// Initially, MSAA will only support forward
enableForwardRenderingOnly = true;
// TODO: Should we disable enableFptlForForwardOpaque in here, instead of in InitializeLightLoopSettings?
// We'd have to move this method to after InitializeLightLoopSettings if we did. It would be nice to centralize
// all MSAA-dependent settings in this method.
// Assuming MSAA is being used, TAA, and therefore, motion vectors are not needed
enableMotionVectors = false;
// TODO: The work will be implemented piecemeal to support all passes
enableDBuffer = false; // no decals
enableDistortion = false; // no gaussian final color
enablePostprocess = false;
enableRoughRefraction = false; // no gaussian pre-refraction
enableSSAO = false;
enableSSR = false;
enableSubsurfaceScattering = false;
enableTransparentObjects = false; // waiting on depth pyramid generation
}
}
static public void RegisterDebug(String menuName, FrameSettings frameSettings)

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl


float _GlobalFog_Extinction;
float4 _VBufferResolution; // { w, h, 1/w, 1/h }
float4 _VBufferScaleAndSliceCount; // { fracVisW, fracVisH, count, 1/count }
float4 _VBufferDepthEncodingParams; // { n, log2(f/n), 1/n, 1/log2(f/n) }
float4 _VBufferDepthEncodingParams; // See the call site for description
float4 _VBufferDepthDecodingParams; // See the call site for description
CBUFFER_END
// ----------------------------------------------------------------------------

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.hlsl


#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
float4 volFog = SampleInScatteredRadianceAndTransmittance(TEXTURE3D_PARAM(_VBufferLighting, s_trilinear_clamp_sampler),
posInput.positionNDC, posInput.linearDepth,
_VBufferResolution, _VBufferScaleAndSliceCount,
_VBufferDepthEncodingParams);
_VBufferResolution,
_VBufferScaleAndSliceCount,
_VBufferDepthEncodingParams,
_VBufferDepthDecodingParams);
fogColor = volFog.rgb;
fogFactor = 1 - volFog.a;
#else

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


}
RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(rtWidth, rtHeight, m_ColorFormat, kDepthStencilBufferBits);
colorRTDesc.sRGB = true;
colorRTDesc.msaaSamples = msaaSamples;
colorRTDesc.enableRandomWrite = false;

57
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2103_BakeMixed.unity


blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &126909927
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &398276648
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &569393405
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &573256290
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &585362627
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &591582530
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &658105329
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &752846307
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &886840555
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &976312494
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1106453251
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1142614819
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1252875748
MeshRenderer:
m_ObjectHideFlags: 2

shadowResolution: 512
shadowDimmer: 1
shadowFadeDistance: 10000
enableContactShadows: 0
contactShadowLength: 0
contactShadowDistanceScaleFactor: 0.5
contactShadowMaxDistance: 50
contactShadowFadeDistance: 5
contactShadowSampleCount: 8
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1546213938
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1589059864
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1636907145
MeshRenderer:
m_ObjectHideFlags: 2

blendNormalDistanceNegative: {x: 0, y: 0, z: 0}
boxSideFadePositive: {x: 1, y: 1, z: 1}
boxSideFadeNegative: {x: 1, y: 1, z: 1}
proxyVolumeComponent: {fileID: 0}
--- !u!23 &1828705049
MeshRenderer:
m_ObjectHideFlags: 2

m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
- target: {fileID: 4048380051118816, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
- target: {fileID: 100000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
propertyPath: m_StaticEditorFlags
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
propertyPath: m_LocalScale.x
value: 3
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
propertyPath: m_LocalScale.y
value: 3
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
propertyPath: m_LocalScale.z
value: 3
objectReference: {fileID: 0}
m_ParentPrefab: {fileID: 100100000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}
m_ParentPrefab: {fileID: 100100000, guid: 9c31666db73c94448ad9133b2aeff0e5, type: 2}
m_IsPrefabParent: 0

1
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/CommonAssets/Cornell Box.fbx.meta


2186277476908879416: ImportLogs
2186277476908879418: ImportLogs
2186277476908879420: ImportLogs
2186277476908879422: ImportLogs
externalObjects:
- first:
type: UnityEngine:Material

1
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/040_UpgradeScene/Models/Environment/Floor.fbx.meta


2186277476908879416: ImportLogs
2186277476908879418: ImportLogs
2186277476908879420: ImportLogs
2186277476908879422: ImportLogs
externalObjects:
- first:
type: UnityEngine:Material

338
ImageTemplates/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity.png

之前 之后
宽度: 853  |  高度: 480  |  大小: 88 KiB

83
ImageTemplates/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity.png.meta


fileFormatVersion: 2
guid: 004cadb485fd995429668566213dc468
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 5
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

87
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/3DObjects/CornelBox/Cornell Box.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1837566155010132}
m_IsPrefabParent: 1
--- !u!1 &1837566155010132
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4048380051118816}
- component: {fileID: 33686852384577776}
- component: {fileID: 23804808622393114}
m_Layer: 0
m_Name: Cornell Box
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &4048380051118816
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1837566155010132}
m_LocalRotation: {x: 0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0, y: 0, z: 0}
m_LocalScale: {x: 3, y: 3, z: 3}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &23804808622393114
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1837566155010132}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 2100000, guid: 75d48353f7ed9d04683bb9f74b121d21, type: 2}
- {fileID: 2100000, guid: ccb6d265c4315eb46bc2af89bda5b225, type: 2}
- {fileID: 2100000, guid: 9e230cd3dd687c74f9fd71088a260bb3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &33686852384577776
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1837566155010132}
m_Mesh: {fileID: 4300000, guid: ec3442293e1c1fb4cbdc0a199ebb03f0, type: 3}

8
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/3DObjects/CornelBox/Cornell Box.prefab.meta


fileFormatVersion: 2
guid: 9c31666db73c94448ad9133b2aeff0e5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

8
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.meta


fileFormatVersion: 2
guid: 0b115fd7a18dc9043ba2f65456a487a0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity
文件差异内容过多而无法显示
查看文件

7
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2203_PlanarProbes.unity.meta


fileFormatVersion: 2
guid: 359ded33a047fd540b5e19a98547f5e2
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
SampleScenes/HDTest/PlanarReflectionTests.meta


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