Grass improvements

This commit is contained in:
Joshua Barretto 2019-06-23 14:55:54 +01:00
parent 86651561a4
commit 2226baa844
3 changed files with 36 additions and 20 deletions

View File

@ -167,7 +167,7 @@ void main() {
//vec4 fxaa_color = texture(src_color, uv); //vec4 fxaa_color = texture(src_color, uv);
vec4 hsva_color = vec4(rgb2hsv(fxaa_color.rgb), fxaa_color.a); vec4 hsva_color = vec4(rgb2hsv(fxaa_color.rgb), fxaa_color.a);
hsva_color.y *= 1.4; hsva_color.y *= 1.3;
hsva_color.x -= 0.015; hsva_color.x -= 0.015;
hsva_color.z *= 0.85; hsva_color.z *= 0.85;
//hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0); //hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0);

View File

@ -83,6 +83,7 @@ impl<'a> SamplerMut for BlockGen<'a> {
water_level, water_level,
river, river,
surface_color, surface_color,
sub_surface_color,
tree_density, tree_density,
forest_kind, forest_kind,
close_trees, close_trees,
@ -143,8 +144,13 @@ impl<'a> SamplerMut for BlockGen<'a> {
let water = Block::new(1, Rgb::new(100, 150, 255)); let water = Block::new(1, Rgb::new(100, 150, 255));
let warm_stone = Block::new(1, Rgb::new(165, 165, 130)); let warm_stone = Block::new(1, Rgb::new(165, 165, 130));
let block = if (wposf.z as f32) < height - 3.0 { let grass_depth = 2.0;
let col = Lerp::lerp(dirt_col, stone_col, (height - 4.0 - wposf.z as f32) * 0.15); let block = if (wposf.z as f32) < height - grass_depth {
let col = Lerp::lerp(
sub_surface_color.map(|e| (e * 255.0) as u8),
stone_col,
(height - grass_depth - wposf.z as f32) * 0.15,
);
// Underground // Underground
if (wposf.z as f32) > alt - 32.0 * chaos { if (wposf.z as f32) > alt - 32.0 * chaos {
@ -154,9 +160,9 @@ impl<'a> SamplerMut for BlockGen<'a> {
} }
} else if (wposf.z as f32) < height { } else if (wposf.z as f32) < height {
let col = Lerp::lerp( let col = Lerp::lerp(
dirt_col.map(|e| e as f32 / 255.0), sub_surface_color,
surface_color, surface_color,
(wposf.z as f32 - (height - 4.0)) * 0.25, (wposf.z as f32 - (height - grass_depth)).div(grass_depth).powf(0.5),
); );
// Surface // Surface
Some(Block::new(1, col.map(|e| (e * 255.0) as u8))) Some(Block::new(1, col.map(|e| (e * 255.0) as u8)))

View File

@ -97,15 +97,17 @@ impl<'a> Sampler for ColumnGen<'a> {
let wposf3d = Vec3::new(wposf.x, wposf.y, alt as f64); let wposf3d = Vec3::new(wposf.x, wposf.y, alt as f64);
let marble = (0.0 let marble_small = (sim.gen_ctx.hill_nz.get((wposf3d.div(3.0)).into_array()) as f32)
+ (sim.gen_ctx.hill_nz.get((wposf3d.div(48.0)).into_array()) as f32).mul(0.75) .add(1.0)
+ (sim.gen_ctx.hill_nz.get((wposf3d.div(3.0)).into_array()) as f32).mul(0.25)) .mul(0.5);
.add(1.0) let marble = (sim.gen_ctx.hill_nz.get((wposf3d.div(48.0)).into_array()) as f32).mul(0.75)
.mul(0.5); .add(1.0)
.mul(0.5)
.add(marble_small.mul(0.25));
// Colours // Colours
let cold_grass = Rgb::new(0.0, 0.3, 0.15); let cold_grass = Rgb::new(0.05, 0.2, 0.1);
let warm_grass = Rgb::new(0.2, 0.8, 0.05); let warm_grass = Rgb::new(0.15, 0.65, 0.05);
let cold_stone = Rgb::new(0.55, 0.7, 0.75); let cold_stone = Rgb::new(0.55, 0.7, 0.75);
let warm_stone = Rgb::new(0.65, 0.65, 0.35); let warm_stone = Rgb::new(0.65, 0.65, 0.35);
let beach_sand = Rgb::new(0.93, 0.84, 0.4); let beach_sand = Rgb::new(0.93, 0.84, 0.4);
@ -116,10 +118,18 @@ impl<'a> Sampler for ColumnGen<'a> {
let sand = Rgb::lerp(beach_sand, desert_sand, marble); let sand = Rgb::lerp(beach_sand, desert_sand, marble);
let cliff = Rgb::lerp(cold_stone, warm_stone, marble); let cliff = Rgb::lerp(cold_stone, warm_stone, marble);
let dirt = Lerp::lerp(
Rgb::new(0.2, 0.1, 0.05),
Rgb::new(0.4, 0.25, 0.0),
marble_small,
);
let turf = grass;
let ground = Rgb::lerp( let ground = Rgb::lerp(
Rgb::lerp( Rgb::lerp(
snow, snow,
grass, turf,
temp.sub(CONFIG.snow_temp) temp.sub(CONFIG.snow_temp)
.sub((marble - 0.5) * 0.05) .sub((marble - 0.5) * 0.05)
.mul(256.0), .mul(256.0),
@ -128,7 +138,7 @@ impl<'a> Sampler for ColumnGen<'a> {
temp.sub(CONFIG.desert_temp).mul(32.0), temp.sub(CONFIG.desert_temp).mul(32.0),
); );
// Work out if we're on a path // Work out if we're on a path or near a town
let near_0 = sim_chunk.location.as_ref().map(|l| l.near[0].block_pos).unwrap_or(Vec2::zero()).map(|e| e as f32); let near_0 = sim_chunk.location.as_ref().map(|l| l.near[0].block_pos).unwrap_or(Vec2::zero()).map(|e| e as f32);
let near_1 = sim_chunk.location.as_ref().map(|l| l.near[1].block_pos).unwrap_or(Vec2::zero()).map(|e| e as f32); let near_1 = sim_chunk.location.as_ref().map(|l| l.near[1].block_pos).unwrap_or(Vec2::zero()).map(|e| e as f32);
@ -140,12 +150,10 @@ impl<'a> Sampler for ColumnGen<'a> {
.abs() .abs()
.div(near_0.distance(near_1)); .div(near_0.distance(near_1));
let (alt, ground) = if dist_to_path < 5.0 { let on_path = dist_to_path < 5.0 || near_0.distance(wposf_turb.map(|e| e as f32)) < 150.0;
(alt - 1.5, Lerp::lerp(
Rgb::new(0.15, 0.075, 0.05), let (alt, ground) = if on_path {
Rgb::new(0.4, 0.25, 0.0), (alt - 1.0, dirt)
marble,
))
} else { } else {
(alt, ground) (alt, ground)
}; };
@ -204,6 +212,7 @@ impl<'a> Sampler for ColumnGen<'a> {
// Beach // Beach
((alt - CONFIG.sea_level - 2.0) / 5.0).min(1.0 - river * 2.0), ((alt - CONFIG.sea_level - 2.0) / 5.0).min(1.0 - river * 2.0),
), ),
sub_surface_color: dirt,
tree_density, tree_density,
forest_kind: sim_chunk.forest_kind, forest_kind: sim_chunk.forest_kind,
close_trees: sim.gen_ctx.tree_gen.get(wpos), close_trees: sim.gen_ctx.tree_gen.get(wpos),
@ -226,6 +235,7 @@ pub struct ColumnSample<'a> {
pub water_level: f32, pub water_level: f32,
pub river: f32, pub river: f32,
pub surface_color: Rgb<f32>, pub surface_color: Rgb<f32>,
pub sub_surface_color: Rgb<f32>,
pub tree_density: f32, pub tree_density: f32,
pub forest_kind: ForestKind, pub forest_kind: ForestKind,
pub close_trees: [(Vec2<i32>, u32); 9], pub close_trees: [(Vec2<i32>, u32); 9],