From 45362afbf4f552cd413c86371f334d5980eefa18 Mon Sep 17 00:00:00 2001 From: Piotrek Date: Thu, 6 May 2021 15:38:51 +0200 Subject: [PATCH] works --- src/app/mod.rs | 1 + src/app/world/generator.rs | 33 ++++++++---------------- src/app/world/mod.rs | 3 ++- src/renderer/buffers/content.rs | 13 +++++++--- src/renderer/mod.rs | 2 +- src/shaders/raytrace/.bin/main.frag.spv | Bin 13692 -> 13692 bytes src/shaders/raytrace/main.frag | 4 +-- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 6a61dab..c2ce0ee 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -28,6 +28,7 @@ impl App { let block = app.world.gen_block(pos); content.write(pos, block); + println!("App initialized"); app } diff --git a/src/app/world/generator.rs b/src/app/world/generator.rs index c6703f2..e1df591 100644 --- a/src/app/world/generator.rs +++ b/src/app/world/generator.rs @@ -39,33 +39,22 @@ impl WorldGen { /* * Generate block */ - pub fn generate(block: &mut WorldBlock) { + pub fn generate(block_pos: &Point3, block: &mut WorldBlock) { let mut rng = rand::thread_rng(); - let mut noise = Perlin::new(); - let mut dirty: Vec = Vec::new(); + let noise = Perlin::new(); - for bx in 0..16 { - for bz in 0..16 { - // Generate height map - let (map, max) = WorldGen::gen_height_map(bx, bz, &mut rng, &noise); - let bh = (max / block::SIZE) + 1; + // Generate height map + let (map, max) = WorldGen::gen_height_map(block_pos.x as usize, block_pos.z as usize, &mut rng, &noise); - // Generate blocks - for by in 0..bh { - // Fill - for x in 0..block::SIZE { - for z in 0..block::SIZE { - // TODO - let h = map[x][z]; - for y in 0..h { - block.set(Point3{x, y, z}, 2); - } - } - } + // Fill + for x in 0..block::SIZE { + for z in 0..block::SIZE { + //let h = map[x][z]; + let h = 16; // testing + for y in 0..h { + block.set(Point3{x, y, z}, 2); } - } } - // loop end } } \ No newline at end of file diff --git a/src/app/world/mod.rs b/src/app/world/mod.rs index 0158a5b..2440bf5 100644 --- a/src/app/world/mod.rs +++ b/src/app/world/mod.rs @@ -32,10 +32,11 @@ impl World { // Generate block for chunk let chunk = self.chunks.get_mut(block_pos).unwrap(); let block = chunk.get_block(&bl_pos); - WorldGen::generate(block); + WorldGen::generate(&bl_pos, block); block } + #[allow(unused)] pub fn get_block(&mut self, block_pos: &Point3) -> Option<&WorldBlock> { // Split world space to chunk and block space let ch_pos = block_pos / chunk::SIZE; diff --git a/src/renderer/buffers/content.rs b/src/renderer/buffers/content.rs index 25d1f2c..4cf8086 100644 --- a/src/renderer/buffers/content.rs +++ b/src/renderer/buffers/content.rs @@ -89,18 +89,23 @@ impl Content { // Allocate new block if value == 0 { - value = self.block_freeidx; + value = self.block_freeidx + 1; self.node_buffer[index] = value as u32; - self.block_freeidx += 1; + self.block_freeidx = value; + //println!("Alloc: {}", value); } + //println!("Index: {} Value: {}", index, value); + // Calculate position in block texture - let y = (value % BLOCK_TEX_SIZE * BLOCK_SIZE) as u32; - let z = (value / BLOCK_TEX_SIZE * BLOCK_SIZE) as u32; + let y = ((value-1) % BLOCK_TEX_SIZE * BLOCK_SIZE) as u32; + let z = ((value-1) / BLOCK_TEX_SIZE * BLOCK_SIZE) as u32; let block_origin = wgpu::Origin3d{ x:0, y, z }; let block_size = wgpu::Extent3d{ width: BLOCK_SIZE as u32, height: BLOCK_SIZE as u32, depth: BLOCK_SIZE as u32 }; let block_bytes : [u8;BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE] = block.materials.try_into().unwrap(); + //println!("Y: {} Z: {}", y, z); + // Write block queue.write_texture( wgpu::TextureCopyView { texture: &self.block_texture, mip_level: 0, origin: block_origin }, &block_bytes, diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index e49b3f0..169bf4c 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -79,7 +79,7 @@ impl Renderer { // Other let start = std::time::Instant::now(); - println!("Initialized"); + println!("Renderer initialized"); Self { surface, device, queue, swapchain_desc, swapchain, texture, raytrace_pass, postprocess_pass, buffers, camera, start } } diff --git a/src/shaders/raytrace/.bin/main.frag.spv b/src/shaders/raytrace/.bin/main.frag.spv index 6beb264dee0f2cf2a11f8facf4c7b7cf2d99336f..bbac1344331fec940201d1da9f8e9865cf1d47bd 100644 GIT binary patch delta 36 pcmey9^(Sis4+kUDWL}Q%f{Y9d4DJjp45xs!A`mlf7UfLW0RXzs2jBnz delta 36 pcmey9^(Sis4+kUjWL}Q%f=mny4DJjp45xs!A`mld7UfLW0RX!D2jKt! diff --git a/src/shaders/raytrace/main.frag b/src/shaders/raytrace/main.frag index d82ad3a..5aaffbd 100644 --- a/src/shaders/raytrace/main.frag +++ b/src/shaders/raytrace/main.frag @@ -15,8 +15,8 @@ layout(set=0, binding=0) uniform Uniform { float _Time; }; layout(set=1, binding=0) uniform usampler3D _NodesTexture; -layout(set=2, binding=0) uniform usampler3D _BricksTexture; -layout(set=3, binding=0) uniform Materials { Material _Materials[256]; }; +layout(set=1, binding=1) uniform usampler3D _BricksTexture; +layout(set=2, binding=0) uniform Materials { Material _Materials[256]; }; // Defines #define EPSILON 0.00000001