|
4 | 4 | namespace UnityEngine.Rendering.PostProcessing |
5 | 5 | { |
6 | 6 | [Serializable] |
7 | | - // TODO: Tooltips |
8 | 7 | public sealed class ScreenSpaceReflections |
9 | 8 | { |
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.")] |
11 | 22 | public bool enabled; |
12 | 23 |
|
| 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.")] |
13 | 37 | public float maximumMarchDistance = 100f; |
14 | 38 |
|
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; |
17 | 41 |
|
18 | | - [Range(0f, 1f)] |
| 42 | + [Range(0f, 1f), Tooltip("Fades reflections close to the screen borders.")] |
19 | 43 | public float attenuation = 0.25f; |
20 | 44 |
|
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 | + } |
27 | 51 |
|
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 | + }; |
31 | 62 |
|
32 | 63 | RenderTexture m_Test; |
33 | 64 | RenderTexture m_Resolve; |
@@ -80,9 +111,20 @@ internal void Render(PostProcessRenderContext context) |
80 | 111 | var cmd = context.command; |
81 | 112 | cmd.BeginSample("Screen-space Reflections"); |
82 | 113 |
|
| 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 | + |
83 | 123 | // Square POT target |
84 | 124 | int size = Mathf.ClosestPowerOfTwo(Mathf.Min(context.width, context.height)); |
85 | | - size >>= downsampling; |
| 125 | + |
| 126 | + if (downsampling) |
| 127 | + size >>= 1; |
86 | 128 |
|
87 | 129 | // The gaussian pyramid compute works in blocks of 8x8 so make sure the last lod has a |
88 | 130 | // minimum size of 8x8 |
@@ -112,11 +154,7 @@ internal void Render(PostProcessRenderContext context) |
112 | 154 | sheet.properties.SetMatrix(ShaderIDs.InverseProjectionMatrix, projectionMatrix.inverse); |
113 | 155 | sheet.properties.SetMatrix(ShaderIDs.ScreenSpaceProjectionMatrix, screenSpaceProjectionMatrix); |
114 | 156 | 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)); |
120 | 158 |
|
121 | 159 | cmd.GetTemporaryRT(ShaderIDs.SSRResolveTemp, size, size, 0, FilterMode.Bilinear, context.sourceFormat); |
122 | 160 | cmd.BlitFullscreenTriangle(context.source, m_Test, sheet, (int)Pass.Test); |
|
0 commit comments