diff --git a/projects/voxelization/resources/shaders/depthPrepass.frag b/projects/voxelization/resources/shaders/depthPrepass.frag index 65592d2cfe161b8522de1a0c3e68fa1d6afa80be..b2401639ed93a97cedd0cab30cbdded2ef5b56ab 100644 --- a/projects/voxelization/resources/shaders/depthPrepass.frag +++ b/projects/voxelization/resources/shaders/depthPrepass.frag @@ -2,6 +2,13 @@ #extension GL_ARB_separate_shader_objects : enable #extension GL_GOOGLE_include_directive : enable -void main() { +#include "perMeshResources.inc" + +layout(location = 0) in vec2 passUV; +void main() { + float alpha = texture(sampler2D(albedoTexture, textureSampler), passUV).a; + if(alpha < 0.5){ + discard; + } } \ No newline at end of file diff --git a/projects/voxelization/resources/shaders/depthPrepass.vert b/projects/voxelization/resources/shaders/depthPrepass.vert index d800c547368c4f2126c880534276a3be3cf336f5..4bb3500eb59214e30fce84862e181fd7e24b7340 100644 --- a/projects/voxelization/resources/shaders/depthPrepass.vert +++ b/projects/voxelization/resources/shaders/depthPrepass.vert @@ -4,6 +4,9 @@ #extension GL_GOOGLE_include_directive : enable layout(location = 0) in vec3 inPosition; +layout(location = 2) in vec2 inUV; + +layout(location = 0) out vec2 passUV; layout( push_constant ) uniform constants{ mat4 mvp; @@ -11,4 +14,5 @@ layout( push_constant ) uniform constants{ void main() { gl_Position = mvp * vec4(inPosition, 1.0); + passUV = inUV; } \ No newline at end of file diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index daf1211f4d728e7dd180fba06c7164cbd70de30b..c3ca1c7f6a1f04883ede6f6e41230c91bcd49058 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -177,20 +177,6 @@ int main(int argc, const char** argv) { vkcv::PassConfig prepassPassDefinition({ prepassAttachment }, msaa); vkcv::PassHandle prepassPass = core.createPass(prepassPassDefinition); - vkcv::PipelineConfig prepassPipelineConfig{ - depthPrepassShader, - windowWidth, - windowHeight, - prepassPass, - vertexLayout, - {}, - true}; - prepassPipelineConfig.m_culling = vkcv::CullMode::Back; - prepassPipelineConfig.m_multisampling = msaa; - prepassPipelineConfig.m_depthTest = vkcv::DepthTest::LessEqual; - - vkcv::PipelineHandle prepassPipeline = core.createGraphicsPipeline(prepassPipelineConfig); - // create descriptor sets vkcv::SamplerHandle colorSampler = core.createSampler( vkcv::SamplerFilterType::LINEAR, @@ -264,13 +250,34 @@ int main(int argc, const char** argv) { perMeshDescriptorSets.push_back(materialDescriptorSets[vertexGroup.materialIndex]); } + // prepass pipeline + vkcv::DescriptorSetHandle prepassDescriptorSet = core.createDescriptorSet(std::vector<vkcv::DescriptorBinding>()); + + vkcv::PipelineConfig prepassPipelineConfig{ + depthPrepassShader, + windowWidth, + windowHeight, + prepassPass, + vertexLayout, + { + core.getDescriptorSet(prepassDescriptorSet).layout, + core.getDescriptorSet(perMeshDescriptorSets[0]).layout }, + true }; + prepassPipelineConfig.m_culling = vkcv::CullMode::Back; + prepassPipelineConfig.m_multisampling = msaa; + prepassPipelineConfig.m_depthTest = vkcv::DepthTest::LessEqual; + + vkcv::PipelineHandle prepassPipeline = core.createGraphicsPipeline(prepassPipelineConfig); + + // forward pipeline vkcv::PipelineConfig forwardPipelineConfig { forwardProgram, windowWidth, windowHeight, forwardPass, vertexLayout, - { core.getDescriptorSet(forwardShadingDescriptorSet).layout, + { + core.getDescriptorSet(forwardShadingDescriptorSet).layout, core.getDescriptorSet(perMeshDescriptorSets[0]).layout }, true }; @@ -408,7 +415,9 @@ int main(int argc, const char** argv) { drawcalls.push_back(vkcv::DrawcallInfo(meshes[i], { vkcv::DescriptorSetUsage(0, core.getDescriptorSet(forwardShadingDescriptorSet).vulkanHandle), vkcv::DescriptorSetUsage(1, core.getDescriptorSet(perMeshDescriptorSets[i]).vulkanHandle) })); - prepassDrawcalls.push_back(vkcv::DrawcallInfo(meshes[i], {})); + prepassDrawcalls.push_back(vkcv::DrawcallInfo(meshes[i], { + vkcv::DescriptorSetUsage(0, core.getDescriptorSet(prepassDescriptorSet).vulkanHandle), + vkcv::DescriptorSetUsage(1, core.getDescriptorSet(perMeshDescriptorSets[i]).vulkanHandle) })); } vkcv::SamplerHandle voxelSampler = core.createSampler(