Skip to content

Commit 6931d28

Browse files
committed
cLens: Use FidelityFX grain formula
1 parent 03bf15f commit 6931d28

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

shaders/cLens.fx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ uniform float _GrainSeedSpeed <
4646
ui_max = 1.0;
4747
> = 0.5;
4848

49-
uniform int _GrainType <
50-
ui_label = "Grain Type";
51-
ui_type = "combo";
52-
ui_items = "Single-Channel\0Multi-Channel\0";
53-
> = 0;
54-
5549
uniform float _GrainScale <
5650
ui_category = "Grain";
5751
ui_label = "Grain Scale";
@@ -96,7 +90,6 @@ float4 PS_Lens(CShade_VS2PS_Quad Input): SV_TARGET0
9690
CShade_SampleColorTex,
9791
Input.HPos.xy,
9892
Input.Tex0,
99-
_GrainType,
10093
_GrainScale,
10194
_GrainAmount,
10295
_ChromAb,

shaders/shared/fidelityfx/cLens.fxh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,18 @@
9797

9898
// Function call to apply film grain effect to inout Color. This call could be skipped entirely as the choice to use the film grain is optional.
9999
void FFX_Lens_ApplyFilmGrain(
100-
in float2 Tex, // The input window coordinate [0, 1), [0, 1).
100+
in float2 Pos, // The input window coordinate [0, Width), [0, Height).
101101
inout float3 Color, // The current running Color, or more clearly, the sampled input Color texture Color after being modified by chromatic aberration function.
102-
in int GrainType, // Grain formula
103102
in float GrainScaleValue, // Scaling constant value for the grain's noise frequency.
104103
in float GrainAmountValue, // Intensity constant value of the grain effect.
105104
in float GrainSeedValue // Seed value for the grain noise, for example, to change how the noise functions effect the grain frame to frame.
106105
)
107106
{
108-
float2 Pos = (Tex * 2.0 - 1.0) * CShade_GetScreenSizeFromTex(Tex);
109-
float2 RandomNumberFine = CProcedural_GetHash2(Pos, 0.0);
110-
float3 GradientN = CProcedural_GetGradientNoise3((Pos / GrainScaleValue / 8.0) + RandomNumberFine, GrainSeedValue, false);
107+
float2 RandomNumberFine = CProcedural_GetHash2(Pos, GrainSeedValue);
108+
float2 GradientN = FFX_Lens_Simplex((Pos / GrainScaleValue) + RandomNumberFine);
111109

112110
const float GrainShape = 3.0;
113-
float3 Grain = (GrainType == 1) ? exp2(-sqrt(abs(GradientN)) * GrainShape) : exp2(-length(GradientN) * GrainShape);
111+
float Grain = exp2(-length(GradientN) * GrainShape);
114112
Grain = 1.0 - 2.0 * Grain;
115113
Color += Grain * min(Color, 1.0 - Color) * GrainAmountValue;
116114
}
@@ -140,7 +138,6 @@
140138
in sampler2D Image,
141139
in float2 HPos,
142140
in float2 Tex,
143-
in int GrainType,
144141
in float GrainScale,
145142
in float GrainAmount,
146143
in float ChromAb,
@@ -155,7 +152,7 @@
155152
// Run Lens
156153
Color = FFX_Lens_SampleWithChromaticAberration(Image, HPos, Tex, Center, RGMag.r, RGMag.g);
157154
FFX_Lens_ApplyVignette(UNormTex, 0.0, Color, Vignette);
158-
FFX_Lens_ApplyFilmGrain(Tex, Color, GrainType, GrainScale, GrainAmount, GrainSeed);
155+
FFX_Lens_ApplyFilmGrain(HPos, Color, GrainScale, GrainAmount, GrainSeed);
159156
}
160157

161158
#endif

0 commit comments

Comments
 (0)