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

[#106] Add motion blur early out for barely moving pixels

parent fe9de4d9
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
...@@ -11,6 +11,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; ...@@ -11,6 +11,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout( push_constant ) uniform constants{ layout( push_constant ) uniform constants{
// computed from delta time and shutter speed // computed from delta time and shutter speed
float motionFactor; float motionFactor;
float minVelocity;
}; };
...@@ -24,6 +25,15 @@ void main(){ ...@@ -24,6 +25,15 @@ void main(){
vec2 uv = vec2(coord) / textureRes; vec2 uv = vec2(coord) / textureRes;
vec2 motion = texture(sampler2D(inMotion, textureSampler), uv).rg; vec2 motion = texture(sampler2D(inMotion, textureSampler), uv).rg;
float velocity = length(motion);
// early out on little movement
if(velocity < minVelocity){
vec3 color = texture(sampler2D(inColor, textureSampler), uv).rgb;
imageStore(outImage, coord, vec4(color, 0.f));
return;
}
motion *= motionFactor; motion *= motionFactor;
vec3 color = vec3(0); vec3 color = vec3(0);
......
...@@ -101,8 +101,9 @@ void App::run() { ...@@ -101,8 +101,9 @@ void App::run() {
eDebugView debugView = eDebugView::None; eDebugView debugView = eDebugView::None;
eMotionBlurInput motionBlurInput = eMotionBlurInput::MotionVectorMaxTileNeighbourhood; eMotionBlurInput motionBlurInput = eMotionBlurInput::MotionVectorMaxTileNeighbourhood;
float objectVerticalSpeed = 0.005; float objectVerticalSpeed = 0.005;
int cameraShutterSpeedInverse = 48; float motionBlurMinVelocity = 0.001;
int cameraShutterSpeedInverse = 48;
glm::mat4 mvpPrevious = glm::mat4(1.f); glm::mat4 mvpPrevious = glm::mat4(1.f);
glm::mat4 viewProjectionPrevious = m_cameraManager.getActiveCamera().getMVP(); glm::mat4 viewProjectionPrevious = m_cameraManager.getActiveCamera().getMVP();
...@@ -285,8 +286,11 @@ void App::run() { ...@@ -285,8 +286,11 @@ void App::run() {
const float fDeltatimeSeconds = microsecondToSecond * std::chrono::duration_cast<std::chrono::microseconds>(frameEndTime - frameStartTime).count(); const float fDeltatimeSeconds = microsecondToSecond * std::chrono::duration_cast<std::chrono::microseconds>(frameEndTime - frameStartTime).count();
const float motionBlurMotionFactor = 1 / (fDeltatimeSeconds * cameraShutterSpeedInverse); const float motionBlurMotionFactor = 1 / (fDeltatimeSeconds * cameraShutterSpeedInverse);
vkcv::PushConstants motionBlurPushConstants(sizeof(float)); vkcv::PushConstants motionBlurPushConstants(sizeof(float) * 2);
motionBlurPushConstants.appendDrawcall(motionBlurMotionFactor);
float motionBlurConstantData[2] = { motionBlurMotionFactor, motionBlurMinVelocity };
motionBlurPushConstants.appendDrawcall(motionBlurConstantData);
m_core.recordComputeDispatchToCmdStream( m_core.recordComputeDispatchToCmdStream(
cmdStream, cmdStream,
...@@ -350,6 +354,7 @@ void App::run() { ...@@ -350,6 +354,7 @@ void App::run() {
ImGui::InputFloat("Object movement speed", &objectVerticalSpeed); ImGui::InputFloat("Object movement speed", &objectVerticalSpeed);
ImGui::InputInt("Camera shutter speed inverse", &cameraShutterSpeedInverse); ImGui::InputInt("Camera shutter speed inverse", &cameraShutterSpeedInverse);
ImGui::DragFloat("Motion blur min velocity", &motionBlurMinVelocity, 0.01, 0, 1);
ImGui::End(); ImGui::End();
gui.endGUI(); gui.endGUI();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment