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

Commit b5ff284

Browse files
committed
Removed "rendering features"; moved AO to profile/volume
1 parent 28df890 commit b5ff284

7 files changed

Lines changed: 187 additions & 190 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using UnityEngine;
2+
using UnityEngine.Rendering.PostProcessing;
3+
4+
namespace UnityEditor.Rendering.PostProcessing
5+
{
6+
[PostProcessEditor(typeof(AmbientOcclusion))]
7+
public sealed class AmbientOcclusionEditor : PostProcessEffectEditor<AmbientOcclusion>
8+
{
9+
SerializedParameterOverride m_Mode;
10+
SerializedParameterOverride m_Intensity;
11+
SerializedParameterOverride m_Color;
12+
SerializedParameterOverride m_AmbientOnly;
13+
SerializedParameterOverride m_ThicknessModifier;
14+
SerializedParameterOverride m_Quality;
15+
SerializedParameterOverride m_Radius;
16+
17+
public override void OnEnable()
18+
{
19+
m_Mode = FindParameterOverride(x => x.mode);
20+
m_Intensity = FindParameterOverride(x => x.intensity);
21+
m_Color = FindParameterOverride(x => x.color);
22+
m_AmbientOnly = FindParameterOverride(x => x.ambientOnly);
23+
m_ThicknessModifier = FindParameterOverride(x => x.thicknessModifier);
24+
m_Quality = FindParameterOverride(x => x.quality);
25+
m_Radius = FindParameterOverride(x => x.radius);
26+
}
27+
28+
public override void OnInspectorGUI()
29+
{
30+
PropertyField(m_Mode);
31+
PropertyField(m_Intensity);
32+
33+
int aoMode = m_Mode.value.intValue;
34+
35+
if (aoMode == (int)AmbientOcclusionMode.ScalableAmbientObscurance)
36+
{
37+
PropertyField(m_Radius);
38+
PropertyField(m_Quality);
39+
}
40+
else if (aoMode == (int)AmbientOcclusionMode.MultiScaleVolumetricObscurance)
41+
{
42+
if (!SystemInfo.supportsComputeShaders)
43+
EditorGUILayout.HelpBox("Multi-scale volumetric obscurance requires compute shader support.", MessageType.Warning);
44+
45+
PropertyField(m_ThicknessModifier);
46+
}
47+
48+
PropertyField(m_Color);
49+
50+
if (Camera.main.actualRenderingPath == RenderingPath.DeferredShading && Camera.main.allowHDR)
51+
PropertyField(m_AmbientOnly);
52+
}
53+
}
54+
}

PostProcessing/Editor/Effects/AmbientOcclusionEditor.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/Editor/PostProcessLayerEditor.cs

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ public sealed class PostProcessLayerEditor : BaseEditor<PostProcessLayer>
2626
SerializedProperty m_FxaaMobileOptimized;
2727
SerializedProperty m_FxaaKeepAlpha;
2828

29-
SerializedProperty m_AOEnabled;
30-
SerializedProperty m_AOMode;
31-
SerializedProperty m_SAOIntensity;
32-
SerializedProperty m_SAORadius;
33-
SerializedProperty m_SAOQuality;
34-
SerializedProperty m_SAOColor;
35-
SerializedProperty m_MSVOIntensity;
36-
SerializedProperty m_MSVOThicknessModifier;
37-
SerializedProperty m_MSVOColor;
38-
SerializedProperty m_AOAmbientOnly;
39-
4029
SerializedProperty m_FogEnabled;
4130
SerializedProperty m_FogExcludeSkybox;
4231

@@ -54,12 +43,6 @@ public sealed class PostProcessLayerEditor : BaseEditor<PostProcessLayer>
5443
new GUIContent("Temporal Anti-aliasing (TAA)")
5544
};
5645

57-
static GUIContent[] s_AmbientOcclusionMethodNames =
58-
{
59-
new GUIContent("Scalable Ambient Obscurance (Classic)"),
60-
new GUIContent("Multi-scale Volumetric Obscurance (Modern)")
61-
};
62-
6346
enum ExportMode
6447
{
6548
FullFrame,
@@ -81,17 +64,6 @@ void OnEnable()
8164
m_TaaMotionBlending = FindProperty(x => x.temporalAntialiasing.motionBlending);
8265
m_FxaaMobileOptimized = FindProperty(x => x.fastApproximateAntialiasing.mobileOptimized);
8366
m_FxaaKeepAlpha = FindProperty(x => x.fastApproximateAntialiasing.keepAlpha);
84-
85-
m_AOEnabled = FindProperty(x => x.ambientOcclusion.enabled);
86-
m_AOMode = FindProperty(x => x.ambientOcclusion.mode);
87-
m_AOAmbientOnly = FindProperty(x => x.ambientOcclusion.ambientOnly);
88-
m_SAOIntensity = FindProperty(x => x.ambientOcclusion.scalableAO.intensity);
89-
m_SAORadius = FindProperty(x => x.ambientOcclusion.scalableAO.radius);
90-
m_SAOQuality = FindProperty(x => x.ambientOcclusion.scalableAO.quality);
91-
m_SAOColor = FindProperty(x => x.ambientOcclusion.scalableAO.color);
92-
m_MSVOIntensity = FindProperty(x => x.ambientOcclusion.multiScaleVO.intensity);
93-
m_MSVOThicknessModifier = FindProperty(x => x.ambientOcclusion.multiScaleVO.thicknessModifier);
94-
m_MSVOColor = FindProperty(x => x.ambientOcclusion.multiScaleVO.color);
9567

9668
m_FogEnabled = FindProperty(x => x.fog.enabled);
9769
m_FogExcludeSkybox = FindProperty(x => x.fog.excludeSkybox);
@@ -148,11 +120,11 @@ public override void OnInspectorGUI()
148120

149121
DoVolumeBlending();
150122
DoAntialiasing();
123+
DoFog(camera);
151124

152125
EditorGUILayout.PropertyField(m_StopNaNPropagation, EditorUtilities.GetContent("Stop NaN Propagation|Automatically replaces NaN/Inf in shaders by a black pixel to avoid breaking some effects. This will slightly affect performances and should only be used if you experience NaN issues that you can't fix. Has no effect on GLES2 platforms."));
153126
EditorGUILayout.Space();
154127

155-
DoRenderingFeatures(camera);
156128
DoToolkit();
157129
DoCustomEffectSorter();
158130

@@ -229,61 +201,6 @@ void DoAntialiasing()
229201
EditorGUILayout.Space();
230202
}
231203

232-
void DoRenderingFeatures(Camera camera)
233-
{
234-
if (RuntimeUtilities.scriptableRenderPipelineActive)
235-
return;
236-
237-
EditorUtilities.DrawSplitter();
238-
m_ShowRenderingFeatures.boolValue = EditorUtilities.DrawHeader("Rendering Features", m_ShowRenderingFeatures.boolValue);
239-
240-
if (m_ShowRenderingFeatures.boolValue)
241-
{
242-
GUILayout.Space(2);
243-
244-
DoAmbientOcclusion(camera);
245-
DoFog(camera);
246-
}
247-
}
248-
249-
void DoAmbientOcclusion(Camera camera)
250-
{
251-
EditorGUILayout.LabelField(EditorUtilities.GetContent("Ambient Occlusion"), EditorStyles.boldLabel);
252-
EditorGUI.indentLevel++;
253-
{
254-
EditorGUILayout.PropertyField(m_AOEnabled);
255-
256-
if (m_AOEnabled.boolValue)
257-
{
258-
int aoMode = m_AOMode.intValue;
259-
m_AOMode.intValue = EditorGUILayout.Popup(EditorUtilities.GetContent("Mode|The ambient occlusion method to use. \"Modern\" is higher quality and faster on desktop & console platforms but requires compute shader support."), aoMode, s_AmbientOcclusionMethodNames);
260-
261-
if (aoMode == (int)AmbientOcclusion.Mode.SAO)
262-
{
263-
EditorGUILayout.PropertyField(m_SAOIntensity);
264-
EditorGUILayout.PropertyField(m_SAORadius);
265-
EditorGUILayout.PropertyField(m_SAOQuality);
266-
EditorGUILayout.PropertyField(m_SAOColor);
267-
}
268-
else if (aoMode == (int)AmbientOcclusion.Mode.MSVO)
269-
{
270-
if (!SystemInfo.supportsComputeShaders)
271-
EditorGUILayout.HelpBox("Multi-scale volumetric obscurance requires compute shader support.", MessageType.Warning);
272-
273-
EditorGUILayout.PropertyField(m_MSVOIntensity);
274-
EditorGUILayout.PropertyField(m_MSVOThicknessModifier);
275-
EditorGUILayout.PropertyField(m_MSVOColor);
276-
}
277-
278-
if (camera != null && camera.actualRenderingPath == RenderingPath.DeferredShading && camera.allowHDR)
279-
EditorGUILayout.PropertyField(m_AOAmbientOnly);
280-
}
281-
}
282-
EditorGUI.indentLevel--;
283-
284-
EditorGUILayout.Space();
285-
}
286-
287204
void DoFog(Camera camera)
288205
{
289206
if (camera == null || camera.actualRenderingPath != RenderingPath.DeferredShading)
@@ -297,7 +214,7 @@ void DoFog(Camera camera)
297214
if (m_FogEnabled.boolValue)
298215
{
299216
EditorGUILayout.PropertyField(m_FogExcludeSkybox);
300-
EditorGUILayout.HelpBox("This effect adds fog compatibility to the deferred rendering path; actual fog settings should be set in the Lighting panel.", MessageType.Info);
217+
EditorGUILayout.HelpBox("This adds fog compatibility to the deferred rendering path; actual fog settings should be set in the Lighting panel.", MessageType.Info);
301218
}
302219
}
303220
EditorGUI.indentLevel--;

