From 717e219003b7b8e222bfd70d8951eda8e4b540f2 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 17 Jan 2023 21:35:45 +0100 Subject: [PATCH] update --- Cargo.toml | 4 ++++ src/game/options.rs | 2 +- src/game/shaders/chunk.rs | 3 +++ src/game/world.rs | 6 ++++-- src/game/world/thread/mesh_gen.rs | 1 + src/game/world/thread/world_gen.rs | 2 +- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81b4777..4c6b812 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,7 @@ strum = { version = "0.24", features = ["derive"] } glam = { version = "0.22", features = ["debug-glam-assert", "mint", "fast-math"] } hashbrown = "0.13" simdnoise = "3.1" + +[features] +default = [] +polygon_rendering = [] diff --git a/src/game/options.rs b/src/game/options.rs index d9fae77..962c5d8 100644 --- a/src/game/options.rs +++ b/src/game/options.rs @@ -5,7 +5,7 @@ pub struct GameOptions { impl Default for GameOptions { fn default() -> Self { Self { - render_distance: 16, + render_distance: if cfg!(debug_assertions) { 8 } else { 16 }, } } } diff --git a/src/game/shaders/chunk.rs b/src/game/shaders/chunk.rs index 9172605..6519030 100644 --- a/src/game/shaders/chunk.rs +++ b/src/game/shaders/chunk.rs @@ -38,7 +38,10 @@ pub const FRAGMENT_SHADER: &str = r#" uniform sampler2D tex; void main() { + // base color from texture color = texture(tex, v_uv); + + //basic lighting color *= vec4(vec3(abs(v_normal.x) + .8 * abs(v_normal.y) + .6 * abs(v_normal.z)), 1.); } "#; diff --git a/src/game/world.rs b/src/game/world.rs index 3e7b657..c4e6612 100644 --- a/src/game/world.rs +++ b/src/game/world.rs @@ -26,7 +26,7 @@ const NEGATIVE_X_NEIGHBOR: usize = 1; const POSITIVE_Z_NEIGHBOR: usize = 2; const NEGATIVE_Z_NEIGHBOR: usize = 3; -const MAX_TASKS: usize = 4; +const MAX_TASKS: usize = 6; pub struct World { pub chunks: HashMap, @@ -58,8 +58,9 @@ impl World { view: [[f32; 4]; 4] ) { let sampler = SamplerBehavior { - minify_filter: MinifySamplerFilter::Nearest, + minify_filter: MinifySamplerFilter::Linear, magnify_filter: MagnifySamplerFilter::Nearest, + max_anisotropy: 8, ..Default::default() }; let draw_parameters = DrawParameters { @@ -68,6 +69,7 @@ impl World { write: true, ..Default::default() }, + #[cfg(feature = "polygon_rendering")] polygon_mode: glium::PolygonMode::Line, backface_culling: glium::draw_parameters::BackfaceCullingMode::CullCounterClockwise, ..Default::default() }; diff --git a/src/game/world/thread/mesh_gen.rs b/src/game/world/thread/mesh_gen.rs index 617ef77..4584bd4 100644 --- a/src/game/world/thread/mesh_gen.rs +++ b/src/game/world/thread/mesh_gen.rs @@ -123,6 +123,7 @@ pub fn generate_mesh(position: IVec2, chunk_data: ChunkData, neighbors: [ChunkDa //TODO replace with a proper texture resolver (or calculate uvs in a shader!) //this is temporary! //also this can only resolve textures on the first row. + const TEX_WIDTH: f32 = 16. / 640.; const TEX_HEIGHT: f32 = 16. / 404.; let x1 = TEX_WIDTH * texture_id as f32; diff --git a/src/game/world/thread/world_gen.rs b/src/game/world/thread/world_gen.rs index 8abf905..40d81ad 100644 --- a/src/game/world/thread/world_gen.rs +++ b/src/game/world/thread/world_gen.rs @@ -13,7 +13,7 @@ pub fn generate_chunk(position: IVec2, seed: u32) -> ChunkData { let mut chunk = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_HEIGHT]; CHUNK_SIZE]); //generate noises - let height_noise = NoiseBuilder::ridge_2d_offset(world_xz.x, CHUNK_SIZE, world_xz.y, CHUNK_SIZE) + let height_noise = NoiseBuilder::fbm_2d_offset(world_xz.x, CHUNK_SIZE, world_xz.y, CHUNK_SIZE) .with_freq(0.01) .with_octaves(4) .with_seed(seed as i32)