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

[#106] Add jitter to motion tile lookup in motion blur to replace hard edges in blur with noise

parent 598c348c
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
Pipeline #26828 passed
...@@ -17,6 +17,7 @@ layout( push_constant ) uniform constants{ ...@@ -17,6 +17,7 @@ layout( push_constant ) uniform constants{
// camera planes are needed to linearize depth // camera planes are needed to linearize depth
float cameraNearPlane; float cameraNearPlane;
float cameraFarPlane; float cameraFarPlane;
float motionTileOffsetLength;
}; };
float linearizeDepth(float depth, float near, float far){ float linearizeDepth(float depth, float near, float far){
...@@ -111,6 +112,22 @@ float dither(ivec2 coord){ ...@@ -111,6 +112,22 @@ float dither(ivec2 coord){
return x ^^ y ? 1 : 0; return x ^^ y ? 1 : 0;
} }
// from https://www.shadertoy.com/view/ttc3zr
uvec2 murmurHash22(uvec2 src) {
const uint M = 0x5bd1e995u;
uvec2 h = uvec2(1190494759u, 2147483647u);
src *= M; src ^= src>>24u; src *= M;
h *= M; h ^= src.x; h *= M; h ^= src.y;
h ^= h>>13u; h *= M; h ^= h>>15u;
return h;
}
vec2 hash22(vec2 src) {
uvec2 h = murmurHash22(floatBitsToUint(src));
return uintBitsToFloat(h & 0x007fffffu | 0x3f800000u) - 1.0;
}
void main(){ void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(outImage)))) if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(outImage))))
...@@ -120,7 +137,9 @@ void main(){ ...@@ -120,7 +137,9 @@ void main(){
ivec2 coord = ivec2(gl_GlobalInvocationID.xy); ivec2 coord = ivec2(gl_GlobalInvocationID.xy);
vec2 uv = vec2(coord + 0.5) / textureRes; // + 0.5 to shift uv into pixel center vec2 uv = vec2(coord + 0.5) / textureRes; // + 0.5 to shift uv into pixel center
vec2 motionNeighbourhoodMax = processMotionVector(texture(sampler2D(inMotionNeighbourhoodMax, nearestSampler), uv).rg); // the motion tile lookup is jittered, so the hard edges in the blur are replaced by noise
vec2 motionOffset = motionTileOffsetLength * (hash22(coord) * 2 - 1) / textureRes;
vec2 motionNeighbourhoodMax = processMotionVector(texture(sampler2D(inMotionNeighbourhoodMax, nearestSampler), uv + motionOffset).rg);
SampleData mainPixel = loadSampleData(uv); SampleData mainPixel = loadSampleData(uv);
......
...@@ -96,7 +96,8 @@ void App::run() { ...@@ -96,7 +96,8 @@ void App::run() {
eMotionVectorVisualisationMode motionVectorVisualisationMode = eMotionVectorVisualisationMode::None; eMotionVectorVisualisationMode motionVectorVisualisationMode = eMotionVectorVisualisationMode::None;
eMotionVectorMode motionBlurMotionMode = eMotionVectorMode::MaxTileNeighbourhood; eMotionVectorMode motionBlurMotionMode = eMotionVectorMode::MaxTileNeighbourhood;
bool freezeFrame = false; bool freezeFrame = false;
float motionBlurTileOffsetLength = 10;
float objectVerticalSpeed = 5; float objectVerticalSpeed = 5;
float objectAmplitude = 0; float objectAmplitude = 0;
float objectMeanHeight = 1; float objectMeanHeight = 1;
...@@ -276,7 +277,8 @@ void App::run() { ...@@ -276,7 +277,8 @@ void App::run() {
cameraNear, cameraNear,
cameraFar, cameraFar,
fDeltaTimeSeconds, fDeltaTimeSeconds,
cameraShutterSpeedInverse); cameraShutterSpeedInverse,
motionBlurTileOffsetLength);
} }
else { else {
eMotionVectorMode debugViewMode; eMotionVectorMode debugViewMode;
...@@ -331,6 +333,7 @@ void App::run() { ...@@ -331,6 +333,7 @@ void App::run() {
ImGui::Begin("Settings"); ImGui::Begin("Settings");
ImGui::Checkbox("Freeze frame", &freezeFrame); ImGui::Checkbox("Freeze frame", &freezeFrame);
ImGui::InputFloat("Motion tile offset length", &motionBlurTileOffsetLength);
ImGui::Combo( ImGui::Combo(
"Debug view", "Debug view",
......
...@@ -58,7 +58,8 @@ vkcv::ImageHandle MotionBlur::render( ...@@ -58,7 +58,8 @@ 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 motionTileOffsetLength) {
computeMotionTiles(cmdStream, motionBufferFullRes); computeMotionTiles(cmdStream, motionBufferFullRes);
...@@ -93,14 +94,16 @@ vkcv::ImageHandle MotionBlur::render( ...@@ -93,14 +94,16 @@ vkcv::ImageHandle MotionBlur::render(
float motionFactor; float motionFactor;
float cameraNearPlane; float cameraNearPlane;
float cameraFarPlane; float cameraFarPlane;
float motionTileOffsetLength;
}; };
MotionBlurConstantData motionBlurConstantData; MotionBlurConstantData motionBlurConstantData;
const float deltaTimeMotionBlur = deltaTimeSeconds; const float deltaTimeMotionBlur = deltaTimeSeconds;
motionBlurConstantData.motionFactor = 1 / (deltaTimeMotionBlur * cameraShutterSpeedInverse); motionBlurConstantData.motionFactor = 1 / (deltaTimeMotionBlur * cameraShutterSpeedInverse);
motionBlurConstantData.cameraNearPlane = cameraNear; motionBlurConstantData.cameraNearPlane = cameraNear;
motionBlurConstantData.cameraFarPlane = cameraFar; motionBlurConstantData.cameraFarPlane = cameraFar;
motionBlurConstantData.motionTileOffsetLength = motionTileOffsetLength;
vkcv::PushConstants motionBlurPushConstants(sizeof(motionBlurConstantData)); vkcv::PushConstants motionBlurPushConstants(sizeof(motionBlurConstantData));
motionBlurPushConstants.appendDrawcall(motionBlurConstantData); motionBlurPushConstants.appendDrawcall(motionBlurConstantData);
......
...@@ -31,7 +31,8 @@ public: ...@@ -31,7 +31,8 @@ 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 motionTileOffsetLength);
vkcv::ImageHandle renderMotionVectorVisualisation( vkcv::ImageHandle renderMotionVectorVisualisation(
const vkcv::CommandStreamHandle cmdStream, const vkcv::CommandStreamHandle cmdStream,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment