testing 32x32x32 nodes world
This commit is contained in:
Generated
+65
@@ -620,6 +620,17 @@ dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gfx-auxil"
|
||||
version = "0.8.0"
|
||||
@@ -1420,6 +1431,12 @@ dependencies = [
|
||||
"miniz_oxide 0.3.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "0.1.5"
|
||||
@@ -1459,6 +1476,46 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "range-alloc"
|
||||
version = "0.1.2"
|
||||
@@ -1762,6 +1819,12 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.69"
|
||||
@@ -1982,11 +2045,13 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytemuck",
|
||||
"byteorder",
|
||||
"cgmath",
|
||||
"fs_extra",
|
||||
"futures",
|
||||
"glob",
|
||||
"image",
|
||||
"rand",
|
||||
"shaderc",
|
||||
"wgpu",
|
||||
"winit",
|
||||
|
||||
@@ -11,8 +11,10 @@ winit = "0.24"
|
||||
wgpu = "0.7"
|
||||
futures = "0.3"
|
||||
bytemuck = { version = "1.5", features = [ "derive" ] }
|
||||
byteorder = "1.4"
|
||||
image = "0.23.14"
|
||||
cgmath = "0.18"
|
||||
rand = "0.8"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user