From 46a1ff4dd277c5dd9735a1a1457d356c9f8b2307 Mon Sep 17 00:00:00 2001
From: Olivier Prat <olivier@zvork.fr>
Date: Fri, 20 Apr 2018 12:02:17 +0200
Subject: [PATCH] Set jitter to O on RenderableWebEntityItems

---
 .../entities-renderer/src/RenderableWebEntityItem.cpp  |  3 +++
 libraries/gpu/src/gpu/Batch.cpp                        | 10 ++++++++++
 libraries/gpu/src/gpu/Batch.h                          |  4 ++++
 libraries/render-utils/src/AntialiasingEffect.cpp      |  2 +-
 libraries/render-utils/src/AntialiasingEffect.h        |  4 ++--
 libraries/render-utils/src/MaterialTextures.slh        |  7 ++++++-
 scripts/developer/utilities/render/antialiasing.qml    |  4 ++++
 7 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp
index f31ed4e238..1c00796e50 100644
--- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp
+++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp
@@ -246,8 +246,11 @@ void WebEntityRenderer::doRender(RenderArgs* args) {
     batch.setResourceTexture(0, _texture);
     float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
 
+    // Turn off jitter for these entities
+    batch.pushProjectionJitter();
     DependencyManager::get<GeometryCache>()->bindWebBrowserProgram(batch, fadeRatio < OPAQUE_ALPHA_THRESHOLD);
     DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, fadeRatio), _geometryId);
