Better snow cover

This commit is contained in:
Joshua Barretto 2022-05-15 15:34:36 +01:00
parent ecf97a53cd
commit cc295b483a
5 changed files with 37 additions and 16 deletions

View File

@ -192,7 +192,7 @@ void main() {
reflect_color *= f_light;
// Prevent the sky affecting light when underground
float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0);
float not_underground = clamp((f_pos.z - f_alt) / 32.0 + 1.0, 0.0, 1.0);
reflect_color *= not_underground;
// /*const */vec3 water_color = srgb_to_linear(vec3(0.2, 0.5, 1.0));
// /*const */vec3 water_color = srgb_to_linear(vec3(0.8, 0.9, 1.0));

View File

@ -51,7 +51,7 @@ void main() {
f_norm = v_norm;
f_col = vec4(vec3(inst_col) * (1.0 / 255.0) * v_col * (hash(inst_pos.xyxy) * 0.35 + 0.65), 1.0);
if ((inst_flags & FLAG_SNOW_COVERED) > 0u) {
if ((inst_flags & FLAG_SNOW_COVERED) > 0u && f_norm.z > 0.0) {
snow_cover = 1.0;
} else {
snow_cover = 0.0;

View File

@ -87,6 +87,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
let spawn_rate = sim.get_interpolated(wpos, |chunk| chunk.spawn_rate)?;
let flux = sim.get_interpolated(wpos, |chunk| chunk.flux)?;
let near_water =
sim.get_interpolated(
wpos,
@ -1108,10 +1109,15 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
})
.max(-humidity.sub(CONFIG.desert_hum))
.mul(4.0)
.add(((marble - 0.5) / 0.5) * 0.5)
.add(((marble_mid - 0.5) / 0.5) * 0.25)
.add(((marble_small - 0.5) / 0.5) * 0.175);
let (alt, ground, sub_surface_color) = if snow_factor <= 0.0 && alt > water_level {
.max(-0.25)
// 'Simulate' avalanches moving snow from areas with high gradients to areas with high flux
.add((gradient.unwrap_or(0.0) - 0.5).max(0.0) * 0.1)
// .add(-flux * 0.003 * gradient.unwrap_or(0.0))
.add(((marble - 0.5) / 0.5) * 0.25)
.add(((marble_mid - 0.5) / 0.5) * 0.125)
.add(((marble_small - 0.5) / 0.5) * 0.0625);
let snow_cover = snow_factor <= 0.0;
let (alt, ground, sub_surface_color) = if snow_cover && alt > water_level {
// Allow snow cover.
(
alt + 1.0 - snow_factor.max(0.0),
@ -1121,7 +1127,6 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
} else {
(alt, ground, sub_surface_color)
};
let snow_cover = snow_factor <= 0.0;
// Make river banks not have grass
let ground = water_dist

View File

@ -554,15 +554,27 @@ impl World {
.reduce_and()
})
.filter(|(_, site)| matches!(&site.kind, SiteKind::GiantTree(_)))
.map(|(_, site)| lod::Object {
kind: lod::ObjectKind::GiantTree,
pos: {
let wpos2d = site.get_origin();
(wpos2d - min_wpos)
.map(|e| e as i16)
.with_z(self.sim().get_alt_approx(wpos2d).unwrap_or(0.0) as i16)
},
flags: lod::Flags::empty(),
.filter_map(|(_, site)| {
let wpos2d = site.get_origin();
let col = ColumnGen::new(self.sim()).get((
wpos2d,
index,
self.sim().calendar.as_ref(),
))?;
Some(lod::Object {
kind: lod::ObjectKind::GiantTree,
pos: {
(wpos2d - min_wpos)
.map(|e| e as i16)
.with_z(self.sim().get_alt_approx(wpos2d).unwrap_or(0.0) as i16)
},
flags: lod::Flags::empty()
| if col.snow_cover {
lod::Flags::SNOW_COVERED
} else {
lod::Flags::empty()
},
})
}),
);

View File

@ -2348,6 +2348,10 @@ impl SimChunk {
const MIN_TREE_HUM: f32 = 0.15;
// Tree density increases exponentially with humidity...
let tree_density = (tree_density * (humidity - MIN_TREE_HUM).max(0.0).mul(1.0 + MIN_TREE_HUM) / temp.max(0.75))
// Places that are *too* wet (like marshes) also get fewer trees because the ground isn't stable enough for
// them.
//.mul((1.0 - flux * 0.05/*(humidity - 0.9).max(0.0) / 0.1*/).max(0.0))
.mul(0.25 + flux * 0.05)
// ...but is ultimately limited by available sunlight (and our tree generation system)
.min(1.0);