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

[#106] Add shutter speed and make motion blur framerate independant

parent a8a3b210
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
...@@ -8,6 +8,12 @@ layout(set=0, binding=3, r11f_g11f_b10f) uniform image2D outImage; ...@@ -8,6 +8,12 @@ layout(set=0, binding=3, r11f_g11f_b10f) uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout( push_constant ) uniform constants{
// computed from delta time and shutter speed
float motionFactor;
};
void main(){ void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(outImage)))) if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(outImage))))
...@@ -18,6 +24,7 @@ void main(){ ...@@ -18,6 +24,7 @@ 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;
motion *= motionFactor;
vec3 color = vec3(0); vec3 color = vec3(0);
const int sampleCount = 16; const int sampleCount = 16;
......
...@@ -101,7 +101,8 @@ void App::run() { ...@@ -101,7 +101,8 @@ 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;
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();
...@@ -126,7 +127,6 @@ void App::run() { ...@@ -126,7 +127,6 @@ void App::run() {
auto frameEndTime = std::chrono::system_clock::now(); auto frameEndTime = std::chrono::system_clock::now();
auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(frameEndTime - frameStartTime); auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(frameEndTime - frameStartTime);
frameStartTime = frameEndTime;
m_cameraManager.update(0.000001 * static_cast<double>(deltatime.count())); m_cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
const glm::mat4 viewProjection = m_cameraManager.getActiveCamera().getMVP(); const glm::mat4 viewProjection = m_cameraManager.getActiveCamera().getMVP();
...@@ -281,12 +281,19 @@ void App::run() { ...@@ -281,12 +281,19 @@ void App::run() {
m_core.prepareImageForSampling(cmdStream, m_renderTargets.colorBuffer); m_core.prepareImageForSampling(cmdStream, m_renderTargets.colorBuffer);
m_core.prepareImageForSampling(cmdStream, motionBuffer); m_core.prepareImageForSampling(cmdStream, motionBuffer);
const float microsecondToSecond = 0.000001;
const float fDeltatimeSeconds = microsecondToSecond * std::chrono::duration_cast<std::chrono::microseconds>(frameEndTime - frameStartTime).count();
const float motionBlurMotionFactor = 1 / (fDeltatimeSeconds * cameraShutterSpeedInverse);
vkcv::PushConstants motionBlurPushConstants(sizeof(float));
motionBlurPushConstants.appendDrawcall(motionBlurMotionFactor);
m_core.recordComputeDispatchToCmdStream( m_core.recordComputeDispatchToCmdStream(
cmdStream, cmdStream,
m_motionBlurDummyPass.pipeline, m_motionBlurDummyPass.pipeline,
fullScreenImageDispatch, fullScreenImageDispatch,
{ vkcv::DescriptorSetUsage(0, m_core.getDescriptorSet(m_motionBlurDummyPass.descriptorSet).vulkanHandle) }, { vkcv::DescriptorSetUsage(0, m_core.getDescriptorSet(m_motionBlurDummyPass.descriptorSet).vulkanHandle) },
vkcv::PushConstants(0)); motionBlurPushConstants);
// gamma correction // gamma correction
vkcv::ImageHandle gammaCorrectionInput; vkcv::ImageHandle gammaCorrectionInput;
...@@ -342,6 +349,7 @@ void App::run() { ...@@ -342,6 +349,7 @@ void App::run() {
static_cast<int>(eMotionBlurInput::OptionCount)); static_cast<int>(eMotionBlurInput::OptionCount));
ImGui::InputFloat("Object movement speed", &objectVerticalSpeed); ImGui::InputFloat("Object movement speed", &objectVerticalSpeed);
ImGui::InputInt("Camera shutter speed inverse", &cameraShutterSpeedInverse);
ImGui::End(); ImGui::End();
gui.endGUI(); gui.endGUI();
...@@ -350,5 +358,6 @@ void App::run() { ...@@ -350,5 +358,6 @@ void App::run() {
viewProjectionPrevious = viewProjection; viewProjectionPrevious = viewProjection;
mvpPrevious = mvp; mvpPrevious = mvp;
frameStartTime = frameEndTime;
} }
} }
\ No newline at end of file
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