diff --git a/voxygen/shaders/figure.frag b/voxygen/shaders/figure.frag index 36dd375a00..d5b8648ebd 100644 --- a/voxygen/shaders/figure.frag +++ b/voxygen/shaders/figure.frag @@ -32,13 +32,8 @@ void main() { vec4(f_norm, 0.0) ).xyz; - float ambient = 0.5; - - vec3 sun_dir = normalize(vec3(1.3, 1.7, 1.1)); - - float sun_diffuse = dot(sun_dir, world_norm) * 0.5; - - vec3 surf_color = model_col.rgb * f_col * (ambient + sun_diffuse); + float light = get_sun_diffuse(world_norm, time_of_day.x); + vec3 surf_color = model_col.rgb * f_col * 2.0 * light; float fog_level = fog(f_pos.xy, focus_pos.xy); vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x); diff --git a/voxygen/shaders/include/sky.glsl b/voxygen/shaders/include/sky.glsl index 4c917ca47a..96aa7ee38a 100644 --- a/voxygen/shaders/include/sky.glsl +++ b/voxygen/shaders/include/sky.glsl @@ -26,41 +26,73 @@ float noise(vec3 p){ return o4.y * d.y + o4.x * (1.0 - d.y); } +vec3 get_sun_dir(float time_of_day) { + const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0); + + float sun_angle_rad = time_of_day * TIME_FACTOR; + vec3 sun_dir = vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad)); + + return sun_dir; +} + +float get_sun_brightness(vec3 sun_dir) { + return max(-sun_dir.z, 0.0); +} + +const float PERSISTENT_AMBIANCE = 0.015; + +float get_sun_diffuse(vec3 norm, float time_of_day) { + const float SUN_AMBIANCE = 0.2; + + vec3 sun_dir = get_sun_dir(time_of_day); + + float sun_light = get_sun_brightness(sun_dir); + + return (SUN_AMBIANCE + max(dot(-norm, sun_dir), 0.0)) * sun_light + PERSISTENT_AMBIANCE; +} + vec3 get_sky_color(vec3 dir, float time_of_day) { bool objects = true; - const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0); - vec2 pos2d = dir.xy / dir.z; const vec3 SKY_TOP = vec3(0.2, 0.3, 0.9); const vec3 SKY_MIDDLE = vec3(0.1, 0.15, 0.7); const vec3 SKY_BOTTOM = vec3(0.025, 0.15, 0.35); - const vec3 SUN_HALO_COLOR = vec3(1.0, 0.7, 0.5) * 0.5; + const vec3 SUN_HALO_COLOR = vec3(1.0, 0.4, 0.3) * 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_dir = get_sun_dir(time_of_day); + float sky_brightness = get_sun_brightness(sun_dir); - 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.0045, 0.0), 1000.0) * SUN_SURF_COLOR; + vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * SUN_HALO_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; - vec3 sky_top; + float brightess = (sky_brightness + PERSISTENT_AMBIANCE); + + vec3 sky_top = SKY_TOP * brightess; if (objects) { - vec3 p = vec3(pos2d + time_of_day * 0.0002, time_of_day * 0.0001); - sky_top = mix(SKY_TOP, vec3(1), pow(noise(p) * 0.8 + noise(p * 3.0) * 0.2, 2.5) * 3.0); - } else { - sky_top = SKY_TOP; + // Clouds + // vec3 p = vec3(pos2d + time_of_day * 0.0002, time_of_day * 0.00003); + // sky_top = mix(sky_top, vec3(1) * brightess, pow(noise(p) * 0.8 + noise(p * 3.0) * 0.2, 2.5) * 3.0); } - vec3 sky_color = mix(mix(SKY_MIDDLE, sky_top, clamp(dir.z, 0, 1)), SKY_BOTTOM, clamp(-dir.z * 5.0, 0, 1)); - if (objects) { - sky_color += sun_light; + sky_top += sun_light; } + vec3 sky_color = mix( + mix( + SKY_MIDDLE * brightess, + sky_top, + clamp(dir.z * 3.0, 0, 1) + ), + SKY_BOTTOM * brightess, + clamp(-dir.z * 3.0, 0, 1) + ); + return sky_color; } diff --git a/voxygen/shaders/terrain.frag b/voxygen/shaders/terrain.frag index e3d350f924..9620347fe2 100644 --- a/voxygen/shaders/terrain.frag +++ b/voxygen/shaders/terrain.frag @@ -28,19 +28,7 @@ void main() { f_norm = vec3(0.0, 0.0, 1.0) * norm_dir; } - float glob_ambience = 0.0005; - - float sun_ambience = 0.3; - - vec3 sun_dir = normalize(vec3(0.7, 1.3, 2.1)); - - float sun_diffuse = max(dot(sun_dir, f_norm), 0.0); - float sun_light = sun_ambience + sun_diffuse; - - float static_light = glob_ambience + min(sun_light, f_light); - - vec3 light = vec3(static_light); - + float light = get_sun_diffuse(f_norm, time_of_day.x) * f_light; vec3 surf_color = f_col * light; float fog_level = fog(f_pos.xy, focus_pos.xy); diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 8b4bd913e3..9597aba4eb 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -56,6 +56,35 @@ impl + ReadVol + Debug, S: VolSize + Clone> Meshable for for z in (range.min.z..range.max.z).rev() { let pos = Vec3::new(x, y, z); + // Create mesh polygons + if let Some(col) = self.get(pos).ok().and_then(|vox| vox.get_color()) { + let avg_light = neighbour_light + .iter() + .map(|row| row.iter()) + .flatten() + .map(|col| col.iter()) + .flatten() + .fold(0.0, |a, x| a + x) + / 27.0; + let light = avg_light; + + let col = col.map(|e| e as f32 / 255.0); + + let offs = (pos - range.min * Vec3::new(1, 1, 0)).map(|e| e as f32) + - Vec3::new(1.0, 1.0, 0.0); + + vol::push_vox_verts( + &mut mesh, + self, + pos, + offs, + col, + |pos, norm, col, ao, light| TerrainVertex::new(pos, norm, Lerp::lerp(Rgb::zero(), col, ao), light), + false, + &neighbour_light, + ); + } + // Shift lighting neighbour_light[2] = neighbour_light[1]; neighbour_light[1] = neighbour_light[0]; @@ -82,35 +111,6 @@ impl + ReadVol + Debug, S: VolSize + Clone> Meshable for .flatten() .copied() .fold(0.0, |a, x| a + x) / 9.0; 3]; 3]; - - // Create mesh polygons - if let Some(col) = self.get(pos).ok().and_then(|vox| vox.get_color()) { - let avg_light = neighbour_light - .iter() - .map(|row| row.iter()) - .flatten() - .map(|col| col.iter()) - .flatten() - .fold(0.0, |a, x| a + x) - / 27.0; - let light = avg_light; - - let col = col.map(|e| e as f32 / 255.0); - - let offs = (pos - range.min * Vec3::new(1, 1, 0)).map(|e| e as f32) - - Vec3::new(1.0, 1.0, 0.0); - - vol::push_vox_verts( - &mut mesh, - self, - pos, - offs, - col, - |pos, norm, col, ao, light| TerrainVertex::new(pos, norm, col * ao, light), - false, - &neighbour_light, - ); - } } } } diff --git a/voxygen/src/mesh/vol.rs b/voxygen/src/mesh/vol.rs index 0effa4f4b9..1b36e05c4e 100644 --- a/voxygen/src/mesh/vol.rs +++ b/voxygen/src/mesh/vol.rs @@ -66,7 +66,7 @@ fn create_quad, Vec3, Rgb, f32, f32) -> P let darkness = darkness_ao.map(|e| e.0); let ao = darkness_ao.map(|e| e.1); - let ao_map = ao;//ao.map(|e| 0.2 + e.powf(1.0) * 0.8); + let ao_map = ao.map(|e| 0.05 + e.powf(1.6) * 0.95); if ao[0].min(ao[2]) < ao[1].min(ao[3]) { Quad::new( diff --git a/world/src/sim/location.rs b/world/src/sim/location.rs index 34eb7d02a3..cea228a4f8 100644 --- a/world/src/sim/location.rs +++ b/world/src/sim/location.rs @@ -55,12 +55,12 @@ fn generate_name(rng: &mut R) -> String { ]; let mut name = String::new(); - for i in 0..rand::random::() % 2 { - name += rand::thread_rng().choose(&consts).unwrap(); - name += rand::thread_rng().choose(&vowels).unwrap(); + for i in 0..rng.gen::() % 2 { + name += rng.choose(&consts).unwrap(); + name += rng.choose(&vowels).unwrap(); } - name += rand::thread_rng().choose(&consts).unwrap(); - name += rand::thread_rng().choose(&tails).unwrap(); + name += rng.choose(&consts).unwrap(); + name += rng.choose(&tails).unwrap(); name }