@@ -58,6 +58,22 @@ public override DepthTextureMode GetCameraFlags()
58
58
return DepthTextureMode . Depth | DepthTextureMode . MotionVectors ;
59
59
}
60
60
61
+ private void CreateTemporaryRT ( PostProcessRenderContext context , int nameID , int width , int height , RenderTextureFormat RTFormat )
62
+ {
63
+ #if ! UNITY_2019_1_OR_NEWER
64
+ bool useDynamicRes = context . camera . allowDynamicResolution ;
65
+ #endif
66
+ var rtDesc = context . GetDescriptor ( 0 , RTFormat , RenderTextureReadWrite . Linear ) ;
67
+ rtDesc . width = width ;
68
+ rtDesc . height = height ;
69
+ var cmd = context . command ;
70
+ #if UNITY_2019_1_OR_NEWER
71
+ cmd . GetTemporaryRT ( nameID , rtDesc , FilterMode . Point ) ;
72
+ #else
73
+ cmd . GetTemporaryRT ( nameID , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
74
+ #endif
75
+ }
76
+
61
77
public override void Render ( PostProcessRenderContext context )
62
78
{
63
79
var cmd = context . command ;
@@ -74,9 +90,6 @@ public override void Render(PostProcessRenderContext context)
74
90
var packedRTFormat = RenderTextureFormat . ARGB2101010 . IsSupported ( )
75
91
? RenderTextureFormat . ARGB2101010
76
92
: RenderTextureFormat . ARGB32 ;
77
- #if ! UNITY_2019_1_OR_NEWER
78
- bool useDynamicRes = context . camera . allowDynamicResolution ;
79
- #endif
80
93
81
94
var sheet = context . propertySheets . Get ( context . resources . shaders . motionBlur ) ;
82
95
cmd . BeginSample ( "MotionBlur" ) ;
@@ -95,49 +108,23 @@ public override void Render(PostProcessRenderContext context)
95
108
sheet . properties . SetFloat ( ShaderIDs . RcpMaxBlurRadius , 1f / maxBlurPixels ) ;
96
109
97
110
int vbuffer = ShaderIDs . VelocityTex ;
98
- var rtDesc = context . GetDescriptor ( 0 , packedRTFormat , RenderTextureReadWrite . Linear ) ;
99
- #if UNITY_2019_1_OR_NEWER
100
- cmd . GetTemporaryRT ( vbuffer , rtDesc , FilterMode . Point ) ;
101
- #else
102
- cmd . GetTemporaryRT ( vbuffer , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
103
- #endif
111
+ CreateTemporaryRT ( context , vbuffer , context . width , context . height , packedRTFormat ) ;
104
112
cmd . BlitFullscreenTriangle ( BuiltinRenderTextureType . None , vbuffer , sheet , ( int ) Pass . VelocitySetup ) ;
105
113
106
114
// Pass 2 - First TileMax filter (1/2 downsize)
107
115
int tile2 = ShaderIDs . Tile2RT ;
108
- rtDesc = context . GetDescriptor ( 0 , vectorRTFormat , RenderTextureReadWrite . Linear ) ;
109
- rtDesc . width = context . width / 2 ;
110
- rtDesc . height = context . height / 2 ;
111
- #if UNITY_2019_1_OR_NEWER
112
- cmd . GetTemporaryRT ( tile2 , rtDesc , FilterMode . Point ) ;
113
- #else
114
- cmd . GetTemporaryRT ( tile2 , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
115
- #endif
116
+ CreateTemporaryRT ( context , tile2 , context . width / 2 , context . height / 2 , vectorRTFormat ) ;
116
117
cmd . BlitFullscreenTriangle ( vbuffer , tile2 , sheet , ( int ) Pass . TileMax1 ) ;
117
118
118
119
// Pass 3 - Second TileMax filter (1/2 downsize)
119
120
int tile4 = ShaderIDs . Tile4RT ;
120
- rtDesc = context . GetDescriptor ( 0 , vectorRTFormat , RenderTextureReadWrite . Linear ) ;
121
- rtDesc . width = context . width / 4 ;
122
- rtDesc . height = context . height / 4 ;
123
- #if UNITY_2019_1_OR_NEWER
124
- cmd . GetTemporaryRT ( tile4 , rtDesc , FilterMode . Point ) ;
125
- #else
126
- cmd . GetTemporaryRT ( tile4 , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
127
- #endif
121
+ CreateTemporaryRT ( context , tile4 , context . width / 4 , context . height / 4 , vectorRTFormat ) ;
128
122
cmd . BlitFullscreenTriangle ( tile2 , tile4 , sheet , ( int ) Pass . TileMax2 ) ;
129
123
cmd . ReleaseTemporaryRT ( tile2 ) ;
130
124
131
125
// Pass 4 - Third TileMax filter (1/2 downsize)
132
126
int tile8 = ShaderIDs . Tile8RT ;
133
- rtDesc = context . GetDescriptor ( 0 , vectorRTFormat , RenderTextureReadWrite . Linear ) ;
134
- rtDesc . width = context . width / 8 ;
135
- rtDesc . height = context . height / 8 ;
136
- #if UNITY_2019_1_OR_NEWER
137
- cmd . GetTemporaryRT ( tile8 , rtDesc , FilterMode . Point ) ;
138
- #else
139
- cmd . GetTemporaryRT ( tile8 , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
140
- #endif
127
+ CreateTemporaryRT ( context , tile8 , context . width / 8 , context . height / 8 , vectorRTFormat ) ;
141
128
cmd . BlitFullscreenTriangle ( tile4 , tile8 , sheet , ( int ) Pass . TileMax2 ) ;
142
129
cmd . ReleaseTemporaryRT ( tile4 ) ;
143
130
@@ -147,29 +134,13 @@ public override void Render(PostProcessRenderContext context)
147
134
sheet . properties . SetFloat ( ShaderIDs . TileMaxLoop , ( int ) ( tileSize / 8f ) ) ;
148
135
149
136
int tile = ShaderIDs . TileVRT ;
150
- rtDesc = context . GetDescriptor ( 0 , vectorRTFormat , RenderTextureReadWrite . Linear ) ;
151
- rtDesc . width = context . width / tileSize ;
152
- rtDesc . height = context . height / tileSize ;
153
- #if UNITY_2019_1_OR_NEWER
154
- cmd . GetTemporaryRT ( tile , rtDesc , FilterMode . Point ) ;
155
- #else
156
- cmd . GetTemporaryRT ( tile , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
157
- #endif
137
+ CreateTemporaryRT ( context , tile , context . width / tileSize , context . height / tileSize , vectorRTFormat ) ;
158
138
cmd . BlitFullscreenTriangle ( tile8 , tile , sheet , ( int ) Pass . TileMaxV ) ;
159
139
cmd . ReleaseTemporaryRT ( tile8 ) ;
160
140
161
141
// Pass 6 - NeighborMax filter
162
- rtDesc = context . GetDescriptor ( 0 , vectorRTFormat , RenderTextureReadWrite . Linear ) ;
163
142
int neighborMax = ShaderIDs . NeighborMaxTex ;
164
- int neighborMaxWidth = context . width / tileSize ;
165
- int neighborMaxHeight = context . height / tileSize ;
166
- rtDesc . width = neighborMaxWidth ;
167
- rtDesc . height = neighborMaxHeight ;
168
- #if UNITY_2019_1_OR_NEWER
169
- cmd . GetTemporaryRT ( neighborMax , rtDesc , FilterMode . Point ) ;
170
- #else
171
- cmd . GetTemporaryRT ( neighborMax , rtDesc . width , rtDesc . height , rtDesc . depthBufferBits , FilterMode . Point , rtDesc . colorFormat , RenderTextureReadWrite . Linear , rtDesc . msaaSamples , rtDesc . enableRandomWrite , rtDesc . memoryless , useDynamicRes ) ;
172
- #endif
143
+ CreateTemporaryRT ( context , neighborMax , context . width / tileSize , context . height / tileSize , vectorRTFormat ) ;
173
144
cmd . BlitFullscreenTriangle ( tile , neighborMax , sheet , ( int ) Pass . NeighborMax ) ;
174
145
cmd . ReleaseTemporaryRT ( tile ) ;
175
146
0 commit comments