I am building a 3d renderer in C++ using Vulkan.hpp. I have a rendering pipeline that…
- User
I am building a 3d renderer in C++ using Vulkan.hpp. I have a rendering pipeline that works in HDR and renders objects with lighting, shadows, PBR bloom and SSAO. I have a separate post rendering stage that mixes the bloom image, converts the HDR image back to LDR and implements gamma correction. By checking the intermediate outputs of the rendering pipeline in RenderDoc I can see that the inputs into this post rendering stage look fine, but the output image is a lot brighter than it should be. I believe there may be issues with the tone mapping that is being applied. From the research I have done I believe that my tone mapping approach should be fairly standard so I'm not sure why it is coming out incorrectly. Is my implementation of tone mapping correct or is there possibly a better algorithms I could implement to get better tone mapping outcomes?
Here is the fragment shader code for the post processing stage:
#version 450
layout(location = 0) out vec4 outColor;
layout(input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput gScene; layout(binding = 1) uniform sampler2D bloomTexture;
layout(binding = 2) uniform PostDataBufferObject { float gamma; float exposure; } postUBO;
layout(location = 0) in vec2 fragTexCoord;
void main() {
vec3 fragScene = subpassLoad(gScene).xyz; vec3 bloomColor = texture(bloomTexture, fragTexCoord).rgb; vec3 bloomFrag = mix(fragScene, bloomColor, 0.04f); float exposure = postUBO.exposure; const float gamma = postUBO.gamma; // exposure tone mapping vec3 mapped = vec3(1.0) - exp(-bloomFrag * exposure); // gamma correction mapped = pow(mapped, vec3(1.0 / gamma)); outColor = vec4(mapped,1.0);}
- Assistant
- User
I have found a more complex version of Reinhard that seems to implement something called a zone system. The rough algorithm is as follows:
Ld(x,y) = (L(x,y)*(1+(L(x,y)/(Lwhite^2)))/(1+L(x,y))
Are you familiar with this algorithm? If so, can you show me code that I could implement within the fragment shader to replicate it?
- Assistant
- User
For refererence, I implement the a form of dynamic exposure adjustment in the lighting stage before the calculation of bloom. Will this new tone mapping approach cause any issues with that approach?
- Assistant
- User
For further reference, the dynamic exposure is adjusted based on the HDR image prior to the tone mapping being applied. This was done partly due to the ease of access of the HDR image compared to the LDR image that is written directly to the swapchain image in a somewhat unique format to other images in the rendering pipeline. Does the fact that the dynamic exposure adjustments are based on the HDR image mitigate some of the concerns?
- Assistant