I am using deferred shading, the gbuffer is composed of normals, metallicness ,roughness, and the depth. However inside the final pass (lighting calculations) I’ve noticed that the background of my final image is not being cleared, It’s actually participating of the light calculation. While trying to sample irradiance and enviromental map, the background is actually sampling it too, using the clear value of my normal (0,0,0,0,0) of the normal attachment. So the result is really weird. I’m using loadOp_Store in every attachment.
GBuffer Pipeline
std::vector<VK_Objects::ATRIBUTES> atributes =
{VK_Objects::ATRIBUTES::VEC3,VK_Objects::ATRIBUTES::VEC3,VK_Objects::ATRIBUTES::VEC2
};
std::vector<std::vector<VK_Objects::ATRIBUTES>>att{ atributes };
pipelineInfo.atributes = att;
pipelineInfo.colorAttachmentsCount = 3;
pipelineInfo.cullMode = VK_CULL_MODE_NONE;
pipelineInfo.dephTest = 1;
pipelineInfo.depthBias = 0;
pipelineInfo.rdpass = &renderpass->passes["G_BUFFER"]->vk_renderpass ;
pipelineInfo.frontFaceClock = VK_FRONT_FACE_CLOCKWISE;
pipelineInfo.vertexOffsets = { 0 };
pipelineInfo.subpass = 0;
Gbuffer renderpass
depthAttachment.description.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
depthAttachment.description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
depthAttachment.description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
depthAttachment.description.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
depthAttachment.description.flags = 0;
depthAttachment.reference.attachment = 3;
depthAttachment.reference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VK_Objects::RenderAttachment metallicRoughnessAttachment;
metallicRoughnessAttachment.description.format = format;
metallicRoughnessAttachment.description.samples = VK_SAMPLE_COUNT_1_BIT;
metallicRoughnessAttachment.description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
metallicRoughnessAttachment.description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
metallicRoughnessAttachment.description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
metallicRoughnessAttachment.description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
metallicRoughnessAttachment.description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
metallicRoughnessAttachment.description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
metallicRoughnessAttachment.description.flags = 0;
metallicRoughnessAttachment.reference.attachment = 1;
metallicRoughnessAttachment.reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VK_Objects::RenderAttachment NormalsAttachment;
NormalsAttachment.description.format = format;
NormalsAttachment.description.samples = VK_SAMPLE_COUNT_1_BIT;
NormalsAttachment.description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
NormalsAttachment.description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
NormalsAttachment.description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
NormalsAttachment.description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
NormalsAttachment.description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
NormalsAttachment.description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
NormalsAttachment.description.flags = 0;
NormalsAttachment.reference.attachment = 2;
NormalsAttachment.reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VK_Objects::RenderAttachment albedoAttachment;
albedoAttachment.description.format = format;
albedoAttachment.description.samples = VK_SAMPLE_COUNT_1_BIT;
albedoAttachment.description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
albedoAttachment.description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
albedoAttachment.description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
albedoAttachment.description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
albedoAttachment.description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
albedoAttachment.description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
albedoAttachment.description.flags = 0;
albedoAttachment.reference.attachment = 0;
albedoAttachment.reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VK_Objects::Subpass subpass;
subpass.description.resize(1);
subpass.dependencies.resize(2);
I’m not trying to render any kind of cubeMap. I’m just sampling it to use in cook_torrance shading.
What am I missing? any clue ?