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

Internal/master #7521

Merged
merged 39 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b0b760e
[YAMATO][HDRP] Divided HDRP playmode test run time by two.
JulienIgnace-Unity Jun 15, 2022
e55505a
New iteration on the water system.
anisunity Jun 15, 2022
b9601b7
[RND-175][URP-964] SSAO Improvements
ellioman Jun 15, 2022
db55fe7
MTT-1785 Marked player settings BuildTargetGroup API as obsolete
cdmazom Jun 15, 2022
62cc093
[URP] Render Graph hotfixes (v2)
jonuuukas Jun 15, 2022
955a832
[URP][2D] Fix vertex color for Sprite Shapes in default URP shaders a…
kennytann Jun 22, 2022
883dd15
[HDRP] Updates to Diffusion profiles handling
adrien-de-tocqueville Jun 22, 2022
61df766
[URP][2D] Fix bug where render target is incorrect when post process …
kennytann Jun 22, 2022
0b1571d
Rendering Layers
lukaschod Jun 22, 2022
a5d317d
Deprecated DrawX commands on the SRPContext + Updated URP&HDRP (v2)
debaetsd Jun 22, 2022
f529672
Changed ACES luminance fit to allow pure whites
sebastienlagarde Jun 22, 2022
e76b183
URP Automatic Alpha-To-Coverage Regression Fixes
gmitrano-unity Jun 22, 2022
46f4136
[URP] Depth Priming + DepthNormalsPass + MSAA fix
manuele-bonanno Jun 22, 2022
6c4197e
Significant improvements to TAA ghosting, added control for jitter sc…
FrancescoC-unity Jun 22, 2022
3b27c69
[Fogbugz 1375978, 1413534] Fixed pb dof artifacts
pmavridis Jun 22, 2022
5e9057a
[VFX] Update Cube Mesh Test
PaulDemeulenaere Jun 22, 2022
e454c59
[Fogbugz # 1423890] Virtual Texturing feedback support feedback for t…
kecho Jun 22, 2022
180c3cf
Fix incorrect use of half for lighting attenuation.
eh-unity Jun 28, 2022
7529e50
[URP] Fixing broken Foundation tests on iPhone
ellioman Jun 28, 2022
f3de423
Add debug view for Motion Vector Intensities
FrancescoC-unity Jun 28, 2022
e26054d
[HDRP] Fix compile error on certain platforms that load the denoising…
pmavridis Jun 28, 2022
fdfd800
[URP] MSAA Swapbuffer fix for Post-processing (v2)
jonuuukas Jun 28, 2022
c38dda0
[23.1][URP][2D] Fix Light2D upgrading issue with m_AlphaBlendOnOverla…
kennytann Jun 28, 2022
82c5374
Fix explicit precision texture declaration macros to emit Texture2D<h…
joravainen Jun 28, 2022
ddf46a2
[URP] Moving the Render Graph toggle from Global Settings to the URP …
manuele-bonanno Jun 28, 2022
24102a0
Public Api doc improvements for URP, 2D URP and Core
ellioman Jun 28, 2022
3a97459
Add Apple Silicon reference images for URP test projects
theopnv Jun 28, 2022
aee83ab
[HDRP] bunch of bug fixes for HDRP (version 5)
sebastienlagarde Jun 28, 2022
1f501a7
Bump graphics packages to 15.0.0
theopnv Jun 28, 2022
76a5e5a
Fix HDRP Yamato issues
sebastienlagarde Jun 28, 2022
d8e5463
[HDRP] quality Review HDRP doc by doc team - 2 - bis
sebastienlagarde Jun 28, 2022
f26d188
[URP] PostPro project: Adding a #if check for XRSettings conditional …
ellioman Jun 28, 2022
7ba7cdf
[VFX] Fix MotionVector with TargetOffset
PaulDemeulenaere Jun 28, 2022
8eb03c2
[URP][RenderGraph] Added URP postfx passes to URP Render Graph (v5)
thomas-zeng Jun 28, 2022
c5ab2fd
[RPW] Tooltips improvement
kirill-titov-u Jun 28, 2022
0e80090
Add .buginfo files to URP folders
pbbastian Jun 28, 2022
043969f
[HDRP] Always use diffusion profiles in previews
adrien-de-tocqueville Jun 28, 2022
9ae0537
[RPW] Allow shader from HDRP and URP correctly fallback to error shader
kirill-titov-u Jun 28, 2022
ba30079
A error is thrown when creating an Output Particle Lit Decal
julienamsellem Jun 28, 2022
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
Prev Previous commit
Next Next commit
[RND-175][URP-964] SSAO Improvements
This PR improves the existing SSAO renderer feature in URP. 
We wanted to give users more options to control performance vs quality. 

New AO Method dropdown
  * Interleaved Gradient Noise (Original method)
  * Blue Noise (New)

New Blur Quality Dropdown
  * High: Bilateral (Original method)
  * Medium: Gaussian (New)
  * Low: Single-Pass Kawase (New)

Improved DownSampling:
It will now not only affect the AO pass but also the blur passes

New Samples Dropdown:
High(12), Medium(8) and Low(4) giving ~10-15% performance gain

New Falloff Field:
Option to control the falloff so the AO pass can early out and skip unnecessary work

Merged passes:
Merging of the AfterOpaque and the last blur passes

New AO Depth test:
To avoid casting AO in incorrect places.
  • Loading branch information
ellioman committed Jun 15, 2022
commit b9601b7f2821ce191a8e42a4aba2a0189096230a
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,126 @@ namespace UnityEditor.Rendering.Universal
internal class ScreenSpaceAmbientOcclusionEditor : Editor
{
#region Serialized Properties
private SerializedProperty m_AOMethod;
private SerializedProperty m_Downsample;
private SerializedProperty m_AfterOpaque;
private SerializedProperty m_Source;
private SerializedProperty m_NormalQuality;
private SerializedProperty m_Intensity;
private SerializedProperty m_DirectLightingStrength;
private SerializedProperty m_Radius;
private SerializedProperty m_SampleCount;
private SerializedProperty m_Falloff;
private SerializedProperty m_Samples;
private SerializedProperty m_BlurQuality;
#endregion

private bool m_IsInitialized = false;
private HeaderBool m_ShowQualitySettings;

class HeaderBool
{
private string key;
public bool value;

internal HeaderBool(string _key, bool _default = false)
{
key = _key;
if (EditorPrefs.HasKey(key))
value = EditorPrefs.GetBool(key);
else
value = _default;
EditorPrefs.SetBool(key, value);
}

internal void SetValue(bool newValue)
{
value = newValue;
EditorPrefs.SetBool(key, value);
}
}


// Structs
private struct Styles
{
public static GUIContent Downsample = EditorGUIUtility.TrTextContent("Downsample", "With this option enabled, Unity downsamples the SSAO effect texture to improve performance. Each dimension of the texture is reduced by a factor of 2.");
public static GUIContent AfterOpaque = EditorGUIUtility.TrTextContent("After Opaque", "With this option enabled, Unity calculates and apply SSAO after the opaque pass to improve performance on mobile platforms with tiled-based GPU architectures. This is not physically correct.");
public static GUIContent Source = EditorGUIUtility.TrTextContent("Source", "The source of the normal vector values.\nDepth Normals: the feature uses the values generated in the Depth Normal prepass.\nDepth: the feature reconstructs the normal values using the depth buffer.\nIn the Deferred rendering path, the feature uses the G-buffer normals texture.");
public static GUIContent NormalQuality = new GUIContent("Normal Quality", "The number of depth texture samples that Unity takes when computing the normals. Low:1 sample, Medium: 5 samples, High: 9 samples.");
public static GUIContent AOMethod = EditorGUIUtility.TrTextContent("Method", "The noise method to use when calculating the Ambient Occlusion value.");
public static GUIContent Intensity = EditorGUIUtility.TrTextContent("Intensity", "The degree of darkness that Ambient Occlusion adds.");
public static GUIContent DirectLightingStrength = EditorGUIUtility.TrTextContent("Direct Lighting Strength", "Controls how much the ambient occlusion affects direct lighting.");
public static GUIContent Radius = EditorGUIUtility.TrTextContent("Radius", "The radius around a given point, where Unity calculates and applies the effect.");
public static GUIContent SampleCount = EditorGUIUtility.TrTextContent("Sample Count", "The number of samples that Unity takes when calculating the obscurance value. Higher values have high performance impact.");
public static GUIContent Falloff = EditorGUIUtility.TrTextContent("Falloff Distance", "The distance from the camera where Ambient Occlusion should be visible.");
public static GUIContent DirectLightingStrength = EditorGUIUtility.TrTextContent("Direct Lighting Strength", "Controls how much the ambient occlusion affects direct lighting.");

public static GUIContent Quality = EditorGUIUtility.TrTextContent("Quality", "");
public static GUIContent Source = EditorGUIUtility.TrTextContent("Source", "The source of the normal vector values.\nDepth Normals: the feature uses the values generated in the Depth Normal prepass.\nDepth: the feature reconstructs the normal values using the depth buffer.\nIn the Deferred rendering path, the feature uses the G-buffer normals texture.");
public static GUIContent NormalQuality = new GUIContent("Normal Quality", "The number of depth texture samples that Unity takes when computing the normals. Low:1 sample, Medium: 5 samples, High: 9 samples.");
public static GUIContent Downsample = EditorGUIUtility.TrTextContent("Downsample", "With this option enabled, Unity downsamples the SSAO effect texture to improve performance. Each dimension of the texture is reduced by a factor of 2.");
public static GUIContent AfterOpaque = EditorGUIUtility.TrTextContent("After Opaque", "With this option enabled, Unity calculates and apply SSAO after the opaque pass to improve performance on mobile platforms with tiled-based GPU architectures. This is not physically correct.");
public static GUIContent BlurQuality = EditorGUIUtility.TrTextContent("Blur Quality", "High: Bilateral, Medium: Gaussian. Low: Kawase (Single Pass).");
public static GUIContent Samples = EditorGUIUtility.TrTextContent("Samples", "The number of samples that Unity takes when calculating the obscurance value. Low:4 samples, Medium: 8 samples, High: 12 samples.");
}

private void Init()
{
m_ShowQualitySettings = new HeaderBool($"SSAO.QualityFoldout", false);

SerializedProperty settings = serializedObject.FindProperty("m_Settings");

m_AOMethod = settings.FindPropertyRelative("AOMethod");
m_Intensity = settings.FindPropertyRelative("Intensity");
m_Radius = settings.FindPropertyRelative("Radius");
m_Falloff = settings.FindPropertyRelative("Falloff");
m_DirectLightingStrength = settings.FindPropertyRelative("DirectLightingStrength");

m_Source = settings.FindPropertyRelative("Source");
m_NormalQuality = settings.FindPropertyRelative("NormalSamples");
m_Downsample = settings.FindPropertyRelative("Downsample");
m_AfterOpaque = settings.FindPropertyRelative("AfterOpaque");
m_NormalQuality = settings.FindPropertyRelative("NormalSamples");
m_Intensity = settings.FindPropertyRelative("Intensity");
m_DirectLightingStrength = settings.FindPropertyRelative("DirectLightingStrength");
m_Radius = settings.FindPropertyRelative("Radius");
m_SampleCount = settings.FindPropertyRelative("SampleCount");
m_BlurQuality = settings.FindPropertyRelative("BlurQuality");
m_Samples = settings.FindPropertyRelative("Samples");

m_IsInitialized = true;
}

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

bool isDeferredRenderingMode = RendererIsDeferred();
EditorGUILayout.PropertyField(m_AOMethod, Styles.AOMethod);
EditorGUILayout.PropertyField(m_Intensity, Styles.Intensity);
EditorGUILayout.PropertyField(m_Radius, Styles.Radius);
EditorGUILayout.PropertyField(m_Falloff, Styles.Falloff);
m_DirectLightingStrength.floatValue = EditorGUILayout.Slider(Styles.DirectLightingStrength, m_DirectLightingStrength.floatValue, 0f, 1f);

EditorGUILayout.PropertyField(m_Downsample, Styles.Downsample);
// Make sure these fields are never below 0.0...
m_Intensity.floatValue = Mathf.Max(m_Intensity.floatValue, 0f);
m_Radius.floatValue = Mathf.Max(m_Radius.floatValue, 0f);
m_Falloff.floatValue = Mathf.Max(m_Falloff.floatValue, 0f);

EditorGUILayout.PropertyField(m_AfterOpaque, Styles.AfterOpaque);
m_ShowQualitySettings.SetValue(EditorGUILayout.Foldout(m_ShowQualitySettings.value, Styles.Quality));
if (m_ShowQualitySettings.value)
{
bool isDeferredRenderingMode = RendererIsDeferred();

GUI.enabled = !isDeferredRenderingMode;
EditorGUILayout.PropertyField(m_Source, Styles.Source);
EditorGUI.indentLevel++;

// We only enable this field when depth source is selected
GUI.enabled = !isDeferredRenderingMode && m_Source.enumValueIndex == (int)ScreenSpaceAmbientOcclusionSettings.DepthSource.Depth;
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_NormalQuality, Styles.NormalQuality);
EditorGUI.indentLevel--;
GUI.enabled = true;
// Selecting source is not available for Deferred Rendering...
GUI.enabled = !isDeferredRenderingMode;
EditorGUILayout.PropertyField(m_Source, Styles.Source);

EditorGUILayout.PropertyField(m_Intensity, Styles.Intensity);
EditorGUILayout.PropertyField(m_Radius, Styles.Radius);
m_DirectLightingStrength.floatValue = EditorGUILayout.Slider(Styles.DirectLightingStrength, m_DirectLightingStrength.floatValue, 0f, 1f);
m_SampleCount.intValue = EditorGUILayout.IntSlider(Styles.SampleCount, m_SampleCount.intValue, 4, 20);
// We only enable this field when depth source is selected...
GUI.enabled = !isDeferredRenderingMode && m_Source.enumValueIndex == (int)ScreenSpaceAmbientOcclusionSettings.DepthSource.Depth;
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_NormalQuality, Styles.NormalQuality);
EditorGUI.indentLevel--;
GUI.enabled = true;

m_Intensity.floatValue = Mathf.Clamp(m_Intensity.floatValue, 0f, m_Intensity.floatValue);
m_Radius.floatValue = Mathf.Clamp(m_Radius.floatValue, 0f, m_Radius.floatValue);
EditorGUILayout.PropertyField(m_Downsample, Styles.Downsample);
EditorGUILayout.PropertyField(m_AfterOpaque, Styles.AfterOpaque);
EditorGUILayout.PropertyField(m_BlurQuality, Styles.BlurQuality);
EditorGUILayout.PropertyField(m_Samples, Styles.Samples);

EditorGUI.indentLevel--;
}
}

private bool RendererIsDeferred()
Expand All @@ -97,10 +148,8 @@ private bool RendererIsDeferred()

var rendererFeatures = rendererData.rendererFeatures;
foreach (var feature in rendererFeatures)
{
if (feature is ScreenSpaceAmbientOcclusion && (ScreenSpaceAmbientOcclusion)feature == ssaoFeature)
return rendererData is UniversalRendererData && ((UniversalRendererData)rendererData).renderingMode == RenderingMode.Deferred;
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ void frag(
//SETUP_DEBUG_TEXTURE_DATA(inputData, input.texCoord1, _MainTex);

half4 finalColor = UniversalFragmentUnlit(inputData, surfaceDescription.BaseColor, alpha);

finalColor.a = OutputAlpha(finalColor.a, isTransparent);

#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(unpacked.positionCS);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV);
finalColor.rgb *= aoFactor.directAmbientOcclusion;
#endif

outColor = finalColor;

#ifdef _WRITE_RENDERING_LAYERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,19 +864,9 @@ static class LitKeywords
scope = KeywordScope.Local,
};

public static readonly KeywordDescriptor ScreenSpaceAmbientOcclusion = new KeywordDescriptor()
{
displayName = "Screen Space Ambient Occlusion",
referenceName = "_SCREEN_SPACE_OCCLUSION",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Global,
stages = KeywordShaderStage.Fragment,
};

public static readonly KeywordCollection Forward = new KeywordCollection
{
{ ScreenSpaceAmbientOcclusion },
{ CoreKeywordDescriptors.ScreenSpaceAmbientOcclusion },
{ CoreKeywordDescriptors.StaticLightmap },
{ CoreKeywordDescriptors.DynamicLightmap },
{ CoreKeywordDescriptors.DirectionalLightmapCombined },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public static PassDescriptor DepthNormalOnly(UniversalTarget target)
renderStates = CoreRenderStates.DepthNormalsOnly(target),
pragmas = CorePragmas.Instanced,
defines = new DefineCollection(),
keywords = new KeywordCollection(),
keywords = new KeywordCollection() { CoreKeywordDescriptors.GBufferNormalsOct },
includes = CoreIncludes.DepthNormalsOnly,

// Custom Interpolator Support
Expand Down Expand Up @@ -2029,6 +2029,16 @@ static class CoreKeywordDescriptors
scope = KeywordScope.Global,
stages = KeywordShaderStage.Fragment,
};

public static readonly KeywordDescriptor ScreenSpaceAmbientOcclusion = new KeywordDescriptor()
{
displayName = "Screen Space Ambient Occlusion",
referenceName = "_SCREEN_SPACE_OCCLUSION",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Global,
stages = KeywordShaderStage.Fragment,
};
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static PassDescriptor DepthNormalOnly(UniversalTarget target)
var result = new PassDescriptor
{
// Definition
displayName = "DepthNormals",
displayName = "DepthNormalsOnly",
referenceName = "SHADERPASS_DEPTHNORMALSONLY",
lightMode = "DepthNormalsOnly",
useInPreview = false,
Expand All @@ -290,7 +290,7 @@ public static PassDescriptor DepthNormalOnly(UniversalTarget target)
renderStates = CoreRenderStates.DepthNormalsOnly(target),
pragmas = CorePragmas.Forward,
defines = new DefineCollection(),
keywords = new KeywordCollection() { CoreKeywords.DOTSDepthNormal },
keywords = new KeywordCollection() { CoreKeywords.DOTSDepthNormal, CoreKeywordDescriptors.GBufferNormalsOct },
includes = CoreIncludes.DepthNormalsOnly,

// Custom Interpolator Support
Expand Down Expand Up @@ -346,6 +346,7 @@ static class UnlitKeywords
CoreKeywordDescriptors.SampleGI,
CoreKeywordDescriptors.DBuffer,
CoreKeywordDescriptors.DebugDisplay,
CoreKeywordDescriptors.ScreenSpaceAmbientOcclusion,
};

public static readonly KeywordCollection DOTSForward = new KeywordCollection
Expand Down
Loading