Compare commits

...

3 Commits

13 changed files with 43 additions and 37 deletions

View File

@ -9,8 +9,8 @@ use winit::{
use super::camera; use super::camera;
use crate::{ use crate::{
gfx::{self, Renderer}, gfx,
voxel, voxel::{self, brickmap::BrickmapRenderer, VoxelRenderer},
}; };
pub struct App<'window> { pub struct App<'window> {
@ -82,7 +82,7 @@ impl<'window> App<'window> {
glam::uvec3(32, 32, 32), glam::uvec3(32, 32, 32),
); );
let mut renderer = voxel::VoxelRenderer::new(&self.render_ctx, &camera_controller)?; let mut renderer = BrickmapRenderer::new(&self.render_ctx, &camera_controller)?;
let mut cumulative_dt = 0.0; let mut cumulative_dt = 0.0;
let mut frames_accumulated = 0.0; let mut frames_accumulated = 0.0;

View File

@ -1,13 +1,11 @@
mod bind_group; mod bind_group;
mod buffer; mod buffer;
mod context; mod context;
mod renderer;
mod texture; mod texture;
pub use self::{ pub use self::{
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder}, bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
buffer::{BufferExt, BulkBufferBuilder}, buffer::{BufferExt, BulkBufferBuilder},
context::Context, context::Context,
renderer::Renderer,
texture::{Texture, TextureBuilder}, texture::{Texture, TextureBuilder},
}; };

View File

@ -1,8 +0,0 @@
use std::time::Duration;
use anyhow::Result;
pub trait Renderer {
fn update(&mut self, dt: &Duration, context: &super::Context) -> Result<()>;
fn render(&self, context: &super::Context) -> Result<()>;
}

View File

@ -0,0 +1,9 @@
mod brickgrid;
mod brickmap_cache;
mod manager;
mod renderer;
mod shading_table;
mod util;
pub use manager::BrickmapManager;
pub use renderer::BrickmapRenderer;

View File

@ -2,24 +2,30 @@ use std::time::Duration;
use anyhow::Result; use anyhow::Result;
use crate::{core, gfx}; use crate::{
core, gfx,
voxel::{renderer::VoxelRenderer, world::WorldManager},
};
use super::BrickmapManager;
#[derive(Debug)] #[derive(Debug)]
pub struct VoxelRenderer { pub struct BrickmapRenderer {
clear_color: wgpu::Color, clear_color: wgpu::Color,
render_texture: gfx::Texture, render_texture: gfx::Texture,
render_pipeline: wgpu::RenderPipeline, render_pipeline: wgpu::RenderPipeline,
brickmap_manager: super::brickworld::BrickmapManager, brickmap_manager: BrickmapManager,
raycast_pipeline: wgpu::ComputePipeline, raycast_pipeline: wgpu::ComputePipeline,
raycast_bind_group: wgpu::BindGroup, raycast_bind_group: wgpu::BindGroup,
unpack_pipeline: wgpu::ComputePipeline, unpack_pipeline: wgpu::ComputePipeline,
unpack_bind_group: wgpu::BindGroup, unpack_bind_group: wgpu::BindGroup,
} }
impl VoxelRenderer { impl BrickmapRenderer {
pub fn new(context: &gfx::Context, camera_controller: &core::CameraController) -> Result<Self> { pub fn new(context: &gfx::Context, camera_controller: &core::CameraController) -> Result<Self> {
log::info!("Creating render shader..."); log::info!("Creating render shader...");
let shader_descriptor = wgpu::include_wgsl!("../../assets/shaders/shader.wgsl"); // TODO: Load the shader better
let shader_descriptor = wgpu::include_wgsl!("../../../assets/shaders/shader.wgsl");
let shader = context.device.create_shader_module(shader_descriptor); let shader = context.device.create_shader_module(shader_descriptor);
log::info!("Creating render texture..."); log::info!("Creating render texture...");
@ -64,7 +70,7 @@ impl VoxelRenderer {
}); });
log::info!("Creating brickmap manager..."); log::info!("Creating brickmap manager...");
let brickmap_manager = super::brickworld::BrickmapManager::new( let brickmap_manager = BrickmapManager::new(
context, context,
glam::uvec3(512, 64, 512), glam::uvec3(512, 64, 512),
usize::pow(64, 3), usize::pow(64, 3),
@ -74,7 +80,8 @@ impl VoxelRenderer {
); );
log::info!("Creating compute pipelines..."); log::info!("Creating compute pipelines...");
let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/brickmap_upload.wgsl"); // TODO: Load the shader better
let cs_descriptor = wgpu::include_wgsl!("../../../assets/shaders/brickmap_upload.wgsl");
let cs = context.device.create_shader_module(cs_descriptor); let cs = context.device.create_shader_module(cs_descriptor);
let unpack_layout = gfx::BindGroupLayoutBuilder::new() let unpack_layout = gfx::BindGroupLayoutBuilder::new()
.with_label("GPU Unpack BGL") .with_label("GPU Unpack BGL")
@ -119,7 +126,8 @@ impl VoxelRenderer {
entry_point: "compute", entry_point: "compute",
}); });
let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/voxel_volume.wgsl"); // TODO: Load the shader better
let cs_descriptor = wgpu::include_wgsl!("../../../assets/shaders/voxel_volume.wgsl");
let cs = context.device.create_shader_module(cs_descriptor); let cs = context.device.create_shader_module(cs_descriptor);
let raycast_layout = gfx::BindGroupLayoutBuilder::new() let raycast_layout = gfx::BindGroupLayoutBuilder::new()
.with_label("Voxel Raycast BGL") .with_label("Voxel Raycast BGL")
@ -178,17 +186,13 @@ impl VoxelRenderer {
}) })
} }
pub fn update_brickmap( pub fn update_brickmap(&mut self, context: &gfx::Context, world: &mut WorldManager) {
&mut self,
context: &gfx::Context,
world: &mut super::world::WorldManager,
) {
self.brickmap_manager self.brickmap_manager
.process_feedback_buffer(context, world); .process_feedback_buffer(context, world);
} }
} }
impl gfx::Renderer for VoxelRenderer { impl VoxelRenderer for BrickmapRenderer {
fn render(&self, context: &gfx::Context) -> Result<()> { fn render(&self, context: &gfx::Context) -> Result<()> {
let frame = context.surface.get_current_texture()?; let frame = context.surface.get_current_texture()?;
let view = frame let view = frame

View File

@ -1,7 +0,0 @@
mod brickgrid;
mod brickmap;
mod brickmap_cache;
mod shading_table;
mod util;
pub use brickmap::BrickmapManager;

View File

@ -1,5 +1,5 @@
pub mod brickworld; pub mod brickmap;
mod voxel_renderer; mod renderer;
pub mod world; pub mod world;
pub use voxel_renderer::*; pub use renderer::VoxelRenderer;

10
src/voxel/renderer.rs Normal file
View File

@ -0,0 +1,10 @@
use std::time::Duration;
use anyhow::Result;
use crate::gfx::Context;
pub trait VoxelRenderer {
fn update(&mut self, dt: &Duration, context: &Context) -> Result<()>;
fn render(&self, context: &Context) -> Result<()>;
}