35 lines
988 B
GLSL
35 lines
988 B
GLSL
/*
|
|
Complex grain shader ported over from MariENB
|
|
(C)2012-2022 Marisa the Magician
|
|
|
|
Edited for reduced texture sampling (3 fetches instead of 6).
|
|
*/
|
|
const float nf = .0005;
|
|
const vec3 nm = vec3(2.05,3.11,2.22);
|
|
const float np = 3.95;
|
|
const float bnp = 1.7;
|
|
|
|
#define darkmask(a,b) (a>0.5)?(2.0*a*(0.5+b)):(1.0-2.0*(1.0-a)*(1.0-((0.5+b))))
|
|
|
|
vec3 grain( in vec3 res, in vec2 coord )
|
|
{
|
|
float ts = Timer*nf;
|
|
float nx = texture(NoiseTexture,coord*nm.x+vec2(ts,0.)).x;
|
|
float ny = texture(NoiseTexture,coord*nm.y+vec2(0.,ts)).x;
|
|
float n = clamp(texture(NoiseTexture,vec2(nx,ny)*nm.z+vec2(ts,ts)).x,0.,1.);
|
|
float nt = pow(n,np);
|
|
float bn = 1.-clamp((res.r+res.g+res.b)/3.,0.,1.);
|
|
bn = pow(bn,bnp);
|
|
res.rgb += vec3(nt*bn*ni);
|
|
return res;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
vec2 coord = TexCoord;
|
|
vec4 res = texture(InputTexture,coord);
|
|
vec2 sfact = max(vec2(640.,400.),vec2(textureSize(InputTexture,0))*.5);
|
|
coord = floor(coord*sfact)/sfact;
|
|
res.rgb = grain(res.rgb,coord);
|
|
FragColor = res;
|
|
}
|