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() endif()
string(REGEX REPLACE "^v" "" ENGINE_VERSION "${ENGINE_VERSION}") 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.comp
SHADERS shaders/gradient_color.comp SHADERS shaders/gradient_color.comp
SHADERS shaders/sky.comp
LIBS glfw fmt vk-bootstrap vulkan LIBS glfw fmt vk-bootstrap vulkan
IMGUI IMGUI
) )

View File

@ -723,7 +723,6 @@ void Engine::initSyncStructures() {
); );
}); });
#ifdef DEBUG #ifdef DEBUG
fmt::println("[Engine:Init] Sync structures created !"); fmt::println("[Engine:Init] Sync structures created !");
#endif #endif
@ -838,22 +837,35 @@ void Engine::initBackgroundPipelines() {
); );
// Create the actual shader // Create the actual shader
VkShaderModule computeDrawShader; VkShaderModule gradientShader;
if ( if (
!vkutil::loadShaderModule( !vkutil::loadShaderModule(
"shaders/gradient_color.spv", "shaders/gradient_color.spv",
_device, _device,
&computeDrawShader &gradientShader
) )
) { ) {
fmt::println("[Engine:Error] Error when building the compute shader !"); 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{ VkPipelineShaderStageCreateInfo stageInfo{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
.stage = VK_SHADER_STAGE_COMPUTE_BIT, .stage = VK_SHADER_STAGE_COMPUTE_BIT,
.module = computeDrawShader, .module = gradientShader,
.pName = "main" .pName = "main"
}; };
@ -864,6 +876,15 @@ void Engine::initBackgroundPipelines() {
.layout = _gradientPipelineLayout .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( VK_CHECK(
vkCreateComputePipelines( vkCreateComputePipelines(
_device, _device,
@ -871,18 +892,50 @@ void Engine::initBackgroundPipelines() {
1, 1,
&computePipelineCreateInfo, &computePipelineCreateInfo,
nullptr, 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 // Do some cleanup
vkDestroyShaderModule( vkDestroyShaderModule(
_device, _device,
computeDrawShader, gradientShader,
nullptr nullptr
); );
_mainDeletionQueue.pushFunction([this]() { vkDestroyShaderModule(
_device,
skyShader,
nullptr
);
_mainDeletionQueue.pushFunction([this, sky, gradient]() {
vkDestroyPipelineLayout( vkDestroyPipelineLayout(
_device, _device,
_gradientPipelineLayout, _gradientPipelineLayout,
@ -891,10 +944,17 @@ void Engine::initBackgroundPipelines() {
vkDestroyPipeline( vkDestroyPipeline(
_device, _device,
_gradientPipeline, sky.pipeline,
nullptr
);
vkDestroyPipeline(
_device,
gradient.pipeline,
nullptr nullptr
); );
}); });
#ifdef DEBUG #ifdef DEBUG
fmt::println("[Engine:Init] Compute pipelines initalized !"); fmt::println("[Engine:Init] Compute pipelines initalized !");
#endif #endif
@ -1036,6 +1096,41 @@ void Engine::buildImgui() {
// Main ImGui things // Main ImGui things
ImGui::ShowDemoWindow(); 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 // Finish everything
ImGui::Render(); ImGui::Render();
} }
@ -1066,10 +1161,12 @@ void Engine::drawBackground(
VkImageSubresourceRange clearRange = vkinit::imageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT); VkImageSubresourceRange clearRange = vkinit::imageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT);
ComputeEffect& effect = backgroundEffects[currentBackgroundEffect];
vkCmdBindPipeline( vkCmdBindPipeline(
cmd, cmd,
VK_PIPELINE_BIND_POINT_COMPUTE, VK_PIPELINE_BIND_POINT_COMPUTE,
_gradientPipeline effect.pipeline
); );
vkCmdBindDescriptorSets( vkCmdBindDescriptorSets(
@ -1083,9 +1180,11 @@ void Engine::drawBackground(
nullptr nullptr
); );
/*
ComputePushConstants pc; ComputePushConstants pc;
pc.data1 = glm::vec4(1, 0, 0, 1); pc.data1 = glm::vec4(1, 0, 0, 1);
pc.data2 = glm::vec4(0, 0, 1, 1); pc.data2 = glm::vec4(0, 0, 1, 1);
*/
vkCmdPushConstants( vkCmdPushConstants(
cmd, cmd,
@ -1093,7 +1192,7 @@ void Engine::drawBackground(
VK_SHADER_STAGE_COMPUTE_BIT, VK_SHADER_STAGE_COMPUTE_BIT,
0, 0,
sizeof(ComputePushConstants), sizeof(ComputePushConstants),
&pc &effect.data
); );
vkCmdDispatch( vkCmdDispatch(