forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBb0eb8adIvan Molodetskikh3 months ago2857 commits

postprocess.frag32 lines, 822 bytesHistoryRawDownload
1uniform float noise;
2uniform float saturation;
3uniform vec4 bg_color;
4
5// Sin-less white noise by David Hoskins (MIT License).
6// https://www.shadertoy.com/view/4djSRW
7float hash12(vec2 p) {
8 vec3 p3 = fract(vec3(p.xyx) * 0.1031);
9 p3 += dot(p3, p3.yzx + 33.33);
10 return fract((p3.x + p3.y) * p3.z);
11}
12
13vec3 saturate(vec3 color, float sat) {
14 const vec3 w = vec3(0.2126, 0.7152, 0.0722);
15 return mix(vec3(dot(color, w)), color, sat);
16}
17
18vec4 postprocess(vec4 color) {
19 if (saturation != 1.0) {
20 color.rgb = saturate(color.rgb, saturation);
21 }
22
23 if (noise > 0.0) {
24 vec2 uv = gl_FragCoord.xy;
25 color.rgb += (hash12(uv) - 0.5) * noise;
26 }
27
28 // Mix bg_color behind the texture (both premultiplied alpha).
29 color = color + bg_color * (1.0 - color.a);
30
31 return color;
32}