Skip to content
Snippets Groups Projects
Verified Commit c8b419c2 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch '69-partikelsystem' of...

Merge branch '69-partikelsystem' of gitlab.uni-koblenz.de:vulkan2021/vkcv-framework into 69-partikelsystem
parents da307b6b 10f9a13a
No related branches found
No related tags found
1 merge request!56Resolve "Partikelsystem"
Pipeline #26068 passed
Showing with 75 additions and 14 deletions
...@@ -24,7 +24,7 @@ if(MSVC) ...@@ -24,7 +24,7 @@ if(MSVC)
endif() endif()
# including headers of dependencies and the VkCV framework # including headers of dependencies and the VkCV framework
target_include_directories(particle_simulation SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include}) target_include_directories(particle_simulation SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include})
# linking with libraries from all dependencies and the VkCV framework # linking with libraries from all dependencies and the VkCV framework
target_link_libraries(particle_simulation vkcv vkcv_testing vkcv_camera) target_link_libraries(particle_simulation vkcv vkcv_testing vkcv_camera vkcv_shader_compiler)
File deleted
File deleted
File deleted
%VULKAN_SDK%\Bin32\glslc.exe shader.vert -o vert.spv
%VULKAN_SDK%\Bin32\glslc.exe shader_water.frag -o frag_water.spv
%VULKAN_SDK%\Bin32\glslc.exe shader_water.comp -o comp_water.spv
%VULKAN_SDK%\Bin32\glslc.exe shader_space.frag -o frag_space.spv
%VULKAN_SDK%\Bin32\glslc.exe shader_space.comp -o comp_space.spv
pause
\ No newline at end of file
File deleted
File deleted
File deleted
#version 440
layout(set=0, binding=0, rgba16f) uniform image2D inImage;
layout(set=0, binding=1, rgba8) uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec3 linearColor = imageLoad(inImage, uv).rgb;
vec3 tonemapped = linearColor / (linearColor + 1); // reinhard tonemapping
vec3 gammaCorrected = pow(tonemapped, vec3(1.f / 2.2f));
imageStore(outImage, uv, vec4(gammaCorrected, 0.f));
}
\ No newline at end of file
File deleted
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <random> #include <random>
#include <glm/gtc/matrix_access.hpp> #include <glm/gtc/matrix_access.hpp>
#include <time.h> #include <time.h>
#include <vkcv/shader/GLSLCompiler.hpp>
int main(int argc, const char **argv) { int main(int argc, const char **argv) {
const char *applicationName = "Particlesystem"; const char *applicationName = "Particlesystem";
...@@ -36,12 +37,12 @@ int main(int argc, const char **argv) { ...@@ -36,12 +37,12 @@ int main(int argc, const char **argv) {
uint16_t indices[3] = {0, 1, 2}; uint16_t indices[3] = {0, 1, 2};
particleIndexBuffer.fill(&indices[0], sizeof(indices)); particleIndexBuffer.fill(&indices[0], sizeof(indices));
vk::Format colorFormat = vk::Format::eR16G16B16A16Sfloat;
// an example attachment for passes that output to the window // an example attachment for passes that output to the window
const vkcv::AttachmentDescription present_color_attachment( const vkcv::AttachmentDescription present_color_attachment(
vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::CLEAR, vkcv::AttachmentOperation::CLEAR,
core.getSwapchain().getFormat()); colorFormat);
vkcv::PassConfig particlePassDefinition({present_color_attachment}); vkcv::PassConfig particlePassDefinition({present_color_attachment});
...@@ -59,8 +60,11 @@ int main(int argc, const char **argv) { ...@@ -59,8 +60,11 @@ int main(int argc, const char **argv) {
// use space or use water // use space or use water
bool useSpace = true; bool useSpace = true;
vkcv::shader::GLSLCompiler compiler;
vkcv::ShaderProgram computeShaderProgram{}; vkcv::ShaderProgram computeShaderProgram{};
computeShaderProgram.addShader(vkcv::ShaderStage::COMPUTE, std::filesystem::path(useSpace? "shaders/comp_space.spv" : "shaders/comp_water.spv")); compiler.compile(vkcv::ShaderStage::COMPUTE, useSpace ? "shaders/shader_space.comp" : "shaders/shader_water.comp", [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
computeShaderProgram.addShader(shaderStage, path);
});
vkcv::DescriptorSetHandle computeDescriptorSet = core.createDescriptorSet(computeShaderProgram.getReflectedDescriptors()[0]); vkcv::DescriptorSetHandle computeDescriptorSet = core.createDescriptorSet(computeShaderProgram.getReflectedDescriptors()[0]);
...@@ -73,8 +77,12 @@ int main(int argc, const char **argv) { ...@@ -73,8 +77,12 @@ int main(int argc, const char **argv) {
const vkcv::VertexLayout computeLayout(computeBindings); const vkcv::VertexLayout computeLayout(computeBindings);
vkcv::ShaderProgram particleShaderProgram{}; vkcv::ShaderProgram particleShaderProgram{};
particleShaderProgram.addShader(vkcv::ShaderStage::VERTEX, std::filesystem::path("shaders/vert.spv")); compiler.compile(vkcv::ShaderStage::VERTEX, "shaders/shader.vert", [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
particleShaderProgram.addShader(vkcv::ShaderStage::FRAGMENT, std::filesystem::path( useSpace? "shaders/frag_space.spv" : "shaders/frag_water.spv")); particleShaderProgram.addShader(shaderStage, path);
});
compiler.compile(vkcv::ShaderStage::FRAGMENT, useSpace ? "shaders/shader_space.frag" : "shaders/shader_water.frag", [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
particleShaderProgram.addShader(shaderStage, path);
});
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet( vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(
particleShaderProgram.getReflectedDescriptors()[0]); particleShaderProgram.getReflectedDescriptors()[0]);
...@@ -208,6 +216,23 @@ int main(int argc, const char **argv) { ...@@ -208,6 +216,23 @@ int main(int argc, const char **argv) {
cameraManager.getCamera(camIndex1).setPosition(glm::vec3(0.0f, 0.0f, -2.0f)); cameraManager.getCamera(camIndex1).setPosition(glm::vec3(0.0f, 0.0f, -2.0f));
cameraManager.getCamera(camIndex1).setCenter(glm::vec3(0.0f, 0.0f, 0.0f)); cameraManager.getCamera(camIndex1).setCenter(glm::vec3(0.0f, 0.0f, 0.0f));
vkcv::ImageHandle colorBuffer = core.createImage(colorFormat, windowWidth, windowHeight, 1, false, true, true).getHandle();
window.e_resize.add([&](int width, int height) {
windowWidth = width;
windowHeight = height;
colorBuffer = core.createImage(colorFormat, windowWidth, windowHeight, 1, false, true, true).getHandle();
});
vkcv::ShaderProgram tonemappingShader;
compiler.compile(vkcv::ShaderStage::COMPUTE, "shaders/tonemapping.comp", [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
tonemappingShader.addShader(shaderStage, path);
});
vkcv::DescriptorSetHandle tonemappingDescriptor = core.createDescriptorSet(tonemappingShader.getReflectedDescriptors()[0]);
vkcv::PipelineHandle tonemappingPipe = core.createComputePipeline(
tonemappingShader,
{ core.getDescriptorSet(tonemappingDescriptor).layout });
std::uniform_real_distribution<float> rdm = std::uniform_real_distribution<float>(0.95f, 1.05f); std::uniform_real_distribution<float> rdm = std::uniform_real_distribution<float>(0.95f, 1.05f);
std::default_random_engine rdmEngine; std::default_random_engine rdmEngine;
while (window.isWindowOpen()) { while (window.isWindowOpen()) {
...@@ -254,7 +279,30 @@ int main(int argc, const char **argv) { ...@@ -254,7 +279,30 @@ int main(int argc, const char **argv) {
particlePipeline, particlePipeline,
pushConstantDataDraw, pushConstantDataDraw,
{drawcalls}, {drawcalls},
{swapchainInput}); { colorBuffer });
core.prepareImageForStorage(cmdStream, colorBuffer);
core.prepareImageForStorage(cmdStream, swapchainInput);
vkcv::DescriptorWrites tonemappingDescriptorWrites;
tonemappingDescriptorWrites.storageImageWrites = {
vkcv::StorageImageDescriptorWrite(0, colorBuffer),
vkcv::StorageImageDescriptorWrite(1, swapchainInput)
};
core.writeDescriptorSet(tonemappingDescriptor, tonemappingDescriptorWrites);
uint32_t tonemappingDispatchCount[3];
tonemappingDispatchCount[0] = std::ceil(windowWidth / 8.f);
tonemappingDispatchCount[1] = std::ceil(windowHeight / 8.f);
tonemappingDispatchCount[2] = 1;
core.recordComputeDispatchToCmdStream(
cmdStream,
tonemappingPipe,
tonemappingDispatchCount,
{vkcv::DescriptorSetUsage(0, core.getDescriptorSet(tonemappingDescriptor).vulkanHandle) },
vkcv::PushConstantData(nullptr, 0));
core.prepareSwapchainImageForPresent(cmdStream); core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream); core.submitCommandStream(cmdStream);
core.endFrame(); core.endFrame();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment