Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 34068b3

Browse files
committed
UI pass & quality presets
1 parent af66bd0 commit 34068b3

3 files changed

Lines changed: 81 additions & 36 deletions

File tree

PostProcessing/Editor/PostProcessLayerEditor.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using UnityEngine.Rendering.PostProcessing;
66
using UnityEditorInternal;
77
using System.IO;
8+
using ScreenSpaceReflections = UnityEngine.Rendering.PostProcessing.ScreenSpaceReflections;
89

910
namespace UnityEditor.Rendering.PostProcessing
1011
{
1112
using SerializedBundleRef = PostProcessLayer.SerializedBundleRef;
1213
using EXRFlags = Texture2D.EXRFlags;
14+
using SSRPreset = UnityEngine.Rendering.PostProcessing.ScreenSpaceReflections.Preset;
1315

1416
[CanEditMultipleObjects, CustomEditor(typeof(PostProcessLayer))]
1517
public sealed class PostProcessLayerEditor : BaseEditor<PostProcessLayer>
@@ -36,11 +38,12 @@ public sealed class PostProcessLayerEditor : BaseEditor<PostProcessLayer>
3638
SerializedProperty m_MSVOThicknessModifier;
3739
SerializedProperty m_MSVOColor;
3840
SerializedProperty m_AOAmbientOnly;
39-
41+
4042
SerializedProperty m_SSREnabled;
43+
SerializedProperty m_SSRPreset;
4144
SerializedProperty m_SSRMaximumIterationCount;
42-
SerializedProperty m_SSRBandwidth;
4345
SerializedProperty m_SSRDownsampling;
46+
SerializedProperty m_SSRThickness;
4447
SerializedProperty m_SSRMaximumMarchDistance;
4548
SerializedProperty m_SSRDistanceFade;
4649
SerializedProperty m_SSRAttenuation;
@@ -102,9 +105,10 @@ void OnEnable()
102105
m_MSVOColor = FindProperty(x => x.ambientOcclusion.multiScaleVO.color);
103106

104107
m_SSREnabled = FindProperty(x => x.screenSpaceReflections.enabled);
108+
m_SSRPreset = FindProperty(x => x.screenSpaceReflections.preset);
105109
m_SSRMaximumIterationCount = FindProperty(x => x.screenSpaceReflections.maximumIterationCount);
106-
m_SSRBandwidth = FindProperty(x => x.screenSpaceReflections.bandwidth);
107110
m_SSRDownsampling = FindProperty(x => x.screenSpaceReflections.downsampling);
111+
m_SSRThickness = FindProperty(x => x.screenSpaceReflections.thickness);
108112
m_SSRMaximumMarchDistance = FindProperty(x => x.screenSpaceReflections.maximumMarchDistance);
109113
m_SSRDistanceFade = FindProperty(x => x.screenSpaceReflections.distanceFade);
110114
m_SSRAttenuation = FindProperty(x => x.screenSpaceReflections.attenuation);
@@ -310,17 +314,23 @@ void DoScreenSpaceReflections(Camera camera)
310314

311315
if (m_SSREnabled.boolValue)
312316
{
313-
EditorGUILayout.HelpBox("Unoptimized and not finished yet. Don't use.", MessageType.Info);
314-
315317
if (camera != null && camera.actualRenderingPath != RenderingPath.DeferredShading)
316318
EditorGUILayout.HelpBox("This effect only works with the deferred rendering path.", MessageType.Warning);
317319

318320
if (!SystemInfo.supportsComputeShaders)
319321
EditorGUILayout.HelpBox("This effect requires compute shader support.", MessageType.Warning);
320322

321-
EditorGUILayout.PropertyField(m_SSRMaximumIterationCount);
322-
EditorGUILayout.PropertyField(m_SSRBandwidth);
323-
EditorGUILayout.PropertyField(m_SSRDownsampling);
323+
EditorGUILayout.PropertyField(m_SSRPreset);
324+
325+
using (new EditorGUI.DisabledScope(m_SSRPreset.intValue != (int)SSRPreset.Custom))
326+
{
327+
EditorGUI.indentLevel++;
328+
EditorGUILayout.PropertyField(m_SSRMaximumIterationCount);
329+
EditorGUILayout.PropertyField(m_SSRThickness);
330+
EditorGUILayout.PropertyField(m_SSRDownsampling);
331+
EditorGUI.indentLevel--;
332+
}
333+
324334
EditorGUILayout.PropertyField(m_SSRMaximumMarchDistance);
325335
EditorGUILayout.PropertyField(m_SSRDistanceFade);
326336
EditorGUILayout.PropertyField(m_SSRAttenuation);

PostProcessing/Runtime/Effects/ScreenSpaceReflections.cs

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,61 @@
44
namespace UnityEngine.Rendering.PostProcessing
55
{
66
[Serializable]
7-
// TODO: Tooltips
87
public sealed class ScreenSpaceReflections
98
{
10-
[Tooltip("Enables screens-space reflections.")]
9+
public enum Preset
10+
{
11+
Lower,
12+
Low,
13+
Medium,
14+
High,
15+
Higher,
16+
Ultra,
17+
Overkill,
18+
Custom
19+
}
20+
21+
[Tooltip("Enables screen-space reflections.")]
1122
public bool enabled;
1223

24+
[Tooltip("Choose a quality preset, or use \"Custom\" to fine tune it. Don't use a preset higher than \"Medium\" if you care about performances on consoles.")]
25+
public Preset preset = Preset.Medium;
26+
27+
[Range(0, 128), Tooltip("Maximum iteration count.")]
28+
public int maximumIterationCount;
29+
30+
[Tooltip("Downsamples the SSR buffer to maximize performances at the cost of a blurrier result.")]
31+
public bool downsampling = true;
32+
33+
[Range(1f, 64f), Tooltip("Ray thickness. Lower values are more expensive but allow the effect to detect smaller details.")]
34+
public float thickness = 8f;
35+
36+
[Tooltip("Maximum distance to traverse after which it will stop drawing reflections.")]
1337
public float maximumMarchDistance = 100f;
1438

15-
[Range(0f, 1f)]
16-
public float distanceFade = 0.25f;
39+
[Range(0f, 1f), Tooltip("Fades reflections close to the near planes.")]
40+
public float distanceFade = 0.5f;
1741

18-
[Range(0f, 1f)]
42+
[Range(0f, 1f), Tooltip("Fades reflections close to the screen borders.")]
1943
public float attenuation = 0.25f;
2044

21-
//>>> Hardcode these settings
22-
[Range(1, 128)]
23-
public int maximumIterationCount = 128;
24-
25-
[Range(1f, 100f)]
26-
public float bandwidth = 8f;
45+
class QualityPreset
46+
{
47+
public int maximumIterationCount;
48+
public float thickness;
49+
public bool downsampling;
50+
}
2751

28-
[Range(0, 4)]
29-
public int downsampling = 0;
30-
//<<<
52+
QualityPreset[] m_Presets =
53+
{
54+
new QualityPreset { maximumIterationCount = 10, thickness = 32, downsampling = true }, // Lower
55+
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = true }, // Low
56+
new QualityPreset { maximumIterationCount = 32, thickness = 16, downsampling = true }, // Medium
57+
new QualityPreset { maximumIterationCount = 48, thickness = 8, downsampling = true }, // High
58+
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = false }, // Higher
59+
new QualityPreset { maximumIterationCount = 48, thickness = 16, downsampling = false }, // Ultra
60+
new QualityPreset { maximumIterationCount = 64, thickness = 12, downsampling = false }, // Overkill
61+
};
3162

3263
RenderTexture m_Test;
3364
RenderTexture m_Resolve;
@@ -80,9 +111,20 @@ internal void Render(PostProcessRenderContext context)
80111
var cmd = context.command;
81112
cmd.BeginSample("Screen-space Reflections");
82113

114+
// Get quality settings
115+
if (preset != Preset.Custom)
116+
{
117+
int id = (int)preset;
118+
maximumIterationCount = m_Presets[id].maximumIterationCount;
119+
thickness = m_Presets[id].thickness;
120+
downsampling = m_Presets[id].downsampling;
121+
}
122+
83123
// Square POT target
84124
int size = Mathf.ClosestPowerOfTwo(Mathf.Min(context.width, context.height));
85-
size >>= downsampling;
125+
126+
if (downsampling)
127+
size >>= 1;
86128

87129
// The gaussian pyramid compute works in blocks of 8x8 so make sure the last lod has a
88130
// minimum size of 8x8
@@ -112,11 +154,7 @@ internal void Render(PostProcessRenderContext context)
112154
sheet.properties.SetMatrix(ShaderIDs.InverseProjectionMatrix, projectionMatrix.inverse);
113155
sheet.properties.SetMatrix(ShaderIDs.ScreenSpaceProjectionMatrix, screenSpaceProjectionMatrix);
114156
sheet.properties.SetVector(ShaderIDs.Params, new Vector4(attenuation, distanceFade, maximumMarchDistance, lodCount));
115-
sheet.properties.SetVector(ShaderIDs.Params2, new Vector4((float)context.width / (float)context.height, (float)size / (float)noiseTex.width, 0f, 0f));
116-
117-
// TOOD: Hardcode these in shader variants (quality levels) for much improved performances
118-
sheet.properties.SetFloat("_Bandwidth", bandwidth);
119-
sheet.properties.SetFloat("_MaximumIterationCount", maximumIterationCount);
157+
sheet.properties.SetVector(ShaderIDs.Params2, new Vector4((float)context.width / (float)context.height, (float)size / (float)noiseTex.width, thickness, maximumIterationCount));
120158

121159
cmd.GetTemporaryRT(ShaderIDs.SSRResolveTemp, size, size, 0, FilterMode.Bilinear, context.sourceFormat);
122160
cmd.BlitFullscreenTriangle(context.source, m_Test, sheet, (int)Pass.Test);

PostProcessing/Shaders/Builtins/ScreenSpaceReflections.hlsl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,15 @@ float4x4 _InverseProjectionMatrix;
7474
float4x4 _ScreenSpaceProjectionMatrix;
7575

7676
float4 _Params; // x: attenuation, y: distance fade, z: maximum march distance, w: blur pyramid lod count
77-
float2 _Params2; // x: aspect ratio, y: noise tiling
77+
float4 _Params2; // x: aspect ratio, y: noise tiling, z: thickness, w: maximum iteration count
7878
#define _Attenuation _Params.x
7979
#define _DistanceFade _Params.y
8080
#define _MaximumMarchDistance _Params.z
8181
#define _BlurPyramidLODCount _Params.w
8282
#define _AspectRatio _Params2.x
8383
#define _NoiseTiling _Params2.y
84-
85-
// TODO: hardcode these
86-
int _MaximumIterationCount;
87-
float _Bandwidth;
84+
#define _Bandwidth _Params2.z
85+
#define _MaximumIterationCount _Params2.w
8886

8987
//
9088
// Helper functions
@@ -130,7 +128,7 @@ float4 ProjectToScreenSpace(float3 position)
130128

131129
// Heavily adapted from McGuire and Mara's original implementation
132130
// http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html
133-
Result march(Ray ray, VaryingsDefault input)
131+
Result March(Ray ray, VaryingsDefault input)
134132
{
135133
Result result;
136134

@@ -196,7 +194,6 @@ Result march(Ray ray, VaryingsDefault input)
196194
float2 z = 0.0;
197195
float4 tracker = float4(endPoints.xy, homogenizers.x, segment.start.z) + derivatives * jitter;
198196

199-
// UNITY_UNROLL
200197
for (int i = 0; i < _MaximumIterationCount; ++i)
201198
{
202199
if (any(result.uv < 0.0) || any(result.uv > 1.0))
@@ -265,7 +262,7 @@ float4 FragTest(VaryingsDefault i) : SV_Target
265262

266263
ray.direction = normalize(reflect(normalize(ray.origin), normal));
267264

268-
Result result = march(ray, i);
265+
Result result = March(ray, i);
269266

270267
float confidence = (float)result.iterationCount / (float)_MaximumIterationCount;
271268
return float4(result.uv, confidence, (float)result.isHit);

0 commit comments

Comments
 (0)