@@ -74,84 +74,25 @@ Vector2 GenerateRandomOffset()
7474 return offset ;
7575 }
7676
77- // Adapted heavily from PlayDead's TAA code
78- // https://github.com/playdeadgames/temporal/blob/master/Assets/Scripts/Extensions.cs
79- Matrix4x4 GetPerspectiveProjectionMatrix ( Camera camera , Vector2 offset )
80- {
81- float vertical = Mathf . Tan ( 0.5f * Mathf . Deg2Rad * camera . fieldOfView ) ;
82- float horizontal = vertical * camera . aspect ;
83- float near = camera . nearClipPlane ;
84- float far = camera . farClipPlane ;
85-
86- offset . x *= horizontal / ( 0.5f * camera . pixelWidth ) ;
87- offset . y *= vertical / ( 0.5f * camera . pixelHeight ) ;
88-
89- float left = ( offset . x - horizontal ) * near ;
90- float right = ( offset . x + horizontal ) * near ;
91- float top = ( offset . y + vertical ) * near ;
92- float bottom = ( offset . y - vertical ) * near ;
93-
94- var matrix = new Matrix4x4 ( ) ;
95-
96- matrix [ 0 , 0 ] = ( 2f * near ) / ( right - left ) ;
97- matrix [ 0 , 1 ] = 0f ;
98- matrix [ 0 , 2 ] = ( right + left ) / ( right - left ) ;
99- matrix [ 0 , 3 ] = 0f ;
100-
101- matrix [ 1 , 0 ] = 0f ;
102- matrix [ 1 , 1 ] = ( 2f * near ) / ( top - bottom ) ;
103- matrix [ 1 , 2 ] = ( top + bottom ) / ( top - bottom ) ;
104- matrix [ 1 , 3 ] = 0f ;
105-
106- matrix [ 2 , 0 ] = 0f ;
107- matrix [ 2 , 1 ] = 0f ;
108- matrix [ 2 , 2 ] = - ( far + near ) / ( far - near ) ;
109- matrix [ 2 , 3 ] = - ( 2f * far * near ) / ( far - near ) ;
110-
111- matrix [ 3 , 0 ] = 0f ;
112- matrix [ 3 , 1 ] = 0f ;
113- matrix [ 3 , 2 ] = - 1f ;
114- matrix [ 3 , 3 ] = 0f ;
115-
116- return matrix ;
117- }
118-
119- Matrix4x4 GetOrthographicProjectionMatrix ( Camera camera , Vector2 offset )
120- {
121- float vertical = camera . orthographicSize ;
122- float horizontal = vertical * camera . aspect ;
123-
124- offset . x *= horizontal / ( 0.5f * camera . pixelWidth ) ;
125- offset . y *= vertical / ( 0.5f * camera . pixelHeight ) ;
126-
127- float left = offset . x - horizontal ;
128- float right = offset . x + horizontal ;
129- float top = offset . y + vertical ;
130- float bottom = offset . y - vertical ;
131-
132- return Matrix4x4 . Ortho ( left , right , bottom , top , camera . nearClipPlane , camera . farClipPlane ) ;
133- }
134-
135- public void SetProjectionMatrix ( Camera camera )
77+ public Matrix4x4 GetJitteredProjectionMatrix ( Camera camera )
13678 {
79+ Matrix4x4 cameraProj ;
13780 jitter = GenerateRandomOffset ( ) ;
13881 jitter *= jitterSpread ;
13982
140- camera . nonJitteredProjectionMatrix = camera . projectionMatrix ;
141-
14283 if ( jitteredMatrixFunc != null )
14384 {
144- camera . projectionMatrix = jitteredMatrixFunc ( camera , jitter ) ;
85+ cameraProj = jitteredMatrixFunc ( camera , jitter ) ;
14586 }
14687 else
14788 {
148- camera . projectionMatrix = camera . orthographic
149- ? GetOrthographicProjectionMatrix ( camera , jitter )
150- : GetPerspectiveProjectionMatrix ( camera , jitter ) ;
89+ cameraProj = camera . orthographic
90+ ? RuntimeUtilities . GetJitteredOrthographicProjectionMatrix ( camera , jitter )
91+ : RuntimeUtilities . GetJitteredPerspectiveProjectionMatrix ( camera , jitter ) ;
15192 }
15293
153- camera . useJitteredProjectionMatrixForTransparentRendering = false ;
15494 jitter = new Vector2 ( jitter . x / camera . pixelWidth , jitter . y / camera . pixelHeight ) ;
95+ return cameraProj ;
15596 }
15697
15798 RenderTexture CheckHistory ( int id , PostProcessRenderContext context )
0 commit comments