diff --git a/projects/indirect_dispatch/assets/shaders/motionVectorMinMax.comp b/projects/indirect_dispatch/assets/shaders/motionVectorMinMax.comp index 4ad350b0d5300aa63a66d7aceb00ea0b642d07ee..06b1b98f37579ae33406691bf19999d42ab7eb83 100644 --- a/projects/indirect_dispatch/assets/shaders/motionVectorMinMax.comp +++ b/projects/indirect_dispatch/assets/shaders/motionVectorMinMax.comp @@ -12,6 +12,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; void main(){ ivec2 outImageRes = imageSize(outMotionMax); + ivec2 inImageRes = textureSize(sampler2D(inMotion, textureSampler), 0); ivec2 motionTileCoord = ivec2(gl_GlobalInvocationID.xy); if(any(greaterThanEqual(motionTileCoord, outImageRes))) @@ -28,6 +29,14 @@ void main(){ for(int x = 0; x < motionTileSize; x++){ for(int y = 0; y < motionTileSize; y++){ ivec2 sampleCoord = motionBufferBaseCoord + ivec2(x, y); + + bool sampleIsOutsideImage = false; + sampleIsOutsideImage = sampleIsOutsideImage || any(greaterThanEqual(sampleCoord, inImageRes)); + sampleIsOutsideImage = sampleIsOutsideImage || any(lessThan(sampleCoord, ivec2(0))); + + if(sampleIsOutsideImage) + continue; + vec2 motionSample = texelFetch(sampler2D(inMotion, textureSampler), sampleCoord, 0).rg; float velocitySample = length(motionSample); diff --git a/projects/indirect_dispatch/assets/shaders/motionVectorMinMaxNeighbourhood.comp b/projects/indirect_dispatch/assets/shaders/motionVectorMinMaxNeighbourhood.comp index 4d6e7c0af6115e816ba087570e5585ffde23b1e6..3f836341a97a683efe88f41416d541624be03a0e 100644 --- a/projects/indirect_dispatch/assets/shaders/motionVectorMinMaxNeighbourhood.comp +++ b/projects/indirect_dispatch/assets/shaders/motionVectorMinMaxNeighbourhood.comp @@ -12,6 +12,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; void main(){ ivec2 outImageRes = imageSize(outMotionMaxNeighbourhood); + ivec2 inImageRes = textureSize(sampler2D(inMotionMax, textureSampler), 0); ivec2 motionTileCoord = ivec2(gl_GlobalInvocationID.xy); if(any(greaterThanEqual(motionTileCoord, outImageRes))) @@ -27,6 +28,13 @@ void main(){ for(int y = -1; y <= 1; y++){ ivec2 sampleCoord = motionTileCoord + ivec2(x, y); + bool sampleIsOutsideImage = false; + sampleIsOutsideImage = sampleIsOutsideImage || any(greaterThanEqual(sampleCoord, inImageRes)); + sampleIsOutsideImage = sampleIsOutsideImage || any(lessThan(sampleCoord, ivec2(0))); + + if(sampleIsOutsideImage) + continue; + vec2 motionSampleMax = texelFetch(sampler2D(inMotionMax, textureSampler), sampleCoord, 0).rg; float velocitySampleMax = length(motionSampleMax); diff --git a/projects/indirect_dispatch/assets/shaders/motionVectorVisualisation.comp b/projects/indirect_dispatch/assets/shaders/motionVectorVisualisation.comp index 1cfb09c87e8288b8ea80c6ddfbe5f0d4918b7f2e..fdceb575feaf24e7114bbcf223585a28955f45b8 100644 --- a/projects/indirect_dispatch/assets/shaders/motionVectorVisualisation.comp +++ b/projects/indirect_dispatch/assets/shaders/motionVectorVisualisation.comp @@ -21,7 +21,10 @@ void main(){ if(any(greaterThanEqual(coord, outImageRes))) return; - vec2 motionVector = texelFetch(sampler2D(inMotion, textureSampler), coord / motionTileSize, 0).rg; + vec2 uv = (coord + 0.5) / vec2(outImageRes); + ivec2 inTextureRes = textureSize(sampler2D(inMotion, textureSampler), 0); + + vec2 motionVector = texelFetch(sampler2D(inMotion, textureSampler), ivec2(uv * inTextureRes), 0).rg; vec2 motionVectorNormalized = clamp(motionVector / range, -1, 1); vec2 color = motionVectorNormalized * 0.5 + 0.5; diff --git a/projects/indirect_dispatch/src/App.cpp b/projects/indirect_dispatch/src/App.cpp index d4afc61c7421bd45c773bbdbc3da796b868869d2..532cef11db5b2bb8b5d741f6505507ff23fa4163 100644 --- a/projects/indirect_dispatch/src/App.cpp +++ b/projects/indirect_dispatch/src/App.cpp @@ -28,7 +28,7 @@ App::App() : VK_MAKE_VERSION(0, 0, 1), { vk::QueueFlagBits::eGraphics ,vk::QueueFlagBits::eCompute , vk::QueueFlagBits::eTransfer }, { VK_KHR_SWAPCHAIN_EXTENSION_NAME })), - m_windowHandle(m_core.createWindow(m_applicationName, m_windowWidth, m_windowHeight, false)), + m_windowHandle(m_core.createWindow(m_applicationName, m_windowWidth, m_windowHeight, true)), m_cameraManager(m_core.getWindow(m_windowHandle)){} bool App::initialize() {