Skip to content
Snippets Groups Projects
Commit f17c558d authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#82] Add lens dirt

parent cccd4f12
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
......@@ -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;
......
projects/voxelization/resources/lensDirt.jpg

131 B

......@@ -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;
......
......@@ -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)};
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment