diff --git a/shaders/cMotionBlur.fx b/shaders/cMotionBlur.fx index 49455d4..582eef0 100644 --- a/shaders/cMotionBlur.fx +++ b/shaders/cMotionBlur.fx @@ -346,7 +346,7 @@ namespace MotionBlur float2 Lucas_Kanade(int Level, float2 Vectors, float4 TexCoord) { /* - Fetch 2x2 bilinear-filtered windows for spatial and temporal dertivatives + Fetch 2x2 bilinear-filtered windows for spatial(S) and temporal(T) dertivatives [TexCoord.xw TexCoord.zw] [TexCoord.xy TexCoord.zy] */ @@ -375,7 +375,7 @@ namespace MotionBlur B2 = IyIt */ - // Solve window equation at matrix A + // Create matrix A and solve its window sum // A.x = A11; A.y = A22; A.z = A12/A22 float3 A = 0.0; A += (S[0].xyx * S[0].xyy); @@ -383,28 +383,31 @@ namespace MotionBlur A += (S[2].xyx * S[2].xyy); A += (S[3].xyx * S[3].xyy); - // Solve window equation at vector B - // B.x = B1; B.y = B2 - float2 B = 0.0; - B += (S[0] * T[0]); - B += (S[1] * T[1]); - B += (S[2] * T[2]); - B += (S[3] * T[3]); - // Ensure Lucas-Kanade's determinant is non-zero A.xy = max(A.xy, FP16_SMALLEST_SUBNORMAL); - // Create -IxIy (A12) for A's determinant and LK matrix + // Create -IxIy (A12) for A^-1 and its determinant A.z = A.z * (-1.0); - // Calculate determinant + // Calculate A^-1 determinant float D = ((A.x * A.y) - (A.z * A.z)); + // Calculate A^-1 + A = (1.0 / D) * A; + + // Create vector B and solve its window sum + // B.x = B1; B.y = B2 + float2 B = 0.0; + B += (S[0] * T[0]); + B += (S[1] * T[1]); + B += (S[2] * T[2]); + B += (S[3] * T[3]); + // Calculate Lucas-Kanade matrix float2 LK = 0.0; LK.x = dot(A.yz, -B.xy); LK.y = dot(A.zx, -B.xy); - LK = (D != 0.0) ? (LK / D) + Vectors : 0.0; + LK = (D != 0.0) ? LK + Vectors : 0.0; return LK; } diff --git a/shaders/cOpticalFlowLK.fx b/shaders/cOpticalFlowLK.fx index 6c12f5c..17e3d9e 100644 --- a/shaders/cOpticalFlowLK.fx +++ b/shaders/cOpticalFlowLK.fx @@ -368,7 +368,7 @@ namespace OpticalFlowLK B2 = IyIt */ - // Solve window equation at matrix A + // Create matrix A and solve its window sum // A.x = A11; A.y = A22; A.z = A12/A22 float3 A = 0.0; A += (S[0].xyx * S[0].xyy); @@ -376,28 +376,31 @@ namespace OpticalFlowLK A += (S[2].xyx * S[2].xyy); A += (S[3].xyx * S[3].xyy); - // Solve window equation at vector B - // B.x = B1; B.y = B2 - float2 B = 0.0; - B += (S[0] * T[0]); - B += (S[1] * T[1]); - B += (S[2] * T[2]); - B += (S[3] * T[3]); - // Ensure Lucas-Kanade's determinant is non-zero A.xy = max(A.xy, FP16_SMALLEST_SUBNORMAL); - // Create -IxIy (A12) for A's determinant and LK matrix + // Create -IxIy (A12) for A^-1 and its determinant A.z = A.z * (-1.0); - // Calculate determinant + // Calculate A^-1 determinant float D = ((A.x * A.y) - (A.z * A.z)); + // Calculate A^-1 + A = (1.0 / D) * A; + + // Create vector B and solve its window sum + // B.x = B1; B.y = B2 + float2 B = 0.0; + B += (S[0] * T[0]); + B += (S[1] * T[1]); + B += (S[2] * T[2]); + B += (S[3] * T[3]); + // Calculate Lucas-Kanade matrix float2 LK = 0.0; LK.x = dot(A.yz, -B.xy); LK.y = dot(A.zx, -B.xy); - LK = (D != 0.0) ? (LK / D) + Vectors : 0.0; + LK = (D != 0.0) ? LK + Vectors : 0.0; return LK; } diff --git a/shaders/kDatamosh.fx b/shaders/kDatamosh.fx index 08ab959..a338ef6 100644 --- a/shaders/kDatamosh.fx +++ b/shaders/kDatamosh.fx @@ -440,7 +440,7 @@ namespace Datamosh B2 = IyIt */ - // Solve window equation at matrix A + // Create matrix A and solve its window sum // A.x = A11; A.y = A22; A.z = A12/A22 float3 A = 0.0; A += (S[0].xyx * S[0].xyy); @@ -448,28 +448,31 @@ namespace Datamosh A += (S[2].xyx * S[2].xyy); A += (S[3].xyx * S[3].xyy); - // Solve window equation at vector B - // B.x = B1; B.y = B2 - float2 B = 0.0; - B += (S[0] * T[0]); - B += (S[1] * T[1]); - B += (S[2] * T[2]); - B += (S[3] * T[3]); - // Ensure Lucas-Kanade's determinant is non-zero A.xy = max(A.xy, FP16_SMALLEST_SUBNORMAL); - // Create -IxIy (A12) for A's determinant and LK matrix + // Create -IxIy (A12) for A^-1 and its determinant A.z = A.z * (-1.0); - // Calculate determinant + // Calculate A^-1 determinant float D = ((A.x * A.y) - (A.z * A.z)); + // Calculate A^-1 + A = (1.0 / D) * A; + + // Create vector B and solve its window sum + // B.x = B1; B.y = B2 + float2 B = 0.0; + B += (S[0] * T[0]); + B += (S[1] * T[1]); + B += (S[2] * T[2]); + B += (S[3] * T[3]); + // Calculate Lucas-Kanade matrix float2 LK = 0.0; LK.x = dot(A.yz, -B.xy); LK.y = dot(A.zx, -B.xy); - LK = (D != 0.0) ? (LK / D) + Vectors : 0.0; + LK = (D != 0.0) ? LK + Vectors : 0.0; return LK; }