Simple Grain
- Fu-Bama
-
Topic Author
- Offline
Less More
4 years 5 months ago - 4 years 5 months ago #1 by Fu-Bama
Simple Grain was created by Fu-Bama
I recently made simple film grain filter as the default one dropped for me like 10FPS in every game.
Minor thing; this one affects black areas. I think it's more realistic that way.
Also, it has limiter for noise seed value, to assure the ting won't Go Skrrrraaa after longer period of playing. ;P
Shader Code:
Minor thing; this one affects black areas. I think it's more realistic that way.
Also, it has limiter for noise seed value, to assure the ting won't Go Skrrrraaa after longer period of playing. ;P
Shader Code:
Warning: Spoiler!
Just copy the code to empty ReShade.fx and rename it to SimpleGrain.fx
/*
Simple Grain PS v1.0.3 (c) 2018 Jacob Maximilian Fober
This work is licensed under the Creative Commons
Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/4.0/.
*/
////////////////////
/////// MENU ///////
////////////////////
#ifndef ShaderAnalyzer
uniform float Intensity <
ui_label = "Noise intensity";
ui_type = "drag";
ui_min = 0.0; ui_max = 1.0; ui_step = 0.002;
> = 0.4;
uniform int Coefficient <
ui_label = "Luma coefficient";
ui_tooltip = "For digital connection use BT.709, for analog (like VGA) use BT.601";
ui_type = "combo";
ui_items = "BT.709\0BT.601\0";
> = 0;
uniform int Framerate <
ui_label = "Noise framerate";
ui_tooltip = "Zero will match in-game framerate";
ui_type = "drag";
ui_min = 0; ui_max = 120; ui_step = 1;
> = 12;
//////////////////////
/////// SHADER ///////
//////////////////////
uniform float Timer < source = "timer"; >;
uniform int FrameCount < source = "framecount"; >;
#endif
// Overlay blending mode
float Overlay(float LayerA, float LayerB)
{
float MinA = min(LayerA, 0.5);
float MinB = min(LayerB, 0.5);
float MaxA = max(LayerA, 0.5);
float MaxB = max(LayerB, 0.5);
return 2 * (MinA * MinB + MaxA + MaxB - MaxA * MaxB) - 1.5;
}
// Noise generator
float SimpleNoise(float p)
{
return frac(sin(dot(p, float2(12.9898, 78.233))) * 43758.5453);
}
#include "ReShade.fxh"
// Shader pass
void SimpleGrainPS(float4 vois : SV_Position, float2 TexCoord : TEXCOORD, out float3 Image : SV_Target)
{
// Choose luma coefficient, if True BT.709 Luma, else BT.601 Luma
const float3 LumaCoefficient = (Coefficient == 0) ?
float3( 0.2126, 0.7152, 0.0722) : float3( 0.299, 0.587, 0.114)
;
// Sample image
Image = tex2D(ReShade::BackBuffer, TexCoord).rgb;
// Mask out bright pixels gamma: (sqrt(5)+1)/2
const float GoldenAB = sqrt(5) * 0.5 + 0.5;
float Mask = pow(1 - dot(Image.rgb, LumaCoefficient), GoldenAB);
// Calculate seed change
float Seed = Framerate == 0 ? FrameCount : floor(Timer * 0.001 * Framerate);
// Protect from enormous numbers
Seed = frac(Seed * 0.0001) * 10000;
// Generate noise * (sqrt(5) + 1) / 4 (to remain brightness)
const float GoldenABh = sqrt(5) * 0.25 + 0.25;
float Noise = saturate(SimpleNoise(Seed * TexCoord.x * TexCoord.y) * GoldenABh);
Noise = lerp(0.5, Noise, Intensity * 0.1 * Mask);
// Blend noise with image
Image.rgb = float3(
Overlay(Image.r, Noise),
Overlay(Image.g, Noise),
Overlay(Image.b, Noise)
);
}
technique SimpleGrain
{
pass
{
VertexShader = PostProcessVS;
PixelShader = SimpleGrainPS;
}
}
Last edit: 4 years 5 months ago by Fu-Bama.
The following user(s) said Thank You: Wicked Sick
Please Log in or Create an account to join the conversation.
- lowenz
-
- Offline
Less More
- Posts: 556
4 years 5 months ago - 4 years 5 months ago #2 by lowenz
Replied by lowenz on topic Simple Grain
Black Areas? Do you mean in a letterboxed frame?
Last edit: 4 years 5 months ago by lowenz.
Please Log in or Create an account to join the conversation.
- Fu-Bama
-
Topic Author
- Offline
4 years 5 months ago - 4 years 5 months ago #3 by Fu-Bama
No, black areas like shadows, black pixels. The default one applies noise 0-black, 1-gray, 0-white pixels.
This one has 1.62 gamma curve, so it's like 1-black, 0.33≈gray, 0-white.
On the picture right side you have white lamp, some medium cans and shadow in the background under the ladder, also there is pure black letterbox with noise applied.
Replied by Fu-Bama on topic Simple Grain
Black Areas? Do you mean in a letterboxed frame?

This one has 1.62 gamma curve, so it's like 1-black, 0.33≈gray, 0-white.
On the picture right side you have white lamp, some medium cans and shadow in the background under the ladder, also there is pure black letterbox with noise applied.
Last edit: 4 years 5 months ago by Fu-Bama.
Please Log in or Create an account to join the conversation.
- UTwelve
-
- Offline
Less More
- Posts: 15
4 years 5 months ago #4 by UTwelve
Replied by UTwelve on topic Simple Grain
Please Log in or Create an account to join the conversation.
- Fu-Bama
-
Topic Author
- Offline
4 years 5 months ago #5 by Fu-Bama
Yes it could, but digital camera ISO is not noise-value, but signal amplify amount.
Signal is amplified with higher ISO, but as things go, background noise is amplified too.
Replied by Fu-Bama on topic Simple Grain
Can be calculated according to the average brightness of the screen?Very nice chart.
Yes it could, but digital camera ISO is not noise-value, but signal amplify amount.
Signal is amplified with higher ISO, but as things go, background noise is amplified too.
Please Log in or Create an account to join the conversation.
- UTwelve
-
- Offline
Less More
- Posts: 15
4 years 5 months ago - 4 years 5 months ago #6 by UTwelve
Replied by UTwelve on topic Simple Grain
During the day(or average brightness),Because ‘auto iso’ ,iso about 100-200iso。
black pixels should be no grain。just black
black pixels should be no grain。just black
Last edit: 4 years 5 months ago by UTwelve.
Please Log in or Create an account to join the conversation.
- brussell
-
- Offline
Less More
- Posts: 328
4 years 5 months ago #7 by brussell
Replied by brussell on topic Simple Grain
Try to add this code for grain depending on average screen luminance.
texture2D texLuminance { Width = 256; Height = 256; Format = R8; MipLevels = 7; };
sampler SamplerLuminance { Texture = texLuminance; };
float PS_Luminance(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
return dot(tex2D(ReShade::BackBuffer, texcoord.xy).xyz, 0.333);
}
void SimpleGrainPS(float4 vois : SV_Position, float2 TexCoord : TEXCOORD, out float3 Image : SV_Target)
{
...
float avglum = tex2Dlod(SamplerLuminance, float4(0.5.xx, 0, 7)).x;
Noise *= (1-avglum);
...
}
technique SimpleGrain {
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Luminance;
RenderTarget = texLuminance;
}
pass
{
VertexShader = PostProcessVS;
PixelShader = SimpleGrainPS;
}
}
Please Log in or Create an account to join the conversation.
- UTwelve
-
- Offline
Less More
- Posts: 15
4 years 5 months ago #8 by UTwelve
Replied by UTwelve on topic Simple Grain
Good use
Please Log in or Create an account to join the conversation.
- BONKERS
-
- Offline
Less More
- Posts: 6
4 years 3 months ago #9 by BONKERS
Replied by BONKERS on topic Simple Grain
Really liked using this shader. Here are a few phone wallpapers I made from screenshots of RE7 using this.
abload.de/img/re7b2pwu4l.jpg
abload.de/img/re7b4ogum1.jpg
abload.de/img/re7b5npusb.jpg
abload.de/img/re7b2pwu4l.jpg
abload.de/img/re7b4ogum1.jpg
abload.de/img/re7b5npusb.jpg
Please Log in or Create an account to join the conversation.
- Wicked Sick
-
- Offline
Less More
- Posts: 516
4 years 3 months ago #10 by Wicked Sick
Replied by Wicked Sick on topic Simple Grain
I really liked this shader. I hope to see it in the repository too.
Please Log in or Create an account to join the conversation.
- BONKERS
-
- Offline
Less More
- Posts: 6
4 years 2 months ago #11 by BONKERS
Replied by BONKERS on topic Simple Grain
One thing I really don't like about this shader though, in order to get a really decently noticeable effect running at same framerate as the game. You have to turn it up a bit. But then it really becomes noticeable that the grain shader affects the luminosity on the lower end of the image and causes it to lose a little bit of contrast and appear just slightly washed out.
Easily visible when turning it off A/B.
Easily visible when turning it off A/B.
Please Log in or Create an account to join the conversation.