Skip to content

Universal Staging #5943

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 14 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added
- Added public api and updated docs for Light2D shape properties.
- Depth Texture setting for Overlay Camera.
- Added Depth Texture setting for Overlay Camera.
- Added Depth Priming support for Vulkan with MSAA.
- Added Shadows and Additional Lights off variants stripping.

### Changed

Expand All @@ -18,7 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fixed the LensFlare flicker with TAA on SceneView (case 1356734).
- Fixed an issue where Unlit and ParticlesUnlit shaders did not have HDR color selection for albedo [case 1283767](https://issuetracker.unity3d.com/issues/built-in-unlit-particle-shader-has-hdr-color-selection-for-albedo-urp-unlit-particles-do-not)
- Fixed a regression where ShaderGraph screen position was not correct in game view and when using XR [1369450]
- Fixed overwriting of preview camera background color. [case 1357004](https://issuetracker.unity3d.com/product/unity/issues/guid/1361557/)
- Fixed ShadowCaster now requires varying normalWS to include changed normals from vertex shader in shader graph.
- Fixed typo in numIterationsEnclosingSphere api name

## [13.0.0] - 2021-09-01
### Added
Expand All @@ -29,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Removed experimental tile deferred code.
- VFX: New shadergraph support directly on Universal target.
- Main light shadow, additional light shadow and additional light keywords are now enabled based on urp setting instead of existence in scene. This allows better variant stripping.

### Fixed
- Added warning for lit shader detailed abledo, if texture is not linear. [1342011](https://issuetracker.unity3d.com/issues/detail-maps-packed-differently-in-built-in-vs-urp)
Expand All @@ -40,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a bug with Sprite Targets in ShaderGraph not rendering correctly in game view [1352225]
- Fix for rendering thumbnails. [case 1348209](https://issuetracker.unity3d.com/issues/preview-of-assets-do-not-show-in-the-project-window)
- Fixed a regression bug where XR camera postion can not be modified in beginCameraRendering [case 1365000]
- Fixed an issue in where installing the Adaptive Performance package caused errors to the inspector UI [1368161](https://issuetracker.unity3d.com/issues/urp-package-throws-compilation-error-cs1525-when-imported-together-with-adaptive-performance-package)

## [12.0.0] - 2021-01-11
### Added
Expand Down Expand Up @@ -214,6 +221,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed graphical artefact when terrain height map is used with rendering layer mask for lighting.
- Fixed an issue where screen space shadows has flickering with deferred mode [case 1354681](https://issuetracker.unity3d.com/issues/screen-space-shadows-flicker-in-scene-view-when-using-deferred-rendering)
- Fixed shadowCascadeBlendCullingFactor to be 1.0
- Fixed missing property values in a RendererFeature of screen space shadows by adding tooltip for it instead of showing them. [case 1327356]

### Changed
- Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Areas where the Universal Render Pipeline (URP) differs from Unity's common ligh

* The [Light component inspector](light-component.md), which displays some URP-specific controls.
* The [Universal Additional Light Data](universal-additional-light-data.md) component, which allows Unity to store Light-related data that is specific to URP.
* Enlighten Realtime Global Illumination is supported in URP from version 12. For more information, see the forum post [Update on Global Illumination 2021](https://forum.unity.com/threads/update-on-global-illumination-2021.1067015/).
* Enlighten Realtime Global Illumination is supported in URP from version 12. For more information, see [Realtime Global Illumination using Enlighten](https://docs.unity3d.com/2021.2/Documentation/Manual/realtime-gi-using-enlighten.html).

For a full comparison of lighting features between Unity's Built-in Render Pipeline and URP, and an up to date list of lighting features that are currently under research, see [this feature comparison chart](universalrp-builtin-feature-comparison.md).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Screen Space Shadows Renderer Feature

The Screen Space Shadows [Renderer Feature](urp-renderer-feature.md) calculates screen-space shadows for opaque objects affected by the main directional light and draws them in the scene. To render screen-space shadows, URP requires an additional render target. This increases the amount of memory your application requires, but if your project uses forward rendering, screen-space shadows can benefit the runtime resource intensity. This is because if you use screen-space shadows, URP doesn't need to access the cascade shadow maps multiple times.
![Show screen space shadows](Images/ssshadows/ssshadows-result.png)<br/>*Screen-space shadows in a sample Scene.*

![Show screen space shadows texture](Images/ssshadows/ssshadows-shadow-texture.png)<br/>*The screen-space shadows texture for the above image.*

## Enabling screen-space shadows

To add screen space shadows to your project, [add the Screen Space Shadows Renderer Feature ](urp-renderer-feature-how-to-add.md) to the URP Renderer.

## Viewing screen-space shadows in the Frame Debugger

After you enable this Renderer Feature, URP renders screen-space shadows in your scene. To distinguish between shadow map shadows and screen-space shadows, you can view the render passes that draws the shadows in the [Frame Debugger](https://docs.unity3d.com/Manual/FrameDebugger.html).
![Show main light shadows in frame debugger](Images/ssshadows/ssshadows-framedebugger.png)<br/>*Screen Space Shadows pass in frame debugger.*

You can compare shadows cast on opaque objects from the screen-space shadow texture or the cascade shadow maps.
![Cast Shadows using screen space shadow stexture](Images/ssshadows/ssshadows-cast-shadow-using-screenspace.png)<br/>*The Frame Debugger shows the screen-space shadows texture.*

![Cast shadows using cascade shadowmaps](Images/ssshadows/ssshadows-cast-shadow-using-cascades.png)<br/>*The Frame Debugger shows shadows from a shadow map.*

## **Requirements and compatibility**

This Renderer Feature uses a depth texture and invokes a depth prepass before it draws opaque objects. It calculates the shadows in screen space before the `DrawOpaqueObjects` render pass. URP doesn't calculate or apply screen-space shadows for transparent objects; it uses [shadow maps](urp-shadows.md) for transparent objects instead. ![Won't cast shadows on transparent from screen space shadow texture](Images/ssshadows/ssshadows-cast-shadow-totransparent.png)*<br/>The Frame Debugger showing that Unity uses shadow maps for transparent objects and screen-space shadows for opaque objects.*
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;

namespace UnityEditor.Rendering.Universal
{
[CustomEditor(typeof(ScreenSpaceShadows))]
internal class ScreenSpaceShadowsEditor : Editor
{
#region Serialized Properties
private SerializedProperty m_SettingsProp;
#endregion

private bool m_IsInitialized = false;

private struct Styles
{
public static GUIContent Description = EditorGUIUtility.TrTextContent("Description", "This feature resolves the cascaded shadows in screen space, so there is no options now. It might have additional settings later.");
}

private void Init()
{
m_SettingsProp = serializedObject.FindProperty("m_Settings");
m_IsInitialized = true;
}

public override void OnInspectorGUI()
{
if (!m_IsInitialized)
{
Init();
}

EditorGUILayout.PropertyField(m_SettingsProp, Styles.Description);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ static class CoreRequiredFields
{
public static readonly FieldCollection ShadowCaster = new FieldCollection()
{
StructFields.Attributes.normalOS,
StructFields.Varyings.normalWS,
};

public static readonly FieldCollection DepthNormals = new FieldCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
$SurfaceDescriptionInputs.AbsoluteWorldSpacePositionPredisplacement:output.AbsoluteWorldSpacePositionPredisplacement = GetAbsolutePositionWS(input.positionWS);
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionWS), _ProjectionParams.x);
$SurfaceDescriptionInputs.PixelPosition: output.PixelPosition = input.positionCS.xy;
$SurfaceDescriptionInputs.NDCPosition: #if defined(USING_STEREO_MATRICES)
$SurfaceDescriptionInputs.NDCPosition: output.NDCPosition = output.ScreenPosition.xy / output.ScreenPosition.w;
$SurfaceDescriptionInputs.NDCPosition: #else
$SurfaceDescriptionInputs.NDCPosition: output.NDCPosition = output.PixelPosition.xy / _ScreenParams.xy;
$SurfaceDescriptionInputs.NDCPosition: #if UNITY_UV_STARTS_AT_TOP
$SurfaceDescriptionInputs.NDCPosition: output.NDCPosition.y = (0.5f - output.NDCPosition.y) * _ProjectionParams.x + 0.5f;
$SurfaceDescriptionInputs.NDCPosition: #else
$SurfaceDescriptionInputs.NDCPosition: output.NDCPosition.y = (output.NDCPosition.y - 0.5f) * _ProjectionParams.x + 0.5f;
$SurfaceDescriptionInputs.NDCPosition: #endif
$SurfaceDescriptionInputs.NDCPosition: #endif
$SurfaceDescriptionInputs.uv0: output.uv0 = input.texCoord0;
$SurfaceDescriptionInputs.uv1: output.uv1 = input.texCoord1;
$SurfaceDescriptionInputs.uv2: output.uv2 = input.texCoord2;
Expand Down
59 changes: 46 additions & 13 deletions com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum ShaderFeatures
MainLightShadowsCascade = (1 << 26),
DrawProcedural = (1 << 27),
ScreenSpaceOcclusionAfterOpaque = (1 << 28),
AdditionalLightsKeepOffVariants = (1 << 29),
ShadowsKeepOffVariants = (1 << 30),
}

[Flags]
Expand Down Expand Up @@ -358,12 +360,22 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa
var stripTool = new StripTool<ShaderFeatures>(features, shader, snippetData, compilerData.shaderKeywordSet, stripUnusedVariants);

// strip main light shadows, cascade and screen variants
// TODO: Strip disabled keyword once no light will re-use same variant
if (stripTool.StripMultiCompileKeepOffVariant(
m_MainLightShadows, ShaderFeatures.MainLightShadows,
m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade,
m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows))
return true;
if (IsFeatureEnabled(ShaderFeatures.ShadowsKeepOffVariants, features))
{
if (stripTool.StripMultiCompileKeepOffVariant(
m_MainLightShadows, ShaderFeatures.MainLightShadows,
m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade,
m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows))
return true;
}
else
{
if (stripTool.StripMultiCompile(
m_MainLightShadows, ShaderFeatures.MainLightShadows,
m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade,
m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows))
return true;
}

// TODO: Strip off variants once we have global soft shadows option for forcing instead as support
if (stripTool.StripMultiCompileKeepOffVariant(m_SoftShadows, ShaderFeatures.SoftShadows))
Expand Down Expand Up @@ -400,9 +412,16 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa
return true;

// No additional light shadows
// TODO: Strip off variants once we support no shadow lights re-use same variant
if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows))
return true;
if (IsFeatureEnabled(ShaderFeatures.ShadowsKeepOffVariants, features))
{
if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows))
return true;
}
else
{
if (stripTool.StripMultiCompile(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows))
return true;
}

if (stripTool.StripMultiCompile(m_ReflectionProbeBlending, ShaderFeatures.ReflectionProbeBlending))
return true;
Expand All @@ -425,10 +444,18 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa
}

// Additional light are shaded per-vertex or per-pixel.
// TODO: Strip off variants once we support no additional lights re-used variants
if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting,
m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights))
return true;
if (IsFeatureEnabled(ShaderFeatures.AdditionalLightsKeepOffVariants, features))
{
if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting,
m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights))
return true;
}
else
{
if (stripTool.StripMultiCompile(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting,
m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights))
return true;
}

