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

[#106] Better motion vector visualisation

parent 898a2709
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
......@@ -18,9 +18,6 @@ void main(){
vec2 uv = vec2(coord) / outImageRes;
vec3 linearColor = texture(sampler2D(inTexture, textureSampler), uv).rgb;
// in case of motion vector visualisation negative values are possible
linearColor = abs(linearColor);
vec3 gammaCorrected = pow(linearColor, vec3(1 / 2.2));
imageStore(outImage, coord, vec4(gammaCorrected, 0.f));
......
#version 440
#extension GL_GOOGLE_include_directive : enable
layout(set=0, binding=0) uniform texture2D inMotion;
layout(set=0, binding=1) uniform sampler textureSampler;
layout(set=0, binding=2, r11f_g11f_b10f) uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout( push_constant ) uniform constants{
float range;
};
void main(){
ivec2 outImageRes = imageSize(outImage);
ivec2 coord = ivec2(gl_GlobalInvocationID.xy);
if(any(greaterThanEqual(coord, outImageRes)))
return;
vec2 uv = vec2(coord) / outImageRes;
vec2 motionVector = texture(sampler2D(inMotion, textureSampler), uv).rg;
vec2 motionVectorNormalized = clamp(motionVector / range, -1, 1);
vec2 color = motionVectorNormalized * 0.5 + 0.5;
imageStore(outImage, coord, vec4(color, 0.5, 0));
}
\ No newline at end of file
......@@ -47,6 +47,9 @@ bool App::initialize() {
if (!loadComputePass(m_core, "resources/shaders/motionVectorMaxNeighbourhood.comp", &m_motionVectorMaxNeighbourhoodPass))
return false;
if (!loadComputePass(m_core, "resources/shaders/motionVectorVisualisation.comp", &m_motionVectorVisualisationPass))
return false;
if (!loadMesh(m_core, "resources/models/sphere.gltf", & m_sphereMesh))
return false;
......@@ -103,9 +106,10 @@ void App::run() {
eDebugView debugView = eDebugView::None;
eMotionBlurInput motionBlurInput = eMotionBlurInput::MotionVectorMaxTileNeighbourhood;
float objectVerticalSpeed = 0.005;
float motionBlurMinVelocity = 0.001;
int cameraShutterSpeedInverse = 30;
float objectVerticalSpeed = 0.005;
float motionBlurMinVelocity = 0.001;
int cameraShutterSpeedInverse = 30;
float motionVectorVisualisationRange = 0.008;
glm::mat4 mvpPrevious = glm::mat4(1.f);
glm::mat4 viewProjectionPrevious = m_cameraManager.getActiveCamera().getMVP();
......@@ -301,24 +305,51 @@ void App::run() {
{ vkcv::DescriptorSetUsage(0, m_core.getDescriptorSet(m_motionBlurDummyPass.descriptorSet).vulkanHandle) },
motionBlurPushConstants);
// gamma correction
vkcv::ImageHandle gammaCorrectionInput;
if (debugView == eDebugView::None)
gammaCorrectionInput = m_renderTargets.motionBlurOutput;
else if (debugView == eDebugView::MotionVector)
gammaCorrectionInput = m_renderTargets.motionBuffer;
else if (debugView == eDebugView::MotionVectorMaxTile)
gammaCorrectionInput = m_renderTargets.motionMax;
else if (debugView == eDebugView::MotionVectorMaxTileNeighbourhood)
gammaCorrectionInput = m_renderTargets.motionMaxNeighbourhood;
else {
vkcv_log(vkcv::LogLevel::ERROR, "Unknown eDebugView enum value");
gammaCorrectionInput = m_renderTargets.motionBlurOutput;
// motion vector debug visualisation
// writes to motion blur output
if (debugView != eDebugView::None) {
vkcv::ImageHandle visualisationInput;
if (debugView == eDebugView::MotionVector)
visualisationInput = m_renderTargets.motionBuffer;
else if (debugView == eDebugView::MotionVectorMaxTile)
visualisationInput = m_renderTargets.motionMax;
else if (debugView == eDebugView::MotionVectorMaxTileNeighbourhood)
visualisationInput = m_renderTargets.motionMaxNeighbourhood;
else {
vkcv_log(vkcv::LogLevel::ERROR, "Unknown eDebugView enum value");
visualisationInput = m_renderTargets.motionBlurOutput;
}
vkcv::DescriptorWrites motionVectorVisualisationDescriptorWrites;
motionVectorVisualisationDescriptorWrites.sampledImageWrites = {
vkcv::SampledImageDescriptorWrite(0, visualisationInput) };
motionVectorVisualisationDescriptorWrites.samplerWrites = {
vkcv::SamplerDescriptorWrite(1, m_linearSampler) };
motionVectorVisualisationDescriptorWrites.storageImageWrites = {
vkcv::StorageImageDescriptorWrite(2, m_renderTargets.motionBlurOutput) };
m_core.writeDescriptorSet(
m_motionVectorVisualisationPass.descriptorSet,
motionVectorVisualisationDescriptorWrites);
m_core.prepareImageForSampling(cmdStream, visualisationInput);
m_core.prepareImageForStorage(cmdStream, m_renderTargets.motionBlurOutput);
vkcv::PushConstants motionVectorVisualisationPushConstants(sizeof(float));
motionVectorVisualisationPushConstants.appendDrawcall(motionVectorVisualisationRange);
m_core.recordComputeDispatchToCmdStream(
cmdStream,
m_motionVectorVisualisationPass.pipeline,
fullScreenImageDispatch,
{ vkcv::DescriptorSetUsage(0, m_core.getDescriptorSet(m_motionVectorVisualisationPass.descriptorSet).vulkanHandle) },
motionVectorVisualisationPushConstants);
}
// gamma correction
vkcv::DescriptorWrites gammaCorrectionDescriptorWrites;
gammaCorrectionDescriptorWrites.sampledImageWrites = {
vkcv::SampledImageDescriptorWrite(0, gammaCorrectionInput) };
vkcv::SampledImageDescriptorWrite(0, m_renderTargets.motionBlurOutput) };
gammaCorrectionDescriptorWrites.samplerWrites = {
vkcv::SamplerDescriptorWrite(1, m_linearSampler) };
gammaCorrectionDescriptorWrites.storageImageWrites = {
......@@ -326,7 +357,7 @@ void App::run() {
m_core.writeDescriptorSet(m_gammaCorrectionPass.descriptorSet, gammaCorrectionDescriptorWrites);
m_core.prepareImageForSampling(cmdStream, gammaCorrectionInput);
m_core.prepareImageForSampling(cmdStream, m_renderTargets.motionBlurOutput);
m_core.prepareImageForStorage (cmdStream, swapchainInput);
m_core.recordComputeDispatchToCmdStream(
......@@ -348,6 +379,10 @@ void App::run() {
debugViewLabels,
static_cast<int>(eDebugView::OptionCount));
if (debugView != eDebugView::None) {
ImGui::InputFloat("Motion vector visualisation range", &motionVectorVisualisationRange);
}
ImGui::Combo(
"Motion blur input",
reinterpret_cast<int*>(&motionBlurInput),
......
......@@ -30,6 +30,7 @@ private:
ComputePassHandles m_motionBlurDummyPass;
ComputePassHandles m_motionVectorMaxPass;
ComputePassHandles m_motionVectorMaxNeighbourhoodPass;
ComputePassHandles m_motionVectorVisualisationPass;
RenderTargets m_renderTargets;
vkcv::SamplerHandle m_linearSampler;
......
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