fix texture format
This commit is contained in:
@@ -2,7 +2,7 @@ use wgpu::util::DeviceExt;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
|
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
|
||||||
const BRICK_NUM : usize = 10000; // 64 bricks in texture
|
const BRICK_NUM : usize = 1; // 64 bricks in texture
|
||||||
|
|
||||||
const BRICK_LEN : usize = BRICK_SIZE*BRICK_SIZE*BRICK_SIZE;
|
const BRICK_LEN : usize = BRICK_SIZE*BRICK_SIZE*BRICK_SIZE;
|
||||||
const DATA_LEN : usize = BRICK_LEN * BRICK_NUM;
|
const DATA_LEN : usize = BRICK_LEN * BRICK_NUM;
|
||||||
@@ -46,7 +46,7 @@ impl BrickBuffer {
|
|||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D3,
|
dimension: wgpu::TextureDimension::D3,
|
||||||
format: wgpu::TextureFormat::R32Uint,
|
format: wgpu::TextureFormat::R8Uint,
|
||||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, // STORAGE?
|
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, // STORAGE?
|
||||||
label: Some("Brick texture"),
|
label: Some("Brick texture"),
|
||||||
}
|
}
|
||||||
@@ -93,6 +93,7 @@ impl BrickBuffer {
|
|||||||
|
|
||||||
// Data
|
// Data
|
||||||
let mut bricks = BrickData::new();
|
let mut bricks = BrickData::new();
|
||||||
|
println!("Brick buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
|
||||||
for x in 0..32 {
|
for x in 0..32 {
|
||||||
for y in 0..16 {
|
for y in 0..16 {
|
||||||
for z in 0..32 {
|
for z in 0..32 {
|
||||||
@@ -102,23 +103,26 @@ impl BrickBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
println!("Brick buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
|
|
||||||
Self { bricks, texture, size, bind_layout, bind_group }
|
Self { bricks, texture, size, bind_layout, bind_group }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&mut self, queue: &wgpu::Queue)
|
/*
|
||||||
|
Write brick data to gpu, should be called to apply changes
|
||||||
|
offset: Brick index to copy
|
||||||
|
*/
|
||||||
|
pub fn write(&mut self, queue: &wgpu::Queue, offset: usize)
|
||||||
{
|
{
|
||||||
return ();
|
|
||||||
|
|
||||||
// Get first brick
|
// Get first brick
|
||||||
let brick_bytes : [u8;BRICK_LEN] = self.bricks.data[0..BRICK_LEN].try_into().unwrap();
|
let brick_offset = offset*BRICK_LEN;
|
||||||
|
let brick_bytes : [u8;BRICK_LEN] = self.bricks.data[brick_offset..brick_offset+BRICK_LEN].try_into().unwrap();
|
||||||
let brick_size = wgpu::Extent3d{ width: BRICK_SIZE as u32, height: BRICK_SIZE as u32, depth: BRICK_SIZE as u32 };
|
let brick_size = wgpu::Extent3d{ width: BRICK_SIZE as u32, height: BRICK_SIZE as u32, depth: BRICK_SIZE as u32 };
|
||||||
|
let brick_origin = wgpu::Origin3d{ x:0, y:0, z: offset as u32 };
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
queue.write_texture(
|
queue.write_texture(
|
||||||
wgpu::TextureCopyView { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d::ZERO },
|
wgpu::TextureCopyView { texture: &self.texture, mip_level: 0, origin: brick_origin },
|
||||||
&brick_bytes,
|
&brick_bytes,
|
||||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: self.size.width, rows_per_image: self.size.height },
|
wgpu::TextureDataLayout { offset: 0, bytes_per_row: brick_size.width, rows_per_image: brick_size.height },
|
||||||
brick_size
|
brick_size
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -111,7 +111,7 @@ impl Renderer {
|
|||||||
node_buffer.write(&queue);
|
node_buffer.write(&queue);
|
||||||
|
|
||||||
let mut brick_buffer = BrickBuffer::new(&device);
|
let mut brick_buffer = BrickBuffer::new(&device);
|
||||||
brick_buffer.write(&queue);
|
brick_buffer.write(&queue, 0);
|
||||||
|
|
||||||
// Pipeline
|
// Pipeline
|
||||||
let pipeline = Self::create_pipeline(&device, &swapchain_desc, &[&uniform_buffer.bind_layout, &node_buffer.bind_layout, &brick_buffer.bind_layout]);
|
let pipeline = Self::create_pipeline(&device, &swapchain_desc, &[&uniform_buffer.bind_layout, &node_buffer.bind_layout, &brick_buffer.bind_layout]);
|
||||||
|
|||||||
Binary file not shown.
@@ -19,6 +19,11 @@ vec3 solve(vec3 point, vec3 view, vec3 normal)
|
|||||||
return (ambient + diffuse + specular) * object_color;
|
return (ambient + diffuse + specular) * object_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 castBricks(vec3 origin, vec3 dir)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
vec3 castNodes(vec3 origin, vec3 dir)
|
vec3 castNodes(vec3 origin, vec3 dir)
|
||||||
{
|
{
|
||||||
// Round input pos to nearest voxel
|
// Round input pos to nearest voxel
|
||||||
@@ -37,7 +42,7 @@ vec3 castNodes(vec3 origin, vec3 dir)
|
|||||||
for(int i=0;i<50;i++)
|
for(int i=0;i<50;i++)
|
||||||
{
|
{
|
||||||
// Get node
|
// Get node
|
||||||
uint node = texelFetch(diffuseTex, ivec3(pos), 0).r;
|
uint node = texelFetch(nodesTexture, ivec3(pos), 0).r;
|
||||||
if(node != 0)
|
if(node != 0)
|
||||||
{
|
{
|
||||||
// Hit point
|
// Hit point
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ layout(set=0, binding=0) uniform Uniforms
|
|||||||
|
|
||||||
//layout(set = 1, binding = 0) uniform texture3D node_tex;
|
//layout(set = 1, binding = 0) uniform texture3D node_tex;
|
||||||
//layout(set = 1, binding = 1) uniform usampler3D node_sampl;
|
//layout(set = 1, binding = 1) uniform usampler3D node_sampl;
|
||||||
layout(set=1,binding=0) uniform usampler3D diffuseTex;
|
layout(set=1,binding=0) uniform usampler3D nodesTexture;
|
||||||
|
layout(set=2,binding=0) uniform usampler3D bricksTexture;
|
||||||
|
|
||||||
// Defines
|
// Defines
|
||||||
#define PI 3.141592
|
#define PI 3.141592
|
||||||
|
|||||||
Reference in New Issue
Block a user