testing 32x32x32 nodes world

This commit is contained in:
Piotrek
2021-04-23 22:15:14 +02:00
parent b59523c13b
commit 526ff05ed2
6 changed files with 117 additions and 14 deletions
+6 -3
View File
@@ -1,5 +1,6 @@
use wgpu::util::DeviceExt;
use std::convert::TryInto;
use rand::prelude::*;
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
const BRICK_NUM : usize = 10000; // x bricks in texture
@@ -94,11 +95,13 @@ impl BrickBuffer {
// Data
let mut bricks = BrickData::new();
println!("Brick buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
let mut rng = rand::thread_rng();
for x in 0..32 {
for y in 0..16 {
for y in 0..32 {
for z in 0..32 {
bricks.set(0, x, y, z, 1);
bricks.set(1, y, x, z, 1);
let value = if rng.gen::<f32>()> 0.99 { 1 } else { 0 };
bricks.set(0, x, y, z, value);
}
}
}
+42 -9
View File
@@ -1,10 +1,31 @@
use byteorder::{ByteOrder, LittleEndian};
use rand::prelude::*;
// 4x4x4 nodes
const WORLD_SIZE: u32 = 4;
const WORLD_SIZE: usize = 32;
const NUM_NODES: usize = (WORLD_SIZE*WORLD_SIZE*WORLD_SIZE) as usize;
struct NodeData {
pub data: Box<[u32]>
}
impl NodeData {
pub fn new() -> Self {
let data = vec![0_u32; NUM_NODES].into_boxed_slice();
Self { data }
}
pub fn set(&mut self, x: usize, y: usize, z: usize, value: u32)
{
let idx = x + WORLD_SIZE * (y + WORLD_SIZE * z);
self.data[idx] = value;
}
}
pub struct NodeBuffer {
nodes: [u32;NUM_NODES],
nodes: NodeData,
texture: wgpu::Texture,
size: wgpu::Extent3d,
pub bind_layout: wgpu::BindGroupLayout,
@@ -16,7 +37,7 @@ impl NodeBuffer {
pub fn new(device: &wgpu::Device) -> Self {
// Create texture
let size = wgpu::Extent3d { width: WORLD_SIZE, height: WORLD_SIZE, depth: WORLD_SIZE };
let size = wgpu::Extent3d { width: WORLD_SIZE as u32, height: WORLD_SIZE as u32, depth: WORLD_SIZE as u32 };
let texture = device.create_texture(
&wgpu::TextureDescriptor {
size: size,
@@ -69,10 +90,22 @@ impl NodeBuffer {
);
// Data
let mut nodes : [u32; NUM_NODES] = [Default::default(); NUM_NODES];
nodes[0] = 1;
nodes[1] = 2;
nodes[2] = 2;
let mut nodes = NodeData::new();
let mut rng = rand::thread_rng();
for x in 0..WORLD_SIZE {
for y in 0..WORLD_SIZE {
for z in 0..WORLD_SIZE {
let value = if rng.gen::<f32>()> 0.5 { 1 } else { 0 };
nodes.set(x, y, z, value);
}
}
}
// for i in 0..WORLD_SIZE {
// nodes.set(i, 0, 0, 1);
// nodes.set(0, i, 0, 1);
// nodes.set(0, 0, i, 1);
// }
// Done
Self { nodes, texture, size, bind_layout, bind_group }
@@ -80,8 +113,8 @@ impl NodeBuffer {
pub fn write(&mut self, queue: &wgpu::Queue) {
// Convert 32 bit values to 8 bit
let bytes = bytemuck::bytes_of(&self.nodes);
println!("Node buffer size: {} kB", bytes.len() as f32 / 1024.0);
let mut bytes = [0_u8; NUM_NODES*4];
LittleEndian::write_u32_into(&self.nodes.data, &mut bytes);
// Write
queue.write_texture(
Binary file not shown.
+2 -2
View File
@@ -63,7 +63,7 @@ vec4 castBricks(vec3 origin, vec3 start, vec3 dir, vec3 incAxis, uint addr)
// Check for bounds
if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
if(pos.x > 32 || pos.y > 32 || pos.z > 32) { break; }
if(pos.x > 31 || pos.y > 31 || pos.z > 31) { break; }
}
return vec4(0.5,0.5,0.5, 0.0);
@@ -88,7 +88,7 @@ vec3 castNodes(vec3 origin, vec3 dir)
vec3 incAxis = vec3(0,0,0);
// Iterate
for(int i=0;i<56;i++)
for(int i=0;i<110;i++)
{
// Get node
uint node = texelFetch(nodesTexture, ivec3(pos), 0).r;