From a037b481157e01bbbeb8ce56b25ace7c7f41adce Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 10 Feb 2021 21:45:29 +0000 Subject: [PATCH] Point light ambiance for less harsh shadows --- assets/voxygen/shaders/figure-frag.glsl | 2 +- assets/voxygen/shaders/include/light.glsl | 3 ++- voxygen/src/scene/terrain.rs | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index a1a74cad20..0deb727bb0 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -182,7 +182,7 @@ void main() { float ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15; - vec3 glow = pow(pow(model_glow.w, 2.0) * (max(dot(f_norm, normalize(model_glow.xyz)), 0.0) * 1.0 + max(1.0 - length(model_glow.xyz), 0.0)), 1) * 4 * GLOW_COLOR; + vec3 glow = pow(pow(model_glow.w, 2.0) * (max(dot(f_norm, normalize(model_glow.xyz)) * 0.5 + 0.5, 0.0) * 1.0 + max(1.0 - length(model_glow.xyz), 0.0)), 1) * 4 * GLOW_COLOR; emitted_light += glow; reflected_light *= ao; diff --git a/assets/voxygen/shaders/include/light.glsl b/assets/voxygen/shaders/include/light.glsl index 8aabebd6ec..ba75b5db71 100644 --- a/assets/voxygen/shaders/include/light.glsl +++ b/assets/voxygen/shaders/include/light.glsl @@ -183,7 +183,8 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve vec3 direct_light = PI * color * strength * square_factor * light_reflection_factor(/*direct_norm_dir*/wnorm, /*cam_to_frag*/view_dir, direct_light_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting); float computed_shadow = ShadowCalculationPoint(i, -difference, wnorm, wpos/*, light_distance*/); // directed_light += is_direct ? max(computed_shadow, /*LIGHT_AMBIANCE*/0.0) * direct_light * square_factor : vec3(0.0); - directed_light += is_direct ? mix(LIGHT_AMBIANCE, 1.0, computed_shadow) * direct_light * square_factor : vec3(0.0); + vec3 ambiance = color * 1.0 / distance_2; // Non-physical hack, but it's pretty subtle and *damn* does it make character shadows look better + directed_light += (is_direct ? mix(LIGHT_AMBIANCE, 1.0, computed_shadow) * direct_light * square_factor : vec3(0.0)) + ambiance; // directed_light += (is_direct ? 1.0 : LIGHT_AMBIANCE) * max(computed_shadow, /*LIGHT_AMBIANCE*/0.0) * direct_light * square_factor;// : vec3(0.0); // directed_light += mix(LIGHT_AMBIANCE, 1.0, computed_shadow) * direct_light * square_factor; // ambient_light += is_direct ? vec3(0.0) : vec3(0.0); // direct_light * square_factor * LIGHT_AMBIANCE; diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 6dfe29d498..bd33ddd770 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -513,7 +513,7 @@ impl Terrain { (e as i32).div_euclid(sz as i32) }); - const AMBIANCE: f32 = 0.2; // 0-1, the proportion of light that should illuminate the rear of an object + const AMBIANCE: f32 = 0.3; // 0-1, the proportion of light that should illuminate the rear of an object let (bias, total, max) = Spiral2d::new() .take(9) @@ -531,13 +531,13 @@ impl Terrain { let rpos = lpos.map(|e| e as f32 + 0.5) - wpos; let level = (*level as f32 - rpos.magnitude()).max(0.0) / SUNLIGHT as f32; ( - bias + rpos.try_normalized().unwrap_or_else(Vec3::zero) * level * (1.0 - AMBIANCE), + bias + rpos.try_normalized().unwrap_or_else(Vec3::zero) * level, total + level, max.max(level), ) }); - (bias.try_normalized().unwrap_or_else(Vec3::zero) / total.max(0.001), self.glow_at_wpos(wpos.map(|e| e.floor() as i32))) + (bias.try_normalized().unwrap_or_else(Vec3::zero) * (1.0 - AMBIANCE) / total.max(0.001), self.glow_at_wpos(wpos.map(|e| e.floor() as i32))) } /// Maintain terrain data. To be called once per tick.