@@ -41,17 +41,16 @@ enum Pass
4141
4242 // Ping-pong between two history textures as we can't read & write the same target in the
4343 // same pass
44- // TODO: We need to make left/right arrays
45- //readonly RenderTexture[] m_HistoryTextures = new RenderTexture[2] ;
46- readonly RenderTexture [ ] [ ] m_HistoryTextures = new RenderTexture [ 2 ] [ ] ;
44+ const int k_NumEyes = 2 ;
45+ const int k_NumHistoryTextures = 2 ;
46+ readonly RenderTexture [ ] [ ] m_HistoryTextures = new RenderTexture [ k_NumEyes ] [ ] ;
4747
48- //int m_HistoryPingPong;
49- int [ ] m_HistoryPingPong = new int [ 2 ] ;
48+ int [ ] m_HistoryPingPong = new int [ k_NumEyes ] ;
5049
5150 public TemporalAntialiasing ( )
5251 {
53- m_HistoryTextures [ 0 ] = new RenderTexture [ 2 ] ;
54- m_HistoryTextures [ 1 ] = new RenderTexture [ 2 ] ;
52+ m_HistoryTextures [ ( int ) Camera . StereoscopicEye . Left ] = new RenderTexture [ k_NumHistoryTextures ] ;
53+ m_HistoryTextures [ ( int ) Camera . StereoscopicEye . Right ] = new RenderTexture [ k_NumHistoryTextures ] ;
5554 }
5655
5756 public bool IsSupported ( )
@@ -132,24 +131,28 @@ public void ConfiguredStereoJitteredProjectionMatrices(PostProcessRenderContext
132131 context . camera . SetStereoProjectionMatrix ( eye , jitteredMatrix ) ;
133132 }
134133
134+ // jitter has to be scaled for the actual eye texture size, not just the intermediate texture size
135+ // which could be double-wide in certain stereo rendering scenarios
135136 jitter = new Vector2 ( jitter . x / context . singleEyeWidth , jitter . y / context . height ) ;
136137 camera . useJitteredProjectionMatrixForTransparentRendering = false ;
137138 }
138139
139140 RenderTexture CheckHistory ( int id , PostProcessRenderContext context )
140141 {
141- //var rt = m_HistoryTextures[id];
142- var rt = m_HistoryTextures [ context . activeEye ] [ id ] ;
142+ var rt = m_HistoryTextures [ context . xrActiveEye ] [ id ] ;
143143
144144 if ( m_ResetHistory || rt == null || ! rt . IsCreated ( ) )
145145 {
146146 RenderTexture . ReleaseTemporary ( rt ) ;
147147
148148 rt = RenderTexture . GetTemporary ( context . width , context . height , 0 , context . sourceFormat ) ;
149- rt . name = "Temporal Anti-aliasing History id #" + id . ToString ( ) + " for eye " + context . activeEye . ToString ( ) ;
149+ if ( XR . XRSettings . isDeviceActive )
150+ rt . name = "Temporal Anti-aliasing History id #" + id . ToString ( ) + " for eye " + context . xrActiveEye . ToString ( ) ;
151+ else
152+ rt . name = "Temporal Anti-aliasing History id #" + id . ToString ( ) ;
153+
150154 rt . filterMode = FilterMode . Bilinear ;
151- //m_HistoryTextures[id] = rt;
152- m_HistoryTextures [ context . activeEye ] [ id ] = rt ;
155+ m_HistoryTextures [ context . xrActiveEye ] [ id ] = rt ;
153156
154157 context . command . BlitFullscreenTriangle ( context . source , rt ) ;
155158 }
@@ -158,18 +161,19 @@ RenderTexture CheckHistory(int id, PostProcessRenderContext context)
158161 // On size change, simply copy the old history to the new one. This looks better
159162 // than completely discarding the history and seeing a few aliased frames.
160163 var rt2 = RenderTexture . GetTemporary ( context . width , context . height , 0 , context . sourceFormat ) ;
161- //rt2.name = "Temporal Anti-aliasing History";
162- rt2 . name = "Temporal Anti-aliasing History id #" + id . ToString ( ) + " for eye " + context . activeEye . ToString ( ) ;
164+ if ( XR . XRSettings . isDeviceActive )
165+ rt2 . name = "Temporal Anti-aliasing History id #" + id . ToString ( ) + " for eye " + context . xrActiveEye . ToString ( ) ;
166+ else
167+ rt2 . name = "Temporal Anti-aliasing History id #" + id . ToString ( ) ;
168+
163169 rt2 . filterMode = FilterMode . Bilinear ;
164- //m_HistoryTextures[id] = rt2;
165- m_HistoryTextures [ context . activeEye ] [ id ] = rt2 ;
170+ m_HistoryTextures [ context . xrActiveEye ] [ id ] = rt2 ;
166171
167172 context . command . BlitFullscreenTriangle ( rt , rt2 ) ;
168173 RenderTexture . ReleaseTemporary ( rt ) ;
169174 }
170175
171- //return m_HistoryTextures[id];
172- return m_HistoryTextures [ context . activeEye ] [ id ] ;
176+ return m_HistoryTextures [ context . xrActiveEye ] [ id ] ;
173177 }
174178
175179 internal void Render ( PostProcessRenderContext context )
@@ -179,12 +183,10 @@ internal void Render(PostProcessRenderContext context)
179183 var cmd = context . command ;
180184 cmd . BeginSample ( "TemporalAntialiasing" ) ;
181185
182- //int pp = m_HistoryPingPong;
183- int pp = m_HistoryPingPong [ context . activeEye ] ;
186+ int pp = m_HistoryPingPong [ context . xrActiveEye ] ;
184187 var historyRead = CheckHistory ( ++ pp % 2 , context ) ;
185188 var historyWrite = CheckHistory ( ++ pp % 2 , context ) ;
186- //m_HistoryPingPong = ++pp % 2;
187- m_HistoryPingPong [ context . activeEye ] = ++ pp % 2 ;
189+ m_HistoryPingPong [ context . xrActiveEye ] = ++ pp % 2 ;
188190
189191 const float kMotionAmplification = 100f * 60f ;
190192 sheet . properties . SetVector ( ShaderIDs . Jitter , jitter ) ;
0 commit comments