Last active
January 5, 2021 02:40
-
-
Save jimmyjonezz/b1acc6097477bf5ef10291f640b6db70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type canvas_item; | |
render_mode blend_mix; | |
uniform bool active = true; | |
uniform int ngg : hint_range(1, 8) = 6; | |
float T(float z) { | |
return z >= 0.5 ? 2.-2.*z : 2.*z; | |
} | |
// маска R | |
float intensity(ivec2 pixel) { | |
const float a1 = 0.75487766624669276; | |
const float a2 = 0.569840290998; | |
return fract(a1 * float(pixel.x) + a2 * float(pixel.y)); | |
} | |
float dither(float gray, int ng, vec4 vl) { | |
// расчет значения серого шума | |
float noised = (2./float(ng)) * T(intensity(ivec2(vl.xy))) + gray - (1./float(ng)); | |
// количество уровней шума | |
return clamp(floor(float(ng) * noised) / (float(ng)-1.), 0.f, 1.f); | |
} | |
void fragment() | |
{ | |
int ng = ngg; // число уровня шума серого | |
vec3 tsample = pow(texture(SCREEN_TEXTURE, SCREEN_UV).rgb, vec3(2.2)); | |
vec3 col; | |
//цветной | |
if (active == true) { | |
col = vec3(dither(tsample.r, ng, FRAGCOORD), | |
dither(tsample.g, ng, FRAGCOORD), | |
dither(tsample.b, ng, FRAGCOORD)); | |
} else { | |
//черно-белый | |
col = vec3(dither(dot(tsample, vec3(0.3, 0.59, 0.11)), ng, FRAGCOORD)); | |
} | |
// вывод на экран с коррекцией гаммы | |
COLOR = vec4(vec3(pow(col, vec3(1.0 / 2.2))), 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment