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

Commit d21e50b

Browse files
committed
Moved SSR to profile / volume
1 parent a923eda commit d21e50b

5 files changed

Lines changed: 151 additions & 82 deletions

File tree

PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public override void OnEnable()
2727

2828
public override void OnInspectorGUI()
2929
{
30+
if (RuntimeUtilities.scriptableRenderPipelineActive)
31+
{
32+
EditorGUILayout.HelpBox("This effect doesn't work with scriptable render pipelines yet.", MessageType.Warning);
33+
return;
34+
}
35+
3036
PropertyField(m_Mode);
3137
PropertyField(m_Intensity);
3238

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using UnityEngine;
2+
using UnityEngine.Rendering.PostProcessing;
3+
4+
namespace UnityEditor.Rendering.PostProcessing
5+
{
6+
[PostProcessEditor(typeof(ScreenSpaceReflections))]
7+
public sealed class ScreenSpaceReflectionsEditor : PostProcessEffectEditor<ScreenSpaceReflections>
8+
{
9+
SerializedParameterOverride m_Preset;
10+
SerializedParameterOverride m_MaximumIterationCount;
11+
SerializedParameterOverride m_Thickness;
12+
SerializedParameterOverride m_Resolution;
13+
SerializedParameterOverride m_MaximumMarchDistance;
14+
SerializedParameterOverride m_DistanceFade;
15+
SerializedParameterOverride m_Attenuation;
16+
17+
public override void OnEnable()
18+
{
19+
m_Preset = FindParameterOverride(x => x.preset);
20+
m_MaximumIterationCount = FindParameterOverride(x => x.maximumIterationCount);
21+
m_Thickness = FindParameterOverride(x => x.thickness);
22+
m_Resolution = FindParameterOverride(x => x.resolution);
23+
m_MaximumMarchDistance = FindParameterOverride(x => x.maximumMarchDistance);
24+
m_DistanceFade = FindParameterOverride(x => x.distanceFade);
25+
m_Attenuation = FindParameterOverride(x => x.attenuation);
26+
}
27+
28+
public override void OnInspectorGUI()
29+
{
30+
if (RuntimeUtilities.scriptableRenderPipelineActive)
31+
{
32+
EditorGUILayout.HelpBox("This effect doesn't work with scriptable render pipelines yet.", MessageType.Warning);
33+
return;
34+
}
35+
36+
if (Camera.main.actualRenderingPath != RenderingPath.DeferredShading)
37+
EditorGUILayout.HelpBox("This effect only works with the deferred rendering path.", MessageType.Warning);
38+
39+
if (!SystemInfo.supportsComputeShaders)
40+
EditorGUILayout.HelpBox("This effect requires compute shader support.", MessageType.Warning);
41+
42+
PropertyField(m_Preset);
43+
44+
if (m_Preset.value.intValue == (int)ScreenSpaceReflectionPreset.Custom)
45+
{
46+
PropertyField(m_MaximumIterationCount);
47+
PropertyField(m_Thickness);
48+
PropertyField(m_Resolution);
49+
50+
EditorGUILayout.Space();
51+
}
52+
53+
PropertyField(m_MaximumMarchDistance);
54+
PropertyField(m_DistanceFade);
55+
PropertyField(m_Attenuation);
56+
}
57+
}
58+
}

PostProcessing/Editor/Effects/ScreenSpaceReflectionsEditor.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PostProcessing/Runtime/Effects/ScreenSpaceReflections.cs

Lines changed: 62 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,83 @@
33

44
namespace UnityEngine.Rendering.PostProcessing
55
{
6-
[Serializable]
7-
public sealed class ScreenSpaceReflections
6+
public enum ScreenSpaceReflectionPreset
87
{
9-
public enum Preset
10-
{
11-
Lower,
12-
Low,
13-
Medium,
14-
High,
15-
Higher,
16-
Ultra,
17-
Overkill,
18-
Custom
19-
}
8+
Lower, Low, Medium, High, Higher, Ultra, Overkill, Custom
9+
}
2010

21-
public enum Resolution
22-
{
23-
Downsampled,
24-
FullSize,
25-
Supersampled
26-
}
11+
public enum ScreenSpaceReflectionResolution
12+
{
13+
Downsampled,
14+
FullSize,
15+
Supersampled
16+
}
2717

28-
[Tooltip("Enables screen-space reflections.")]
29-
public bool enabled;
18+
[Serializable]
19+
public sealed class ScreenSpaceReflectionPresetParameter : ParameterOverride<ScreenSpaceReflectionPreset> {}
20+
21+
[Serializable]
22+
public sealed class ScreenSpaceReflectionResolutionParameter : ParameterOverride<ScreenSpaceReflectionResolution> {}
3023

24+
[Serializable]
25+
[PostProcess(typeof(ScreenSpaceReflectionsRenderer), "Unity/Screen-space reflections")]
26+
public sealed class ScreenSpaceReflections : PostProcessEffectSettings
27+
{
3128
[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.")]
32-
public Preset preset = Preset.Medium;
29+
public ScreenSpaceReflectionPresetParameter preset = new ScreenSpaceReflectionPresetParameter { value = ScreenSpaceReflectionPreset.Medium };
3330

3431
[Range(0, 256), Tooltip("Maximum iteration count.")]
35-
public int maximumIterationCount;
32+
public IntParameter maximumIterationCount = new IntParameter { value = 16 };
3633

3734
[Tooltip("Changes the size of the SSR buffer. Downsample it to maximize performances or supersample it to get slow but higher quality results.")]
38-
public Resolution resolution = Resolution.Downsampled;
35+
public ScreenSpaceReflectionResolutionParameter resolution = new ScreenSpaceReflectionResolutionParameter { value = ScreenSpaceReflectionResolution.Downsampled };
3936

4037
[Range(1f, 64f), Tooltip("Ray thickness. Lower values are more expensive but allow the effect to detect smaller details.")]
41-
public float thickness = 8f;
38+
public FloatParameter thickness = new FloatParameter { value = 8f };
4239

4340
[Tooltip("Maximum distance to traverse after which it will stop drawing reflections.")]
44-
public float maximumMarchDistance = 100f;
41+
public FloatParameter maximumMarchDistance = new FloatParameter { value = 100f };
4542

4643
[Range(0f, 1f), Tooltip("Fades reflections close to the near planes.")]
47-
public float distanceFade = 0.5f;
44+
public FloatParameter distanceFade = new FloatParameter { value = 0.5f };
4845

4946
[Range(0f, 1f), Tooltip("Fades reflections close to the screen borders.")]
50-
public float attenuation = 0.25f;
47+
public FloatParameter attenuation = new FloatParameter { value = 0.25f };
48+
49+
public override bool IsEnabledAndSupported(PostProcessRenderContext context)
50+
{
51+
return enabled
52+
&& context.camera.actualRenderingPath == RenderingPath.DeferredShading
53+
&& SystemInfo.supportsMotionVectors
54+
&& SystemInfo.supportsComputeShaders
55+
&& SystemInfo.copyTextureSupport > CopyTextureSupport.None;
56+
}
57+
}
58+
59+
public sealed class ScreenSpaceReflectionsRenderer : PostProcessEffectRenderer<ScreenSpaceReflections>
60+
{
61+
RenderTexture m_Resolve;
62+
RenderTexture m_History;
63+
int[] m_MipIDs;
5164

5265
class QualityPreset
5366
{
5467
public int maximumIterationCount;
5568
public float thickness;
56-
public Resolution downsampling;
69+
public ScreenSpaceReflectionResolution downsampling;
5770
}
5871

5972
QualityPreset[] m_Presets =
6073
{
61-
new QualityPreset { maximumIterationCount = 10, thickness = 32, downsampling = Resolution.Downsampled }, // Lower
62-
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = Resolution.Downsampled }, // Low
63-
new QualityPreset { maximumIterationCount = 32, thickness = 16, downsampling = Resolution.Downsampled }, // Medium
64-
new QualityPreset { maximumIterationCount = 48, thickness = 8, downsampling = Resolution.Downsampled }, // High
65-
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = Resolution.FullSize }, // Higher
66-
new QualityPreset { maximumIterationCount = 48, thickness = 16, downsampling = Resolution.FullSize }, // Ultra
67-
new QualityPreset { maximumIterationCount = 128, thickness = 12, downsampling = Resolution.Supersampled }, // Overkill
74+
new QualityPreset { maximumIterationCount = 10, thickness = 32, downsampling = ScreenSpaceReflectionResolution.Downsampled }, // Lower
75+
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = ScreenSpaceReflectionResolution.Downsampled }, // Low
76+
new QualityPreset { maximumIterationCount = 32, thickness = 16, downsampling = ScreenSpaceReflectionResolution.Downsampled }, // Medium
77+
new QualityPreset { maximumIterationCount = 48, thickness = 8, downsampling = ScreenSpaceReflectionResolution.Downsampled }, // High
78+
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = ScreenSpaceReflectionResolution.FullSize }, // Higher
79+
new QualityPreset { maximumIterationCount = 48, thickness = 16, downsampling = ScreenSpaceReflectionResolution.FullSize }, // Ultra
80+
new QualityPreset { maximumIterationCount = 128, thickness = 12, downsampling = ScreenSpaceReflectionResolution.Supersampled }, // Overkill
6881
};
6982

