Merge branch 'zesterer/tiny-fixes' into 'master'

Remove colour banding

See merge request veloren/veloren!3153
This commit is contained in:
Joshua Barretto 2022-01-27 01:03:56 +00:00
commit 25543b45c5
3 changed files with 19 additions and 7 deletions

View File

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added arthropods - Added arthropods
- A 'point light glow' effect, making lanterns and other point lights more visually pronounced - A 'point light glow' effect, making lanterns and other point lights more visually pronounced
- Generate random name for site2 sites - Generate random name for site2 sites
- Shader dithering to remove banding from scenes with large colour gradients
### Changed ### Changed

View File

@ -10,9 +10,9 @@ float hash(vec4 p) {
return (fract(p.x * p.y * (1.0 - p.z) * p.w * (p.x + p.y + p.z + p.w)) - 0.5) * 2.0; return (fract(p.x * p.y * (1.0 - p.z) * p.w * (p.x + p.y + p.z + p.w)) - 0.5) * 2.0;
} }
#define M1 1597334677U //1719413*929 #define M1 2047667443U
#define M2 3812015801U //140473*2467*11 #define M2 3883706873U
#define M3 2741598923U #define M3 3961281721U
float hash_one(uint q) { float hash_one(uint q) {
uint n = ((M3 * q) ^ M2) * M1; uint n = ((M3 * q) ^ M2) * M1;
@ -20,6 +20,13 @@ float hash_one(uint q) {
return float(n) * (1.0 / float(0xffffffffU)); return float(n) * (1.0 / float(0xffffffffU));
} }
float hash_two(uvec2 q) {
q *= uvec2(M1, M2);
uint n = q.x ^ q.y;
n = n * (n ^ (n >> 15));
return float(n) * (1.0 / float(0xffffffffU));
}
float hash_fast(uvec3 q) { float hash_fast(uvec3 q) {
q *= uvec3(M1, M2, M3); q *= uvec3(M1, M2, M3);

View File

@ -197,15 +197,15 @@ void main() {
// return; // return;
// } // }
vec2 sample_uv = uv;
#ifdef EXPERIMENTAL_UNDERWARPER #ifdef EXPERIMENTAL_UNDERWARPER
vec2 uv = uv;
if (medium.x == MEDIUM_WATER) { if (medium.x == MEDIUM_WATER) {
uv += sin(uv.yx * 40 + tick.xx * 1.0) * 0.003; sample_uv += sin(uv.yx * 40 + tick.xx * 1.0) * 0.003;
} }
#endif #endif
vec4 aa_color = aa_apply(t_src_color, s_src_color, uv * screen_res.xy, screen_res.xy); vec4 aa_color = aa_apply(t_src_color, s_src_color, sample_uv * screen_res.xy, screen_res.xy);
#ifdef EXPERIMENTAL_SOBEL #ifdef EXPERIMENTAL_SOBEL
vec3 s[8]; vec3 s[8];
s[0] = aa_sample(uv, vec2(-1, 1)); s[0] = aa_sample(uv, vec2(-1, 1));
@ -282,5 +282,9 @@ void main() {
} }
#endif #endif
// 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);
tgt_color = vec4(final_color.rgb, 1); tgt_color = vec4(final_color.rgb, 1);
} }