--wip-- [skip ci]

This commit is contained in:
2025-07-01 23:18:28 +01:00
parent 349813c608
commit 33baf4ede9
4 changed files with 99 additions and 11 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ const vec2 full_screen_triangle[3] = {
}; };
void main() { void main() {
vec2 tri = (full_screen_triangle[gl_VertexIndex] * 2.0) - 1.0; vec2 tri = (full_screen_triangle[gl_VertexIndex - gl_BaseVertex] * 2.0) - 1.0;
v_pos = tri; v_pos = tri;
gl_Position = vec4(v_pos, 0.5, 1.0); gl_Position = vec4(v_pos, gl_BaseVertex / 65536.0 , 1.0);
} }
+1
View File
@@ -6,6 +6,7 @@ layout(push_constant) uniform PushConstantData {
vec3 dimensions; vec3 dimensions;
vec3 lowest_corner; vec3 lowest_corner;
uint enable[16]; uint enable[16];
float material;
} pc; } pc;
layout(set = 0, binding = 0) uniform Lights { layout(set = 0, binding = 0) uniform Lights {
+93 -9
View File
@@ -47,7 +47,10 @@ use vulkano::{
QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType, QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType,
}, },
format::Format, format::Format,
image::{Image, ImageCreateInfo, ImageType, ImageUsage, SampleCount, view::ImageView}, image::{
Image, ImageCreateInfo, ImageType, ImageUsage, SampleCount,
view::{ImageView, ImageViewCreateInfo},
},
instance::{Instance, InstanceCreateInfo, InstanceExtensions}, instance::{Instance, InstanceCreateInfo, InstanceExtensions},
memory::allocator::{ memory::allocator::{
AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, StandardMemoryAllocator, AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, StandardMemoryAllocator,
@@ -59,7 +62,7 @@ use vulkano::{
graphics::{ graphics::{
GraphicsPipelineCreateInfo, GraphicsPipelineCreateInfo,
color_blend::{ColorBlendAttachmentState, ColorBlendState}, color_blend::{ColorBlendAttachmentState, ColorBlendState},
depth_stencil::{DepthState, DepthStencilState}, depth_stencil::{CompareOp, DepthState, DepthStencilState},
input_assembly::InputAssemblyState, input_assembly::InputAssemblyState,
multisample::MultisampleState, multisample::MultisampleState,
rasterization::{CullMode, FrontFace, PolygonMode, RasterizationState}, rasterization::{CullMode, FrontFace, PolygonMode, RasterizationState},
@@ -211,6 +214,8 @@ struct RenderContext {
render_pass: Arc<RenderPass>, render_pass: Arc<RenderPass>,
framebuffers: Vec<Arc<Framebuffer>>, framebuffers: Vec<Arc<Framebuffer>>,
color_buffer: Arc<ImageView>, color_buffer: Arc<ImageView>,
material_colour_buffer: Arc<ImageView>,
material_depth_buffer: Arc<ImageView>,
normal_buffer: Arc<ImageView>, normal_buffer: Arc<ImageView>,
depth_buffer: Arc<ImageView>, depth_buffer: Arc<ImageView>,
shader_modules: ShaderModules, shader_modules: ShaderModules,
@@ -512,6 +517,7 @@ impl App {
geometry_shader: true, geometry_shader: true,
maintenance4: true, maintenance4: true,
fill_mode_non_solid: true, fill_mode_non_solid: true,
shader_draw_parameters: true,
..DeviceFeatures::empty() ..DeviceFeatures::empty()
}, },
..Default::default() ..Default::default()
@@ -781,6 +787,18 @@ impl ApplicationHandler for App {
load_op: Clear, load_op: Clear,
store_op: Store, store_op: Store,
}, },
material_as_colour: {
format: Format::R16_UNORM,
samples: 1,
load_op: Clear,
store_op: DontCare,
},
material_as_depth: {
format: Format::D,
samples: 1,
load_op: Load,
store_op: DontCare,
},
color: { color: {
format: Format::A2B10G10R10_UNORM_PACK32, format: Format::A2B10G10R10_UNORM_PACK32,
samples: 1, samples: 1,
@@ -801,13 +819,13 @@ impl ApplicationHandler for App {
}, },
}, },
passes: [{ passes: [{
color: [], color: [material_as_colour],
depth_stencil: {depth}, depth_stencil: {depth},
input: [], input: [],
}, },
{ {
color: [color, normals], color: [color, normals],
depth_stencil: {}, depth_stencil: {material_as_depth},
input: [depth], input: [depth],
}, },
{ {
@@ -829,8 +847,14 @@ impl ApplicationHandler for App {
depth_range: 0.0..=1.0, depth_range: 0.0..=1.0,
}; };
let (framebuffers, color_buffer, normal_buffer, depth_buffer) = let (
framebuffer_generation(&images, &render_pass, &self.memory_allocator); framebuffers,
color_buffer,
material_colour_buffer,
material_depth_buffer,
normal_buffer,
depth_buffer,
) = framebuffer_generation(&images, &render_pass, &self.memory_allocator);
let lighting_pipeline = pipeline_recompile( let lighting_pipeline = pipeline_recompile(
&render_pass, &render_pass,
@@ -862,6 +886,8 @@ impl ApplicationHandler for App {
render_pass, render_pass,
framebuffers, framebuffers,
color_buffer, color_buffer,
material_colour_buffer,
material_depth_buffer,
normal_buffer, normal_buffer,
depth_buffer, depth_buffer,
shader_modules, shader_modules,
@@ -1031,6 +1057,8 @@ impl App {
( (
rcx.framebuffers, rcx.framebuffers,
rcx.color_buffer, rcx.color_buffer,
rcx.material_colour_buffer,
rcx.material_depth_buffer,
rcx.normal_buffer, rcx.normal_buffer,
rcx.depth_buffer, rcx.depth_buffer,
) = framebuffer_generation(&new_images, &rcx.render_pass, &self.memory_allocator); ) = framebuffer_generation(&new_images, &rcx.render_pass, &self.memory_allocator);
@@ -1174,6 +1202,7 @@ impl App {
dimensions: Vec3::ONE.to_array().into(), dimensions: Vec3::ONE.to_array().into(),
lowest_corner: Vec3::ZERO.into(), lowest_corner: Vec3::ZERO.into(),
enable: [0; 16], enable: [0; 16],
material: 0.,
}; };
let uniform_data = implicit_vs::Camera { let uniform_data = implicit_vs::Camera {
@@ -1504,6 +1533,8 @@ fn framebuffer_generation(
Arc<ImageView>, Arc<ImageView>,
Arc<ImageView>, Arc<ImageView>,
Arc<ImageView>, Arc<ImageView>,
Arc<ImageView>,
Arc<ImageView>,
) { ) {
let depth_buffer = ImageView::new_default( let depth_buffer = ImageView::new_default(
Image::new( Image::new(
@@ -1541,6 +1572,41 @@ fn framebuffer_generation(
) )
.unwrap(); .unwrap();
let material_image = Image::new(
allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::D16_UNORM,
extent: images[0].extent(),
usage: ImageUsage::COLOR_ATTACHMENT
| ImageUsage::DEPTH_STENCIL_ATTACHMENT
| ImageUsage::TRANSIENT_ATTACHMENT,
..Default::default()
},
AllocationCreateInfo::default(),
)
.unwrap();
let material_colour_buffer = ImageView::new(
material_image.clone(),
ImageViewCreateInfo {
format: Format::R16_UNORM,
usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT,
..ImageViewCreateInfo::from_image(&material_image)
},
)
.unwrap();
let material_depth_buffer = ImageView::new(
material_image.clone(),
ImageViewCreateInfo {
format: Format::D16_UNORM,
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT,
..ImageViewCreateInfo::from_image(&material_image)
},
)
.unwrap();
let normal_buffer = ImageView::new_default( let normal_buffer = ImageView::new_default(
Image::new( Image::new(
allocator.clone(), allocator.clone(),
@@ -1568,6 +1634,8 @@ fn framebuffer_generation(
FramebufferCreateInfo { FramebufferCreateInfo {
attachments: vec![ attachments: vec![
view, view,
material_colour_buffer.clone(),
material_depth_buffer.clone(),
color_buffer.clone(), color_buffer.clone(),
normal_buffer.clone(), normal_buffer.clone(),
depth_buffer.clone(), depth_buffer.clone(),
@@ -1579,7 +1647,14 @@ fn framebuffer_generation(
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
(framebuffers, color_buffer, normal_buffer, depth_buffer) (
framebuffers,
color_buffer,
material_colour_buffer,
material_depth_buffer,
normal_buffer,
depth_buffer,
)
} }
fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConstant> { fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConstant> {
@@ -1714,7 +1789,10 @@ fn deferred_pipelines_recompile(
..Default::default() ..Default::default()
}), }),
multisample_state: Some(MultisampleState::default()), multisample_state: Some(MultisampleState::default()),
color_blend_state: None, color_blend_state: Some(ColorBlendState::with_attachment_states(
deferred_subpass.num_color_attachments(),
ColorBlendAttachmentState::default(),
)),
subpass: Some(deferred_subpass.into()), subpass: Some(deferred_subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout.clone()) ..GraphicsPipelineCreateInfo::layout(layout.clone())
}, },
@@ -1778,7 +1856,13 @@ fn deferred_pipelines_recompile(
polygon_mode: PolygonMode::Fill, polygon_mode: PolygonMode::Fill,
..RasterizationState::default() ..RasterizationState::default()
}), }),
depth_stencil_state: None, depth_stencil_state: Some(DepthStencilState {
depth: Some(DepthState {
write_enable: false,
compare_op: CompareOp::Equal,
}),
..Default::default()
}),
multisample_state: Some(MultisampleState::default()), multisample_state: Some(MultisampleState::default()),
color_blend_state: Some(ColorBlendState::with_attachment_states( color_blend_state: Some(ColorBlendState::with_attachment_states(
normals_subpass.num_color_attachments(), normals_subpass.num_color_attachments(),
+3
View File
@@ -8,6 +8,8 @@ layout(location = 0) in vec4 pos;
layout(depth_greater) out float gl_FragDepth; layout(depth_greater) out float gl_FragDepth;
layout(location = 0) out float material;
float scene(vec3 p) { float scene(vec3 p) {
return length(p) - 1.0; return length(p) - 1.0;
} }
@@ -44,6 +46,7 @@ void main() {
{ {
vec4 tpoint = camera_uniforms.proj * camera_uniforms.view * pc.world * vec4(p, 1); vec4 tpoint = camera_uniforms.proj * camera_uniforms.view * pc.world * vec4(p, 1);
gl_FragDepth = (tpoint.z / tpoint.w); gl_FragDepth = (tpoint.z / tpoint.w);
material = pc.material;
} }
else else
{ {