Skip to content

Commit

Permalink
Do different determinant check
Browse files Browse the repository at this point in the history
  • Loading branch information
brimson committed Jul 15, 2022
1 parent 6e607d6 commit f6c87fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions shaders/cMotionBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace OpticalFlowLK
[Macros for resolution sizes and scaling]
*/

#define FP16_MINIMUM float((1.0 / float(1 << 14)) * (0.0 + (1.0 / 1024.0)))

#define RCP_HEIGHT (1.0 / BUFFER_HEIGHT)
#define ASPECT_RATIO (BUFFER_WIDTH * RCP_HEIGHT)
#define ROUND_UP_EVEN(x) int(x) + (int(x) % 2)
Expand Down Expand Up @@ -347,15 +349,15 @@ namespace OpticalFlowLK
S[3] = tex2D(Sample_Common_1_C, TexCoord.zy).xy;

// A.x = Ix^2 (A11); A.y = Iy^2 (A22); A.z = IxIy (A12)
float3 A = 0.0;
float3 A = float3(FP16_MINIMUM, FP16_MINIMUM, 0.0);
A += (S[0].xyx * S[0].xyy);
A += (S[1].xyx * S[1].xyy);
A += (S[2].xyx * S[2].xyy);
A += (S[3].xyx * S[3].xyy);
A /= 4.0;

// Determinant
float D = (A.z * A.z - A.x * A.y);
float D = (A.x * A.y - A.z * A.z);

// Temporal derivative window in 4 bilinear fetches
float T[4];
Expand All @@ -372,8 +374,7 @@ namespace OpticalFlowLK
B += (S[3] * T[3]);
B /= 4.0;

float2 UV = ((A.yx * B.xy - A.zz * B.yx) / D) + Vectors;
UV = isinf(UV) ? 0.0 : UV;
float2 UV = (D != 0.0) ? ((A.yx * B.xy - A.zz * B.yx) / D) + Vectors : 0.0;
return UV;
}

Expand Down
9 changes: 5 additions & 4 deletions shaders/cOpticalFlowLK.fx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace OpticalFlowLK
/*
[Macros for resolution sizes and scaling]
*/

#define FP16_MINIMUM float((1.0 / float(1 << 14)) * (0.0 + (1.0 / 1024.0)))

#define RCP_HEIGHT (1.0 / BUFFER_HEIGHT)
#define ASPECT_RATIO (BUFFER_WIDTH * RCP_HEIGHT)
Expand Down Expand Up @@ -340,15 +342,15 @@ namespace OpticalFlowLK
S[3] = tex2D(Sample_Common_1_C, TexCoord.zy).xy;

// A.x = Ix^2 (A11); A.y = Iy^2 (A22); A.z = IxIy (A12)
float3 A = 0.0;
float3 A = float3(FP16_MINIMUM, FP16_MINIMUM, 0.0);
A += (S[0].xyx * S[0].xyy);
A += (S[1].xyx * S[1].xyy);
A += (S[2].xyx * S[2].xyy);
A += (S[3].xyx * S[3].xyy);
A /= 4.0;

// Determinant
float D = (A.z * A.z - A.x * A.y);
float D = (A.x * A.y - A.z * A.z);

// Temporal derivative window in 4 bilinear fetches
float T[4];
Expand All @@ -365,8 +367,7 @@ namespace OpticalFlowLK
B += (S[3] * T[3]);
B /= 4.0;

float2 UV = ((A.yx * B.xy - A.zz * B.yx) / D) + Vectors;
UV = isinf(UV) ? 0.0 : UV;
float2 UV = (D != 0.0) ? ((A.yx * B.xy - A.zz * B.yx) / D) + Vectors : 0.0;
return UV;
}

Expand Down
7 changes: 3 additions & 4 deletions shaders/kDatamosh.fx
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ namespace Datamosh
S[3] = tex2D(Sample_Common_1_C, TexCoord.zy).xy;

// A.x = Ix^2 (A11); A.y = Iy^2 (A22); A.z = IxIy (A12)
float3 A = 0.0;
float3 A = float3(FP16_MINIMUM, FP16_MINIMUM, 0.0);
A += (S[0].xyx * S[0].xyy);
A += (S[1].xyx * S[1].xyy);
A += (S[2].xyx * S[2].xyy);
A += (S[3].xyx * S[3].xyy);
A /= 4.0;

// Determinant
float D = (A.z * A.z - A.x * A.y);
float D = (A.x * A.y - A.z * A.z);

// Temporal derivative window in 4 bilinear fetches
float T[4];
Expand All @@ -439,8 +439,7 @@ namespace Datamosh
B += (S[3] * T[3]);
B /= 4.0;

float2 UV = ((A.yx * B.xy - A.zz * B.yx) / D) + Vectors;
UV = isinf(UV) ? 0.0 : UV;
float2 UV = (D != 0.0) ? ((A.yx * B.xy - A.zz * B.yx) / D) + Vectors : 0.0;
return UV;
}

Expand Down

0 comments on commit f6c87fc

Please sign in to comment.