Skip to content

Hdrp/deferred shadow quality multi compile #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public enum ShaderOptions

AreaLights = 1,

[System.Obsolete("Deferred shadow can now assume any value, so this field is not used anymore.")]
DeferredShadowFiltering = HDShadowFilteringQuality.Medium,

BarnDoor = 0
};

Expand All @@ -66,6 +68,7 @@ public class ShaderConfig
public static int s_ProbeVolumesAdditiveBlending = (int)ShaderOptions.ProbeVolumesAdditiveBlending;
public static int s_AreaLights = (int)ShaderOptions.AreaLights;
public static int s_BarnDoor = (int)ShaderOptions.BarnDoor;
[System.Obsolete("Deferred shadow can now assume any value, so this field is not used anymore.")]
public static HDShadowFilteringQuality s_DeferredShadowFiltering = (HDShadowFilteringQuality)ShaderOptions.DeferredShadowFiltering;
}
}
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Replaced "High Quality" Volumetric Lighting with "Screen Resolution Percentage" and "Volume Slice Count" on the Fog volume component.
- Merged material samples and shader samples
- Update material samples scene visuals
- Use multi_compile API for deferred compute shader with shadow mask.

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ For example, you can use it to:

* Enable [ray tracing](Ray-Tracing-Getting-Started.html).
* Enable [camera-relative rendering](Camera-Relative-Rendering.html).
* Control the shadow filtering mode for deferred rendering.

## Using the HDRP Config package

Expand Down Expand Up @@ -36,7 +35,7 @@ To ensure that the two files are synchronized, you should follow the first metho
<a name="Example"></a>
### Example

You can use the method described above to change the shadow filtering mode for the [Lit Shader](Lit-Shader.html) in deferred mode:
You can use the method described above to disable [Camera-Relative rendering](Camera-Relative-Rendering.html):

1. In the **ShaderConfig.cs** file, set **DeferredShadowFiltering** to **HDShadowFilteringQuality.High**.
2. Generate the **ShaderConfig.cs.hlsl** file (**Edit > RenderPipeline > Generate Include Files**). Now, in the **ShaderConfig.cs.hlsl** file, the **SHADEROPTIONS_DEFERRED_SHADOW_FILTERING** define should be set to **2** (**#define SHADEROPTIONS_DEFERRED_SHADOW_FILTERING (2)**).
1. In the **ShaderConfig.cs** file, set **CameraRelativeRendering** to **0**.
2. Generate the **ShaderConfig.cs.hlsl** file (**Edit > RenderPipeline > Generate Include Files**). Now, in the **ShaderConfig.cs.hlsl** file, the **SHADEROPTIONS_CAMERA_RELATIVE_RENDERING** define should be set to **0**
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ Using high shadow bias values may result in light "leaking" through Meshes. This

After HDRP captures a shadow map, it processes filtering on the map in order to decrease the aliasing effect that occurs on low resolution shadow maps. Different filters affect the perceived sharpness of shadows.

To change which filter HDRP uses, the method depends on which filter quality you want to use and whether your HDRP Project uses [forward or deferred rendering](Forward-And-Deferred-Rendering.md).

* **Forward rendering**: Change the **Filtering Quality** property in your Unity Project’s [HDRP Asset](HDRP-Asset.html). This method works for every filter quality. There are currently three filter quality presets for directional and punctual lights. For information on the available filter qualities, see the [Filtering Qualities table](HDRP-Asset.html#FilteringQualities).
* **Deferred rendering**: For **Low** and **Medium** filter qualities, use the same method as forward rendering. If you want to use **High** quality (PCSS) filtering, you need to enable it in the [HDRP Config package](HDRP-Config-Package.html). For information on how to do this, see the [Example section](HDRP-Config-Package.html#Example) of the Config package documentation.
To change which shadow filter quality to use, change the **Filtering Quality** property in your Unity Project’s [HDRP Asset](HDRP-Asset.html). Higher quality have impact on GPU performance.
There are currently three filter quality presets for directional and punctual lights. For information on the available filter qualities, see the [Filtering Qualities table](HDRP-Asset.html#FilteringQualities).

## Shadowmasks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [2019.1 to 2019.2](Upgrading-from-2019.1-to-2019.2)
* [2019.2 to 2019.3](Upgrading-from-2019.2-to-2019.3)
* [2019.3 to 2020.1](Upgrading-from-2019.3-to-2020.1)
* [2020.1 to 2020.2](Upgrading-from-2020.1-to-2020.2)
* Volume Framework
* [Volumes](Volumes)
* [Volume Profiles](Volume-Profile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Upgrading HDRP from Unity 2020.1 to Unity 2020.2

In the High Definition Render Pipeline (HDRP), some features work differently between major versions of Unity. This document helps you upgrade HDRP from Unity 2020.1 to 2020.2.

## Shadows
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I named this generically Shadows as when the shadow caching rewrite lands I might need to add something here.


From Unity 2020.2, it is not necessary to change the [HDRP Config package](HDRP-Config-Package.html) in order to set the [Shadows filtering quality](HDRP-Asset.html#FilteringQualities) for Deferred rendering. Instead the filtering quality can be simply set on the [HDRP Asset](HDRP-Asset.html#FilteringQualities) similarly to what was previously setting only the quality for Forward.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public CommonShaderPreprocessor() { }

protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData)
{
// TODO: We need to perform compute shader stripping as soon as it is possible. Most egregious case would be the shadow filtering quality for Deferred.compute

// Strip every useless shadow configs
var shadowInitParams = hdrpAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,7 @@ static void Drawer_SectionShadows(SerializedHDRenderPipelineAsset serialized, Ed

if (!serialized.renderPipelineSettings.supportedLitShaderMode.hasMultipleDifferentValues)
{
bool isDeferredOnly = serialized.renderPipelineSettings.supportedLitShaderMode.intValue == (int)RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly;

// Deferred Only mode does not allow to change filtering quality, but rather it is hardcoded.
if (isDeferredOnly)
serialized.renderPipelineSettings.hdShadowInitParams.shadowFilteringQuality.intValue = (int)ShaderConfig.s_DeferredShadowFiltering;

using (new EditorGUI.DisabledScope(isDeferredOnly))
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.hdShadowInitParams.shadowFilteringQuality, Styles.filteringQuality);
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.hdShadowInitParams.shadowFilteringQuality, Styles.filteringQuality);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Shader "Hidden/HDRP/Deferred"
#pragma multi_compile _ OUTPUT_SPLIT_LIGHTING
#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH

#define USE_FPTL_LIGHTLIST // deferred opaque always use FPTL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#pragma multi_compile _ SHADOWS_SHADOWMASK

#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to do this also for deferred.shader and tiledeferred.shader

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Yes I always forget about those two. Will do!


#ifdef DEBUG_DISPLAY
// Don't care about this warning in debug
# pragma warning( disable : 4714 ) // sum of temp registers and indexable temp registers times 256 threads exceeds the recommended total 16384. Performance may be reduced at kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Shader "Hidden/HDRP/DeferredTile"
#pragma multi_compile _ OUTPUT_SPLIT_LIGHTING // Split lighting is utilized during the SSS pass.
#pragma multi_compile _ SHADOWS_SHADOWMASK /// Variant with and without shadowmask
#pragma multi_compile VARIANT0 VARIANT1 VARIANT2 VARIANT3 VARIANT4 VARIANT5 VARIANT6 VARIANT7 VARIANT8 VARIANT9 VARIANT10 VARIANT11 VARIANT12 VARIANT13 VARIANT14 VARIANT15 VARIANT16 VARIANT17 VARIANT18 VARIANT19 VARIANT20 VARIANT21 VARIANT22 VARIANT23 VARIANT24 VARIANT25 VARIANT26 VARIANT27 VARIANT28
#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH

#define USE_INDIRECT // otherwise TileVariantToFeatureFlags() will not be defined in Lit.hlsl!!!

Expand Down Expand Up @@ -301,6 +302,7 @@ Shader "Hidden/HDRP/DeferredTile"
#pragma multi_compile _ OUTPUT_SPLIT_LIGHTING
#pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ SHADOWS_SHADOWMASK /// Variant with and without shadowmask
#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH

#define USE_FPTL_LIGHTLIST 1 // deferred opaque always use FPTL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3816,6 +3816,22 @@ static void RenderComputeDeferredLighting(in DeferredLightingParameters paramete
cmd.SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, resources.lightListBuffer);
parameters.deferredComputeShader.shaderKeywords = null;

switch (HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.shadowFilteringQuality)
{
case HDShadowFilteringQuality.Low:
parameters.deferredComputeShader.EnableKeyword("SHADOW_LOW");
break;
case HDShadowFilteringQuality.Medium:
parameters.deferredComputeShader.EnableKeyword("SHADOW_MEDIUM");
break;
case HDShadowFilteringQuality.High:
parameters.deferredComputeShader.EnableKeyword("SHADOW_HIGH");
break;
default:
parameters.deferredComputeShader.EnableKeyword("SHADOW_MEDIUM");
break;
}

if (parameters.enableShadowMasks)
{
parameters.deferredComputeShader.EnableKeyword("SHADOWS_SHADOWMASK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
// Since we use slope-scale bias, the constant bias is for now set as a small fixed value
#define FIXED_UNIFORM_BIAS (1.0f / 65536.0f)

// We can't use multi_compile for compute shaders so we force the shadow algorithm
#if SHADERPASS == SHADERPASS_DEFERRED_LIGHTING || (defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT)
#if (defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT)

#if SHADEROPTIONS_DEFERRED_SHADOW_FILTERING == HDSHADOWFILTERINGQUALITY_LOW
#define SHADOW_LOW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ internal static HDShadowAtlasInitParams GetDefault()
shadowResolutionDirectional = new IntScalableSetting(new []{ 256, 512, 1024, 2048 }, ScalableSettingSchemaId.With4Levels),
shadowResolutionArea = new IntScalableSetting(new []{ 256, 512, 1024, 2048 }, ScalableSettingSchemaId.With4Levels),
shadowResolutionPunctual = new IntScalableSetting(new []{ 256, 512, 1024, 2048 }, ScalableSettingSchemaId.With4Levels),
shadowFilteringQuality = ShaderConfig.s_DeferredShadowFiltering,
supportScreenSpaceShadows = false,
maxScreenSpaceShadowSlots = 4,
screenSpaceShadowBufferFormat = ScreenSpaceShadowFormat.R16G16B16A16,
shadowFilteringQuality = HDShadowFilteringQuality.Medium,
supportScreenSpaceShadows = false,
maxScreenSpaceShadowSlots = 4,
screenSpaceShadowBufferFormat = ScreenSpaceShadowFormat.R16G16B16A16,
maxDirectionalShadowMapResolution = 2048,
maxAreaShadowMapResolution = 2048,
maxPunctualShadowMapResolution = 2048,
Expand Down