Skip to content

Commit

Permalink
cMotionEstimation: Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Oct 5, 2024
1 parent 671538d commit b0609c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions shaders/kDatamosh.fx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ float2 GetMVBlocks(float2 MV, float2 Tex, out float3 Random)
Random.z = RandUV(Tex.yx - Time.xx);

// Normalized screen space -> Pixel coordinates
MV = CMotionEstimation_UnnormalizeMotionVectors(MV * _Scale, TexSize);
MV = CMotionEstimation_UnnormalizeMV(MV * _Scale, TexSize);

// Small random displacement (diffusion)
MV += (Random.xy - 0.5) * _Diffusion;
Expand Down Expand Up @@ -275,7 +275,7 @@ float4 PS_Datamosh(CShade_VS2PS_Quad Input) : SV_TARGET0
float RandomMotion = RandUV(Input.Tex0 + length(MV));

// Pixel coordinates -> Normalized screen space
MV = CMotionEstimation_NormalizeMotionVectors(MV, TexSize);
MV = CMotionEstimation_NormalizeMV(MV, TexSize);

// Color from the original image
float4 Source = CShade_BackBuffer2D(Input.Tex0);
Expand Down
6 changes: 3 additions & 3 deletions shaders/shared/cMotionEstimation.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#define INCLUDE_CMOTIONESTIMATION

// [-1.0, 1.0] -> [Width, Height]
float2 CMotionEstimation_UnnormalizeMotionVectors(float2 Vectors, float2 ImageSize)
float2 CMotionEstimation_UnnormalizeMV(float2 Vectors, float2 ImageSize)
{
return Vectors / abs(ImageSize);
}

// [Width, Height] -> [-1.0, 1.0]
float2 CMotionEstimation_NormalizeMotionVectors(float2 Vectors, float2 ImageSize)
float2 CMotionEstimation_NormalizeMV(float2 Vectors, float2 ImageSize)
{
return clamp(Vectors * abs(ImageSize), -1.0, 1.0);
}
Expand Down Expand Up @@ -116,7 +116,7 @@
Vectors = CMath_HalfToNorm(Vectors);

// Propagate normalized motion vectors in Norm Range
Vectors += CMotionEstimation_NormalizeMotionVectors(Flow, PixelSize);
Vectors += CMotionEstimation_NormalizeMV(Flow, PixelSize);

// Clamp motion vectors to restrict range to valid lengths
Vectors = clamp(Vectors, -1.0, 1.0);
Expand Down

0 comments on commit b0609c6

Please sign in to comment.