33
44namespace 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}
0 commit comments