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

[#106] Replaced motion blur noise with dither to reduce visible noise

parent faf68405
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
Pipeline #26782 passed
...@@ -15,7 +15,6 @@ layout( push_constant ) uniform constants{ ...@@ -15,7 +15,6 @@ 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 time;
}; };
float linearizeDepth(float depth, float near, float far){ float linearizeDepth(float depth, float near, float far){
...@@ -77,19 +76,16 @@ SampleData loadSampleData(vec2 uv){ ...@@ -77,19 +76,16 @@ SampleData loadSampleData(vec2 uv){
return data; return data;
} }
// simple hash/noise function from: https://www.shadertoy.com/view/ttc3zr // simple binary dither pattern
uint murmurHash12(uvec2 src) { // could be optimized to avoid modulo and branch
const uint M = 0x5bd1e995u; float dither(ivec2 coord){
uint h = 1190494759u;
src *= M; src ^= src>>24u; src *= M; int ditherSize = 4;
h *= M; h ^= src.x; h *= M; h ^= src.y;
h ^= h>>13u; h *= M; h ^= h>>15u; bool x = coord.x % ditherSize < (ditherSize / 2);
return h; bool y = coord.y % ditherSize < (ditherSize / 2);
}
return x ^^ y ? 1 : 0;
float hash12(vec2 src) {
uint h = murmurHash12(floatBitsToUint(src));
return uintBitsToFloat(h & 0x007fffffu | 0x3f800000u) - 1.0;
} }
void main(){ void main(){
...@@ -126,7 +122,9 @@ void main(){ ...@@ -126,7 +122,9 @@ void main(){
vec2 uvEnd = clamp(uv + mainPixel.motion, 0, 1); vec2 uvEnd = clamp(uv + mainPixel.motion, 0, 1);
// samples are placed evenly, but the entire filter is jittered // samples are placed evenly, but the entire filter is jittered
float random = hash12(uv + time) - 0.5; // in range [-0.5, 0.5] // dither returns either 0 or 1
// the sampleUV code expects an offset in range [-0.5, 0.5], so the dither is rescaled to a binary -0.25/0.25
float random = dither(coord) * 0.5 - 0.25;
for(int i = 0; i < sampleCount; i++){ for(int i = 0; i < sampleCount; i++){
vec2 sampleUV = mix(uvStart, uvEnd, (i + random + 1) / float(sampleCount + 1)); vec2 sampleUV = mix(uvStart, uvEnd, (i + random + 1) / float(sampleCount + 1));
......
...@@ -7,8 +7,6 @@ layout(set=0, binding=2, rgba8) uniform image2D outMotionMaxNeighbourhood; ...@@ -7,8 +7,6 @@ layout(set=0, binding=2, rgba8) uniform image2D outMotionMaxNeighbourhood;
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;
const int motionTileSize = 8;
void main(){ void main(){
ivec2 outImageRes = imageSize(outMotionMaxNeighbourhood); ivec2 outImageRes = imageSize(outMotionMaxNeighbourhood);
......
...@@ -305,7 +305,6 @@ void App::run() { ...@@ -305,7 +305,6 @@ void App::run() {
float minVelocity; float minVelocity;
float cameraNearPlane; float cameraNearPlane;
float cameraFarPlane; float cameraFarPlane;
float time;
}; };
MotionBlurConstantData motionBlurConstantData; MotionBlurConstantData motionBlurConstantData;
...@@ -323,7 +322,6 @@ void App::run() { ...@@ -323,7 +322,6 @@ void App::run() {
m_cameraManager.getActiveCamera().getNearFar(cameraNear, cameraFar); m_cameraManager.getActiveCamera().getNearFar(cameraNear, cameraFar);
motionBlurConstantData.cameraNearPlane = cameraNear; motionBlurConstantData.cameraNearPlane = cameraNear;
motionBlurConstantData.cameraFarPlane = cameraFar; motionBlurConstantData.cameraFarPlane = cameraFar;
motionBlurConstantData.time = fCurrentTime;
vkcv::PushConstants motionBlurPushConstants(sizeof(motionBlurConstantData)); vkcv::PushConstants motionBlurPushConstants(sizeof(motionBlurConstantData));
motionBlurPushConstants.appendDrawcall(motionBlurConstantData); motionBlurPushConstants.appendDrawcall(motionBlurConstantData);
......
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