+    batch.popProjectionJitter();
 }
 
 bool WebEntityRenderer::hasWebSurface() {
diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp
index 2b60070cb7..84a7c275f0 100644
--- a/libraries/gpu/src/gpu/Batch.cpp
+++ b/libraries/gpu/src/gpu/Batch.cpp
@@ -266,11 +266,21 @@ void Batch::setProjectionTransform(const Mat4& proj) {
 }
 
 void Batch::setProjectionJitter(float jx, float jy) {
+	_projectionJitter.x = jx;
+	_projectionJitter.y = jy;
+	pushProjectionJitter(jx, jy);
+}
+
+void Batch::pushProjectionJitter(float jx, float jy) { 
 	ADD_COMMAND(setProjectionJitter);
 	_params.emplace_back(jx);
 	_params.emplace_back(jy);
 }
 
+void Batch::popProjectionJitter() { 
+	pushProjectionJitter(_projectionJitter.x, _projectionJitter.y);
+}
+
 void Batch::setViewportTransform(const Vec4i& viewport) {
     ADD_COMMAND(setViewportTransform);
 
diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h
index c08158b982..ed928e08e6 100644
--- a/libraries/gpu/src/gpu/Batch.h
+++ b/libraries/gpu/src/gpu/Batch.h
@@ -168,6 +168,9 @@ public:
     void setViewTransform(const Transform& view, bool camera = true);
     void setProjectionTransform(const Mat4& proj);
 	void setProjectionJitter(float jx = 0.0f, float jy = 0.0f);
+	// Very simple 1 level stack management of jitter.
+	void pushProjectionJitter(float jx = 0.0f, float jy = 0.0f);
+	void popProjectionJitter();
     // Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels
     void setViewportTransform(const Vec4i& viewport);
     void setDepthRangeTransform(float nearDepth, float farDepth);
@@ -498,6 +501,7 @@ public:
 
     NamedBatchDataMap _namedData;
 
+	glm::vec2 _projectionJitter{ 0.0f, 0.0f };
     bool _enableStereo{ true };
     bool _enableSkybox { false };
 
diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp
index 78b33c39f7..fea78f27e5 100644
--- a/libraries/render-utils/src/AntialiasingEffect.cpp
+++ b/libraries/render-utils/src/AntialiasingEffect.cpp
@@ -283,7 +283,7 @@ const gpu::PipelinePointer& Antialiasing::getDebugBlendPipeline() {
 }
 
 void Antialiasing::configure(const Config& config) {
-    _sharpen = config.sharpen;
+    _sharpen = config.sharpen * 0.25f;
     if (!_isSharpenEnabled) {
         _sharpen = 0.0f;
     }
diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h
index 7d6f05da4e..a89666f58b 100644
--- a/libraries/render-utils/src/AntialiasingEffect.h
+++ b/libraries/render-utils/src/AntialiasingEffect.h
@@ -58,7 +58,7 @@ class JitterSample {
 public:
 
     enum {
-        SEQUENCE_LENGTH = 16 
+        SEQUENCE_LENGTH = 64 
     };
 
     using Config = JitterSampleConfig;
@@ -110,7 +110,7 @@ public:
     float sharpen{ 0.05f };
 
     bool constrainColor{ true };
-    float covarianceGamma{ 1.0f };
+    float covarianceGamma{ 0.65f };
     bool feedbackColor{ false };
 
     float debugX{ 0.0f };
diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh
index 57fcf9cea1..4bcd74eefe 100644
--- a/libraries/render-utils/src/MaterialTextures.slh
+++ b/libraries/render-utils/src/MaterialTextures.slh
@@ -67,6 +67,7 @@ TextureTable(0, matTex);
 <@if withAlbedo@>
 #define albedoMap 0
 vec4 fetchAlbedoMap(vec2 uv) {
+    // Should take into account TAA_TEXTURE_LOD_BIAS?
     return tableTexValue(matTex, albedoMap, uv);
 }
 <@endif@>
@@ -74,6 +75,7 @@ vec4 fetchAlbedoMap(vec2 uv) {
 <@if withRoughness@>
 #define roughnessMap 4
 float fetchRoughnessMap(vec2 uv) {
+    // Should take into account TAA_TEXTURE_LOD_BIAS?
     return tableTexValue(matTex, roughnessMap, uv).r;
 }
 <@endif@>
@@ -81,6 +83,7 @@ float fetchRoughnessMap(vec2 uv) {
 <@if withNormal@>
 #define normalMap 1
 vec3 fetchNormalMap(vec2 uv) {
+    // Should take into account TAA_TEXTURE_LOD_BIAS?
     return tableTexValue(matTex, normalMap, uv).xyz;
 }
 <@endif@>
@@ -88,6 +91,7 @@ vec3 fetchNormalMap(vec2 uv) {
 <@if withMetallic@>
 #define metallicMap 2
 float fetchMetallicMap(vec2 uv) {
+    // Should take into account TAA_TEXTURE_LOD_BIAS?
     return tableTexValue(matTex, metallicMap, uv).r;
 }
 <@endif@>
@@ -95,6 +99,7 @@ float fetchMetallicMap(vec2 uv) {
 <@if withEmissive@>
 #define emissiveMap 3
 vec3 fetchEmissiveMap(vec2 uv) {
+    // Should take into account TAA_TEXTURE_LOD_BIAS?
     return tableTexValue(matTex, emissiveMap, uv).rgb;
 }
 <@endif@>
@@ -158,7 +163,7 @@ vec3 fetchEmissiveMap(vec2 uv) {
 <@if withOcclusion@>
 uniform sampler2D occlusionMap;
 float fetchOcclusionMap(vec2 uv) {
-    return texture(occlusionMap, uv, TAA_TEXTURE_LOD_BIAS).r;
+    return texture(occlusionMap, uv).r;
 }
 <@endif@>
 
diff --git a/scripts/developer/utilities/render/antialiasing.qml b/scripts/developer/utilities/render/antialiasing.qml
index e8034c48bd..8bdd5c6a0d 100644
--- a/scripts/developer/utilities/render/antialiasing.qml
+++ b/scripts/developer/utilities/render/antialiasing.qml
@@ -98,6 +98,7 @@ Rectangle {
                 property: "covarianceGamma"
                 max: 1.5
                 min: 0.5
+                height: 38
             }                          
             Separator {}          
             HifiControls.CheckBox {
@@ -114,6 +115,7 @@ Rectangle {
                 property: "blend"
                 max: 1.0
                 min: 0.0
+                height: 38
             }
     
             ConfigSlider {
@@ -162,6 +164,7 @@ Rectangle {
                 property: "debugShowVelocityThreshold"
                 max: 50
                 min: 0.0
+                height: 38
             }
             ConfigSlider {
                 label: qsTr("Debug Orb Zoom")
@@ -170,6 +173,7 @@ Rectangle {
                 property: "debugOrbZoom"
                 max: 32.0
                 min: 1.0
+                height: 38
             }    
         }
     }