diff --git a/Cargo.lock b/Cargo.lock index b21fbf5..a2f64c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,7 +121,7 @@ checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -228,6 +228,12 @@ dependencies = [ "jobserver", ] +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -303,7 +309,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -412,7 +418,7 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -551,7 +557,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -633,7 +639,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "winapi", ] @@ -659,7 +665,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -792,7 +798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "libc", "memoffset", ] @@ -805,7 +811,7 @@ checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ "autocfg", "bitflags", - "cfg-if", + "cfg-if 1.0.0", "libc", "memoffset", ] @@ -916,7 +922,7 @@ version = "0.3.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e9829e16c5e112e94efb5e2ad1fe17f8c1c99bb0fcdc8c65c44e935d904767d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "redox_syscall 0.2.16", "wasm-bindgen", "web-sys", @@ -947,13 +953,32 @@ version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", "smallvec", "windows-sys 0.45.0", ] +[[package]] +name = "paste" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" +dependencies = [ + "paste-impl", + "proc-macro-hack", +] + +[[package]] +name = "paste-impl" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" +dependencies = [ + "proc-macro-hack", +] + [[package]] name = "percent-encoding" version = "2.2.0" @@ -994,6 +1019,12 @@ dependencies = [ "toml_edit", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" version = "1.0.56" @@ -1122,6 +1153,25 @@ dependencies = [ "tiny-skia", ] +[[package]] +name = "simdeez" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ec898e1be717eee4b54a84ff2fc94ecb5a1b992d4ad148ce30575b45745662" +dependencies = [ + "cfg-if 0.1.10", + "paste", +] + +[[package]] +name = "simdnoise" +version = "3.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f69a3fa031fc2906ffe27aecc55bdd2c9cb95327c4695ea814a083145fa462" +dependencies = [ + "simdeez", +] + [[package]] name = "slotmap" version = "1.0.6" @@ -1238,7 +1288,7 @@ dependencies = [ "arrayref", "arrayvec", "bytemuck", - "cfg-if", + "cfg-if 1.0.0", "png", "tiny-skia-path", ] @@ -1316,6 +1366,7 @@ dependencies = [ "glam", "log", "pollster", + "simdnoise", "wgpu", "winit", ] @@ -1332,7 +1383,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -1357,7 +1408,7 @@ version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1482,7 +1533,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d745a1b6d91d85c33defbb29f0eee0450e1d2614d987e14bf6baf26009d132d7" dependencies = [ "arrayvec", - "cfg-if", + "cfg-if 1.0.0", "js-sys", "log", "naga", diff --git a/Cargo.toml b/Cargo.toml index 67e052e..82275c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,6 @@ env_logger = "0.10.0" glam = "0.23.0" log = "0.4.17" pollster = "0.3.0" +simdnoise = "3.1.6" wgpu = "0.15.1" winit = "0.28.3" diff --git a/src/voxel/brickmap.rs b/src/voxel/brickmap.rs index 7c5670c..1b7f2a0 100644 --- a/src/voxel/brickmap.rs +++ b/src/voxel/brickmap.rs @@ -161,6 +161,21 @@ impl BrickmapManager { let chunk_y = data[i * 4 + 1]; let chunk_z = data[i * 4 + 2]; + let noise_vals = simdnoise::NoiseBuilder::fbm_3d_offset( + chunk_x as f32 * 8.0, + 8, + chunk_y as f32 * 8.0, + 8, + chunk_z as f32 * 8.0, + 8, + ) + .with_seed(0) + .with_freq(0.005) + .with_octaves(3) + .with_gain(0.5) + .with_lacunarity(2.0) + .generate(); + // Generate full data let mut chunk = [(false, 0u32); 512]; for z in 0..8 { @@ -168,10 +183,8 @@ impl BrickmapManager { for x in 0..8 { let idx = (x + y * 8 + z * 8 * 8) as usize; - // Just checks if the point is in the sphere - let pos = glam::vec3(x as f32, y as f32, z as f32); - if (pos - sphere_center).length_squared() <= sphere_r2 { - // Pack the local position as a colour + let val = noise_vals.0[idx]; + if val > 0.0 { let mut albedo = 0u32; albedo += ((x + 1) * 32 - 1) << 24; albedo += ((y + 1) * 32 - 1) << 16;