--wip-- [skip ci]
This commit is contained in:
@@ -11,7 +11,7 @@ const vec2 full_screen_triangle[3] = {
|
||||
};
|
||||
|
||||
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;
|
||||
gl_Position = vec4(v_pos, 0.5, 1.0);
|
||||
gl_Position = vec4(v_pos, gl_BaseVertex / 65536.0 , 1.0);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ layout(push_constant) uniform PushConstantData {
|
||||
vec3 dimensions;
|
||||
vec3 lowest_corner;
|
||||
uint enable[16];
|
||||
float material;
|
||||
} pc;
|
||||
|
||||
layout(set = 0, binding = 0) uniform Lights {
|
||||
|
||||
+93
-9
@@ -47,7 +47,10 @@ use vulkano::{
|
||||
QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType,
|
||||
},
|
||||
format::Format,
|
||||
image::{Image, ImageCreateInfo, ImageType, ImageUsage, SampleCount, view::ImageView},
|
||||
image::{
|
||||
Image, ImageCreateInfo, ImageType, ImageUsage, SampleCount,
|
||||
view::{ImageView, ImageViewCreateInfo},
|
||||
},
|
||||
instance::{Instance, InstanceCreateInfo, InstanceExtensions},
|
||||
memory::allocator::{
|
||||
AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, StandardMemoryAllocator,
|
||||
@@ -59,7 +62,7 @@ use vulkano::{
|
||||
graphics::{
|
||||
GraphicsPipelineCreateInfo,
|
||||
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
||||
depth_stencil::{DepthState, DepthStencilState},
|
||||
depth_stencil::{CompareOp, DepthState, DepthStencilState},
|
||||
input_assembly::InputAssemblyState,
|
||||
multisample::MultisampleState,
|
||||
rasterization::{CullMode, FrontFace, PolygonMode, RasterizationState},
|
||||
@@ -211,6 +214,8 @@ struct RenderContext {
|
||||
render_pass: Arc<RenderPass>,
|
||||
framebuffers: Vec<Arc<Framebuffer>>,
|
||||
color_buffer: Arc<ImageView>,
|
||||
material_colour_buffer: Arc<ImageView>,
|
||||
material_depth_buffer: Arc<ImageView>,
|
||||
normal_buffer: Arc<ImageView>,
|
||||
depth_buffer: Arc<ImageView>,
|
||||
shader_modules: ShaderModules,
|
||||
@@ -512,6 +517,7 @@ impl App {
|
||||
geometry_shader: true,
|
||||
maintenance4: true,
|
||||
fill_mode_non_solid: true,
|
||||
shader_draw_parameters: true,
|
||||
..DeviceFeatures::empty()
|
||||
},
|
||||
..Default::default()
|
||||
@@ -781,6 +787,18 @@ impl ApplicationHandler for App {
|
||||
load_op: Clear,
|
||||
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: {
|
||||
format: Format::A2B10G10R10_UNORM_PACK32,
|
||||
samples: 1,
|
||||
@@ -801,13 +819,13 @@ impl ApplicationHandler for App {
|
||||
},
|
||||
},
|
||||
passes: [{
|
||||
color: [],
|
||||
color: [material_as_colour],
|
||||
depth_stencil: {depth},
|
||||
input: [],
|
||||
},
|
||||
{
|
||||
color: [color, normals],
|
||||
depth_stencil: {},
|
||||
depth_stencil: {material_as_depth},
|
||||
input: [depth],
|
||||
},
|
||||
{
|
||||
@@ -829,8 +847,14 @@ impl ApplicationHandler for App {
|
||||
depth_range: 0.0..=1.0,
|
||||
};
|
||||
|
||||
let (framebuffers, color_buffer, normal_buffer, depth_buffer) =
|
||||
framebuffer_generation(&images, &render_pass, &self.memory_allocator);
|
||||
let (
|
||||
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(
|
||||
&render_pass,
|
||||
@@ -862,6 +886,8 @@ impl ApplicationHandler for App {
|
||||
render_pass,
|
||||
framebuffers,
|
||||
color_buffer,
|
||||
material_colour_buffer,
|
||||
material_depth_buffer,
|
||||
normal_buffer,
|
||||
depth_buffer,
|
||||
shader_modules,
|
||||
@@ -1031,6 +1057,8 @@ impl App {
|
||||
(
|
||||
rcx.framebuffers,
|
||||
rcx.color_buffer,
|
||||
rcx.material_colour_buffer,
|
||||
rcx.material_depth_buffer,
|
||||
rcx.normal_buffer,
|
||||
rcx.depth_buffer,
|
||||
) = framebuffer_generation(&new_images, &rcx.render_pass, &self.memory_allocator);
|
||||
@@ -1174,6 +1202,7 @@ impl App {
|
||||
dimensions: Vec3::ONE.to_array().into(),
|
||||
lowest_corner: Vec3::ZERO.into(),
|
||||
enable: [0; 16],
|
||||
material: 0.,
|
||||
};
|
||||
|
||||
let uniform_data = implicit_vs::Camera {
|
||||
@@ -1504,6 +1533,8 @@ fn framebuffer_generation(
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
) {
|
||||
let depth_buffer = ImageView::new_default(
|
||||
Image::new(
|
||||
@@ -1541,6 +1572,41 @@ fn framebuffer_generation(
|
||||
)
|
||||
.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(
|
||||
Image::new(
|
||||
allocator.clone(),
|
||||
@@ -1568,6 +1634,8 @@ fn framebuffer_generation(
|
||||
FramebufferCreateInfo {
|
||||
attachments: vec![
|
||||
view,
|
||||
material_colour_buffer.clone(),
|
||||
material_depth_buffer.clone(),
|
||||
color_buffer.clone(),
|
||||
normal_buffer.clone(),
|
||||
depth_buffer.clone(),
|
||||
@@ -1579,7 +1647,14 @@ fn framebuffer_generation(
|
||||
})
|
||||
.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> {
|
||||
@@ -1714,7 +1789,10 @@ fn deferred_pipelines_recompile(
|
||||
..Default::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()),
|
||||
..GraphicsPipelineCreateInfo::layout(layout.clone())
|
||||
},
|
||||
@@ -1778,7 +1856,13 @@ fn deferred_pipelines_recompile(
|
||||
polygon_mode: PolygonMode::Fill,
|
||||
..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()),
|
||||
color_blend_state: Some(ColorBlendState::with_attachment_states(
|
||||
normals_subpass.num_color_attachments(),
|
||||
|
||||
@@ -8,6 +8,8 @@ layout(location = 0) in vec4 pos;
|
||||
|
||||
layout(depth_greater) out float gl_FragDepth;
|
||||
|
||||
layout(location = 0) out float material;
|
||||
|
||||
float scene(vec3 p) {
|
||||
return length(p) - 1.0;
|
||||
}
|
||||
@@ -44,6 +46,7 @@ void main() {
|
||||
{
|
||||
vec4 tpoint = camera_uniforms.proj * camera_uniforms.view * pc.world * vec4(p, 1);
|
||||
gl_FragDepth = (tpoint.z / tpoint.w);
|
||||
material = pc.material;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user