Skip to content
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

Mixed cached shadow maps (Cached static + dynamic rendered every frame) #1559

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
840c954
UI for mixed cached shadows
FrancescoC-unity Jul 30, 2020
2b256fb
Baby steps (# 1)
FrancescoC-unity Aug 3, 2020
c5fb40c
Baby steps (# 2)
FrancescoC-unity Aug 3, 2020
1929450
Extrapolate the update request data into a function
FrancescoC-unity Aug 3, 2020
a6ba1cd
Commit before blit code
FrancescoC-unity Aug 3, 2020
44c347e
Need to switch branch
FrancescoC-unity Aug 4, 2020
fb1a74a
Need to switch branch
FrancescoC-unity Aug 4, 2020
f0bf347
Working as long the light does not move.
FrancescoC-unity Aug 7, 2020
3a70423
Fixed area light case
FrancescoC-unity Aug 7, 2020
ea84332
Make it render graph ready
FrancescoC-unity Aug 7, 2020
6fe07a8
Make sure we correctly update the freshly updated cached shadows
FrancescoC-unity Aug 7, 2020
b99be9d
Raw update upon movement option (Missing API for threshold)
FrancescoC-unity Aug 7, 2020
e09e735
Threshold API
FrancescoC-unity Aug 10, 2020
b6626b0
Add unity binary tag
FrancescoC-unity Aug 10, 2020
93f1a32
New docs
FrancescoC-unity Aug 10, 2020
56340b7
Shader name change
FrancescoC-unity Aug 10, 2020
de8888a
Merge branch 'HDRP/staging' into HDRP/cached-shadows-with-dynamic-cas…
FrancescoC-unity Aug 10, 2020
d3c8be5
Update docs
FrancescoC-unity Aug 10, 2020
e5164e4
Fix bad merge
FrancescoC-unity Aug 11, 2020
a8612ba
Update Shadows-in-HDRP.md
JordanL8 Aug 12, 2020
da7a5a9
For now disable the directional light case.
FrancescoC-unity Aug 25, 2020
94f559e
Merge branch 'HDRP/staging' into HDRP/cached-shadows-with-dynamic-cas…
FrancescoC-unity Aug 25, 2020
9f5d479
Disable directional mixed.
FrancescoC-unity Aug 26, 2020
23aee85
Make it disabled under define
FrancescoC-unity Oct 2, 2020
37f2c40
Remove docs
FrancescoC-unity Oct 2, 2020
a735c24
Merge branch 'HDRP/staging' into HDRP/cached-shadows-with-dynamic-cas…
FrancescoC-unity Oct 6, 2020
62b598f
Implement rendergraph version
FrancescoC-unity Oct 6, 2020
1f013ca
Remove superflous blit
FrancescoC-unity Oct 6, 2020
f7ee31a
Tentative fix for yamato.
FrancescoC-unity Oct 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
Expand Up @@ -316,6 +316,19 @@ public TextureHandle CreateTexture(TextureHandle texture)
return m_Resources.CreateTexture(m_Resources.GetTextureResourceDesc(texture.handle));
}

/// <summary>
/// Create a new Render Graph Texture if the passed handle is invalid and use said handle as output.
/// If the passed handle is valid, no texture is created.
/// </summary>
/// <param name="texture">Texture from which the descriptor should be used.</param>
/// <returns>A new TextureHandle.</returns>
public void CreateTextureIfInvalid(in TextureDesc desc, ref TextureHandle texture)
{
if (!texture.IsValid())
texture = m_Resources.CreateTexture(desc);
}


/// <summary>
/// Gets the descriptor of the specified Texture resource.
/// </summary>
Expand Down
Expand Up @@ -111,6 +111,9 @@ When a Light that caches its shadows renders its shadow map for the first time,
If the Light's **Update Mode** is set to **OnDemand**, you can manually request HDRP to update the Light's shadow map. To do this, access the Light's **HDAdditionalLightData** component and call the `RequestShadowMapRendering` function. Also, if the Light has multiple shadows (e.g. multiple cascades of a directional light), you can request the update of a specific sub-shadow. To do this, use the `RequestSubShadowMapRendering(shadowIndex)` function.
For a Light that does cache its shadows, if you disable it or set its **Update Mode** to **Every Frame**, you can tell HDRP to preserve the Light's shadow map's place in the cached shadow atlas. This means that, if you enable the Light again, HDRP does not need to re-render the shadow map or place it into a shadow atlas. For information on how to make a Light preserve its shadow map's place in the cached shadow atlas, see [Preserving shadow atlas placement](#preserving-shadow-atlas-placement).

As a shortcut for a common case, HDRP offers an option to automatically trigger an update when either the position or rotation of a light changes above a certain threshold. To enable this option, select a [Light](https://github.com/Unity-Technologies/Graphics/pull/Light-Component.md) and, in the **Shadow** section of its Inspector, enable **Update on light movement**.
You can customize the threshold that HDRP uses to determine how much a light needs to move or rotate to trigger an update. To do this, use the properties: `cachedShadowTranslationUpdateThreshold` and `cachedShadowAngleUpdateThreshold` properties on the Light's **HDAdditionalLightData** component. Note that point lights ignore the angle differences when determining if they need to perform an update in this mode.

### Customising shadow caching
HDRP caches shadow maps for punctual Lights into one atlas, area Lights into another, and directional Lights into the same atlas as non-cached Directional Lights. You can change the resolution of the first two cached shadow atlases independently of one another. To do this:

Expand Down
Expand Up @@ -116,6 +116,8 @@ sealed class Styles
public readonly GUIContent contactShadows = new GUIContent("Enable", "Enable support for Contact Shadows on this Light. This is better for lights with a lot of visible shadows.");
public readonly GUIContent rayTracedContactShadow = new GUIContent("Ray Tracing (Preview)", "Uses ray tracing to compute the contact shadow for a light.");
public readonly GUIContent shadowUpdateMode = new GUIContent("Update Mode", "Specifies when HDRP updates the shadow map.");
public readonly GUIContent shadowAlwaysDrawDynamic = new GUIContent("Always draw dynamic", "Specifies whether HDRP renders dynamic shadow caster every frame regardless of the update mode.");
public readonly GUIContent shadowUpdateOnLightTransformChange = new GUIContent("Update on light movement", "Whether a cached shadow map will be automatically updated when the light transform changes.");
public readonly GUIContent useCustomSpotLightShadowCone = new GUIContent("Custom Spot Angle", "When enabled, this Spot Light uses the custom angle for shadow map rendering.");
public readonly GUIContent customSpotLightShadowCone = new GUIContent("Shadow Angle", "Controls the custom angle this Spot Light uses for shadow map rendering.");

Expand Down
Expand Up @@ -1021,6 +1021,15 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner)
{
EditorGUILayout.PropertyField(serialized.shadowUpdateMode, s_Styles.shadowUpdateMode);

if(serialized.shadowUpdateMode.intValue > 0 && serialized.type != HDLightType.Directional)
{
#if MIXED_CACHED_SHADOW
EditorGUILayout.PropertyField(serialized.shadowAlwaysDrawDynamic, s_Styles.shadowAlwaysDrawDynamic);
#endif
EditorGUILayout.PropertyField(serialized.shadowUpdateUponTransformChange, s_Styles.shadowUpdateOnLightTransformChange);

}

HDLightType lightType = serialized.type;

using (var change = new EditorGUI.ChangeCheckScope())
Expand Down
Expand Up @@ -94,6 +94,8 @@ internal class SerializedHDLight
public SerializedProperty shadowTint;
public SerializedProperty penumbraTint;
public SerializedProperty shadowUpdateMode;
public SerializedProperty shadowAlwaysDrawDynamic;
public SerializedProperty shadowUpdateUponTransformChange;
public SerializedScalableSettingValue shadowResolution;

// Bias control
Expand Down Expand Up @@ -408,6 +410,8 @@ public SerializedHDLight(HDAdditionalLightData[] lightDatas, LightEditor.Setting
shadowTint = o.Find("m_ShadowTint");
penumbraTint = o.Find("m_PenumbraTint");
shadowUpdateMode = o.Find("m_ShadowUpdateMode");
shadowAlwaysDrawDynamic = o.Find("m_AlwaysDrawDynamicShadows");
shadowUpdateUponTransformChange = o.Find("m_UpdateShadowOnLightMovement");
shadowResolution = new SerializedScalableSettingValue(o.Find((HDAdditionalLightData l) => l.shadowResolution));

slopeBias = o.Find("m_SlopeBias");
Expand Down