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

[#82] Add alpha to coverage to anti-alias alpha tested geometry

parent 53c30ffa
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
...@@ -32,7 +32,8 @@ namespace vkcv { ...@@ -32,7 +32,8 @@ namespace vkcv {
Multisampling m_multisampling = Multisampling::None; Multisampling m_multisampling = Multisampling::None;
CullMode m_culling = CullMode::None; CullMode m_culling = CullMode::None;
DepthTest m_depthTest = DepthTest::LessEqual; DepthTest m_depthTest = DepthTest::LessEqual;
bool m_depthWrite = true; bool m_depthWrite = true;
bool m_alphaToCoverage = false;
}; };
} }
\ No newline at end of file
...@@ -6,9 +6,15 @@ ...@@ -6,9 +6,15 @@
layout(location = 0) in vec2 passUV; layout(location = 0) in vec2 passUV;
layout(location = 0) out vec4 outColor; // only used for alpha to coverage, not actually written to
// coverage to alpha techniques explained in: https://bgolus.medium.com/anti-aliased-alpha-test-the-esoteric-alpha-to-coverage-8b177335ae4f
void main() { void main() {
float alpha = texture(sampler2D(albedoTexture, textureSampler), passUV).a; float alpha = texture(sampler2D(albedoTexture, textureSampler), passUV).a;
if(alpha < 0.5){ float alphaCutoff = 0.5;
discard;
} // scale alpha to one pixel width
alpha = (alpha - alphaCutoff) / max(fwidth(alpha), 0.0001) + 0.5;
outColor.a = alpha;
} }
\ No newline at end of file
...@@ -263,9 +263,10 @@ int main(int argc, const char** argv) { ...@@ -263,9 +263,10 @@ int main(int argc, const char** argv) {
core.getDescriptorSet(prepassDescriptorSet).layout, core.getDescriptorSet(prepassDescriptorSet).layout,
core.getDescriptorSet(perMeshDescriptorSets[0]).layout }, core.getDescriptorSet(perMeshDescriptorSets[0]).layout },
true }; true };
prepassPipelineConfig.m_culling = vkcv::CullMode::Back; prepassPipelineConfig.m_culling = vkcv::CullMode::Back;
prepassPipelineConfig.m_multisampling = msaa; prepassPipelineConfig.m_multisampling = msaa;
prepassPipelineConfig.m_depthTest = vkcv::DepthTest::LessEqual; prepassPipelineConfig.m_depthTest = vkcv::DepthTest::LessEqual;
prepassPipelineConfig.m_alphaToCoverage = true;
vkcv::PipelineHandle prepassPipeline = core.createGraphicsPipeline(prepassPipelineConfig); vkcv::PipelineHandle prepassPipeline = core.createGraphicsPipeline(prepassPipelineConfig);
......
...@@ -193,7 +193,7 @@ namespace vkcv ...@@ -193,7 +193,7 @@ namespace vkcv
false, false,
0.f, 0.f,
nullptr, nullptr,
false, config.m_alphaToCoverage,
false false
); );
......
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