From 08146a76181de8efca1456af21e73816e0a88d55 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 17 Apr 2018 11:28:59 +0200 Subject: [PATCH] Used previous projection matrix to limit overblur --- .../render-utils/src/DeferredFrameTransform.cpp | 3 +++ libraries/render-utils/src/DeferredFrameTransform.h | 13 ++++++++----- libraries/render-utils/src/DeferredTransform.slh | 1 + libraries/render-utils/src/MaterialTextures.slh | 4 ++-- .../render-utils/src/simple_opaque_web_browser.slf | 4 +++- .../src/simple_transparent_web_browser.slf | 4 +++- .../src/velocityBuffer_cameraMotion.slf | 2 +- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/libraries/render-utils/src/DeferredFrameTransform.cpp b/libraries/render-utils/src/DeferredFrameTransform.cpp index d1c51bf46f..de6aca4034 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.cpp +++ b/libraries/render-utils/src/DeferredFrameTransform.cpp @@ -38,6 +38,9 @@ void DeferredFrameTransform::update(RenderArgs* args) { args->getViewFrustum().evalProjectionMatrix(frameTransformBuffer.projectionMono); + frameTransformBuffer.previousProjection[0] = frameTransformBuffer.projection[0]; + frameTransformBuffer.previousProjection[1] = frameTransformBuffer.projection[1]; + // Running in stereo ? bool isStereo = args->isStereo(); if (!isStereo) { diff --git a/libraries/render-utils/src/DeferredFrameTransform.h b/libraries/render-utils/src/DeferredFrameTransform.h index 8c2f0a7321..04cc4adeb3 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.h +++ b/libraries/render-utils/src/DeferredFrameTransform.h @@ -43,11 +43,14 @@ protected: glm::vec4 depthInfo; // Stereo info is { isStereoFrame, halfWidth } glm::vec4 stereoInfo{ 0.0 }; - // Mono proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space - glm::mat4 projection[2]; - // Inverse proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space - glm::mat4 invProjection[2]; - // THe mono projection for sure + // Mono proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space + glm::mat4 projection[2]; + // Inverse proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space + glm::mat4 invProjection[2]; + // Mono proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space of + // the previous frame + glm::mat4 previousProjection[2]; + // THe mono projection for sure glm::mat4 projectionMono; // Inv View matrix from eye space (mono) to world space glm::mat4 invView; diff --git a/libraries/render-utils/src/DeferredTransform.slh b/libraries/render-utils/src/DeferredTransform.slh index 6b0e1cd642..45a3d56ab7 100644 --- a/libraries/render-utils/src/DeferredTransform.slh +++ b/libraries/render-utils/src/DeferredTransform.slh @@ -32,6 +32,7 @@ struct DeferredFrameTransform { vec4 _stereoInfo; mat4 _projection[2]; mat4 _invProjection[2]; + mat4 _previousProjection[2]; mat4 _projectionMono; mat4 _viewInverse; mat4 _view; diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index 592aa37461..e7b2a8d285 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -11,8 +11,6 @@ <@if not MODEL_MATERIAL_TEXTURES_SLH@> <@def MODEL_MATERIAL_TEXTURES_SLH@> -#define TAA_TEXTURE_LOD_BIAS -1.0 - <@func declareMaterialTexMapArrayBuffer()@> const int MAX_TEXCOORDS = 2; @@ -49,6 +47,8 @@ TexMapArray getTexMapArray() { <@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion, withScattering)@> +#define TAA_TEXTURE_LOD_BIAS -1.0 + <@include gpu/TextureTable.slh@> #ifdef GPU_TEXTURE_TABLE_BINDLESS diff --git a/libraries/render-utils/src/simple_opaque_web_browser.slf b/libraries/render-utils/src/simple_opaque_web_browser.slf index af7ef78682..8e81369562 100644 --- a/libraries/render-utils/src/simple_opaque_web_browser.slf +++ b/libraries/render-utils/src/simple_opaque_web_browser.slf @@ -15,6 +15,8 @@ <@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> +#define TAA_TEXTURE_LOD_BIAS -1.0 + // the albedo texture uniform sampler2D originalTexture; @@ -24,7 +26,7 @@ in vec4 _color; in vec2 _texCoord0; void main(void) { - vec4 texel = texture(originalTexture, _texCoord0.st); + vec4 texel = texture(originalTexture, _texCoord0.st, TAA_TEXTURE_LOD_BIAS); texel = color_sRGBAToLinear(texel); packDeferredFragmentUnlit(normalize(_normal), 1.0, _color.rgb * texel.rgb); } diff --git a/libraries/render-utils/src/simple_transparent_web_browser.slf b/libraries/render-utils/src/simple_transparent_web_browser.slf index 414f3f683f..7a68bb12c3 100644 --- a/libraries/render-utils/src/simple_transparent_web_browser.slf +++ b/libraries/render-utils/src/simple_transparent_web_browser.slf @@ -15,6 +15,8 @@ <@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> +#define TAA_TEXTURE_LOD_BIAS -1.0 + // the albedo texture uniform sampler2D originalTexture; @@ -24,7 +26,7 @@ in vec4 _color; in vec2 _texCoord0; void main(void) { - vec4 texel = texture(originalTexture, _texCoord0.st); + vec4 texel = texture(originalTexture, _texCoord0.st, TAA_TEXTURE_LOD_BIAS); texel = color_sRGBAToLinear(texel); packDeferredFragmentTranslucent( normalize(_normal), diff --git a/libraries/render-utils/src/velocityBuffer_cameraMotion.slf b/libraries/render-utils/src/velocityBuffer_cameraMotion.slf index 22a95b55d1..913b0b83d9 100644 --- a/libraries/render-utils/src/velocityBuffer_cameraMotion.slf +++ b/libraries/render-utils/src/velocityBuffer_cameraMotion.slf @@ -32,7 +32,7 @@ void main(void) { vec3 worldPos = (getViewInverse() * vec4(eyePos, 1.0)).xyz; vec3 prevEyePos = (getPreviousView() * vec4(worldPos, 1.0)).xyz; - vec4 prevClipPos = (frameTransform._projection[stereoSide.x] * vec4(prevEyePos, 1.0)); + vec4 prevClipPos = (frameTransform._previousProjection[stereoSide.x] * vec4(prevEyePos, 1.0)); vec2 prevUV = 0.5 * (prevClipPos.xy / prevClipPos.w) + vec2(0.5); //vec2 imageSize = getWidthHeight(0);