diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp index 06329d8086a0b16a9b24a6c1f60f540a6e81aecb..a572fdaaf3c2f08b571e363cd23050fa8a145569 100644 --- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp +++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp @@ -368,7 +368,7 @@ int loadScene(const std::string &path, Scene &scene){ TextureData loadTexture(const std::filesystem::path& path) { TextureData texture; - uint8_t* data = stbi_load("resources/RadialLut.png", &texture.width, &texture.height, &texture.componentCount, 4); + uint8_t* data = stbi_load(path.string().c_str(), &texture.width, &texture.height, &texture.componentCount, 4); texture.data.resize(texture.width * texture.height * 4); memcpy(texture.data.data(), data, texture.data.size()); return texture; diff --git a/projects/voxelization/resources/lensDirt.jpg b/projects/voxelization/resources/lensDirt.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f941567527fe92f23aa6955e15ba95dc46881dad --- /dev/null +++ b/projects/voxelization/resources/lensDirt.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95982351ecf3d4d129d17612b40a8092944a285c0bffdd74d4886dd8489695ca +size 107603 diff --git a/projects/voxelization/resources/shaders/bloomFlaresComposite.comp b/projects/voxelization/resources/shaders/bloomFlaresComposite.comp index 2bf8a5e6aa52b3ea42cf1ae3ec583b37599c356b..45d50fdcfb109524ef35eac669610130a732a074 100644 --- a/projects/voxelization/resources/shaders/bloomFlaresComposite.comp +++ b/projects/voxelization/resources/shaders/bloomFlaresComposite.comp @@ -7,6 +7,7 @@ layout(set=0, binding=2) uniform sampler linearSample layout(set=0, binding=3, r11f_g11f_b10f) uniform image2D colorBuffer; layout(set=0, binding=4) uniform texture2D radialLUT; layout(set=0, binding=5) uniform sampler radialLUTSampler; +layout(set=0, binding=6) uniform texture2D dirtTexture; layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; @@ -31,6 +32,19 @@ float starburst(vec2 uv){ return mix(1, burst, falloff); } +float getLensDirtWeight(vec2 uv){ + vec2 targetTextureRes = imageSize(colorBuffer); + float targetAspectRatio = targetTextureRes.x / targetTextureRes.y; + + vec2 dirtTextureRes = textureSize(sampler2D(dirtTexture, linearSampler), 0); + float dirtAspectRatio = dirtTextureRes.x / dirtTextureRes.y; + + uv.x *= targetAspectRatio / dirtAspectRatio; + float dirt = texture(sampler2D(dirtTexture, radialLUTSampler), uv).r; + float dirtStrength = 0.75; + return mix(1, dirt, dirtStrength); +} + void main() { if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(colorBuffer)))){ @@ -53,7 +67,11 @@ void main() float main_weight = 1 - (bloom_weight + lens_weight); lens_color *= starburst(UV); - + + float lensDirtWeight = getLensDirtWeight(UV); + bloom_weight *= lensDirtWeight; + lens_weight *= lensDirtWeight; + composite_color.rgb = blur_color * bloom_weight + lens_color * lens_weight + main_color * main_weight; diff --git a/projects/voxelization/src/BloomAndFlares.cpp b/projects/voxelization/src/BloomAndFlares.cpp index 03518b79fc0a9363af8cb10fe1e9033f8ac06758..3e0066b2b8bb5baad1bbb47ba4aa55cfa9455c94 100644 --- a/projects/voxelization/src/BloomAndFlares.cpp +++ b/projects/voxelization/src/BloomAndFlares.cpp @@ -2,6 +2,13 @@ #include <vkcv/shader/GLSLCompiler.hpp> #include <vkcv/asset/asset_loader.hpp> +vkcv::Image loadLenseDirtTexture(vkcv::Core* corePtr) { + const auto texture = vkcv::asset::loadTexture("resources/lensDirt.jpg"); + vkcv::Image image = corePtr->createImage(vk::Format::eR8G8B8A8Unorm, texture.width, texture.height); + image.fill((void*)texture.data.data(), texture.data.size()); + return image; +} + BloomAndFlares::BloomAndFlares( vkcv::Core *p_Core, vk::Format colorBufferFormat, @@ -22,7 +29,8 @@ BloomAndFlares::BloomAndFlares( vkcv::SamplerAddressMode::REPEAT)), m_Blur(p_Core->createImage(colorBufferFormat, m_Width, m_Height, 1, true, true, false)), m_LensFeatures(p_Core->createImage(colorBufferFormat, m_Width, m_Height, 1, true, true, false)), - m_radialLut(p_Core->createImage(vk::Format::eR8G8B8A8Unorm, 128, 10, 1)) + m_radialLut(p_Core->createImage(vk::Format::eR8G8B8A8Unorm, 128, 10, 1)), + m_lensDirt(loadLenseDirtTexture(p_Core)) { vkcv::shader::GLSLCompiler compiler; @@ -286,7 +294,8 @@ void BloomAndFlares::execCompositePipe(const vkcv::CommandStreamHandle &cmdStrea vkcv::DescriptorWrites compositeWrites; compositeWrites.sampledImageWrites = {vkcv::SampledImageDescriptorWrite(0, m_Blur.getHandle()), vkcv::SampledImageDescriptorWrite(1, m_LensFeatures.getHandle()), - vkcv::SampledImageDescriptorWrite(4, m_radialLut.getHandle()) }; + vkcv::SampledImageDescriptorWrite(4, m_radialLut.getHandle()), + vkcv::SampledImageDescriptorWrite(6, m_lensDirt.getHandle()) }; compositeWrites.samplerWrites = {vkcv::SamplerDescriptorWrite(2, m_LinearSampler), vkcv::SamplerDescriptorWrite(5, m_RadialLutSampler) }; compositeWrites.storageImageWrites = {vkcv::StorageImageDescriptorWrite(3, colorAttachment)}; diff --git a/projects/voxelization/src/BloomAndFlares.hpp b/projects/voxelization/src/BloomAndFlares.hpp index f86c75c4ba21b0c78f93b7d86c824fd5af013df0..2b410e5b256c5820d908372d2e23fd495853274a 100644 --- a/projects/voxelization/src/BloomAndFlares.hpp +++ b/projects/voxelization/src/BloomAndFlares.hpp @@ -27,7 +27,7 @@ private: vkcv::Image m_LensFeatures; vkcv::Image m_radialLut; - + vkcv::Image m_lensDirt; vkcv::PipelineHandle m_DownsamplePipe; std::vector<vkcv::DescriptorSetHandle> m_DownsampleDescSets; // per mip desc set