tree sway and shadow improvements
[WindSway-HDRP.git] / Library / PackageCache / com.unity.postprocessing@2.1.2 / PostProcessing / Runtime / Effects / AmbientOcclusion.cs
blob5ca51dcf04fab4655c2f1bb40899b3c730fa7ca7
1 using System;
3 namespace UnityEngine.Rendering.PostProcessing
5 /// <summary>
6 /// Ambient occlusion modes.
7 /// </summary>
8 public enum AmbientOcclusionMode
10 /// <summary>
11 /// A standard implementation of ambient obscurance that works on non modern platforms. If
12 /// you target a compute-enabled platform we recommend that you use
13 /// <see cref="MultiScaleVolumetricObscurance"/> instead.
14 /// </summary>
15 ScalableAmbientObscurance,
17 /// <summary>
18 /// A modern version of ambient occlusion heavily optimized for consoles and desktop
19 /// platforms.
20 /// </summary>
21 MultiScaleVolumetricObscurance
24 /// <summary>
25 /// Quality settings for <see cref="AmbientOcclusionMode.ScalableAmbientObscurance"/>.
26 /// </summary>
27 public enum AmbientOcclusionQuality
29 /// <summary>
30 /// 4 samples + downsampling.
31 /// </summary>
32 Lowest,
34 /// <summary>
35 /// 6 samples + downsampling.
36 /// </summary>
37 Low,
39 /// <summary>
40 /// 10 samples + downsampling.
41 /// </summary>
42 Medium,
44 /// <summary>
45 /// 8 samples.
46 /// </summary>
47 High,
49 /// <summary>
50 /// 12 samples.
51 /// </summary>
52 Ultra
55 /// <summary>
56 /// A volume parameter holding a <see cref="AmbientOcclusionMode"/> value.
57 /// </summary>
58 [Serializable]
59 public sealed class AmbientOcclusionModeParameter : ParameterOverride<AmbientOcclusionMode> {}
61 /// <summary>
62 /// A volume parameter holding a <see cref="AmbientOcclusionQuality"/> value.
63 /// </summary>
64 [Serializable]
65 public sealed class AmbientOcclusionQualityParameter : ParameterOverride<AmbientOcclusionQuality> {}
67 /// <summary>
68 /// This class holds settings for the Ambient Occlusion effect.
69 /// </summary>
70 [Serializable]
71 [PostProcess(typeof(AmbientOcclusionRenderer), "Unity/Ambient Occlusion")]
72 public sealed class AmbientOcclusion : PostProcessEffectSettings
74 // Shared parameters
76 /// <summary>
77 /// The ambient occlusion method to use.
78 /// </summary>
79 [Tooltip("The ambient occlusion method to use. \"Multi Scale Volumetric Obscurance\" is higher quality and faster on desktop & console platforms but requires compute shader support.")]
81 public AmbientOcclusionModeParameter mode = new AmbientOcclusionModeParameter { value = AmbientOcclusionMode.MultiScaleVolumetricObscurance };
83 /// <summary>
84 /// The degree of darkness added by ambient occlusion.
85 /// </summary>
86 [Range(0f, 4f), Tooltip("The degree of darkness added by ambient occlusion. Higher values produce darker areas.")]
87 public FloatParameter intensity = new FloatParameter { value = 0f };
89 /// <summary>
90 /// A custom color to use for the ambient occlusion.
91 /// </summary>
92 [ColorUsage(false), Tooltip("The custom color to use for the ambient occlusion. The default is black.")]
94 public ColorParameter color = new ColorParameter { value = Color.black };
96 /// <summary>
97 /// Only affects ambient lighting. This mode is only available with the Deferred rendering
98 /// path and HDR rendering. Objects rendered with the Forward rendering path won't get any
99 /// ambient occlusion.
100 /// </summary>
101 [Tooltip("Check this box to mark this Volume as to only affect 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.")]
102 public BoolParameter ambientOnly = new BoolParameter { value = true };
104 // MSVO-only parameters
106 /// <summary>
107 /// The tolerance of the noise filter to changes in the depth pyramid.
108 /// </summary>
109 [Range(-8f, 0f)]
110 public FloatParameter noiseFilterTolerance = new FloatParameter { value = 0f }; // Hidden
112 /// <summary>
113 /// The tolerance of the bilateral blur filter to depth changes.
114 /// </summary>
115 [Range(-8f, -1f)]
116 public FloatParameter blurTolerance = new FloatParameter { value = -4.6f }; // Hidden
118 /// <summary>
119 /// The tolerance of the upsampling pass to depth changes.
120 /// </summary>
121 [Range(-12f, -1f)]
122 public FloatParameter upsampleTolerance = new FloatParameter { value = -12f }; // Hidden
124 /// <summary>
125 /// Modifies the thickness of occluders. This increases dark areas but also introduces dark
126 /// halo around objects.
127 /// </summary>
128 [Range(1f, 10f), Tooltip("This modifies the thickness of occluders. It increases the size of dark areas and also introduces a dark halo around objects.")]
129 public FloatParameter thicknessModifier = new FloatParameter { value = 1f };
131 // HDRP-only parameters
133 /// <summary>
134 /// Modifies he influence of direct lighting on ambient occlusion. This is only used in the
135 /// HD Render Pipeline currently.
136 /// </summary>
137 [Range(0f, 1f), Tooltip("Modifies the influence of direct lighting on ambient occlusion.")]
138 public FloatParameter directLightingStrength = new FloatParameter { value = 0f };
140 // SAO-only parameters
141 /// <summary>
142 /// Radius of sample points, which affects extent of darkened areas.
143 /// </summary>
144 [Tooltip("The radius of sample points. This affects the size of darkened areas.")]
145 public FloatParameter radius = new FloatParameter { value = 0.25f };
147 /// <summary>
148 /// The number of sample points, which affects quality and performance. Lowest, Low & Medium
149 /// passes are downsampled. High and Ultra are not and should only be used on high-end
150 /// hardware.
151 /// </summary>
152 [Tooltip("The number of sample points. This affects both quality and performance. For \"Lowest\", \"Low\", and \"Medium\", passes are downsampled. For \"High\" and \"Ultra\", they are not and therefore you should only \"High\" and \"Ultra\" on high-end hardware.")]
153 public AmbientOcclusionQualityParameter quality = new AmbientOcclusionQualityParameter { value = AmbientOcclusionQuality.Medium };
155 // SRPs can call this method without a context set (see HDRP).
156 // We need a better way to handle this than checking for a null context, context should
157 // never be null.
158 /// <inheritdoc />
159 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
161 bool state = enabled.value
162 && intensity.value > 0f;
164 if (mode.value == AmbientOcclusionMode.ScalableAmbientObscurance)
166 state &= !RuntimeUtilities.scriptableRenderPipelineActive;
168 if (context != null)
170 state &= context.resources.shaders.scalableAO
171 && context.resources.shaders.scalableAO.isSupported;
174 else if (mode.value == AmbientOcclusionMode.MultiScaleVolumetricObscurance)
176 #if UNITY_2017_1_OR_NEWER
177 if (context != null)
179 state &= context.resources.shaders.multiScaleAO
180 && context.resources.shaders.multiScaleAO.isSupported
181 && context.resources.computeShaders.multiScaleAODownsample1
182 && context.resources.computeShaders.multiScaleAODownsample2
183 && context.resources.computeShaders.multiScaleAORender
184 && context.resources.computeShaders.multiScaleAOUpsample;
187 state &= SystemInfo.supportsComputeShaders
188 && !RuntimeUtilities.isAndroidOpenGL
189 && RenderTextureFormat.RFloat.IsSupported()
190 && RenderTextureFormat.RHalf.IsSupported()
191 && RenderTextureFormat.R8.IsSupported();
192 #else
193 state = false;
194 #endif
197 return state;
201 internal interface IAmbientOcclusionMethod
203 DepthTextureMode GetCameraFlags();
204 void RenderAfterOpaque(PostProcessRenderContext context);
205 void RenderAmbientOnly(PostProcessRenderContext context);
206 void CompositeAmbientOnly(PostProcessRenderContext context);
207 void Release();
210 internal sealed class AmbientOcclusionRenderer : PostProcessEffectRenderer<AmbientOcclusion>
212 IAmbientOcclusionMethod[] m_Methods;
214 public override void Init()
216 if (m_Methods == null)
218 m_Methods = new IAmbientOcclusionMethod[]
220 new ScalableAO(settings),
221 new MultiScaleVO(settings),
226 public bool IsAmbientOnly(PostProcessRenderContext context)
228 var camera = context.camera;
229 return settings.ambientOnly.value
230 && camera.actualRenderingPath == RenderingPath.DeferredShading
231 && camera.allowHDR;
234 public IAmbientOcclusionMethod Get()
236 return m_Methods[(int)settings.mode.value];
239 public override DepthTextureMode GetCameraFlags()
241 return Get().GetCameraFlags();
244 public override void Release()
246 foreach (var m in m_Methods)
247 m.Release();
250 public ScalableAO GetScalableAO()
252 return (ScalableAO)m_Methods[(int)AmbientOcclusionMode.ScalableAmbientObscurance];
255 public MultiScaleVO GetMultiScaleVO()
257 return (MultiScaleVO)m_Methods[(int)AmbientOcclusionMode.MultiScaleVolumetricObscurance];
260 // Unused
261 public override void Render(PostProcessRenderContext context)