PostProcessing/Runtime/Effects/AmbientOcclusion.cs

Lines changed: 90 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,129 @@
22

33
namespace UnityEngine.Rendering.PostProcessing
44
{
5-
public interface IAmbientOcclusionMethod
5+
public enum AmbientOcclusionMode
66
{
7-
DepthTextureMode GetCameraFlags();
8-
bool IsSupported(PostProcessRenderContext context);
9-
void RenderAfterOpaque(PostProcessRenderContext context);
10-
void RenderAmbientOnly(PostProcessRenderContext context);
11-
void CompositeAmbientOnly(PostProcessRenderContext context);
12-
void Release();
7+
ScalableAmbientObscurance,
8+
MultiScaleVolumetricObscurance
139
}
1410

11+
public enum AmbientOcclusionQuality
12+
{
13+
Lowest,
14+
Low,
15+
Medium,
16+
High,
17+
Ultra
18+
}
19+
20+
[Serializable]
21+
public sealed class AmbientOcclusionModeParameter : ParameterOverride<AmbientOcclusionMode> {}
22+
23+
[Serializable]
24+
public sealed class AmbientOcclusionQualityParameter : ParameterOverride<AmbientOcclusionQuality> {}
25+
1526
[Serializable]
16-
public sealed class AmbientOcclusion
27+
[PostProcess(typeof(AmbientOcclusionRenderer), "Unity/Ambient Occlusion")]
28+
public sealed class AmbientOcclusion : PostProcessEffectSettings
1729
{
18-
public enum Mode
19-
{
20-
SAO,
21-
MSVO
22-
}
30+
// Shared parameters
31+
[Tooltip("The ambient occlusion method to use. \"Modern\" is higher quality and faster on desktop & console platforms but requires compute shader support.")]
32+
public AmbientOcclusionModeParameter mode = new AmbientOcclusionModeParameter { value = AmbientOcclusionMode.MultiScaleVolumetricObscurance };
2333

24-
[Tooltip("Enables ambient occlusion.")]
25-
public bool enabled = false;
34+
[Range(0f, 4f), Tooltip("Degree of darkness added by ambient occlusion.")]
35+
public FloatParameter intensity = new FloatParameter { value = 0f };
2636

27-
public Mode mode = Mode.MSVO;
37+
[ColorUsage(false), Tooltip("Custom color to use for the ambient occlusion.")]
38+
public ColorParameter color = new ColorParameter { value = Color.black };
2839

2940
[Tooltip("Only affects ambient lighting. This mode is only available with the Deferred rendering path and HDR rendering. Objects rendered with the Forward rendering path won't get any ambient occlusion.")]
30-
public bool ambientOnly = false;
41+
public BoolParameter ambientOnly = new BoolParameter { value = true };
3142

32-
// Polymorphism doesn't play well with serialization in Unity so we have to keep explicit
33-
// references... Would be nice to have this more dynamic to allow user-custom AO methods.
34-
public ScalableAO scalableAO;
35-
public MultiScaleVO multiScaleVO;
43+
// MSVO-only parameters
44+
[Range(-8f, 0f)]
45+
public FloatParameter noiseFilterTolerance = new FloatParameter { value = 0f }; // Hidden
3646

37-
IAmbientOcclusionMethod[] m_Methods;
47+
[Range(-8f, -1f)]
48+
public FloatParameter blurTolerance = new FloatParameter { value = -4.6f }; // Hidden
49+
50+
[Range(-12f, -1f)]
51+
public FloatParameter upsampleTolerance = new FloatParameter { value = -12f }; // Hidden
52+
53+
[Range(1f, 10f), Tooltip("Modifies thickness of occluders. This increases dark areas but also introduces dark halo around objects.")]
54+
public FloatParameter thicknessModifier = new FloatParameter { value = 1f };
55+
56+
// SAO-only parameters
57+
[Tooltip("Radius of sample points, which affects extent of darkened areas.")]
58+
public FloatParameter radius = new FloatParameter { value = 0.25f };
59+
60+
[Tooltip("Number of sample points, which affects quality and performance. Lowest, Low & Medium passes are downsampled. High and Ultra are not and should only be used on high-end hardware.")]
61+
public AmbientOcclusionQualityParameter quality = new AmbientOcclusionQualityParameter { value = AmbientOcclusionQuality.Medium };
3862

39-
public AmbientOcclusion()
63+
public override bool IsEnabledAndSupported(PostProcessRenderContext context)
4064
{
41-
if (scalableAO == null) scalableAO = new ScalableAO();
42-
if (multiScaleVO == null) multiScaleVO = new MultiScaleVO();
65+
bool state = enabled.value
66+
&& intensity.value > 0f
67+
&& !RuntimeUtilities.scriptableRenderPipelineActive;
4368

44-
m_Methods = new IAmbientOcclusionMethod[] { scalableAO, multiScaleVO };
69+
if (mode.value == AmbientOcclusionMode.MultiScaleVolumetricObscurance)
70+
state &= SystemInfo.supportsComputeShaders && SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat);
71+
72+
return state;
4573
}
74+
}
75+
76+
public interface IAmbientOcclusionMethod
77+
{
78+
DepthTextureMode GetCameraFlags();
79+
void RenderAfterOpaque(PostProcessRenderContext context);
80+
void RenderAmbientOnly(PostProcessRenderContext context);
81+
void CompositeAmbientOnly(PostProcessRenderContext context);
82+
void Release();
83+
}
4684

47-
public bool IsEnabledAndSupported(PostProcessRenderContext context)
85+
public sealed class AmbientOcclusionRenderer : PostProcessEffectRenderer<AmbientOcclusion>
86+
{
87+
IAmbientOcclusionMethod[] m_Methods;
88+
89+
public override void Init()
4890
{
49-
return enabled && Get().IsSupported(context);
91+
if (m_Methods == null)
92+
{
93+
m_Methods = new IAmbientOcclusionMethod[]
94+
{
95+
new ScalableAO(settings),
96+
new MultiScaleVO(settings),
97+
};
98+
}
5099
}
51100

52101
public bool IsAmbientOnly(PostProcessRenderContext context)
53102
{
54103
var camera = context.camera;
55-
return ambientOnly
104+
return settings.ambientOnly.value
56105
&& camera.actualRenderingPath == RenderingPath.DeferredShading
57106
&& camera.allowHDR;
58107
}
59108

60109
public IAmbientOcclusionMethod Get()
61110
{
62-
return m_Methods[(int)mode];
111+
return m_Methods[(int)settings.mode.value];
112+
}
113+
114+
public override DepthTextureMode GetCameraFlags()
115+
{
116+
return Get().GetCameraFlags();
63117
}
64118

65-
public void Release()
119+
public override void Release()
66120
{
67121
foreach (var m in m_Methods)
68122
m.Release();
69123
}
124+
125+
// Unused
126+
public override void Render(PostProcessRenderContext context)
127+
{
128+
}
70129
}
71130
}

0 commit comments

Comments
 (0)