Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Changed TAA Jitter method to include camera matrix in calculations #377

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 9 additions & 30 deletions PostProcessing/Runtime/Utils/RuntimeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,40 +371,19 @@ public static float Exp2(float x)
// https://github.com/playdeadgames/temporal/blob/master/Assets/Scripts/Extensions.cs
public static Matrix4x4 GetJitteredPerspectiveProjectionMatrix(Camera camera, Vector2 offset)
{
float vertical = Mathf.Tan(0.5f * Mathf.Deg2Rad * camera.fieldOfView);
float horizontal = vertical * camera.aspect;
float near = camera.nearClipPlane;
float far = camera.farClipPlane;

offset.x *= horizontal / (0.5f * camera.pixelWidth);
offset.y *= vertical / (0.5f * camera.pixelHeight);

float left = (offset.x - horizontal) * near;
float right = (offset.x + horizontal) * near;
float top = (offset.y + vertical) * near;
float bottom = (offset.y - vertical) * near;

var matrix = new Matrix4x4();
float near = camera.nearClipPlane;
float far = camera.farClipPlane;

matrix[0, 0] = (2f * near) / (right - left);
matrix[0, 1] = 0f;
matrix[0, 2] = (right + left) / (right - left);
matrix[0, 3] = 0f;
float vertical = Mathf.Tan(0.5f * Mathf.Deg2Rad * camera.fieldOfView) * near;
float horizontal = vertical * camera.aspect;

matrix[1, 0] = 0f;
matrix[1, 1] = (2f * near) / (top - bottom);
matrix[1, 2] = (top + bottom) / (top - bottom);
matrix[1, 3] = 0f;
offset.x *= horizontal / (0.5f * camera.pixelWidth);
offset.y *= vertical / (0.5f * camera.pixelHeight);

matrix[2, 0] = 0f;
matrix[2, 1] = 0f;
matrix[2, 2] = -(far + near) / (far - near);
matrix[2, 3] = -(2f * far * near) / (far - near);
var matrix = camera.projectionMatrix;

matrix[3, 0] = 0f;
matrix[3, 1] = 0f;
matrix[3, 2] = -1f;
matrix[3, 3] = 0f;
matrix[0, 2] += offset.x / horizontal;
matrix[1, 2] += offset.y / vertical;

return matrix;
}
Expand Down