Skip to content

Commit

Permalink
Use gradient noise for blur
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Oct 1, 2023
1 parent 45853bd commit b5468ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion shaders/cMotionBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace cMotionBlur
[unroll]
for (int k = 0; k < Samples; ++k)
{
float Random = (GetGradientNoise(Input.HPos.xy + k) * 2.0) - 1.0;
float Random = (GetIGNoise(Input.HPos.xy + k) * 2.0) - 1.0;
float2 RandomTex = Input.Tex0.xy + (ScaledVelocity * Random);
OutputColor += tex2D(CShade_SampleColorTex, RandomTex);
}
Expand Down
6 changes: 3 additions & 3 deletions shaders/cNoiseBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ uniform float _Radius <
ui_label = "Radius";
ui_type = "slider";
ui_min = 0.0;
ui_max = 64.0;
> = 32.0;
ui_max = 1.0;
> = 0.5;


/*
Expand All @@ -24,7 +24,7 @@ float4 PS_NoiseBlur(VS2PS_Quad Input) : SV_TARGET0
const float Pi2 = acos(-1.0) * 2.0;
const float2 ScreenSize = int2(BUFFER_WIDTH, BUFFER_HEIGHT);
const float2 PixelSize = 1.0 / ScreenSize;
float Noise = Pi2 * GetValueNoise(Input.Tex0.xy * 256.0);
float Noise = Pi2 * GetGradientNoise(Input.Tex0.xy * 256.0);

float2 Rotation = 0.0;
sincos(Noise, Rotation.y, Rotation.x);
Expand Down
31 changes: 29 additions & 2 deletions shaders/shared/cImageProcessing.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@
http://www.iryoku.com/downloads/Next-Generation-Post-Processing-in-Call-of-Duty-Advanced-Warfare-v18.pptx
*/

float GetGradientNoise(float2 Position)
float GetIGNoise(float2 Position)
{
return frac(52.9829189 * frac(dot(Position, float2(0.06711056, 0.00583715))));
}

float3 GetDither(float2 Position)
{
return GetGradientNoise(Position) / 255.0;
return GetIGNoise(Position) / 255.0;
}

/*
Expand All @@ -189,6 +189,7 @@
}

/*
GetGradientNoise(): https://iquilezles.org/articles/gradientnoise/
GetQuintic(): https://iquilezles.org/articles/texture/
The MIT License (MIT)
Expand Down Expand Up @@ -230,6 +231,32 @@
return lerp(lerp(A, B, UV.x), lerp(C, D, UV.x), UV.y);
}

float GetGradient(float2 I, float2 F, float2 O)
{
// Get constants
const float TwoPi = acos(-1.0) * 2.0;

// Calculate random hash rotation
float Hash = GetHash(I + O) * TwoPi;
float2 HashSinCos = float2(sin(Hash), cos(Hash));

// Calculate final dot-product
return dot(HashSinCos, F - O);
}

float GetGradientNoise(float2 Tex)
{
float2 I = floor(Tex);
float2 F = frac(Tex);
float A = GetGradient(I, F, float2(0.0, 0.0));
float B = GetGradient(I, F, float2(1.0, 0.0));
float C = GetGradient(I, F, float2(0.0, 1.0));
float D = GetGradient(I, F, float2(1.0, 1.0));
float2 UV = GetQuintic(F);
float Noise = lerp(lerp(A, B, UV.x), lerp(C, D, UV.x), UV.y);
return saturate((Noise * 0.5) + 0.5);
}

/*
[Color Processing]
*/
Expand Down

0 comments on commit b5468ca

Please sign in to comment.