Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
7f9a76bd71
|
|||
|
757eb2a572
|
|||
|
0828f2ced0
|
|||
|
406763b8db
|
|||
|
d069271542
|
|||
|
93c01910cb
|
23
src/main.rs
23
src/main.rs
@@ -147,9 +147,7 @@ fn training() {
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
||||
| wgpu::TextureUsages::TEXTURE_BINDING
|
||||
| wgpu::TextureUsages::COPY_SRC,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
});
|
||||
let graphics_texture_view = graphics_texture.create_view(&wgpu::TextureViewDescriptor {
|
||||
@@ -255,8 +253,8 @@ fn training() {
|
||||
fn a(a: v0::Vector3) -> [f32; 2] {
|
||||
[a.y, a.x]
|
||||
}
|
||||
fn add<T: core::ops::Add>(lhs: T, rhs: T) -> T::Output {
|
||||
lhs + rhs
|
||||
fn sub<T: core::ops::Sub>(lhs: T, rhs: T) -> T::Output {
|
||||
lhs - rhs
|
||||
}
|
||||
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
@@ -267,14 +265,14 @@ fn training() {
|
||||
graphics.encode_commands(
|
||||
&mut encoder,
|
||||
&graphics_texture_view,
|
||||
add(world_offset, p(output_event.event.position).into()),
|
||||
sub(p(output_event.event.position).into(), world_offset),
|
||||
a(output_event.event.angles).into(),
|
||||
);
|
||||
|
||||
// copy the depth texture into ram
|
||||
encoder.copy_texture_to_buffer(
|
||||
wgpu::TexelCopyTextureInfo {
|
||||
texture: &graphics_texture,
|
||||
texture: graphics.depth_texture(),
|
||||
mip_level: 0,
|
||||
origin: wgpu::Origin3d::ZERO,
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
@@ -285,7 +283,7 @@ fn training() {
|
||||
offset: 0,
|
||||
// This needs to be a multiple of 256.
|
||||
bytes_per_row: Some(stride_size as u32),
|
||||
rows_per_image: None,
|
||||
rows_per_image: Some(size.y),
|
||||
},
|
||||
},
|
||||
wgpu::Extent3d {
|
||||
@@ -311,24 +309,25 @@ fn training() {
|
||||
}
|
||||
output_staging_buffer.unmap();
|
||||
|
||||
println!("{texture_data:?}");
|
||||
|
||||
let inputs_start = inputs.len();
|
||||
// discombolulate stride
|
||||
for y in 0..size.y {
|
||||
inputs.extend(
|
||||
texture_data[(stride_size * y) as usize
|
||||
..(stride_size * y + size.x * size_of::<f32>() as u32) as usize]
|
||||
.chunks_exact(4)
|
||||
.map(|b| b[0] as f32 + b[1] as f32 + b[2] as f32),
|
||||
.map(|b| f32::from_le_bytes(b.try_into().unwrap())),
|
||||
)
|
||||
}
|
||||
let inputs_end = inputs.len();
|
||||
println!("inputs = {:?}", &inputs[inputs_start..inputs_end]);
|
||||
|
||||
// write a png
|
||||
output_image_native(
|
||||
&inputs[i * INPUT..(i + 1) * INPUT]
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|f| f as u8)
|
||||
.map(|f| (f * 255.0) as u8)
|
||||
.collect::<Vec<u8>>(),
|
||||
(SIZE_X, SIZE_Y),
|
||||
format!("depth_images/{i}.png").into(),
|
||||
|
||||
Reference in New Issue
Block a user