|
|
|
@ -65,8 +65,13 @@ pub struct RenderState {
|
|
|
|
|
pub(in crate::render) forward_pass: Pass,
|
|
|
|
|
pub(in crate::render) forward_depth: wgpu::TextureView,
|
|
|
|
|
|
|
|
|
|
// Gbuffer bs
|
|
|
|
|
pub(in crate::render) gbuffer_pass: Pass,
|
|
|
|
|
pub(in crate::render) gbuffer_cam_projection_buffer: wgpu::Buffer,
|
|
|
|
|
pub(in crate::render) gbuffer_depth: wgpu::TextureView,
|
|
|
|
|
pub(in crate::render) gbuffer_target_views: Vec<Arc<TextureView>>,
|
|
|
|
|
|
|
|
|
|
// this is for the set=1 entity uniforms
|
|
|
|
|
entity_bind_group_layout: BindGroupLayout,
|
|
|
|
|
|
|
|
|
|
pub(in crate::render) light_uniform_buf: wgpu::Buffer,
|
|
|
|
@ -310,8 +315,17 @@ impl RenderState {
|
|
|
|
|
// This pass is just going to forward the vertex info to the fragments
|
|
|
|
|
// And they are going to render to the gbuffer
|
|
|
|
|
let g_buffer_pass = {
|
|
|
|
|
|
|
|
|
|
let uniform_size = mem::size_of::<CameraProjectionView>() as wgpu::BufferAddress;
|
|
|
|
|
|
|
|
|
|
// The g-buffers camera projection matrix that we stream data to
|
|
|
|
|
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
|
|
|
|
label: Some("g-buffers CameraProjectionView uniform buffer"),
|
|
|
|
|
size: uniform_size,
|
|
|
|
|
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
|
|
|
mapped_at_creation: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Pretty sure this is the camera projction
|
|
|
|
|
let bind_group_layout =
|
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
|
|
@ -328,24 +342,8 @@ impl RenderState {
|
|
|
|
|
}],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Pipeline is similar between passes, but with a different label
|
|
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
|
|
|
|
label: Some("g-buffer input pipeline layout"),
|
|
|
|
|
bind_group_layouts: &[&bind_group_layout, &entity_bind_group_layout],
|
|
|
|
|
push_constant_ranges: &[],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Holds the shadow uniforms, which is just a 4 vec of quaternians
|
|
|
|
|
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
|
|
|
|
label: Some("shadow pass shadow uniform buffer"),
|
|
|
|
|
size: uniform_size,
|
|
|
|
|
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
|
|
|
mapped_at_creation: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create bind group
|
|
|
|
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
|
|
|
label: Some("Shadow uniform bind group"),
|
|
|
|
|
label: Some("g-buffers uniform bind group"),
|
|
|
|
|
layout: &bind_group_layout,
|
|
|
|
|
entries: &[
|
|
|
|
|
wgpu::BindGroupEntry {
|
|
|
|
@ -360,12 +358,19 @@ impl RenderState {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create the render pipeline
|
|
|
|
|
let vs_module =
|
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.vert.spv"));
|
|
|
|
|
let fs_module =
|
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.frag.spv"));
|
|
|
|
|
|
|
|
|
|
// The bind group layouts are accessed by layout(set = X, binding = x)
|
|
|
|
|
// in the shader.
|
|
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
|
|
|
|
label: Some("g-buffer input pipeline layout"),
|
|
|
|
|
bind_group_layouts: &[&bind_group_layout, &entity_bind_group_layout],
|
|
|
|
|
push_constant_ranges: &[],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
|
label: Some("shadow"),
|
|
|
|
|
layout: Some(&pipeline_layout),
|
|
|
|
@ -514,6 +519,19 @@ impl RenderState {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Pre init the gbuffers camera projection uniform
|
|
|
|
|
let gbuffer_cam_uniform_size =
|
|
|
|
|
mem::size_of::<CameraProjectionView>() as wgpu::BufferAddress;
|
|
|
|
|
|
|
|
|
|
let gbuffer_cam_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
|
|
|
|
label: Some("g-buffer camera projection uniform buffer"),
|
|
|
|
|
size: gbuffer_cam_uniform_size,
|
|
|
|
|
usage: wgpu::BufferUsage::UNIFORM
|
|
|
|
|
| wgpu::BufferUsage::COPY_SRC
|
|
|
|
|
| wgpu::BufferUsage::COPY_DST,
|
|
|
|
|
mapped_at_creation: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Pre init the light uniform, with slots enough for MAX_LIGHTS
|
|
|
|
|
let light_uniform_size =
|
|
|
|
|
(Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
|
|
|
|
@ -559,6 +577,16 @@ impl RenderState {
|
|
|
|
|
50.0,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let g_buffer_camera_projection_matrix = CameraProjectionView {
|
|
|
|
|
proj: *mx_projection.as_ref(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let g_buffer_camera_projection_uniform = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
|
label: Some("g-buffer camera projection uniform buffer"),
|
|
|
|
|
contents: bytemuck::bytes_of(&g_buffer_camera_projection_matrix),
|
|
|
|
|
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let forward_pass = {
|
|
|
|
|
// Create pipeline layout
|
|
|
|
|
let bind_group_layout =
|
|
|
|
@ -722,7 +750,7 @@ impl RenderState {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
|
|
|
|
let forward_depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
|
|
|
|
size: wgpu::Extent3d {
|
|
|
|
|
width: sc_desc.width,
|
|
|
|
|
height: sc_desc.height,
|
|
|
|
@ -733,9 +761,38 @@ impl RenderState {
|
|
|
|
|
dimension: wgpu::TextureDimension::D2,
|
|
|
|
|
format: Self::DEPTH_FORMAT,
|
|
|
|
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
|
|
|
|
label: Some("Depth Texture"),
|
|
|
|
|
label: Some("Forward Depth Texture"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let g_buffer_depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
|
|
|
|
size: wgpu::Extent3d {
|
|
|
|
|
width: sc_desc.width,
|
|
|
|
|
height: sc_desc.height,
|
|
|
|
|
depth: 1,
|
|
|
|
|
},
|
|
|
|
|
mip_level_count: 1,
|
|
|
|
|
sample_count: 1,
|
|
|
|
|
dimension: wgpu::TextureDimension::D2,
|
|
|
|
|
format: Self::DEPTH_FORMAT,
|
|
|
|
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
|
|
|
|
label: Some("g-buffer depth texture"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let mut g_buffer_depth_texture_views = (0..2)
|
|
|
|
|
.map(|i| {
|
|
|
|
|
Arc::new(shadow_texture.create_view(&wgpu::TextureViewDescriptor {
|
|
|
|
|
label: Some("g-buffer depth texture"),
|
|
|
|
|
format: None,
|
|
|
|
|
dimension: Some(wgpu::TextureViewDimension::D2),
|
|
|
|
|
aspect: wgpu::TextureAspect::All,
|
|
|
|
|
base_mip_level: 0,
|
|
|
|
|
level_count: None,
|
|
|
|
|
base_array_layer: i as u32,
|
|
|
|
|
array_layer_count: NonZeroU32::new(1),
|
|
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
// Imgui renderer
|
|
|
|
|
let renderer_config = ImguiRendererConfig {
|
|
|
|
|
texture_format: sc_desc.format,
|
|
|
|
@ -745,6 +802,12 @@ impl RenderState {
|
|
|
|
|
ImguiRenderer::new(&mut imgui_context.context, &device, &queue, renderer_config);
|
|
|
|
|
|
|
|
|
|
RenderState {
|
|
|
|
|
|
|
|
|
|
gbuffer_pass: g_buffer_pass,
|
|
|
|
|
gbuffer_cam_projection_buffer: g_buffer_camera_projection_uniform,
|
|
|
|
|
gbuffer_depth: g_buffer_depth_texture.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
|
|
|
gbuffer_target_views: g_buffer_depth_texture_views,
|
|
|
|
|
|
|
|
|
|
swapchain: swap_chain,
|
|
|
|
|
queue: queue,
|
|
|
|
|
size,
|
|
|
|
@ -752,8 +815,7 @@ impl RenderState {
|
|
|
|
|
lights_are_dirty: true,
|
|
|
|
|
shadow_pass,
|
|
|
|
|
forward_pass,
|
|
|
|
|
forward_depth: depth_texture.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
|
|
|
gbuffer_pass: g_buffer_pass,
|
|
|
|
|
forward_depth: forward_depth_texture.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
|
|
|
entity_bind_group_layout: entity_bind_group_layout,
|
|
|
|
|
shadow_target_views: shadow_target_views,
|
|
|
|
|
light_uniform_buf,
|
|
|
|
|