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

[#106] Adjusted velocity clamping, removed manual settings for min velocity...

[#106] Adjusted velocity clamping, removed manual settings for min velocity and motion blur delta time limit
parent f9649fbe
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
Pipeline #26819 passed
...@@ -12,8 +12,8 @@ layout(set=0, binding=5, r11f_g11f_b10f) uniform image2D outImage; ...@@ -12,8 +12,8 @@ layout(set=0, binding=5, 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{ layout( push_constant ) uniform constants{
float motionScaleFactor; // computed from delta time and shutter speed // computed from delta time and shutter speed
float minVelocity; float motionScaleFactor;
// camera planes are needed to linearize depth // camera planes are needed to linearize depth
float cameraNearPlane; float cameraNearPlane;
float cameraFarPlane; float cameraFarPlane;
...@@ -76,12 +76,14 @@ vec2 processMotionVector(vec2 motion){ ...@@ -76,12 +76,14 @@ vec2 processMotionVector(vec2 motion){
vec2 motionHalf = motion * 0.5; vec2 motionHalf = motion * 0.5;
vec2 motionScaled = motionHalf * motionScaleFactor; // scale factor contains shutter speed and delta time vec2 motionScaled = motionHalf * motionScaleFactor; // scale factor contains shutter speed and delta time
// pixels are anisotropic so the smaller dimension is used, so the clamping is conservative float velocityPixels = length(motionScaled * imageSize(outImage));
float pixelSize = 1.f / max(imageSize(outImage).x, imageSize(outImage).y); float epsilon = 0.0001;
float velocity = length(motionScaled);
float epsilon = 0.0001; // pixels are anisotropic, so the ratio for clamping the velocity is computed in pixels instead of uv coordinates
vec2 motionPixel = motionScaled * imageSize(outImage);
// this clamps the motion to not exceed the radius given by the motion tile size // this clamps the motion to not exceed the radius given by the motion tile size
return motionScaled * max(0.5 * pixelSize, min(velocity, motionTileSize * pixelSize)) / (velocity + epsilon); return motionScaled * max(0.5, min(velocityPixels, motionTileSize)) / (velocityPixels + epsilon);
} }
SampleData loadSampleData(vec2 uv){ SampleData loadSampleData(vec2 uv){
...@@ -122,8 +124,8 @@ void main(){ ...@@ -122,8 +124,8 @@ void main(){
SampleData mainPixel = loadSampleData(uv); SampleData mainPixel = loadSampleData(uv);
// early out on little movement // early out on movement less than half a pixel
if(length(motionNeighbourhoodMax) <= minVelocity){ if(length(motionNeighbourhoodMax * imageSize(outImage)) <= 0.5){
imageStore(outImage, coord, vec4(mainPixel.color, 0.f)); imageStore(outImage, coord, vec4(mainPixel.color, 0.f));
return; return;
} }
......
...@@ -94,7 +94,6 @@ void App::run() { ...@@ -94,7 +94,6 @@ void App::run() {
float objectVerticalSpeed = 5; float objectVerticalSpeed = 5;
float objectAmplitude = 1; float objectAmplitude = 1;
float objectMeanHeight = 1; float objectMeanHeight = 1;
float motionBlurMinVelocity = 0.001;
int cameraShutterSpeedInverse = 24; int cameraShutterSpeedInverse = 24;
float motionVectorVisualisationRange = 0.008; float motionVectorVisualisationRange = 0.008;
...@@ -114,7 +113,7 @@ void App::run() { ...@@ -114,7 +113,7 @@ void App::run() {
sceneObjects.push_back(ground); sceneObjects.push_back(ground);
Object sphere; Object sphere;
sphere.meshResources = m_sphereMesh; sphere.meshResources = m_cubeMesh;
sphere.modelMatrixUpdate = [&](float time, Object& obj) { sphere.modelMatrixUpdate = [&](float time, Object& obj) {
const float currentHeight = objectMeanHeight + objectAmplitude * glm::sin(time * objectVerticalSpeed); const float currentHeight = objectMeanHeight + objectAmplitude * glm::sin(time * objectVerticalSpeed);
obj.modelMatrix = glm::translate(glm::mat4(1), glm::vec3(0, currentHeight, 0)); obj.modelMatrix = glm::translate(glm::mat4(1), glm::vec3(0, currentHeight, 0));
...@@ -249,8 +248,7 @@ void App::run() { ...@@ -249,8 +248,7 @@ void App::run() {
cameraNear, cameraNear,
cameraFar, cameraFar,
fDeltaTimeSeconds, fDeltaTimeSeconds,
cameraShutterSpeedInverse, cameraShutterSpeedInverse);
motionBlurMinVelocity);
} }
else { else {
eMotionVectorMode debugViewMode; eMotionVectorMode debugViewMode;
...@@ -320,7 +318,6 @@ void App::run() { ...@@ -320,7 +318,6 @@ void App::run() {
static_cast<int>(eMotionVectorMode::OptionCount)); static_cast<int>(eMotionVectorMode::OptionCount));
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::InputFloat("Object movement speed", &objectVerticalSpeed); ImGui::InputFloat("Object movement speed", &objectVerticalSpeed);
ImGui::InputFloat("Object movement amplitude", &objectAmplitude); ImGui::InputFloat("Object movement amplitude", &objectAmplitude);
......
...@@ -58,8 +58,7 @@ vkcv::ImageHandle MotionBlur::render( ...@@ -58,8 +58,7 @@ vkcv::ImageHandle MotionBlur::render(
const float cameraNear, const float cameraNear,
const float cameraFar, const float cameraFar,
const float deltaTimeSeconds, const float deltaTimeSeconds,
const float cameraShutterSpeedInverse, const float cameraShutterSpeedInverse) {
const float motionBlurMinVelocity) {
computeMotionTiles(cmdStream, motionBufferFullRes); computeMotionTiles(cmdStream, motionBufferFullRes);
...@@ -92,16 +91,14 @@ vkcv::ImageHandle MotionBlur::render( ...@@ -92,16 +91,14 @@ vkcv::ImageHandle MotionBlur::render(
// must match layout in "motionBlur.comp" // must match layout in "motionBlur.comp"
struct MotionBlurConstantData { struct MotionBlurConstantData {
float motionFactor; float motionFactor;
float minVelocity;
float cameraNearPlane; float cameraNearPlane;
float cameraFarPlane; float cameraFarPlane;
}; };
MotionBlurConstantData motionBlurConstantData; MotionBlurConstantData motionBlurConstantData;
const float deltaTimeMotionBlur = std::max(deltaTimeSeconds, MotionBlurConfig::timeScaleMax); const float deltaTimeMotionBlur = deltaTimeSeconds;
motionBlurConstantData.motionFactor = 1 / (deltaTimeMotionBlur * cameraShutterSpeedInverse); motionBlurConstantData.motionFactor = 1 / (deltaTimeMotionBlur * cameraShutterSpeedInverse);
motionBlurConstantData.minVelocity = motionBlurMinVelocity;
motionBlurConstantData.cameraNearPlane = cameraNear; motionBlurConstantData.cameraNearPlane = cameraNear;
motionBlurConstantData.cameraFarPlane = cameraFar; motionBlurConstantData.cameraFarPlane = cameraFar;
......
...@@ -31,8 +31,7 @@ public: ...@@ -31,8 +31,7 @@ public:
const float cameraNear, const float cameraNear,
const float cameraFar, const float cameraFar,
const float deltaTimeSeconds, const float deltaTimeSeconds,
const float cameraShutterSpeedInverse, const float cameraShutterSpeedInverse);
const float motionBlurMinVelocity);
vkcv::ImageHandle renderMotionVectorVisualisation( vkcv::ImageHandle renderMotionVectorVisualisation(
const vkcv::CommandStreamHandle cmdStream, const vkcv::CommandStreamHandle cmdStream,
......
...@@ -4,11 +4,5 @@ ...@@ -4,11 +4,5 @@
namespace MotionBlurConfig { namespace MotionBlurConfig {
const vk::Format motionVectorTileFormat = vk::Format::eR16G16Sfloat; const vk::Format motionVectorTileFormat = vk::Format::eR16G16Sfloat;
const vk::Format outputColorFormat = vk::Format::eB10G11R11UfloatPack32; const vk::Format outputColorFormat = vk::Format::eB10G11R11UfloatPack32;
const uint32_t maxMotionTileSize = 20; // must match "motionTileSize" in motionVectorMax.comp const uint32_t maxMotionTileSize = 20; // must match "motionTileSize" in motionBlurConfig.inc
// small mouse movements are restricted to pixel level and therefore quite unprecise
// therefore extrapolating movement at high framerates results in big jerky movements
// this results in wide sudden motion blur, which looks quite bad
// as a workaround the time scale is limited to a maximum value
const float timeScaleMax = 1.f / 60;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment