Skip to content
Snippets Groups Projects
Verified Commit 0a9a1156 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch '82-voxel-cone-tracing' of...

Merge branch '82-voxel-cone-tracing' of gitlab.uni-koblenz.de:vulkan2021/vkcv-framework into 82-voxel-cone-tracing
parents 96467f96 bf060d67
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
Pipeline #26011 passed
...@@ -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
...@@ -2,6 +2,19 @@ ...@@ -2,6 +2,19 @@
#extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable #extension GL_GOOGLE_include_directive : enable
void main() { #include "perMeshResources.inc"
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() {
float alpha = texture(sampler2D(albedoTexture, textureSampler), passUV).a;
float alphaCutoff = 0.5;
// 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
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#extension GL_GOOGLE_include_directive : enable #extension GL_GOOGLE_include_directive : enable
layout(location = 0) in vec3 inPosition; layout(location = 0) in vec3 inPosition;
layout(location = 2) in vec2 inUV;
layout(location = 0) out vec2 passUV;
layout( push_constant ) uniform constants{ layout( push_constant ) uniform constants{
mat4 mvp; mat4 mvp;
...@@ -11,4 +14,5 @@ layout( push_constant ) uniform constants{ ...@@ -11,4 +14,5 @@ layout( push_constant ) uniform constants{
void main() { void main() {
gl_Position = mvp * vec4(inPosition, 1.0); gl_Position = mvp * vec4(inPosition, 1.0);
passUV = inUV;
} }
\ No newline at end of file
...@@ -177,20 +177,6 @@ int main(int argc, const char** argv) { ...@@ -177,20 +177,6 @@ int main(int argc, const char** argv) {
vkcv::PassConfig prepassPassDefinition({ prepassAttachment }, msaa); vkcv::PassConfig prepassPassDefinition({ prepassAttachment }, msaa);
vkcv::PassHandle prepassPass = core.createPass(prepassPassDefinition); 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 // create descriptor sets
vkcv::SamplerHandle colorSampler = core.createSampler( vkcv::SamplerHandle colorSampler = core.createSampler(
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
...@@ -264,13 +250,35 @@ int main(int argc, const char** argv) { ...@@ -264,13 +250,35 @@ int main(int argc, const char** argv) {
perMeshDescriptorSets.push_back(materialDescriptorSets[vertexGroup.materialIndex]); 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;
prepassPipelineConfig.m_alphaToCoverage = true;
vkcv::PipelineHandle prepassPipeline = core.createGraphicsPipeline(prepassPipelineConfig);
// forward pipeline
vkcv::PipelineConfig forwardPipelineConfig { vkcv::PipelineConfig forwardPipelineConfig {
forwardProgram, forwardProgram,
windowWidth, windowWidth,
windowHeight, windowHeight,
forwardPass, forwardPass,
vertexLayout, vertexLayout,
{ core.getDescriptorSet(forwardShadingDescriptorSet).layout, {
core.getDescriptorSet(forwardShadingDescriptorSet).layout,
core.getDescriptorSet(perMeshDescriptorSets[0]).layout }, core.getDescriptorSet(perMeshDescriptorSets[0]).layout },
true true
}; };
...@@ -408,7 +416,9 @@ int main(int argc, const char** argv) { ...@@ -408,7 +416,9 @@ int main(int argc, const char** argv) {
drawcalls.push_back(vkcv::DrawcallInfo(meshes[i], { drawcalls.push_back(vkcv::DrawcallInfo(meshes[i], {
vkcv::DescriptorSetUsage(0, core.getDescriptorSet(forwardShadingDescriptorSet).vulkanHandle), vkcv::DescriptorSetUsage(0, core.getDescriptorSet(forwardShadingDescriptorSet).vulkanHandle),
vkcv::DescriptorSetUsage(1, core.getDescriptorSet(perMeshDescriptorSets[i]).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( vkcv::SamplerHandle voxelSampler = core.createSampler(
......
...@@ -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