idk stuff, need to try on another machine

This commit is contained in:
2024-09-12 19:12:44 -04:00
parent b6db483189
commit 244440c38a
9 changed files with 305 additions and 232 deletions

View File

@@ -162,7 +162,7 @@ impl Client<'_> {
match event {
WindowEvent::CloseRequested => self.exit = true,
WindowEvent::Resized(size) => self.renderer.resize(size),
WindowEvent::RedrawRequested => self.renderer.draw(),
// WindowEvent::RedrawRequested => self.renderer.draw(),
WindowEvent::CursorLeft { .. } => {
self.input.clear();
}

View File

@@ -110,7 +110,7 @@ impl<'a> Renderer<'a> {
label: None,
timestamp_writes: None,
});
self.voxel_pipeline.compute(&mut compute_pass, self.config.width, self.config.height);
self.voxel_pipeline.compute(&mut compute_pass);
drop(compute_pass);
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
@@ -123,14 +123,15 @@ impl<'a> Renderer<'a> {
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
}),
// depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
// view: &self.depth_texture.view,
// depth_ops: Some(wgpu::Operations {
// load: wgpu::LoadOp::Clear(1.0),
// store: wgpu::StoreOp::Store,
// }),
// stencil_ops: None,
// }),
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

View File

@@ -54,7 +54,7 @@ impl DepthTexture {
pub struct StorageTexture {
binding: u32,
visibility: wgpu::ShaderStages,
pub texture: wgpu::Texture,
pub buf: wgpu::Texture,
pub view: wgpu::TextureView,
pub sampler: wgpu::Sampler,
}
@@ -97,7 +97,7 @@ impl StorageTexture {
Self {
visibility,
binding,
texture,
buf: texture,
view,
sampler,
}

View File

@@ -28,9 +28,12 @@ struct VoxelGroup {
};
@compute
@workgroup_size(16, 16, 1)
@workgroup_size(8, 8, 1)
fn main(@builtin(global_invocation_id) cell: vec3<u32>) {
// get position of the pixel; eye at origin, pixel on plane z = 1
if cell.x >= view.width || cell.y >= view.height {
return;
}
let win_dim = vec2<f32>(f32(view.width), f32(view.height));
let aspect = win_dim.y / win_dim.x;
let pixel_pos = vec3<f32>(
@@ -41,8 +44,11 @@ fn main(@builtin(global_invocation_id) cell: vec3<u32>) {
let dir = view.transform * vec4<f32>(normalize(pixel_pos), 0.0);
var color = trace_full(pos, dir);
// var color = vec4<f32>(0.0);
let light_mult = clamp((-dot(dir.xyz, global_lights[0].dir) - 0.99) * 200.0, 0.0, 1.0);
let sky_color = light_mult * vec3<f32>(1.0, 1.0, 1.0);
let sun_color = light_mult * vec3<f32>(1.0, 1.0, 1.0);
let sky_bg = vec3<f32>(0.3, 0.6, 1.0);
let sky_color = sun_color + sky_bg * (1.0 - light_mult);
color += vec4<f32>(sky_color * (1.0 - color.a), 1.0 - color.a);
color.a = 1.0;
textureStore(output, cell.xy, color);
@@ -51,7 +57,7 @@ fn main(@builtin(global_invocation_id) cell: vec3<u32>) {
const ZERO3F = vec3<f32>(0.0);
const ZERO2F = vec2<f32>(0.0);
const DEPTH = 16u;
const FULL_ALPHA = 0.9999;
const FULL_ALPHA = 0.999;
fn trace_full(pos_view: vec4<f32>, dir_view: vec4<f32>) -> vec4<f32> {
let gi = 0;

View File

@@ -149,13 +149,7 @@ impl VoxelPipeline {
unclipped_depth: false,
conservative: false,
},
depth_stencil: Some(wgpu::DepthStencilState {
format: DepthTexture::DEPTH_FORMAT,
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
}),
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
@@ -309,10 +303,10 @@ impl VoxelPipeline {
.update(device, encoder, belt, size, &updates);
self.id_map.insert(id, (i, group));
self.update_bind_group(device);
self.update_cbind_group(device);
}
pub fn update_bind_group(&mut self, device: &wgpu::Device) {
pub fn update_cbind_group(&mut self, device: &wgpu::Device) {
self.cbind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &self.cbind_group_layout,
entries: &[
@@ -338,7 +332,7 @@ impl VoxelPipeline {
wgpu::ShaderStages::COMPUTE | wgpu::ShaderStages::FRAGMENT,
4,
);
self.update_bind_group(device);
self.update_cbind_group(device);
self.bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &self.bind_group_layout,
entries: &[
@@ -405,9 +399,14 @@ impl VoxelPipeline {
render_pass.draw(0..4, 0..1);
}
pub fn compute(&self, pass: &mut wgpu::ComputePass, w: u32, h: u32) {
pub const WORKGROUP_SIZE: u32 = 8;
pub fn compute(&self, pass: &mut wgpu::ComputePass) {
pass.set_pipeline(&self.compute_pipeline);
pass.set_bind_group(0, &self.cbind_group, &[]);
pass.dispatch_workgroups(w / 16, h / 16, 1);
let buf = &self.texture.buf;
let x = (buf.width() - 1) / Self::WORKGROUP_SIZE + 1;
let y = (buf.height() - 1) / Self::WORKGROUP_SIZE + 1;
pass.dispatch_workgroups(x, y, 1);
}
}