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

[#81] Add tonemapping

parent e7d8aaf5
No related branches found
No related tags found
1 merge request!68Resolve "Complete Voxelization"
...@@ -40,7 +40,7 @@ void main() { ...@@ -40,7 +40,7 @@ void main() {
vec3 N = normalize(passNormal); vec3 N = normalize(passNormal);
vec3 sun = sunStrength * sunColor * clamp(dot(N, L), 0, 1); vec3 sun = sunStrength * sunColor * clamp(dot(N, L), 0, 1);
sun *= shadowTest(passPos); sun *= shadowTest(passPos);
vec3 ambient = vec3(0.1); vec3 ambient = vec3(0.05);
vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb;
outColor = albedo * (sun + ambient); outColor = albedo * (sun + ambient);
} }
\ No newline at end of file
...@@ -11,8 +11,9 @@ void main(){ ...@@ -11,8 +11,9 @@ void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){ if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){
return; return;
} }
ivec2 uv = ivec2(gl_GlobalInvocationID.xy); ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec3 linearColor = imageLoad(inImage, uv).rgb; vec3 linearColor = imageLoad(inImage, uv).rgb;
vec3 gammaCorrected = pow(linearColor, vec3(1.f / 2.2f)); vec3 tonemapped = linearColor / (linearColor + 1); // reinhard tonemapping
vec3 gammaCorrected = pow(tonemapped, vec3(1.f / 2.2f));
imageStore(outImage, uv, vec4(gammaCorrected, 0.f)); imageStore(outImage, uv, vec4(gammaCorrected, 0.f));
} }
\ No newline at end of file
...@@ -159,7 +159,7 @@ int main(int argc, const char** argv) { ...@@ -159,7 +159,7 @@ int main(int argc, const char** argv) {
glm::vec3 direction; glm::vec3 direction;
float padding; float padding;
glm::vec3 sunColor = glm::vec3(1.f); glm::vec3 sunColor = glm::vec3(1.f);
float sunStrength = 1.f; float sunStrength = 8.f;
glm::mat4 lightMatrix; glm::mat4 lightMatrix;
}; };
LightInfo lightInfo; LightInfo lightInfo;
...@@ -275,15 +275,15 @@ int main(int argc, const char** argv) { ...@@ -275,15 +275,15 @@ int main(int argc, const char** argv) {
} }
}); });
// gamma correction compute shader // tonemapping compute shader
vkcv::ShaderProgram gammaCorrectionProgram; vkcv::ShaderProgram tonemappingProgram;
compiler.compile(vkcv::ShaderStage::COMPUTE, "resources/shaders/gammaCorrection.comp", compiler.compile(vkcv::ShaderStage::COMPUTE, "resources/shaders/tonemapping.comp",
[&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
gammaCorrectionProgram.addShader(shaderStage, path); tonemappingProgram.addShader(shaderStage, path);
}); });
vkcv::DescriptorSetHandle gammaCorrectionDescriptorSet = core.createDescriptorSet(gammaCorrectionProgram.getReflectedDescriptors()[0]); vkcv::DescriptorSetHandle tonemappingDescriptorSet = core.createDescriptorSet(tonemappingProgram.getReflectedDescriptors()[0]);
vkcv::PipelineHandle gammaCorrectionPipeline = core.createComputePipeline(gammaCorrectionProgram, vkcv::PipelineHandle tonemappingPipeline = core.createComputePipeline(tonemappingProgram,
{ core.getDescriptorSet(gammaCorrectionDescriptorSet).layout }); { core.getDescriptorSet(tonemappingDescriptorSet).layout });
// model matrices per mesh // model matrices per mesh
std::vector<glm::mat4> modelMatrices; std::vector<glm::mat4> modelMatrices;
...@@ -347,11 +347,11 @@ int main(int argc, const char** argv) { ...@@ -347,11 +347,11 @@ int main(int argc, const char** argv) {
auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(end - start); auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
// update descriptor sets which use swapchain image // update descriptor sets which use swapchain image
vkcv::DescriptorWrites gammaCorrectionDescriptorWrites; vkcv::DescriptorWrites tonemappingDescriptorWrites;
gammaCorrectionDescriptorWrites.storageImageWrites = { tonemappingDescriptorWrites.storageImageWrites = {
vkcv::StorageImageDescriptorWrite(0, colorBuffer), vkcv::StorageImageDescriptorWrite(0, colorBuffer),
vkcv::StorageImageDescriptorWrite(1, swapchainInput) }; vkcv::StorageImageDescriptorWrite(1, swapchainInput) };
core.writeDescriptorSet(gammaCorrectionDescriptorSet, gammaCorrectionDescriptorWrites); core.writeDescriptorSet(tonemappingDescriptorSet, tonemappingDescriptorWrites);
start = end; start = end;
cameraManager.update(0.000001 * static_cast<double>(deltatime.count())); cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
...@@ -427,10 +427,10 @@ int main(int argc, const char** argv) { ...@@ -427,10 +427,10 @@ int main(int argc, const char** argv) {
voxelization.renderVoxelVisualisation(cmdStream, viewProjectionCamera, renderTargets); voxelization.renderVoxelVisualisation(cmdStream, viewProjectionCamera, renderTargets);
} }
const uint32_t gammaCorrectionLocalGroupSize = 8; const uint32_t tonemappingLocalGroupSize = 8;
const uint32_t gammaCorrectionDispatchCount[3] = { const uint32_t tonemappingDispatchCount[3] = {
static_cast<uint32_t>(glm::ceil(windowWidth / static_cast<float>(gammaCorrectionLocalGroupSize))), static_cast<uint32_t>(glm::ceil(windowWidth / static_cast<float>(tonemappingLocalGroupSize))),
static_cast<uint32_t>(glm::ceil(windowHeight / static_cast<float>(gammaCorrectionLocalGroupSize))), static_cast<uint32_t>(glm::ceil(windowHeight / static_cast<float>(tonemappingLocalGroupSize))),
1 1
}; };
...@@ -439,9 +439,9 @@ int main(int argc, const char** argv) { ...@@ -439,9 +439,9 @@ int main(int argc, const char** argv) {
core.recordComputeDispatchToCmdStream( core.recordComputeDispatchToCmdStream(
cmdStream, cmdStream,
gammaCorrectionPipeline, tonemappingPipeline,
gammaCorrectionDispatchCount, tonemappingDispatchCount,
{ vkcv::DescriptorSetUsage(0, core.getDescriptorSet(gammaCorrectionDescriptorSet).vulkanHandle) }, { vkcv::DescriptorSetUsage(0, core.getDescriptorSet(tonemappingDescriptorSet).vulkanHandle) },
vkcv::PushConstantData(nullptr, 0)); vkcv::PushConstantData(nullptr, 0));
// present and end // present and end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment