From 7f857daa91565dfbf24ba29b18f47c6cd796fc9c Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 18 May 2019 17:35:53 +0100 Subject: [PATCH] Colour adjustment and server crash fix Former-commit-id: 7a1f6dcccc9869472f6044407d063ea86bb12dd3 --- server/src/lib.rs | 5 +++-- voxygen/shaders/postprocess.frag | 32 +++++++++++++++++++++++--------- voxygen/shaders/skybox.frag | 10 +++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 71de1caf76..71e15f991f 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -557,8 +557,9 @@ impl Server { pub fn generate_chunk(&mut self, key: Vec2) { if self.pending_chunks.insert(key) { let chunk_tx = self.chunk_tx.clone(); - self.thread_pool - .execute(move || chunk_tx.send((key, World::generate_chunk(key))).unwrap()); + self.thread_pool.execute(move || { + let _ = chunk_tx.send((key, World::generate_chunk(key))); + }); } } diff --git a/voxygen/shaders/postprocess.frag b/voxygen/shaders/postprocess.frag index 610e05efbd..dd32d414f2 100644 --- a/voxygen/shaders/postprocess.frag +++ b/voxygen/shaders/postprocess.frag @@ -144,18 +144,32 @@ vec4 fxaa_apply(sampler2D tex, vec2 fragCoord, vec2 resolution) { return fxaa(tex, fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM); } +vec3 rgb2hsv(vec3 c) { + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) { + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + void main() { vec2 uv = (f_pos + 1.0) * 0.5; - /* - float px_size = 8.0; - vec2 px_count = screen_res.xy / px_size; - vec2 uv2 = floor(uv * px_count) / px_count; - */ + vec4 fxaa_color = fxaa_apply(src_color, uv * screen_res.xy, screen_res.xy); - vec4 color = fxaa_apply(src_color, uv * screen_res.xy, screen_res.xy); + vec4 hsva_color = vec4(rgb2hsv(fxaa_color.rgb), fxaa_color.a); + hsva_color.y += 0.17; + hsva_color.x -= 0.015; + hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0); + vec4 final_color = vec4(hsv2rgb(hsva_color.rgb), hsva_color.a); - tgt_color = 1.0 - 1.0 / (color + 1.0); - - //tgt_color = ceil(tgt_color * 10.0) / 10.0; + tgt_color = final_color; } diff --git a/voxygen/shaders/skybox.frag b/voxygen/shaders/skybox.frag index 0358df7a49..986a3434fb 100644 --- a/voxygen/shaders/skybox.frag +++ b/voxygen/shaders/skybox.frag @@ -16,17 +16,17 @@ const float PI = 3.141592; vec3 get_sky_color(vec3 dir, float time_of_day) { const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0); - const vec3 SKY_TOP = vec3(0.0, 0.3, 1.0); - const vec3 SKY_BOTTOM = vec3(0.0, 0.05, 0.2); + const vec3 SKY_TOP = vec3(0.1, 0.5, 1.0); + const vec3 SKY_BOTTOM = vec3(0.025, 0.08, 0.2); - const vec3 SUN_HALO_COLOR = vec3(1.0, 0.8, 0.5); - const vec3 SUN_SURF_COLOR = vec3(1.0, 0.8, 0.0) * 100.0; + const vec3 SUN_HALO_COLOR = vec3(1.0, 0.7, 0.5); + const vec3 SUN_SURF_COLOR = vec3(1.0, 0.9, 0.35) * 200.0; float sun_angle_rad = time_of_day * TIME_FACTOR; vec3 sun_dir = vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad)); vec3 sun_halo = pow(max(dot(dir, sun_dir), 0.0), 8.0) * SUN_HALO_COLOR; - vec3 sun_surf = pow(max(dot(dir, sun_dir), 0.0), 1000.0) * SUN_SURF_COLOR; + vec3 sun_surf = pow(max(dot(dir, sun_dir) - 0.0045, 0.0), 1000.0) * SUN_SURF_COLOR; vec3 sun_light = sun_halo + sun_surf; return mix(SKY_BOTTOM, SKY_TOP, (dir.z + 1.0) / 2.0) + sun_light;