mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/srgb-dither' into 'master'
Dither in nonlinear srgb space and dithering related experimental shader options See merge request veloren/veloren!3160
This commit is contained in:
commit
18f6077321
@ -109,4 +109,14 @@ vec3 smooth_rand(vec3 pos, float lerp_axis) {
|
||||
vec3 r1 = rand_perm_3(vec3(pos.x, pos.y, pos.z) + floor(lerp_axis + 1.0));
|
||||
return r0 + (r1 - r0) * fract(lerp_axis);
|
||||
}
|
||||
|
||||
// Transform normal distribution to triangle distribution.
|
||||
float norm2tri(float n) {
|
||||
// TODO: compare perf with adding two normal noise distributions
|
||||
bool flip = n > 0.5;
|
||||
n = flip ? 1.0 - n : n;
|
||||
n = sqrt(n / 2.0);
|
||||
n = flip ? 1.0 - n : n;
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
@ -282,9 +282,26 @@ void main() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef EXPERIMENTAL_NODITHER
|
||||
// Add a small amount of very cheap dithering noise to remove banding from gradients
|
||||
// TODO: Instead of 256, detect the colour resolution of the display
|
||||
final_color.rgb = max(vec3(0), final_color.rgb - hash_two(uvec2(uv * screen_res.xy)) / 256.0);
|
||||
// TODO: Consider dithering each color channel independently.
|
||||
// TODO: Consider varying dither over time.
|
||||
// TODO: Instead of 255, detect the colour resolution of the color attachment
|
||||
float noise = hash_two(uvec2(uv * screen_res.xy));
|
||||
#ifndef EXPERIMENTAL_NONSRGBDITHER
|
||||
#ifndef EXPERIMENTAL_TRIANGLENOISEDITHER
|
||||
noise = noise - 0.5;
|
||||
#else
|
||||
// TODO: there is something special we have to do to remove bias
|
||||
// on the bounds when using triangle distribution
|
||||
noise = 2.0 * norm2tri(noise) - 1.0;
|
||||
#endif
|
||||
final_color.rgb = srgb_to_linear(linear_to_srgb(final_color.rgb) + noise / 255.0);
|
||||
#else
|
||||
// NOTE: GPU will clamp value
|
||||
final_color.rgb = final_color.rgb - noise / 255.0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
tgt_color = vec4(final_color.rgb, 1);
|
||||
}
|
||||
|
@ -447,4 +447,10 @@ pub enum ExperimentalShader {
|
||||
Underwarper,
|
||||
/// Remove caustics from underwater terrain when shiny water is enabled.
|
||||
NoCaustics,
|
||||
/// Don't dither color in post-processing.
|
||||
NoDither,
|
||||
/// Don't use the nonlinear srgb space for dithering color.
|
||||
NonSrgbDither,
|
||||
/// Use triangle PDF noise for dithering instead of uniform noise.
|
||||
TriangleNoiseDither,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user