|
|
|
@ -33,11 +33,13 @@ use crate::current_ui;
|
|
|
|
|
use crate::geometry::{load_obj, RawMesh, Vertex};
|
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
|
use crate::render::{EntityUniforms, ForwardUniforms, ShadowUniforms};
|
|
|
|
|
use crate::render::{EntityUniforms, ForwardUniforms, ShadowUniforms, CameraProjectionView};
|
|
|
|
|
|
|
|
|
|
/// A render pass consists of a pipeline, bindgroup, and uniform buf
|
|
|
|
|
/// The uniform buf is just the ShadowUniforms or ForwardUniforms
|
|
|
|
|
/// They are uniform across all cu's.
|
|
|
|
|
/// And the bindgroup is just the localbindgroup (the EntityUniforms) and the rest
|
|
|
|
|
///
|
|
|
|
|
pub struct Pass {
|
|
|
|
|
pub pipeline: wgpu::RenderPipeline,
|
|
|
|
|
pub bind_group: wgpu::BindGroup,
|
|
|
|
@ -45,6 +47,7 @@ pub struct Pass {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct RenderState {
|
|
|
|
|
|
|
|
|
|
swapchain: SwapChain,
|
|
|
|
|
swapchain_description: SwapChainDescriptor,
|
|
|
|
|
instance: Arc<Instance>,
|
|
|
|
@ -62,6 +65,8 @@ pub struct RenderState {
|
|
|
|
|
pub(in crate::render) forward_pass: Pass,
|
|
|
|
|
pub(in crate::render) forward_depth: wgpu::TextureView,
|
|
|
|
|
|
|
|
|
|
pub(in crate::render) gbuffer_pass: Pass,
|
|
|
|
|
|
|
|
|
|
entity_bind_group_layout: BindGroupLayout,
|
|
|
|
|
|
|
|
|
|
pub(in crate::render) light_uniform_buf: wgpu::Buffer,
|
|
|
|
@ -302,6 +307,107 @@ impl RenderState {
|
|
|
|
|
hands-off global lighting / point lights
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
// Pretty sure this is the camera projction
|
|
|
|
|
let bind_group_layout =
|
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
|
|
|
label: Some("g-buffer input pass bindgroup layout (cam)"),
|
|
|
|
|
entries: &[wgpu::BindGroupLayoutEntry {
|
|
|
|
|
binding: 0, // global
|
|
|
|
|
visibility: wgpu::ShaderStage::VERTEX,
|
|
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
|
ty: wgpu::BufferBindingType::Uniform,
|
|
|
|
|
min_binding_size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
|
has_dynamic_offset: false,
|
|
|
|
|
},
|
|
|
|
|
count: None,
|
|
|
|
|
}],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 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"),
|
|
|
|
|
layout: &bind_group_layout,
|
|
|
|
|
entries: &[
|
|
|
|
|
wgpu::BindGroupEntry {
|
|
|
|
|
binding: 0,
|
|
|
|
|
resource: wgpu::BindingResource::Buffer {
|
|
|
|
|
buffer: &uniform_buf,
|
|
|
|
|
offset: 0,
|
|
|
|
|
size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 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"));
|
|
|
|
|
|
|
|
|
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
|
label: Some("shadow"),
|
|
|
|
|
layout: Some(&pipeline_layout),
|
|
|
|
|
|
|
|
|
|
vertex: VertexState {
|
|
|
|
|
module: &vs_module,
|
|
|
|
|
entry_point: "main",
|
|
|
|
|
buffers: &[vb_desc.clone()],
|
|
|
|
|
},
|
|
|
|
|
fragment: Some(FragmentState {
|
|
|
|
|
module: &fs_module,
|
|
|
|
|
entry_point: "main",
|
|
|
|
|
targets: &[],
|
|
|
|
|
}),
|
|
|
|
|
primitive: wgpu::PrimitiveState {
|
|
|
|
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
|
|
|
front_face: wgpu::FrontFace::Ccw,
|
|
|
|
|
cull_mode: wgpu::CullMode::Back,
|
|
|
|
|
..Default::default()
|
|
|
|
|
},
|
|
|
|
|
depth_stencil: Some(wgpu::DepthStencilState {
|
|
|
|
|
format: Self::SHADOW_FORMAT,
|
|
|
|
|
depth_write_enabled: true,
|
|
|
|
|
depth_compare: wgpu::CompareFunction::LessEqual,
|
|
|
|
|
stencil: wgpu::StencilState::default(),
|
|
|
|
|
bias: wgpu::DepthBiasState {
|
|
|
|
|
constant: 2, // corresponds to bilinear filtering
|
|
|
|
|
slope_scale: 2.0,
|
|
|
|
|
clamp: 0.0,
|
|
|
|
|
},
|
|
|
|
|
clamp_depth: device.features().contains(wgpu::Features::DEPTH_CLAMPING),
|
|
|
|
|
}),
|
|
|
|
|
multisample: wgpu::MultisampleState::default(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Pass {
|
|
|
|
|
pipeline,
|
|
|
|
|
bind_group,
|
|
|
|
|
uniform_buf,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let shadow_pass = {
|
|
|
|
|
let uniform_size = mem::size_of::<ShadowUniforms>() as wgpu::BufferAddress;
|
|
|
|
|
|
|
|
|
@ -356,14 +462,6 @@ impl RenderState {
|
|
|
|
|
size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wgpu::BindGroupEntry {
|
|
|
|
|
binding: 1,
|
|
|
|
|
resource: wgpu::BindingResource::Buffer {
|
|
|
|
|
buffer: &g_buffer,
|
|
|
|
|
offset: 0,
|
|
|
|
|
size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
label: Some("Shadow uniform bind group"),
|
|
|
|
|
});
|
|
|
|
@ -655,6 +753,7 @@ impl RenderState {
|
|
|
|
|
shadow_pass,
|
|
|
|
|
forward_pass,
|
|
|
|
|
forward_depth: depth_texture.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
|
|
|
gbuffer_pass: g_buffer_pass,
|
|
|
|
|
entity_bind_group_layout: entity_bind_group_layout,
|
|
|
|
|
shadow_target_views: shadow_target_views,
|
|
|
|
|
light_uniform_buf,
|
|
|
|
|