@@ -58,6 +58,22 @@ public override DepthTextureMode GetCameraFlags()
5858 return DepthTextureMode . Depth | DepthTextureMode . MotionVectors ;
5959 }
6060
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+
6177 public override void Render ( PostProcessRenderContext context )
6278 {
6379 var cmd = context . command ;
@@ -74,9 +90,6 @@ public override void Render(PostProcessRenderContext context)
7490 var packedRTFormat = RenderTextureFormat . ARGB2101010 . IsSupported ( )
7591 ? RenderTextureFormat . ARGB2101010
7692 : RenderTextureFormat . ARGB32 ;
77- #if ! UNITY_2019_1_OR_NEWER
78- bool useDynamicRes = context . camera . allowDynamicResolution ;
79- #endif
8093
8194 var sheet = context . propertySheets . Get ( context . resources . shaders . motionBlur ) ;
8295 cmd . BeginSample ( "MotionBlur" ) ;
@@ -95,49 +108,23 @@ public override void Render(PostProcessRenderContext context)
95108 sheet . properties . SetFloat ( ShaderIDs . RcpMaxBlurRadius , 1f / maxBlurPixels ) ;
96109
97110 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 ) ;
104112 cmd . BlitFullscreenTriangle ( BuiltinRenderTextureType . None , vbuffer , sheet , ( int ) Pass . VelocitySetup ) ;
105113
106114 // Pass 2 - First TileMax filter (1/2 downsize)
107115 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 ) ;
116117 cmd . BlitFullscreenTriangle ( vbuffer , tile2 , sheet , ( int ) Pass . TileMax1 ) ;
117118
118119 // Pass 3 - Second TileMax filter (1/2 downsize)
119120 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 ) ;
128122 cmd . BlitFullscreenTriangle ( tile2 , tile4 , sheet , ( int ) Pass . TileMax2 ) ;
129123 cmd . ReleaseTemporaryRT ( tile2 ) ;
130124
131125 // Pass 4 - Third TileMax filter (1/2 downsize)
132126 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 ) ;
141128 cmd . BlitFullscreenTriangle ( tile4 , tile8 , sheet , ( int ) Pass . TileMax2 ) ;
142129 cmd . ReleaseTemporaryRT ( tile4 ) ;
143130
@@ -147,29 +134,13 @@ public override void Render(PostProcessRenderContext context)
147134 sheet . properties . SetFloat ( ShaderIDs . TileMaxLoop , ( int ) ( tileSize / 8f ) ) ;
148135
149136 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 ) ;
158138 cmd . BlitFullscreenTriangle ( tile8 , tile , sheet , ( int ) Pass . TileMaxV ) ;
159139 cmd . ReleaseTemporaryRT ( tile8 ) ;
160140
161141 // Pass 6 - NeighborMax filter
162- rtDesc = context . GetDescriptor ( 0 , vectorRTFormat , RenderTextureReadWrite . Linear ) ;
163142 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 ) ;
173144 cmd . BlitFullscreenTriangle ( tile , neighborMax , sheet , ( int ) Pass . NeighborMax ) ;
174145 cmd . ReleaseTemporaryRT ( tile ) ;
175146
0 commit comments