finally, zbufferium

ecs
q3k 2020-03-16 01:03:59 +01:00
parent 63d276f664
commit a792b18eb8
4 changed files with 30 additions and 7 deletions

View File

@ -50,7 +50,7 @@ fn main() {
for x in -10..10 {
for y in -10..10 {
for z in -10..10 {
let transform = cgm::Matrix4::from_translation(cgm::Vector3::new((x as f32)*4.0, (y as f32)*2.0, (z as f32)*4.0));
let transform = cgm::Matrix4::from_translation(cgm::Vector3::new((x as f32)*4.0, (y as f32)*4.0, (z as f32)*4.0));
let cube = render::renderable::Object {
mesh: mesh_cube.clone(),
transform
@ -76,7 +76,7 @@ fn main() {
cgm::Point3::new(
position.cos() * 10.0 * (((position*2.0).cos()/2.0)+1.0),
position.sin() * 10.0 * (((position*2.0).cos()/2.0)+1.0),
2.0
3.0
),
cgm::Point3::new(0.0, 0.0, 0.0),
cgm::Vector3::new(0.0, 0.0, 1.0)

View File

@ -207,7 +207,7 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
let mut primary = vc::AutoCommandBufferBuilder::primary_one_time_submit(device.clone(), qf)
.unwrap()
.begin_render_pass(framebuffer.clone(), false, vec![[0.0, 0.0, 0.0, 1.0].into()])
.begin_render_pass(framebuffer.clone(), false, vec![[0.0, 0.0, 0.0, 1.0].into(), vulkano::format::ClearValue::Depth(1.0)])
.unwrap();

View File

@ -116,6 +116,7 @@ impl Forward {
.cull_mode_back()
.front_face_counter_clockwise()
.blend_pass_through()
.depth_stencil(vulkano::pipeline::depth_stencil::DepthStencil::simple_depth_test())
.render_pass(vf::Subpass::from(render_pass.clone(), 0).unwrap())
.build(device.clone())
.unwrap())

View File

@ -67,8 +67,15 @@ impl<WT: 'static + Send + Sync> SwapchainBinding<WT> {
log::info!("Swap chain: present mode {:?}, {} images", present_mode, images.len());
let render_pass = Self::create_render_pass(surface_binding, chain.format());
let framebuffers = Self::create_framebuffers(render_pass.clone(), images.clone());
let depth_format = Self::find_depth_format();
let depth_image = vm::AttachmentImage::with_usage(
surface_binding.device.clone(),
chain.dimensions(),
depth_format,
vm::ImageUsage { depth_stencil_attachment: true, ..vm::ImageUsage::none() },
).unwrap();
let render_pass = Self::create_render_pass(surface_binding, chain.format(), depth_format);
let framebuffers = Self::create_framebuffers(render_pass.clone(), images.clone(), depth_image);
Self {
chain,
@ -80,7 +87,8 @@ impl<WT: 'static + Send + Sync> SwapchainBinding<WT> {
fn create_render_pass(
surface_binding: &super::surface_binding::SurfaceBinding<WT>,
color_format: vulkano::format::Format,
color_format: vf::Format,
depth_format: vf::Format,
) -> Arc<dyn vfb::RenderPassAbstract + Send + Sync> {
let device = surface_binding.device.clone();
@ -91,11 +99,19 @@ impl<WT: 'static + Send + Sync> SwapchainBinding<WT> {
store: Store,
format: color_format,
samples: 1,
},
depth: {
load: Clear,
store: DontCare,
format: depth_format,
samples: 1,
initial_layout: ImageLayout::Undefined,
final_layout: ImageLayout::DepthStencilAttachmentOptimal,
}
},
pass: {
color: [color],
depth_stencil: {}
depth_stencil: {depth}
}
).unwrap())
}
@ -103,11 +119,13 @@ impl<WT: 'static + Send + Sync> SwapchainBinding<WT> {
fn create_framebuffers(
render_pass: Arc<dyn vfb::RenderPassAbstract + Send + Sync>,
images: Vec<Arc<vm::SwapchainImage<WT>>>,
depth_image: Arc<vm::AttachmentImage<vf::Format>>,
) -> Vec<Arc<dyn vfb::FramebufferAbstract + Send + Sync>> {
images.iter()
.map(|image| {
let fba: Arc<dyn vfb::FramebufferAbstract + Send + Sync> = Arc::new(vfb::Framebuffer::start(render_pass.clone())
.add(image.clone()).unwrap()
.add(depth_image.clone()).unwrap()
.build().unwrap());
fba
})
@ -137,5 +155,9 @@ impl<WT: 'static + Send + Sync> SwapchainBinding<WT> {
capabilities.current_extent.expect("could not get current extent")
}
fn find_depth_format() -> vf::Format {
// TODO: actually do it
vf::Format::D16Unorm
}
}