Simple Grain
- Fu-Bama
- Topic Author
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:
/*
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;
}
}
Please Log in or Create an account to join the conversation.
- lowenz
Please Log in or Create an account to join the conversation.
No, black areas like shadows, black pixels. The default one applies noise 0-black, 1-gray, 0-white pixels.lowenz wrote: 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.
Please Log in or Create an account to join the conversation.
- UTwelve
Can be calculated according to the average brightness of the screen? Like a real camera AUTO ISO
example
Light: iso200
dark: iso6400
(Not rigorous)
Please Log in or Create an account to join the conversation.
Very nice chart.UTwelve wrote: Can be calculated according to the average brightness of the screen?
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
black pixels should be no grain。just black
Please Log in or Create an account to join the conversation.
- brussell
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
- BONKERS
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
Please Log in or Create an account to join the conversation.
- BONKERS
Easily visible when turning it off A/B.
Please Log in or Create an account to join the conversation.