if (stripTool.StripMultiCompile(m_ClusteredRendering, ShaderFeatures.ClusteredRendering))
return true;
Expand Down Expand Up @@ -921,6 +948,12 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline
}
}

if (!renderer.stripShadowsOffVariants)
shaderFeatures |= ShaderFeatures.ShadowsKeepOffVariants;

if (!renderer.stripAdditionalLightOffVariants)
shaderFeatures |= ShaderFeatures.AdditionalLightsKeepOffVariants;

var rendererClustered = false;

ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ internal class SerializedUniversalRenderPipelineAsset
public SerializedProperty colorGradingLutSize { get; }
public SerializedProperty useFastSRGBLinearConversion { get; }

#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
public SerializedProperty useAdaptivePerformance { get; }

#endif
public UniversalRenderPipelineAsset asset { get; }
public SerializedObject serializedObject { get; }

Expand Down Expand Up @@ -129,8 +130,9 @@ public SerializedUniversalRenderPipelineAsset(SerializedObject serializedObject)

useFastSRGBLinearConversion = serializedObject.FindProperty("m_UseFastSRGBLinearConversion");

#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
useAdaptivePerformance = serializedObject.FindProperty("m_UseAdaptivePerformance");

#endif
string Key = "Universal_Shadow_Setting_Unit:UI_State";
state = new EditorPrefBoolFlags<EditorUtils.Unit>(Key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static bool ValidateRendererGraphicsAPIs(UniversalRenderPipelineAsset pipelineAs
CED.AdditionalPropertiesFoldoutGroup(Styles.shadowSettingsText, Expandable.Shadows, k_ExpandedState, ExpandableAdditional.Shadows, k_AdditionalPropertiesState, DrawShadows, DrawShadowsAdditional),
CED.AdditionalPropertiesFoldoutGroup(Styles.postProcessingSettingsText, Expandable.PostProcessing, k_ExpandedState, ExpandableAdditional.PostProcessing, k_AdditionalPropertiesState, DrawPostProcessing, DrawPostProcessingAdditional)
#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
, CED.FoldoutGroup(Styles.adaptivePerformanceText, Expandable.AdaptivePerformance, k_ExpandedState, CED.Group(DrawAdvanced)),
, CED.FoldoutGroup(Styles.adaptivePerformanceText, Expandable.AdaptivePerformance, k_ExpandedState, CED.Group(DrawAdaptivePerformance))
#endif
);

Expand Down Expand Up @@ -472,9 +472,8 @@ static void DrawPostProcessingAdditional(SerializedUniversalRenderPipelineAsset
#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER
static void DrawAdaptivePerformance(SerializedUniversalRenderPipelineAsset serialized, Editor ownerEditor)
{
EditorGUILayout.PropertyField(m_UseAdaptivePerformance, Styles.useAdaptivePerformance);
EditorGUILayout.PropertyField(serialized.useAdaptivePerformance, Styles.useAdaptivePerformance);
}

#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -918,13 +918,20 @@ public bool useAdaptivePerformance
set { m_UseAdaptivePerformance = value; }
}

/// <summary>
/// Set to true to enable a conservative method for calculating the size and position of the minimal enclosing sphere around the frustum cascade corner points for shadow culling.
/// </summary>
public bool conservativeEnclosingSphere
{
get { return m_ConservativeEnclosingSphere; }
set { m_ConservativeEnclosingSphere = value; }
}

public int numItertionsEnclosingSphere
/// <summary>
/// Set the number of iterations to reduce the cascade culling enlcosing sphere to be closer to the absolute minimun enclosing sphere, but will also require more CPU computation for increasing values.
/// This parameter is used only when conservativeEnclosingSphere is set to true. Default value is 64.
/// </summary>
public int numIterationsEnclosingSphere
{
get { return m_NumIterationsEnclosingSphere; }
set { m_NumIterationsEnclosingSphere = value; }
Expand Down
Loading