70-
RenderTexture m_Test;
71-
RenderTexture m_Resolve;
72-
RenderTexture m_History;
73-
int[] m_MipIDs;
74-
75-
bool m_ResetHistory = true;
76-
7783
enum Pass
7884
{
7985
Test,
@@ -82,16 +88,7 @@ enum Pass
8288
Composite
8389
}
8490

85-
internal bool IsEnabledAndSupported(PostProcessRenderContext context)
86-
{
87-
return enabled
88-
&& context.camera.actualRenderingPath == RenderingPath.DeferredShading
89-
&& SystemInfo.supportsMotionVectors
90-
&& SystemInfo.supportsComputeShaders
91-
&& SystemInfo.copyTextureSupport > CopyTextureSupport.None;
92-
}
93-
94-
internal DepthTextureMode GetCameraFlags()
91+
public override DepthTextureMode GetCameraFlags()
9592
{
9693
return DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
9794
}
@@ -115,28 +112,28 @@ internal void CheckRT(ref RenderTexture rt, int width, int height, RenderTexture
115112
}
116113
}
117114

118-
internal void Render(PostProcessRenderContext context)
115+
public override void Render(PostProcessRenderContext context)
119116
{
120117
var cmd = context.command;
121118
cmd.BeginSample("Screen-space Reflections");
122119

123120
// Get quality settings
124-
if (preset != Preset.Custom)
121+
if (settings.preset.value != ScreenSpaceReflectionPreset.Custom)
125122
{
126-
int id = (int)preset;
127-
maximumIterationCount = m_Presets[id].maximumIterationCount;
128-
thickness = m_Presets[id].thickness;
129-
resolution = m_Presets[id].downsampling;
123+
int id = (int)settings.preset.value;
124+
settings.maximumIterationCount.value = m_Presets[id].maximumIterationCount;
125+
settings.thickness.value = m_Presets[id].thickness;
126+
settings.resolution.value = m_Presets[id].downsampling;
130127
}
131128

132-
maximumMarchDistance = Mathf.Max(0f, maximumMarchDistance);
129+
settings.maximumMarchDistance.value = Mathf.Max(0f, settings.maximumMarchDistance.value);
133130

134131
// Square POT target
135132
int size = Mathf.ClosestPowerOfTwo(Mathf.Min(context.width, context.height));
136133

137-
if (resolution == Resolution.Downsampled)
134+
if (settings.resolution.value == ScreenSpaceReflectionResolution.Downsampled)
138135
size >>= 1;
139-
else if (resolution == Resolution.Supersampled)
136+
else if (settings.resolution.value == ScreenSpaceReflectionResolution.Supersampled)
140137
size <<= 1;
141138

142139
// The gaussian pyramid compute works in blocks of 8x8 so make sure the last lod has a
@@ -171,8 +168,8 @@ internal void Render(PostProcessRenderContext context)
171168
sheet.properties.SetMatrix(ShaderIDs.InverseViewMatrix, context.camera.worldToCameraMatrix.inverse);
172169
sheet.properties.SetMatrix(ShaderIDs.InverseProjectionMatrix, projectionMatrix.inverse);
173170
sheet.properties.SetMatrix(ShaderIDs.ScreenSpaceProjectionMatrix, screenSpaceProjectionMatrix);
174-
sheet.properties.SetVector(ShaderIDs.Params, new Vector4(attenuation, distanceFade, maximumMarchDistance, lodCount));
175-
sheet.properties.SetVector(ShaderIDs.Params2, new Vector4((float)context.width / (float)context.height, (float)size / (float)noiseTex.width, thickness, maximumIterationCount));
171+
sheet.properties.SetVector(ShaderIDs.Params, new Vector4(settings.attenuation.value, settings.distanceFade.value, settings.maximumMarchDistance.value, lodCount));
172+
sheet.properties.SetVector(ShaderIDs.Params2, new Vector4((float)context.width / (float)context.height, (float)size / (float)noiseTex.width, settings.thickness.value, settings.maximumIterationCount.value));
176173

177174
cmd.GetTemporaryRT(ShaderIDs.Test, size, size, 0, FilterMode.Point, context.sourceFormat);
178175
cmd.BlitFullscreenTriangle(context.source, ShaderIDs.Test, sheet, (int)Pass.Test);
@@ -225,19 +222,12 @@ internal void Render(PostProcessRenderContext context)
225222
cmd.EndSample("Screen-space Reflections");
226223
}
227224

228-
internal void Release()
225+
public override void Release()
229226
{
230-
RuntimeUtilities.Destroy(m_Test);
231227
RuntimeUtilities.Destroy(m_Resolve);
232228
RuntimeUtilities.Destroy(m_History);
233-
m_Test = null;
234229
m_Resolve = null;
235230
m_History = null;
236231
}
237-
238-
internal void ResetHistory()
239-
{
240-
m_ResetHistory = true;
241-
}
242232
}
243233
}

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public enum Antialiasing
2929
public TemporalAntialiasing temporalAntialiasing;
3030
public SubpixelMorphologicalAntialiasing subpixelMorphologicalAntialiasing;
3131
public FastApproximateAntialiasing fastApproximateAntialiasing;
32-
public ScreenSpaceReflections screenSpaceReflections;
3332
public Fog fog;
3433
public Dithering dithering;
3534

@@ -138,7 +137,6 @@ public void Init(PostProcessResources resources)
138137
{
139138
if (resources != null) m_Resources = resources;
140139

141-
RuntimeUtilities.CreateIfNull(ref screenSpaceReflections);
142140
RuntimeUtilities.CreateIfNull(ref temporalAntialiasing);
143141
RuntimeUtilities.CreateIfNull(ref subpixelMorphologicalAntialiasing);
144142
RuntimeUtilities.CreateIfNull(ref fastApproximateAntialiasing);
@@ -226,7 +224,6 @@ void OnDisable()
226224
}
227225

