@@ -16,6 +16,7 @@ static class Uniforms
1616 internal static readonly int _RcpAspect = Shader . PropertyToID ( "_RcpAspect" ) ;
1717 internal static readonly int _MainTex = Shader . PropertyToID ( "_MainTex" ) ;
1818 internal static readonly int _HistoryCoC = Shader . PropertyToID ( "_HistoryCoC" ) ;
19+ internal static readonly int _HistoryWeight = Shader . PropertyToID ( "_HistoryWeight" ) ;
1920 internal static readonly int _DepthOfFieldParams = Shader . PropertyToID ( "_DepthOfFieldParams" ) ;
2021 }
2122
@@ -92,43 +93,36 @@ public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasC
9293 source . filterMode = FilterMode . Point ;
9394
9495 // Pass #1 - Downsampling, prefiltering and CoC calculation
95- Graphics . Blit ( source , rt1 , material , 0 ) ;
96-
97- // Pass #2 - CoC Antialiasing
98- var pass = rt1 ;
99- if ( antialiasCoC )
96+ if ( ! antialiasCoC )
10097 {
101- pass = context . renderTextureFactory . Get ( context . width / 2 , context . height / 2 , 0 , RenderTextureFormat . ARGBHalf ) ;
102-
103- if ( m_CoCHistory == null || ! m_CoCHistory . IsCreated ( ) || m_CoCHistory . width != context . width / 2 || m_CoCHistory . height != context . height / 2 )
104- {
105- m_CoCHistory = RenderTexture . GetTemporary ( context . width / 2 , context . height / 2 , 0 , RenderTextureFormat . RHalf ) ;
106- m_CoCHistory . filterMode = FilterMode . Point ;
107- m_CoCHistory . name = "CoC History" ;
108- Graphics . Blit ( rt1 , m_CoCHistory , material , 6 ) ;
109- }
98+ Graphics . Blit ( source , rt1 , material , 0 ) ;
99+ }
100+ else
101+ {
102+ var initial = m_CoCHistory == null || ! m_CoCHistory . IsCreated ( ) || m_CoCHistory . width != context . width / 2 || m_CoCHistory . height != context . height / 2 ;
110103
111104 var tempCoCHistory = RenderTexture . GetTemporary ( context . width / 2 , context . height / 2 , 0 , RenderTextureFormat . RHalf ) ;
112105 tempCoCHistory . filterMode = FilterMode . Point ;
113106 tempCoCHistory . name = "CoC History" ;
114107
115- m_MRT [ 0 ] = pass . colorBuffer ;
108+ m_MRT [ 0 ] = rt1 . colorBuffer ;
116109 m_MRT [ 1 ] = tempCoCHistory . colorBuffer ;
117- material . SetTexture ( Uniforms . _MainTex , rt1 ) ;
110+ material . SetTexture ( Uniforms . _MainTex , source ) ;
118111 material . SetTexture ( Uniforms . _HistoryCoC , m_CoCHistory ) ;
112+ material . SetFloat ( Uniforms . _HistoryWeight , initial ? 0 : 0.5f ) ;
119113 Graphics . SetRenderTarget ( m_MRT , rt1 . depthBuffer ) ;
120- GraphicsUtils . Blit ( material , 5 ) ;
114+ GraphicsUtils . Blit ( material , 1 ) ;
121115
122116 RenderTexture . ReleaseTemporary ( m_CoCHistory ) ;
123117 m_CoCHistory = tempCoCHistory ;
124118 }
125119
126- // Pass #3 - Bokeh simulation
120+ // Pass #2 - Bokeh simulation
127121 var rt2 = context . renderTextureFactory . Get ( context . width / 2 , context . height / 2 , 0 , RenderTextureFormat . ARGBHalf ) ;
128- Graphics . Blit ( pass , rt2 , material , 1 + ( int ) settings . kernelSize ) ;
122+ Graphics . Blit ( rt1 , rt2 , material , 2 + ( int ) settings . kernelSize ) ;
129123
130- // Pass #4 - Postfilter blur
131- Graphics . Blit ( rt2 , rt1 , material , 7 ) ;
124+ // Pass #3 - Postfilter blur
125+ Graphics . Blit ( rt2 , rt1 , material , 6 ) ;
132126
133127 if ( context . profile . debugViews . IsModeActive ( DebugMode . FocusPlane ) )
134128 {
@@ -142,9 +136,7 @@ public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasC
142136 uberMaterial . EnableKeyword ( "DEPTH_OF_FIELD" ) ;
143137 }
144138
145- if ( antialiasCoC )
146- context . renderTextureFactory . Release ( pass ) ;
147-
139+ context . renderTextureFactory . Release ( rt1 ) ;
148140 context . renderTextureFactory . Release ( rt2 ) ;
149141 source . filterMode = FilterMode . Bilinear ;
150142 }
0 commit comments