|
97 | 97 |
|
98 | 98 | // 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.
|
99 | 99 | 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). |
101 | 101 | 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 |
103 | 102 | in float GrainScaleValue, // Scaling constant value for the grain's noise frequency.
|
104 | 103 | in float GrainAmountValue, // Intensity constant value of the grain effect.
|
105 | 104 | in float GrainSeedValue // Seed value for the grain noise, for example, to change how the noise functions effect the grain frame to frame.
|
106 | 105 | )
|
107 | 106 | {
|
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); |
111 | 109 |
|
112 | 110 | 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); |
114 | 112 | Grain = 1.0 - 2.0 * Grain;
|
115 | 113 | Color += Grain * min(Color, 1.0 - Color) * GrainAmountValue;
|
116 | 114 | }
|
|
140 | 138 | in sampler2D Image,
|
141 | 139 | in float2 HPos,
|
142 | 140 | in float2 Tex,
|
143 |
| - in int GrainType, |
144 | 141 | in float GrainScale,
|
145 | 142 | in float GrainAmount,
|
146 | 143 | in float ChromAb,
|
|
155 | 152 | // Run Lens
|
156 | 153 | Color = FFX_Lens_SampleWithChromaticAberration(Image, HPos, Tex, Center, RGMag.r, RGMag.g);
|
157 | 154 | 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); |
159 | 156 | }
|
160 | 157 |
|
161 | 158 | #endif
|
0 commit comments