228226
temporalAntialiasing.Release();
229-
screenSpaceReflections.Release();
230227
m_LogHistogram.Release();
231228

232229
foreach (var bundle in m_Bundles.Values)
@@ -279,19 +276,23 @@ void OnPreCull()
279276

280277
SetupContext(context);
281278

279+
context.command = m_LegacyCmdBufferOpaque;
280+
UpdateSettingsIfNeeded(context);
281+
282282
// Lighting & opaque-only effects
283283
var aoBundle = GetBundle<AmbientOcclusion>();
284284
var aoSettings = aoBundle.CastSettings<AmbientOcclusion>();
285285
var aoRenderer = aoBundle.CastRenderer<AmbientOcclusionRenderer>();
286286

287-
int opaqueOnlyEffects = 0;
288-
bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context);
289287
bool aoSupported = aoSettings.IsEnabledAndSupported(context);
290288
bool aoAmbientOnly = aoRenderer.IsAmbientOnly(context);
291289
bool isAmbientOcclusionDeferred = aoSupported && aoAmbientOnly;
292290
bool isAmbientOcclusionOpaque = aoSupported && !aoAmbientOnly;
293-
bool isScreenSpaceReflectionsActive = screenSpaceReflections.IsEnabledAndSupported(context);
294-
bool isFogActive = fog.IsEnabledAndSupported(context);
291+
292+
var ssrBundle = GetBundle<ScreenSpaceReflections>();
293+
var ssrSettings = ssrBundle.settings;
294+
var ssrRenderer = ssrBundle.renderer;
295+
bool isScreenSpaceReflectionsActive = ssrSettings.IsEnabledAndSupported(context);
295296

296297
// Ambient-only AO is a special case and has to be done in separate command buffers
297298
if (isAmbientOcclusionDeferred)
@@ -311,7 +312,10 @@ void OnPreCull()
311312
context.command = m_LegacyCmdBufferOpaque;
312313
aoRenderer.Get().RenderAfterOpaque(context);
313314
}
314-
315+
316+
bool isFogActive = fog.IsEnabledAndSupported(context);
317+
bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context);
318+
int opaqueOnlyEffects = 0;
315319
opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0;
316320
opaqueOnlyEffects += isFogActive ? 1 : 0;
317321
opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0;
@@ -342,7 +346,7 @@ void OnPreCull()
342346

343347
if (isScreenSpaceReflectionsActive)
344348
{
345-
screenSpaceReflections.Render(context);
349+
ssrRenderer.Render(context);
346350
opaqueOnlyEffects--;
347351
var prevSource = context.source;
348352
context.source = context.destination;
@@ -461,7 +465,6 @@ public void ResetHistory()
461465
bundle.Value.ResetHistory();
462466

463467
temporalAntialiasing.ResetHistory();
464-
screenSpaceReflections.ResetHistory();
465468
}
466469

467470
public bool HasOpaqueOnlyEffects(PostProcessRenderContext context)

0 commit comments

Comments
 (0)