Compare commits

..

2 Commits

Author SHA1 Message Date
Alexandre
e3fd8a5b2b Fixed some format missmatch 2026-07-20 00:25:56 +02:00
Alexandre
f54f70d9d4 Added more shaders, and an ImGui window to choose the shader 2026-07-20 00:13:12 +02:00
3 changed files with 114 additions and 10 deletions

View File

@ -50,3 +50,7 @@ if (NOT ENGINE_HASH OR GIT_HASH_ERROR_CODE)
endif()
string(REGEX REPLACE "^v" "" ENGINE_VERSION "${ENGINE_VERSION}")
set(ENGINE_VERSION "${ENGINE_VERSION}-${CMAKE_BUILD_TYPE}")
message(STATUS "Engine Version: ${ENGINE_VERSION}")

View File

@ -200,6 +200,7 @@ addBinary (
SHADERS shaders/gradient.comp
SHADERS shaders/gradient_color.comp
SHADERS shaders/sky.comp
LIBS glfw fmt vk-bootstrap vulkan
IMGUI
)

View File

@ -723,7 +723,6 @@ void Engine::initSyncStructures() {
);
});
#ifdef DEBUG
fmt::println("[Engine:Init] Sync structures created !");
#endif
@ -838,22 +837,35 @@ void Engine::initBackgroundPipelines() {
);
// Create the actual shader
VkShaderModule computeDrawShader;
VkShaderModule gradientShader;
if (
!vkutil::loadShaderModule(
"shaders/gradient_color.spv",
_device,
&computeDrawShader
&gradientShader
)
) {
fmt::println("[Engine:Error] Error when building the compute shader !");
}
// Create the second shader
VkShaderModule skyShader;
if (
!vkutil::loadShaderModule(
"shaders/sky.spv",
_device,
&skyShader
)
) {
fmt::println("[Engine:Error] Error while building the compute shader !");
}
// Fist Shader
VkPipelineShaderStageCreateInfo stageInfo{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
.module = computeDrawShader,
.module = gradientShader,
.pName = "main"
};
@ -864,6 +876,15 @@ void Engine::initBackgroundPipelines() {
.layout = _gradientPipelineLayout
};
ComputeEffect gradient {
.name = "gradient",
.layout = _gradientPipelineLayout,
.data = {
.data1 = glm::vec4(1, 0, 0, 1),
.data2 = glm::vec4(0, 0, 1, 1)
}
};
VK_CHECK(
vkCreateComputePipelines(
_device,
@ -871,18 +892,50 @@ void Engine::initBackgroundPipelines() {
1,
&computePipelineCreateInfo,
nullptr,
&_gradientPipeline
&gradient.pipeline
);
);
// Change the shader module to create the sky shader
computePipelineCreateInfo.stage.module = skyShader;
ComputeEffect sky {
.name = "sky",
.layout = _gradientPipelineLayout,
.data = {
.data1 = glm::vec4(0.1, 0.2, 0.4, 0.97)
}
};
VK_CHECK(
vkCreateComputePipelines(
_device,
VK_NULL_HANDLE,
1,
&computePipelineCreateInfo,
nullptr,
&sky.pipeline
);
);
// Add the effects into the array
backgroundEffects.push_back(gradient);
backgroundEffects.push_back(sky);
// Do some cleanup
vkDestroyShaderModule(
_device,
computeDrawShader,
gradientShader,
nullptr
);
_mainDeletionQueue.pushFunction([this]() {
vkDestroyShaderModule(
_device,
skyShader,
nullptr
);
_mainDeletionQueue.pushFunction([this, sky, gradient]() {
vkDestroyPipelineLayout(
_device,
_gradientPipelineLayout,
@ -891,10 +944,17 @@ void Engine::initBackgroundPipelines() {
vkDestroyPipeline(
_device,
_gradientPipeline,
sky.pipeline,
nullptr
);
vkDestroyPipeline(
_device,
gradient.pipeline,
nullptr
);
});
#ifdef DEBUG
fmt::println("[Engine:Init] Compute pipelines initalized !");
#endif
@ -1036,6 +1096,41 @@ void Engine::buildImgui() {
// Main ImGui things
ImGui::ShowDemoWindow();
if(ImGui::Begin("background")) {
ComputeEffect& selected = backgroundEffects[currentBackgroundEffect];
ImGui::Text(
"Selected effect: %s",
selected.name
);
ImGui::SliderInt(
"Effect Index",
&currentBackgroundEffect,
0,
backgroundEffects.size() - 1
);
ImGui::InputFloat4(
"data1",
(float*)& selected.data.data1
);
ImGui::InputFloat4(
"data2",
(float*)& selected.data.data2
);
ImGui::InputFloat4(
"data3",
(float*)& selected.data.data3
);
ImGui::InputFloat4(
"data4",
(float*)& selected.data.data4
);
}
ImGui::End();
// Finish everything
ImGui::Render();
}
@ -1066,10 +1161,12 @@ void Engine::drawBackground(
VkImageSubresourceRange clearRange = vkinit::imageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT);
ComputeEffect& effect = backgroundEffects[currentBackgroundEffect];
vkCmdBindPipeline(
cmd,
VK_PIPELINE_BIND_POINT_COMPUTE,
_gradientPipeline
effect.pipeline
);
vkCmdBindDescriptorSets(
@ -1083,9 +1180,11 @@ void Engine::drawBackground(
nullptr
);
/*
ComputePushConstants pc;
pc.data1 = glm::vec4(1, 0, 0, 1);
pc.data2 = glm::vec4(0, 0, 1, 1);
*/
vkCmdPushConstants(
cmd,
@ -1093,7 +1192,7 @@ void Engine::drawBackground(
VK_SHADER_STAGE_COMPUTE_BIT,
0,
sizeof(ComputePushConstants),
&pc
&effect.data
);
vkCmdDispatch(