mirror of
https://github.com/slendidev/lunar.git
synced 2025-12-14 03:49:51 +02:00
@@ -19,6 +19,7 @@ shader_sources = files(
|
|||||||
'triangle.vert',
|
'triangle.vert',
|
||||||
'triangle_mesh.frag',
|
'triangle_mesh.frag',
|
||||||
'triangle_mesh.vert',
|
'triangle_mesh.vert',
|
||||||
|
'tex_image.frag',
|
||||||
)
|
)
|
||||||
|
|
||||||
spirv_shaders = []
|
spirv_shaders = []
|
||||||
|
|||||||
13
shaders/tex_image.frag
Normal file
13
shaders/tex_image.frag
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 in_color;
|
||||||
|
layout (location = 1) in vec2 in_uv;
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 out_frag_color;
|
||||||
|
|
||||||
|
layout (set = 0, binding = 0) uniform sampler2D tex;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
out_frag_color = texture(tex, in_uv) * vec4(in_color, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#extension GL_EXT_buffer_reference : require
|
#extension GL_EXT_buffer_reference : require
|
||||||
|
|
||||||
layout (location = 0) out vec3 out_color;
|
layout (location = 0) out vec3 out_color;
|
||||||
layout (location = 1) out vec3 out_uv;
|
layout (location = 1) out vec2 out_uv;
|
||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
vec3 position;
|
vec3 position;
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ auto Application::run() -> void
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
if (m_show_imgui) {
|
if (m_show_imgui) {
|
||||||
|
ImGui::SetNextWindowCollapsed(true, ImGuiCond_Once);
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
|
|
||||||
ImGui::SetNextWindowSize({ 100, 50 });
|
ImGui::SetNextWindowSize({ 100, 50 });
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ auto Mesh::load_gltf_meshes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool OVERRIDE_COLORS = true;
|
constexpr bool OVERRIDE_COLORS = false;
|
||||||
if (OVERRIDE_COLORS) {
|
if (OVERRIDE_COLORS) {
|
||||||
for (auto &vtx : vertices) {
|
for (auto &vtx : vertices) {
|
||||||
vtx.color = smath::Vec4(vtx.normal, 1.f);
|
vtx.color = smath::Vec4(vtx.normal, 1.f);
|
||||||
|
|||||||
@@ -356,6 +356,15 @@ auto VulkanRenderer::descriptors_init() -> void
|
|||||||
vkDestroyDescriptorSetLayout(
|
vkDestroyDescriptorSetLayout(
|
||||||
m_vkb.dev, m_vk.gpu_scene_data_descriptor_layout, nullptr);
|
m_vkb.dev, m_vk.gpu_scene_data_descriptor_layout, nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_vk.single_image_descriptor_layout
|
||||||
|
= DescriptorLayoutBuilder()
|
||||||
|
.add_binding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
|
||||||
|
.build(m_logger, m_vkb.dev, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
|
m_vk.deletion_queue.emplace([&]() {
|
||||||
|
vkDestroyDescriptorSetLayout(
|
||||||
|
m_vkb.dev, m_vk.single_image_descriptor_layout, nullptr);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VulkanRenderer::pipelines_init() -> void
|
auto VulkanRenderer::pipelines_init() -> void
|
||||||
@@ -479,7 +488,7 @@ auto VulkanRenderer::mesh_pipeline_init() -> void
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t triangle_frag_shader_data[] {
|
uint8_t triangle_frag_shader_data[] {
|
||||||
#embed "triangle_mesh_frag.spv"
|
#embed "tex_image_frag.spv"
|
||||||
};
|
};
|
||||||
VkShaderModule triangle_frag_shader {};
|
VkShaderModule triangle_frag_shader {};
|
||||||
if (!vkutil::load_shader_module(
|
if (!vkutil::load_shader_module(
|
||||||
@@ -499,6 +508,8 @@ auto VulkanRenderer::mesh_pipeline_init() -> void
|
|||||||
layout_ci.pNext = nullptr;
|
layout_ci.pNext = nullptr;
|
||||||
layout_ci.pushConstantRangeCount = 1;
|
layout_ci.pushConstantRangeCount = 1;
|
||||||
layout_ci.pPushConstantRanges = &push_constant_range;
|
layout_ci.pPushConstantRanges = &push_constant_range;
|
||||||
|
layout_ci.setLayoutCount = 1;
|
||||||
|
layout_ci.pSetLayouts = &m_vk.single_image_descriptor_layout;
|
||||||
|
|
||||||
VK_CHECK(m_logger,
|
VK_CHECK(m_logger,
|
||||||
vkCreatePipelineLayout(
|
vkCreatePipelineLayout(
|
||||||
@@ -862,18 +873,6 @@ auto VulkanRenderer::draw_geometry(VkCommandBuffer cmd) -> void
|
|||||||
|
|
||||||
vkCmdBeginRendering(cmd, &render_info);
|
vkCmdBeginRendering(cmd, &render_info);
|
||||||
|
|
||||||
auto view { smath::matrix_look_at(smath::Vec3 { 0.0f, 0.0f, 3.0f },
|
|
||||||
smath::Vec3 { 0.0f, 0.0f, 0.0f }, smath::Vec3 { 0.0f, 1.0f, 0.0f },
|
|
||||||
false) };
|
|
||||||
auto projection {
|
|
||||||
smath::matrix_perspective(smath::deg(70.0f),
|
|
||||||
static_cast<float>(m_vk.draw_extent.width)
|
|
||||||
/ static_cast<float>(m_vk.draw_extent.height),
|
|
||||||
0.1f, 10000.0f),
|
|
||||||
};
|
|
||||||
projection[1][1] *= -1;
|
|
||||||
auto view_projection { projection * view };
|
|
||||||
|
|
||||||
vkCmdBindPipeline(
|
vkCmdBindPipeline(
|
||||||
cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, m_vk.triangle_pipeline);
|
cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, m_vk.triangle_pipeline);
|
||||||
|
|
||||||
@@ -894,6 +893,30 @@ auto VulkanRenderer::draw_geometry(VkCommandBuffer cmd) -> void
|
|||||||
|
|
||||||
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, m_vk.mesh_pipeline);
|
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, m_vk.mesh_pipeline);
|
||||||
|
|
||||||
|
auto const image_set { m_vk.get_current_frame().frame_descriptors.allocate(
|
||||||
|
m_logger, m_vkb.dev, m_vk.single_image_descriptor_layout) };
|
||||||
|
DescriptorWriter()
|
||||||
|
.write_image(0, m_vk.error_image.image_view,
|
||||||
|
m_vk.default_sampler_nearest,
|
||||||
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||||
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
|
||||||
|
.update_set(m_vkb.dev, image_set);
|
||||||
|
|
||||||
|
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
|
m_vk.mesh_pipeline_layout, 0, 1, &image_set, 0, nullptr);
|
||||||
|
|
||||||
|
auto view { smath::matrix_look_at(smath::Vec3 { 0.0f, 0.0f, 3.0f },
|
||||||
|
smath::Vec3 { 0.0f, 0.0f, 0.0f }, smath::Vec3 { 0.0f, 1.0f, 0.0f },
|
||||||
|
false) };
|
||||||
|
auto projection {
|
||||||
|
smath::matrix_perspective(smath::deg(70.0f),
|
||||||
|
static_cast<float>(m_vk.draw_extent.width)
|
||||||
|
/ static_cast<float>(m_vk.draw_extent.height),
|
||||||
|
0.1f, 10000.0f),
|
||||||
|
};
|
||||||
|
projection[1][1] *= -1;
|
||||||
|
auto view_projection { projection * view };
|
||||||
|
|
||||||
GPUDrawPushConstants push_constants;
|
GPUDrawPushConstants push_constants;
|
||||||
auto rect_model { smath::scale(
|
auto rect_model { smath::scale(
|
||||||
smath::translate(smath::Vec3 { 0.0f, 0.0f, -5.0f }),
|
smath::translate(smath::Vec3 { 0.0f, 0.0f, -5.0f }),
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ private:
|
|||||||
GPUSceneData scene_data {};
|
GPUSceneData scene_data {};
|
||||||
VkDescriptorSetLayout gpu_scene_data_descriptor_layout;
|
VkDescriptorSetLayout gpu_scene_data_descriptor_layout;
|
||||||
|
|
||||||
|
VkDescriptorSetLayout single_image_descriptor_layout;
|
||||||
|
|
||||||
VkPipeline gradient_pipeline {};
|
VkPipeline gradient_pipeline {};
|
||||||
VkPipelineLayout gradient_pipeline_layout {};
|
VkPipelineLayout gradient_pipeline_layout {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user