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

[#70] Render into offscreen float buffer for main passes

parent e8018ca0
No related branches found
No related tags found
1 merge request!57Resolve "Basic voxelization"
#version 440
layout(set=0, binding=0, rgba8) uniform image2D sceneImage;
layout(set=0, binding=0, r11f_g11f_b10f) 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(sceneImage)))){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec3 linearColor = imageLoad(sceneImage, uv).rgb;
vec3 linearColor = imageLoad(inImage, uv).rgb;
vec3 gammaCorrected = pow(linearColor, vec3(1.f / 2.2f));
imageStore(sceneImage, uv, vec4(gammaCorrected, 0.f));
imageStore(outImage, uv, vec4(gammaCorrected, 0.f));
}
\ No newline at end of file
......@@ -103,10 +103,11 @@ int main(int argc, const char** argv) {
vertexBufferIndex++;
}
const vkcv::AttachmentDescription present_color_attachment(
const vk::Format colorBufferFormat = vk::Format::eB10G11R11UfloatPack32;
const vkcv::AttachmentDescription color_attachment(
vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::CLEAR,
core.getSwapchainImageFormat()
colorBufferFormat
);
const vk::Format depthBufferFormat = vk::Format::eD32Sfloat;
......@@ -116,7 +117,7 @@ int main(int argc, const char** argv) {
depthBufferFormat
);
vkcv::PassConfig forwardPassDefinition({ present_color_attachment, depth_attachment });
vkcv::PassConfig forwardPassDefinition({ color_attachment, depth_attachment });
vkcv::PassHandle forwardPass = core.createPass(forwardPassDefinition);
vkcv::shader::GLSLCompiler compiler;
......@@ -174,7 +175,8 @@ int main(int argc, const char** argv) {
vkcv::SamplerAddressMode::CLAMP_TO_EDGE
);
vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight).getHandle();
vkcv::ImageHandle depthBuffer = core.createImage(depthBufferFormat, windowWidth, windowHeight).getHandle();
vkcv::ImageHandle colorBuffer = core.createImage(colorBufferFormat, windowWidth, windowHeight, 1, true, true).getHandle();
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
......@@ -288,7 +290,7 @@ int main(int argc, const char** argv) {
const vkcv::AttachmentDescription voxelVisualisationColorAttachments(
vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::LOAD,
core.getSwapchainImageFormat()
colorBufferFormat
);
const vkcv::AttachmentDescription voxelVisualisationDepthAttachments(
......@@ -435,6 +437,7 @@ int main(int argc, const char** argv) {
if ((swapchainWidth != windowWidth) || ((swapchainHeight != windowHeight))) {
depthBuffer = core.createImage(depthBufferFormat, swapchainWidth, swapchainHeight).getHandle();
colorBuffer = core.createImage(colorBufferFormat, swapchainWidth, swapchainHeight, 1, true, true).getHandle();
windowWidth = swapchainWidth;
windowHeight = swapchainHeight;
......@@ -445,7 +448,9 @@ int main(int argc, const char** argv) {
// update descriptor sets which use swapchain image
vkcv::DescriptorWrites gammaCorrectionDescriptorWrites;
gammaCorrectionDescriptorWrites.storageImageWrites = { vkcv::StorageImageDescriptorWrite(0, swapchainInput) };
gammaCorrectionDescriptorWrites.storageImageWrites = {
vkcv::StorageImageDescriptorWrite(0, colorBuffer),
vkcv::StorageImageDescriptorWrite(1, swapchainInput) };
core.writeDescriptorSet(gammaCorrectionDescriptorSet, gammaCorrectionDescriptorWrites);
start = end;
......@@ -510,7 +515,7 @@ int main(int argc, const char** argv) {
}
vkcv::PushConstantData pushConstantData((void*)mainPassMatrices.data(), 2 * sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
const std::vector<vkcv::ImageHandle> renderTargets = { colorBuffer, depthBuffer };
const vkcv::PushConstantData shadowPushConstantData((void*)mvpLight.data(), sizeof(glm::mat4));
const vkcv::PushConstantData voxelizationPushConstantData((void*)voxelizationMatrices.data(), 2 * sizeof(glm::mat4));
......@@ -583,6 +588,7 @@ int main(int argc, const char** argv) {
};
core.prepareImageForStorage(cmdStream, swapchainInput);
core.prepareImageForStorage(cmdStream, colorBuffer);
core.recordComputeDispatchToCmdStream(
cmdStream,
......
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