Skip to content

Commit

Permalink
Merge pull request #7977 from Unity-Technologies/internal/2023.1/staging
Browse files Browse the repository at this point in the history
Internal/2023.1/staging
  • Loading branch information
UnityAljosha authored Oct 16, 2023
2 parents 76b5adb + c4ca3c5 commit c1f9ff1
Show file tree
Hide file tree
Showing 57 changed files with 376 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ internal enum FPTLMaxLightSizes
Ultra = 255
}

internal enum PathTracingLightListSizes
{
Low = 8,
Medium = 16,
High = 32,
Ultra = 64
}


/// <summary>
/// Project-wide shader configuration options.
/// </summary>
Expand Down Expand Up @@ -53,7 +62,18 @@ public enum ShaderOptions
/// Lower count will mean some memory savings.
/// Note: For any rendering bigger than 4k (in native) it is recommended to use Low count per tile, to avoid possible artifacts.
/// </summary>
FPTLMaxLightCount = FPTLMaxLightSizes.High
FPTLMaxLightCount = FPTLMaxLightSizes.High,

/// <summary>
/// The upper limit for the maximum amount of elements per cell in the light cluster. The maximum can be set in the project settings. This value caps the maximum.
/// </summary>
LightClusterMaxCellElementCount = 24,

/// <summary>
/// Maximum number of lights used in the path tracer light list. This number can be one of the prespecified possibilities in PathTracingLightListSizes, or can be chosen manually.
/// Lower count will mean some memory savings.
/// </summary>
PathTracingMaxLightCount = PathTracingLightListSizes.Medium
};

// Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl
Expand Down Expand Up @@ -94,6 +114,12 @@ public class ShaderConfig
/// <summary>Indicates the maximum number of lights available for Fine Prunning Tile Lighting.</summary>
/// <seealso cref="ShaderOptions.FPTLMaxLightCount"/>
public static int FPTLMaxLightCount = (int)ShaderOptions.FPTLMaxLightCount;
/// <summary>Indicates the cap on the maximum number of elements per cell in the light cluster.</summary>
/// <seealso cref="ShaderOptions.LightClusterMaxCellElementCount"/>
public const int LightClusterMaxCellElementCount = (int)ShaderOptions.LightClusterMaxCellElementCount;
/// <summary>Indicates the maximum number of lights in the path tracing light list.</summary>
/// <seealso cref="ShaderOptions.PathTracingMaxLightCount"/>
public static int PathTracingMaxLightCount = (int)ShaderOptions.PathTracingMaxLightCount;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define SHADEROPTIONS_BARN_DOOR (0)
#define SHADEROPTIONS_GLOBAL_MIP_BIAS (1)
#define SHADEROPTIONS_FPTLMAX_LIGHT_COUNT (63)
#define SHADEROPTIONS_PATH_TRACING_MAX_LIGHT_COUNT (16)

//
// UnityEngine.Rendering.HighDefinition.InternalLightCullingDefs: static fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ For example, you can use it to:
* Disable Area Light.
* Disable Pre-exposition.
* Enable [camera-relative rendering](Camera-Relative-Rendering.md).
* Increase the size of the tile and cluster light list for rasterization.
* Increase the size of [the Path Tracing light list](Ray-Tracing-Path-Tracing.md).

## Using the HDRP Config package

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ If there is any noise that affects the exposure in the final converged frame, ad

* **Limit Max**

## Path tracing and Light sources

Due to the fundamentally different nature of Path Tracing, light sources are queried differently. To support this, the path tracer needs to build some additional data structures that contain light source information. These data structures limit the maximum number of lights that can be evaluated in local neighborhoods. In the current implementation, there are two such data structures.

The first one is the [Ray Tracing Light Cluster](Ray-Tracing-Light-Cluster.md). It is used to resolve the lights around a specific point. The maximum number of lights per cell in this cluster can be increased if necessary.

The second one is the Path Tracing light list, an internal data structure used to capture all light sources relevant to a specific path segment. If too many light sources are close to each other, they might not all fit in the light list. This might result in artifacts. To remove these artifacts, you can change the `PathTracingMaxLightCount` setting through the [HDRP Config mechanism](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/HDRP-Config-Package.html).

## Limitations

This section contains information on the limitations of HDRP's path tracing implementation. Mainly, this is a list of features that HDRP supports in its rasterized render pipeline, but not in its path-traced render pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add
[!include[](snippets/shader-properties/surface-options/alpha-clipping.md)]
[!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)]
[!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)]
[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)]
[!include[](snippets/shader-properties/surface-options/double-sided-mode.md)]
[!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)]
[!include[](snippets/shader-properties/surface-options/receive-decals.md)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add
[!include[](snippets/shader-properties/surface-options/alpha-clipping.md)]
[!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)]
[!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)]
[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)]
[!include[](snippets/shader-properties/surface-options/double-sided-mode.md)]
[!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)]
[!include[](snippets/shader-properties/surface-options/receive-decals.md)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add
[!include[](snippets/shader-properties/surface-options/alpha-clipping.md)]
[!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)]
[!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)]
[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)]
[!include[](snippets/shader-properties/surface-options/double-sided-mode.md)]
[!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)]
[!include[](snippets/shader-properties/surface-options/receive-decals.md)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add
[!include[](snippets/shader-properties/surface-options/alpha-clipping.md)]
[!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)]
[!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)]
[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)]
[!include[](snippets/shader-properties/surface-options/double-sided-mode.md)]
[!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)]
[!include[](snippets/shader-properties/surface-options/receive-decals.md)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add
[!include[](snippets/shader-properties/surface-options/alpha-clipping.md)]
[!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)]
[!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)]
[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)]
[!include[](snippets/shader-properties/surface-options/double-sided.md)]
[!include[](snippets/shader-properties/surface-options/ss-depth-offset.md)]
[!include[](snippets/shader-properties/surface-options/conservative-depth-offset.md)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<tr>
<td>- **Exclude from Temporal Upscaling and Anti Aliasing**</td>
<td>

Indicates whether the render pipeline excludes this surface from any temporal upscalers (TU) and temporal anti-aliasing (AA). This is useful when the surface looks blurry when TAA or any Temporal Upscaler is enabled and especially useful for animated textures (such as video player in a surface).
This setting only works for Transparent surfaces due to the fact that there are no more stencil bits open.

</td>
</tr>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ sealed class HDMetadata : ScriptableObject
[SerializeField]
bool m_HasVertexModificationInMotionVector;

[SerializeField]
bool m_IsVFXCompatible;

public ShaderID shaderID
{
get => m_ShaderID;
Expand Down Expand Up @@ -67,5 +70,11 @@ public bool hasVertexModificationInMotionVector
get => m_HasVertexModificationInMotionVector;
set => m_HasVertexModificationInMotionVector = value;
}

public bool isVFXCompatible
{
get => m_IsVFXCompatible;
set => m_IsVFXCompatible = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,24 @@ public static void AddStencilShaderProperties(PropertyCollector collector, Syste
collector.AddToggleProperty(kEnableBlendModePreserveSpecularLighting, false, HLSLDeclaration.UnityPerMaterial);
}

bool excludeFromTUAndAA = systemData?.excludeFromTUAndAA ?? false;
collector.AddToggleProperty(kExcludeFromTUAndAA, excludeFromTUAndAA);

// Configure render state
BaseLitAPI.ComputeStencilProperties(receivesLighting, forwardOnly, ssrStencil, splitLighting, out int stencilRef, out int stencilWriteMask,
out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer,
out int stencilRefMV, out int stencilWriteMaskMV
);
BaseLitAPI.ComputeStencilProperties(
receivesLighting,
forwardOnly,
ssrStencil,
splitLighting,
excludeFromTUAndAA,
out int stencilRef,
out int stencilWriteMask,
out int stencilRefDepth,
out int stencilWriteMaskDepth,
out int stencilRefGBuffer,
out int stencilWriteMaskGBuffer,
out int stencilRefMV,
out int stencilWriteMaskMV);

// All these properties values will be patched with the material keyword update
collector.AddIntProperty("_StencilRef", stencilRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public virtual ScriptableObject GetMetadataObject(GraphDataReadOnly graph)
hdMetadata.migrateFromOldCrossPipelineSG = m_MigrateFromOldCrossPipelineSG;
hdMetadata.hdSubTargetVersion = systemData.version;
hdMetadata.hasVertexModificationInMotionVector = systemData.customVelocity || systemData.tessellation || graph.AnyVertexAnimationActive();
hdMetadata.isVFXCompatible = graph.IsVFXCompatible();
return hdMetadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected override void CreatePropertyGUI()
}

AddProperty(customVelocityText, () => systemData.customVelocity, (newValue) => systemData.customVelocity = newValue);
AddProperty(excludeFromTUAndAAText, () => systemData.excludeFromTUAndAA, (newValue) => systemData.excludeFromTUAndAA = newValue);

AddProperty(tessellationEnableText, () => systemData.tessellation, (newValue) => systemData.tessellation = newValue);
if (systemData.tessellation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public bool alphaTest
set => m_AlphaTest = value;
}

[SerializeField]
bool m_ExcludeFromTUAndAA = false;
public bool excludeFromTUAndAA
{
get => m_ExcludeFromTUAndAA;
set => m_ExcludeFromTUAndAA = value;
}

[SerializeField, Obsolete("Keep for migration")]
internal bool m_TransparentDepthPrepass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ internal static class Styles
public static GUIContent specularAAScreenSpaceVarianceText = new GUIContent("Screen space variance", "Controls the strength of the Specular AA reduction. Higher values give a more blurry result and less aliasing.");
public static GUIContent specularAAThresholdText = new GUIContent("Threshold", "Controls the effect of Specular AA reduction. A values of 0 does not apply reduction, higher values allow higher reduction.");

public static GUIContent excludeFromTUAndAAText = new GUIContent("Exclude From Temporal Upscalers and Anti Aliasing", "When enabled, the current material wont be temporaly sampled during TAA and will have reduced ghosting on upscalers.");

// SSR
public static GUIContent receivesSSRText = new GUIContent("Receive SSR", "When enabled, this Material can receive screen space reflections.");
public static GUIContent receivesSSRTransparentText = new GUIContent("Receive SSR Transparent", "When enabled, this Material can receive screen space reflections. This will force a transparent depth prepass on the object if HDRP supports it.");
Expand Down Expand Up @@ -182,6 +184,7 @@ enum DisplacementModeLitTessellation { None = DisplacementMode.None, Tessellatio
MaterialProperty specularAAThreshold = null;
const string kSpecularAAThreshold = "_SpecularAAThreshold";
MaterialProperty transmissionEnable = null;
MaterialProperty excludeFromTUAndAA = null;

// Per pixel displacement params
MaterialProperty ppdMinSamples = null;
Expand Down Expand Up @@ -311,6 +314,7 @@ public override void LoadMaterialProperties()
blendMode = FindProperty(kBlendMode);

transmissionEnable = FindProperty(kTransmissionEnable);
excludeFromTUAndAA = FindProperty(kExcludeFromTUAndAA);

if ((m_Features & Features.DoubleSidedNormalMode) != 0)
{
Expand Down Expand Up @@ -768,6 +772,9 @@ protected void DrawLitSurfaceOptions()
materialEditor.ShaderProperty(receivesSSR, Styles.receivesSSRText);
}

if (excludeFromTUAndAA != null && BaseLitAPI.CompatibleWithExcludeFromTUAndAA(surfaceTypeValue, renderQueue))
materialEditor.ShaderProperty(excludeFromTUAndAA, Styles.excludeFromTUAndAAText);

if (enableGeometricSpecularAA != null)
{
materialEditor.ShaderProperty(enableGeometricSpecularAA, Styles.enableGeometricSpecularAAText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
stencilRefWaterVar.displayName = "Stencil Water Ref GBuffer";
stencilRefWaterVar.hidden = true;
stencilRefWaterVar.floatType = FloatType.Default;
stencilRefWaterVar.value = (int)StencilUsage.WaterSurface;
stencilRefWaterVar.value = (int)(StencilUsage.WaterSurface | StencilUsage.ExcludeFromTUAndAA);
stencilRefWaterVar.overrideHLSLDeclaration = true;
stencilRefWaterVar.hlslDeclarationOverride = HLSLDeclaration.Global;
stencilRefWaterVar.generatePropertyBlock = false;
Expand All @@ -431,7 +431,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
stencilWriteMaskWaterVar.displayName = "Stencil Water Write Mask GBuffer";
stencilWriteMaskWaterVar.hidden = true;
stencilWriteMaskWaterVar.floatType = FloatType.Default;
stencilWriteMaskWaterVar.value = (int)StencilUsage.WaterSurface;
stencilWriteMaskWaterVar.value = (int)(StencilUsage.WaterSurface | StencilUsage.ExcludeFromTUAndAA);
stencilWriteMaskWaterVar.overrideHLSLDeclaration = true;
stencilWriteMaskWaterVar.hlslDeclarationOverride = HLSLDeclaration.Global;
stencilWriteMaskWaterVar.generatePropertyBlock = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override IEnumerable<string> filteredOutSettings
yield return "castShadows";
yield return "sort";
yield return "useAlphaClipping";
yield return "excludeFromTAA";
yield return "excludeFromTUAndAA";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected override IEnumerable<string> filteredOutSettings
{
yield return "onlyAmbientLighting";
yield return "preserveSpecularLighting";
yield return "excludeFromTAA";
yield return "excludeFromTUAndAA";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected override IEnumerable<string> filteredOutSettings
yield return nameof(sortMode);
yield return nameof(enableRayTracing);
yield return nameof(revertSorting);
yield return nameof(excludeFromTAA);
yield return nameof(excludeFromTUAndAA);
yield return nameof(computeCulling);
yield return nameof(vfxSystemSortPriority);
yield return nameof(sortingPriority);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class VFXHDRPBinder : VFXSRPBinder
public override string SRPAssetTypeStr { get { return typeof(HDRenderPipelineAsset).Name; } }
public override Type SRPOutputDataType { get { return typeof(VFXHDRPSubOutput); } }

public override bool IsShaderVFXCompatible(Shader shader) => shader.TryGetMetadataOfType<HDMetadata>(out var metadata) && metadata.isVFXCompatible;

public override void SetupMaterial(Material mat, bool hasMotionVector = false, bool hasShadowCasting = false, ShaderGraphVfxAsset shaderGraph = null)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override bool supportsMotionVector
&& transparentRenderQueue != TransparentRenderQueue.AfterPostProcessing;
}
}
public override bool supportsExcludeFromTAA { get { return !owner.isBlendModeOpaque; } }
public override bool supportsExcludeFromTUAndAA { get { return !owner.isBlendModeOpaque; } }

bool GeneratesWithShaderGraph()
{
Expand Down Expand Up @@ -199,12 +199,12 @@ private void GetStencilStateGBuffer(out int stencilWriteMask, out int stencilRef
stencilRef |= hasSubsurfaceScattering ? (int)StencilUsage.SubsurfaceScattering : 0;
}

private void GetStencilStateForward(out int stencilWriteMask, out int stencilRef, bool excludeFromTAA)
private void GetStencilStateForward(out int stencilWriteMask, out int stencilRef, bool excludeFromTUAndAA)
{
GetStencilStateCommon(out stencilWriteMask, out stencilRef);

stencilWriteMask |= excludeFromTAA ? (int)StencilUsage.ExcludeFromTAA : 0;
stencilRef |= excludeFromTAA ? (int)StencilUsage.ExcludeFromTAA : 0;
stencilWriteMask |= excludeFromTUAndAA ? (int)StencilUsage.ExcludeFromTUAndAA : 0;
stencilRef |= excludeFromTUAndAA ? (int)StencilUsage.ExcludeFromTUAndAA : 0;
}

public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> GetStencilStateOverridesStr()
Expand All @@ -222,7 +222,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> GetStencilSta
yield return CreateStencilStateOverrideStr("${VFXStencilGBuffer}", stencilWriteMaskGBuffer, stencilRefGBuffer);

int stencilWriteMaskForward, stencilRefForward;
GetStencilStateForward(out stencilWriteMaskForward, out stencilRefForward, owner.hasExcludeFromTAA);
GetStencilStateForward(out stencilWriteMaskForward, out stencilRefForward, owner.hasExcludeFromTUAndAA);
yield return CreateStencilStateOverrideStr("${VFXStencilForward}", stencilWriteMaskForward, stencilRefForward);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public partial class HDRenderPipeline
internal const int k_MaxDecalsOnScreen = 2048;
internal const int k_MaxPlanarReflectionsOnScreen = 16;
internal const int k_MaxCubeReflectionsOnScreen = 64;
internal const int k_MaxLightsPerClusterCell = 24;
internal const int k_MaxLightsPerClusterCell = ShaderConfig.LightClusterMaxCellElementCount;
internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f;

#if UNITY_SWITCH
Expand Down
Loading

0 comments on commit c1f9ff1

Please sign in to comment.