From bed7752a1a0560b1535525adfa671392b2617f7f Mon Sep 17 00:00:00 2001
From: Olivier Prat <olivier@zvork.fr>
Date: Tue, 15 May 2018 12:27:04 +0200
Subject: [PATCH 1/5] Fixed bug with highlighting and TAA

---
 libraries/render-utils/src/HighlightEffect.cpp    | 9 +++++++--
 libraries/render-utils/src/HighlightEffect.h      | 6 +++---
 libraries/render-utils/src/RenderDeferredTask.cpp | 9 ++++++---
 libraries/render-utils/src/RenderDeferredTask.h   | 2 +-
 libraries/render/src/render/DrawStatus.cpp        | 6 +++++-
 libraries/render/src/render/DrawStatus.h          | 5 +++--
 6 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/libraries/render-utils/src/HighlightEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp
index d151da766b..3905d3a54c 100644
--- a/libraries/render-utils/src/HighlightEffect.cpp
+++ b/libraries/render-utils/src/HighlightEffect.cpp
@@ -169,6 +169,7 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c
 
         glm::mat4 projMat;
         Transform viewMat;
+        const auto jitter = inputs.get2();
         args->getViewFrustum().evalProjectionMatrix(projMat);
         args->getViewFrustum().evalViewTransform(viewMat);
 
@@ -183,6 +184,7 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c
             // Setup camera, projection and viewport for all items
             batch.setViewportTransform(args->_viewport);
             batch.setProjectionTransform(projMat);
+            batch.setProjectionJitter(jitter.x, jitter.y);
             batch.setViewTransform(viewMat);
 
             std::vector<ShapeKey> skinnedShapeKeys{};
@@ -356,6 +358,7 @@ void DebugHighlight::run(const render::RenderContextPointer& renderContext, cons
         assert(renderContext->args);
         assert(renderContext->args->hasViewFrustum());
         RenderArgs* args = renderContext->args;
+        const auto jitter = input.get2();
 
         gpu::doInBatch("DebugHighlight::run", args->_context, [&](gpu::Batch& batch) {
             batch.setViewportTransform(args->_viewport);
@@ -368,6 +371,7 @@ void DebugHighlight::run(const render::RenderContextPointer& renderContext, cons
             args->getViewFrustum().evalProjectionMatrix(projMat);
             args->getViewFrustum().evalViewTransform(viewMat);
             batch.setProjectionTransform(projMat);
+            batch.setProjectionJitter(jitter.x, jitter.y);
             batch.setViewTransform(viewMat, true);
             batch.setModelTransform(Transform());
 
@@ -480,6 +484,7 @@ void DrawHighlightTask::build(JobModel& task, const render::Varying& inputs, ren
     const auto sceneFrameBuffer = inputs.getN<Inputs>(1);
     const auto primaryFramebuffer = inputs.getN<Inputs>(2);
     const auto deferredFrameTransform = inputs.getN<Inputs>(3);
+    const auto jitter = inputs.getN<Inputs>(4);
 
     // Prepare the ShapePipeline
     auto shapePlumber = std::make_shared<ShapePlumber>();
@@ -515,7 +520,7 @@ void DrawHighlightTask::build(JobModel& task, const render::Varying& inputs, ren
             stream << "HighlightMask" << i;
             name = stream.str();
         }
-        const auto drawMaskInputs = DrawHighlightMask::Inputs(sortedBounds, highlightRessources).asVarying();
+        const auto drawMaskInputs = DrawHighlightMask::Inputs(sortedBounds, highlightRessources, jitter).asVarying();
         const auto highlightedRect = task.addJob<DrawHighlightMask>(name, drawMaskInputs, i, shapePlumber, sharedParameters);
         if (i == 0) {
             highlight0Rect = highlightedRect;
@@ -532,7 +537,7 @@ void DrawHighlightTask::build(JobModel& task, const render::Varying& inputs, ren
     }
 
     // Debug highlight
-    const auto debugInputs = DebugHighlight::Inputs(highlightRessources, const_cast<const render::Varying&>(highlight0Rect)).asVarying();
+    const auto debugInputs = DebugHighlight::Inputs(highlightRessources, const_cast<const render::Varying&>(highlight0Rect), jitter).asVarying();
     task.addJob<DebugHighlight>("HighlightDebug", debugInputs);
 }
 
diff --git a/libraries/render-utils/src/HighlightEffect.h b/libraries/render-utils/src/HighlightEffect.h
index 90a8e730ce..7c1db795fb 100644
--- a/libraries/render-utils/src/HighlightEffect.h
+++ b/libraries/render-utils/src/HighlightEffect.h
@@ -113,7 +113,7 @@ private:
 class DrawHighlightMask {
 public:
 
-    using Inputs = render::VaryingSet2<render::ShapeBounds, HighlightRessourcesPointer>;
+    using Inputs = render::VaryingSet3<render::ShapeBounds, HighlightRessourcesPointer, glm::vec2>;
     using Outputs = glm::ivec4;
     using JobModel = render::Job::ModelIO<DrawHighlightMask, Inputs, Outputs>;
 
@@ -182,7 +182,7 @@ signals:
 
 class DebugHighlight {
 public:
-    using Inputs = render::VaryingSet2<HighlightRessourcesPointer, glm::ivec4>;
+    using Inputs = render::VaryingSet3<HighlightRessourcesPointer, glm::ivec4, glm::vec2>;
     using Config = DebugHighlightConfig;
     using JobModel = render::Job::ModelI<DebugHighlight, Inputs, Config>;
 
@@ -205,7 +205,7 @@ private:
 class DrawHighlightTask {
 public:
 
-    using Inputs = render::VaryingSet4<RenderFetchCullSortTask::BucketList, DeferredFramebufferPointer, gpu::FramebufferPointer, DeferredFrameTransformPointer>;
+    using Inputs = render::VaryingSet5<RenderFetchCullSortTask::BucketList, DeferredFramebufferPointer, gpu::FramebufferPointer, DeferredFrameTransformPointer, glm::vec2>;
     using Config = render::Task::Config;
     using JobModel = render::Task::ModelI<DrawHighlightTask, Inputs, Config>;
 
diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp
index bea298122e..ab1d831ead 100644
--- a/libraries/render-utils/src/RenderDeferredTask.cpp
+++ b/libraries/render-utils/src/RenderDeferredTask.cpp
@@ -178,7 +178,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
     task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs);
 
     // Render transparent objects forward in LightingBuffer
-    const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel, lightClusters).asVarying();
+    const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel, lightClusters, jitter).asVarying();
     task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber);
 
     // Light Cluster Grid Debuging job
@@ -192,7 +192,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
     const auto selectionBaseName = "contextOverlayHighlightList";
     const auto selectedItems = addSelectItemJobs(task, selectionBaseName, metas, opaques, transparents);
 
-    const auto outlineInputs = DrawHighlightTask::Inputs(items.get0(), deferredFramebuffer, lightingFramebuffer, deferredFrameTransform).asVarying();
+    const auto outlineInputs = DrawHighlightTask::Inputs(items.get0(), deferredFramebuffer, lightingFramebuffer, deferredFrameTransform, jitter).asVarying();
     task.addJob<DrawHighlightTask>("DrawHighlight", outlineInputs);
 
     task.addJob<EndGPURangeTimer>("HighlightRangeTimer", outlineRangeTimer);
@@ -277,7 +277,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
             // Grab a texture map representing the different status icons and assign that to the drawStatsuJob
             auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg";
             auto statusIconMap = DependencyManager::get<TextureCache>()->getImageTexture(iconMapPath, image::TextureUsage::STRICT_TEXTURE);
-            task.addJob<DrawStatus>("DrawStatus", opaques, DrawStatus(statusIconMap));
+            const auto drawStatusInputs = DrawStatus::Input(opaques, jitter).asVarying();
+            task.addJob<DrawStatus>("DrawStatus", drawStatusInputs, DrawStatus(statusIconMap));
         }
 
         task.addJob<DebugZoneLighting>("DrawZoneStack", deferredFrameTransform);
@@ -315,6 +316,7 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
     const auto& inItems = inputs.get0();
     const auto& lightingModel = inputs.get1();
     const auto& lightClusters = inputs.get2();
+    const auto jitter = inputs.get3();
     auto deferredLightingEffect = DependencyManager::get<DeferredLightingEffect>();
 
     RenderArgs* args = renderContext->args;
@@ -332,6 +334,7 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
         args->getViewFrustum().evalViewTransform(viewMat);
 
         batch.setProjectionTransform(projMat);
+        batch.setProjectionJitter(jitter.x, jitter.y);
         batch.setViewTransform(viewMat);
 
         // Setup lighting model for all items;
diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h
index b923ec0878..9917058790 100644
--- a/libraries/render-utils/src/RenderDeferredTask.h
+++ b/libraries/render-utils/src/RenderDeferredTask.h
@@ -41,7 +41,7 @@ protected:
 
 class DrawDeferred {
 public:
-    using Inputs = render::VaryingSet3 <render::ItemBounds, LightingModelPointer, LightClustersPointer>;
+    using Inputs = render::VaryingSet4<render::ItemBounds, LightingModelPointer, LightClustersPointer, glm::vec2>;
     using Config = DrawDeferredConfig;
     using JobModel = render::Job::ModelI<DrawDeferred, Inputs, Config>;
 
diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp
index 56802a3239..496b2000a9 100644
--- a/libraries/render/src/render/DrawStatus.cpp
+++ b/libraries/render/src/render/DrawStatus.cpp
@@ -104,7 +104,7 @@ void DrawStatus::configure(const Config& config) {
     _showNetwork = config.showNetwork;
 }
 
-void DrawStatus::run(const RenderContextPointer& renderContext, const ItemBounds& inItems) {
+void DrawStatus::run(const RenderContextPointer& renderContext, const Input& input) {
     assert(renderContext->args);
     assert(renderContext->args->hasViewFrustum());
     RenderArgs* args = renderContext->args;
@@ -112,6 +112,9 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const ItemBounds
     const int NUM_STATUS_VEC4_PER_ITEM = 2;
     const int VEC4_LENGTH = 4;
 
+    const auto& inItems = input.get0();
+    const auto jitter = input.get1();
+
     // FIrst thing, we collect the bound and the status for all the items we want to render
     int nbItems = 0;
     {
@@ -171,6 +174,7 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const ItemBounds
         batch.setViewportTransform(args->_viewport);
 
         batch.setProjectionTransform(projMat);
+        batch.setProjectionJitter(jitter.x, jitter.y);
         batch.setViewTransform(viewMat, true);
         batch.setModelTransform(Transform());
 
diff --git a/libraries/render/src/render/DrawStatus.h b/libraries/render/src/render/DrawStatus.h
index 2e0adb4653..9e05471cd6 100644
--- a/libraries/render/src/render/DrawStatus.h
+++ b/libraries/render/src/render/DrawStatus.h
@@ -39,13 +39,14 @@ namespace render {
     class DrawStatus {
     public:
         using Config = DrawStatusConfig;
-        using JobModel = Job::ModelI<DrawStatus, ItemBounds, Config>;
+        using Input = VaryingSet2<ItemBounds, glm::vec2>;
+        using JobModel = Job::ModelI<DrawStatus, Input, Config>;
 
         DrawStatus() {}
         DrawStatus(const gpu::TexturePointer statusIconMap) { setStatusIconMap(statusIconMap); }
 
         void configure(const Config& config);
-        void run(const RenderContextPointer& renderContext, const ItemBounds& inItems);
+        void run(const RenderContextPointer& renderContext, const Input& input);
 
         const gpu::PipelinePointer getDrawItemBoundsPipeline();
         const gpu::PipelinePointer getDrawItemStatusPipeline();

From d10b5a16f291b860a0c213f1ad0636cf0b94f55b Mon Sep 17 00:00:00 2001
From: Olivier Prat <olivier@zvork.fr>
Date: Tue, 15 May 2018 15:09:02 +0200
Subject: [PATCH 2/5] Turned off jitter with FXAA

---
 .../render-utils/src/AntialiasingEffect.cpp     | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp
index f77b4fc68b..249d2bbc47 100644
--- a/libraries/render-utils/src/AntialiasingEffect.cpp
+++ b/libraries/render-utils/src/AntialiasingEffect.cpp
@@ -482,16 +482,14 @@ JitterSample::SampleSequence::SampleSequence(){
 }
 
 void JitterSample::configure(const Config& config) {
-    _freeze = config.freeze;
-    if (config.stop || _freeze) {
+    _freeze = config.stop || config.freeze;
+    if (config.freeze) {
         auto pausedIndex = config.getIndex();
         if (_sampleSequence.currentIndex != pausedIndex) {
             _sampleSequence.currentIndex = pausedIndex;
         }
-    } else {
-        if (_sampleSequence.currentIndex < 0) {
-            _sampleSequence.currentIndex = config.getIndex();
-        }
+    } else if (config.stop) {
+        _sampleSequence.currentIndex = -1;
     }
     _scale = config.scale;
 }
@@ -505,7 +503,12 @@ void JitterSample::run(const render::RenderContextPointer& renderContext, Output
             current = -1;
         }
     }
-    jitter = _sampleSequence.offsets[(current < 0 ? SEQUENCE_LENGTH : current)];
+
+    jitter.x = 0.0f;
+    jitter.y = 0.0f;
+    if (current >= 0) {
+        jitter = _sampleSequence.offsets[current];
+    }
 }
 
 

From 179801dab6fe1802163491b63624fad688e7aaaa Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Tue, 15 May 2018 17:22:28 -0700
Subject: [PATCH 3/5] FIxing the transparent ambient lighting  bug

---
 .../render-utils/src/DeferredBufferWrite.slh  |  7 ++--
 .../render-utils/src/DeferredGlobalLight.slh  |  6 +--
 .../src/DeferredLightingEffect.cpp            | 39 +++++++++++--------
 .../render-utils/src/DeferredLightingEffect.h |  4 +-
 libraries/render-utils/src/GeometryCache.cpp  |  4 +-
 libraries/render-utils/src/Haze.slf           |  2 +-
 libraries/render-utils/src/LightClusters.cpp  |  2 +-
 libraries/render-utils/src/LightingModel.cpp  |  9 +++++
 libraries/render-utils/src/LightingModel.h    | 11 +++++-
 libraries/render-utils/src/LightingModel.slh  |  5 +++
 .../render-utils/src/RenderDeferredTask.cpp   | 29 ++++++++++----
 .../render-utils/src/RenderForwardTask.cpp    |  2 +-
 libraries/render/src/render/ShapePipeline.cpp |  6 +--
 libraries/render/src/render/ShapePipeline.h   |  5 ++-
 .../utilities/render/deferredLighting.qml     |  3 +-
 15 files changed, 90 insertions(+), 44 deletions(-)

diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh
index 49db49af2a..ae8d6fa277 100644
--- a/libraries/render-utils/src/DeferredBufferWrite.slh
+++ b/libraries/render-utils/src/DeferredBufferWrite.slh
@@ -27,6 +27,7 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
 }
 
 <@include DefaultMaterials.slh@>
+<@include LightingModel.slh@>
 
 void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) {
     if (alpha != 1.0) {
@@ -36,7 +37,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness
     _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
     _fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion);
     
-    _fragColor3 = vec4(emissive, 1.0);
+    _fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0);
 }
 
 void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 lightmap) {
@@ -46,9 +47,9 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r
 
     _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
     _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
-    _fragColor2 = vec4(lightmap, 1.0);
+    _fragColor2 = vec4(isLightmapEnabled() * lightmap, 1.0);
 
-    _fragColor3 = vec4(lightmap * albedo, 1.0);
+    _fragColor3 = vec4(isLightmapEnabled() * lightmap * albedo, 1.0);
 }
 
 void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh
index f6c1d290a7..bb712bf9d2 100644
--- a/libraries/render-utils/src/DeferredGlobalLight.slh
+++ b/libraries/render-utils/src/DeferredGlobalLight.slh
@@ -140,7 +140,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
     color += directionalSpecular;
 
     // Attenuate the light if haze effect selected
-    if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
+    if ((isHazeEnabled() > 0) && (hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
         color = computeHazeColorKeyLightAttenuation(color, lightDirection, fragPositionWS);    
     }
 
@@ -234,7 +234,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
     color += (ambientSpecular + directionalSpecular) / opacity;
 
     // Haze
-    if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
+    if ((isHazeEnabled() > 0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
         vec4 colorV4 = computeHazeColor(
             vec4(color, 1.0),               // fragment original color
             positionES,                     // fragment position in eye   coordinates
@@ -272,7 +272,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
     color += (ambientSpecular + directionalSpecular) / opacity;
 
     // Haze
-    if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
+    if ((isHazeEnabled() > 0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
         vec4 colorV4 = computeHazeColor(
             vec4(color, 1.0),               // fragment original color
             positionES,                     // fragment position in eye   coordinates
diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp
index 956b6c4a58..3074bb2e7f 100644
--- a/libraries/render-utils/src/DeferredLightingEffect.cpp
+++ b/libraries/render-utils/src/DeferredLightingEffect.cpp
@@ -61,20 +61,22 @@ enum DeferredShader_MapSlot {
     DEFERRED_BUFFER_EMISSIVE_UNIT = 2,
     DEFERRED_BUFFER_DEPTH_UNIT = 3,
     DEFERRED_BUFFER_OBSCURANCE_UNIT = 4,
-    SHADOW_MAP_UNIT = 5,
-    SKYBOX_MAP_UNIT = SHADOW_MAP_UNIT + SHADOW_CASCADE_MAX_COUNT,
-    DEFERRED_BUFFER_LINEAR_DEPTH_UNIT,
-    DEFERRED_BUFFER_CURVATURE_UNIT,
-    DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT,
-    SCATTERING_LUT_UNIT,
-    SCATTERING_SPECULAR_UNIT,
+    DEFERRED_BUFFER_LINEAR_DEPTH_UNIT = 5,
+    DEFERRED_BUFFER_CURVATURE_UNIT = 6,
+    DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT = 7,
+    SCATTERING_LUT_UNIT = 8,
+    SCATTERING_SPECULAR_UNIT = 9,
+    SKYBOX_MAP_UNIT = render::ShapePipeline::Slot::LIGHT_AMBIENT_MAP, // unit = 10
+    SHADOW_MAP_UNIT = 11,
+    nextAvailableUnit = SHADOW_MAP_UNIT + SHADOW_CASCADE_MAX_COUNT
 };
 enum DeferredShader_BufferSlot {
     DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT = 0,
     CAMERA_CORRECTION_BUFFER_SLOT,
     SCATTERING_PARAMETERS_BUFFER_SLOT,
     LIGHTING_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::LIGHTING_MODEL,
-    LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT,
+    KEY_LIGHT_SLOT = render::ShapePipeline::Slot::KEY_LIGHT,
+    LIGHT_ARRAY_SLOT = render::ShapePipeline::Slot::LIGHT_ARRAY_BUFFER,
     LIGHT_AMBIENT_SLOT = render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER,
     HAZE_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::HAZE_MODEL,
     LIGHT_INDEX_GPU_SLOT,
@@ -149,17 +151,20 @@ void DeferredLightingEffect::unsetKeyLightBatch(gpu::Batch& batch, int lightBuff
 }
 
 void DeferredLightingEffect::setupLocalLightsBatch(gpu::Batch& batch,
-                                                   int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit,
+                                                   int lightArrayBufferUnit, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit,
                                                    const LightClustersPointer& lightClusters) {
     // Bind the global list of lights and the visible lights this frame
-    batch.setUniformBuffer(_localLightLocations->lightBufferUnit, lightClusters->_lightStage->getLightArrayBuffer());
+    batch.setUniformBuffer(lightArrayBufferUnit, lightClusters->_lightStage->getLightArrayBuffer());
 
     batch.setUniformBuffer(frustumGridBufferUnit, lightClusters->_frustumGridBuffer);
     batch.setUniformBuffer(clusterGridBufferUnit, lightClusters->_clusterGridBuffer);
     batch.setUniformBuffer(clusterContentBufferUnit, lightClusters->_clusterContentBuffer);
 }
 
-void DeferredLightingEffect::unsetLocalLightsBatch(gpu::Batch& batch, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit) {
+void DeferredLightingEffect::unsetLocalLightsBatch(gpu::Batch& batch, int lightArrayBufferUnit, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit) {
+    if (lightArrayBufferUnit >= 0) {
+        batch.setUniformBuffer(lightArrayBufferUnit, nullptr);
+    }
     if (clusterGridBufferUnit >= 0) {
         batch.setUniformBuffer(clusterGridBufferUnit, nullptr);
     }
@@ -194,7 +199,8 @@ static gpu::ShaderPointer makeLightProgram(const gpu::ShaderPointer& vertShader,
     slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), LIGHTING_MODEL_BUFFER_SLOT));
     slotBindings.insert(gpu::Shader::Binding(std::string("hazeBuffer"), HAZE_MODEL_BUFFER_SLOT));
     slotBindings.insert(gpu::Shader::Binding(std::string("subsurfaceScatteringParametersBuffer"), SCATTERING_PARAMETERS_BUFFER_SLOT));
-    slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), LIGHT_GPU_SLOT));
+    slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), KEY_LIGHT_SLOT));
+    slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), LIGHT_ARRAY_SLOT));
     slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), LIGHT_AMBIENT_SLOT));
     slotBindings.insert(gpu::Shader::Binding(std::string("lightIndexBuffer"), LIGHT_INDEX_GPU_SLOT));
 
@@ -592,7 +598,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
         batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform));
 
         // Setup the global lighting
-        deferredLightingEffect->setupKeyLightBatch(args, batch, locations->keyLightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT);
+        deferredLightingEffect->setupKeyLightBatch(args, batch, KEY_LIGHT_SLOT, LIGHT_AMBIENT_SLOT, SKYBOX_MAP_UNIT);
 
         // Haze
         if (haze) {
@@ -601,7 +607,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
         
         batch.draw(gpu::TRIANGLE_STRIP, 4);
 
-        deferredLightingEffect->unsetKeyLightBatch(batch, locations->keyLightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT);
+        deferredLightingEffect->unsetKeyLightBatch(batch, KEY_LIGHT_SLOT, LIGHT_AMBIENT_SLOT, SKYBOX_MAP_UNIT);
 
         for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) {
             batch.setResourceTexture(SHADOW_MAP_UNIT+i, nullptr);
@@ -656,8 +662,9 @@ void RenderDeferredLocals::run(const render::RenderContextPointer& renderContext
 
         auto& lightIndices = lightClusters->_visibleLightIndices;
         if (!lightIndices.empty() && lightIndices[0] > 0) {
-            deferredLightingEffect->setupLocalLightsBatch(batch, LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT,
-                                                          lightClusters);
+            deferredLightingEffect->setupLocalLightsBatch(batch,
+                LIGHT_ARRAY_SLOT, LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT,
+                lightClusters);
 
             // Local light pipeline
             batch.setPipeline(deferredLightingEffect->_localLight);
diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h
index ce7ecacbbe..3b77b8137e 100644
--- a/libraries/render-utils/src/DeferredLightingEffect.h
+++ b/libraries/render-utils/src/DeferredLightingEffect.h
@@ -51,8 +51,8 @@ public:
     void setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit);
     void unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit);
 
-    void setupLocalLightsBatch(gpu::Batch& batch, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit, const LightClustersPointer& lightClusters);
-    void unsetLocalLightsBatch(gpu::Batch& batch, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit);
+    void setupLocalLightsBatch(gpu::Batch& batch, int lightArrayBufferUnit, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit, const LightClustersPointer& lightClusters);
+    void unsetLocalLightsBatch(gpu::Batch& batch, int lightArrayBufferUnit, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit);
 
     void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; };
     void setAmbientOcclusionEnabled(bool enable) { _ambientOcclusionEnabled = enable; }
diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp
index 8be142d939..0d8561ad21 100644
--- a/libraries/render-utils/src/GeometryCache.cpp
+++ b/libraries/render-utils/src/GeometryCache.cpp
@@ -2264,7 +2264,7 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp
             slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), render::ShapePipeline::Slot::LIGHTING_MODEL));
             slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), render::ShapePipeline::Slot::KEY_LIGHT));
             slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER));
-            slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), render::ShapePipeline::Slot::MAP::LIGHT_AMBIENT));
+            slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), render::ShapePipeline::Slot::MAP::LIGHT_AMBIENT_MAP));
             gpu::Shader::makeProgram(*_simpleShader, slotBindings);
             gpu::Shader::makeProgram(*_transparentShader, slotBindings);
             gpu::Shader::makeProgram(*_unlitShader, slotBindings);
@@ -2284,7 +2284,7 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp
             slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), render::ShapePipeline::Slot::LIGHTING_MODEL));
             slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), render::ShapePipeline::Slot::KEY_LIGHT));
             slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER));
-            slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), render::ShapePipeline::Slot::MAP::LIGHT_AMBIENT));
+            slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), render::ShapePipeline::Slot::MAP::LIGHT_AMBIENT_MAP));
             slotBindings.insert(gpu::Shader::Binding(std::string("fadeMaskMap"), render::ShapePipeline::Slot::MAP::FADE_MASK));
             gpu::Shader::makeProgram(*_simpleFadeShader, slotBindings);
             gpu::Shader::makeProgram(*_unlitFadeShader, slotBindings);
diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf
index b9f23fd932..dc4f04b144 100644
--- a/libraries/render-utils/src/Haze.slf
+++ b/libraries/render-utils/src/Haze.slf
@@ -42,7 +42,7 @@ in vec2 varTexCoord0;
 out vec4 outFragColor;
 
 void main(void) {
-    if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) != HAZE_MODE_IS_ACTIVE) {
+    if ((isHazeEnabled() == 0) || (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) != HAZE_MODE_IS_ACTIVE) {
         discard;
     }
 
diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp
index ea02edb601..36d3fe9e49 100644
--- a/libraries/render-utils/src/LightClusters.cpp
+++ b/libraries/render-utils/src/LightClusters.cpp
@@ -39,7 +39,7 @@ enum LightClusterGridShader_MapSlot {
 enum LightClusterGridShader_BufferSlot {
     DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT = 0,
     CAMERA_CORRECTION_BUFFER_SLOT = 1,
-    LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT,
+    LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT_ARRAY_BUFFER,
     LIGHT_INDEX_GPU_SLOT = 7,
     LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT = 8,
     LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT = 9,
diff --git a/libraries/render-utils/src/LightingModel.cpp b/libraries/render-utils/src/LightingModel.cpp
index 30801ac69e..23d4c66fd5 100644
--- a/libraries/render-utils/src/LightingModel.cpp
+++ b/libraries/render-utils/src/LightingModel.cpp
@@ -49,6 +49,14 @@ void LightingModel::setBackground(bool enable) {
 bool LightingModel::isBackgroundEnabled() const {
     return (bool)_parametersBuffer.get<Parameters>().enableBackground;
 }
+void LightingModel::setHaze(bool enable) {
+    if (enable != isHazeEnabled()) {
+        _parametersBuffer.edit<Parameters>().enableHaze = (float)enable;
+    }
+}
+bool LightingModel::isHazeEnabled() const {
+    return (bool)_parametersBuffer.get<Parameters>().enableHaze;
+}
 void LightingModel::setObscurance(bool enable) {
     if (enable != isObscuranceEnabled()) {
         _parametersBuffer.edit<Parameters>().enableObscurance = (float)enable;
@@ -160,6 +168,7 @@ void MakeLightingModel::configure(const Config& config) {
     _lightingModel->setEmissive(config.enableEmissive);
     _lightingModel->setLightmap(config.enableLightmap);
     _lightingModel->setBackground(config.enableBackground);
+    _lightingModel->setHaze(config.enableHaze);
 
     _lightingModel->setObscurance(config.enableObscurance);
 
diff --git a/libraries/render-utils/src/LightingModel.h b/libraries/render-utils/src/LightingModel.h
index e058b10921..c71917603c 100644
--- a/libraries/render-utils/src/LightingModel.h
+++ b/libraries/render-utils/src/LightingModel.h
@@ -36,6 +36,9 @@ public:
     void setBackground(bool enable);
     bool isBackgroundEnabled() const;
 
+    void setHaze(bool enable);
+    bool isHazeEnabled() const;
+
     void setObscurance(bool enable);
     bool isObscuranceEnabled() const;
 
@@ -86,7 +89,6 @@ protected:
         float enableSpecular{ 1.0f };
         float enableAlbedo{ 1.0f };
 
-
         float enableAmbientLight{ 1.0f };
         float enableDirectionalLight{ 1.0f };
         float enablePointLight{ 1.0f };
@@ -99,6 +101,11 @@ protected:
         float enableMaterialTexturing { 1.0f };
         float enableWireframe { 0.0f }; // false by default
 
+        float enableHaze{ 1.0f };
+        float spare1;  // Needed for having the LightingModel class aligned on a 4 scalar boundary for gpu 
+        float spare2;
+        float spare3;
+
         Parameters() {}
     };
     UniformBufferView _parametersBuffer;
@@ -116,6 +123,7 @@ class MakeLightingModelConfig : public render::Job::Config {
     Q_PROPERTY(bool enableEmissive MEMBER enableEmissive NOTIFY dirty)
     Q_PROPERTY(bool enableLightmap MEMBER enableLightmap NOTIFY dirty)
     Q_PROPERTY(bool enableBackground MEMBER enableBackground NOTIFY dirty)
+    Q_PROPERTY(bool enableHaze MEMBER enableHaze NOTIFY dirty)
 
     Q_PROPERTY(bool enableObscurance MEMBER enableObscurance NOTIFY dirty)
 
@@ -158,6 +166,7 @@ public:
     bool showLightContour { false }; // false by default
 
     bool enableWireframe { false }; // false by default
+    bool enableHaze{ true };
 
 signals:
     void dirty();
diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh
index 6a5982f1e8..309a4899a2 100644
--- a/libraries/render-utils/src/LightingModel.slh
+++ b/libraries/render-utils/src/LightingModel.slh
@@ -18,6 +18,7 @@ struct LightingModel {
     PRECISIONQ vec4 _ScatteringDiffuseSpecularAlbedo;
     PRECISIONQ vec4 _AmbientDirectionalPointSpot;
     PRECISIONQ vec4 _ShowContourObscuranceWireframe;
+    PRECISIONQ vec4 _Haze_spareyzw;
 };
 
 uniform lightingModelBuffer{
@@ -74,6 +75,10 @@ float isWireframeEnabled() {
     return lightingModel._ShowContourObscuranceWireframe.z;
 }
 
+float isHazeEnabled() {
+    return lightingModel._Haze_spareyzw.x;
+}
+
 <@endfunc@>
 <$declareLightingModel()$>
 
diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp
index ab1d831ead..3ea56f8542 100644
--- a/libraries/render-utils/src/RenderDeferredTask.cpp
+++ b/libraries/render-utils/src/RenderDeferredTask.cpp
@@ -340,11 +340,18 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
         // Setup lighting model for all items;
         batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
 
-        deferredLightingEffect->setupLocalLightsBatch(batch, 
-                                                      render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT,
-                                                      render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT,
-                                                      render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT,
-                                                      lightClusters);
+        // Set the light
+        deferredLightingEffect->setupKeyLightBatch(args, batch,
+            render::ShapePipeline::Slot::KEY_LIGHT,
+            render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER,
+            render::ShapePipeline::Slot::LIGHT_AMBIENT_MAP);
+
+        deferredLightingEffect->setupLocalLightsBatch(batch,
+            render::ShapePipeline::Slot::LIGHT_ARRAY_BUFFER,
+            render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT,
+            render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT,
+            render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT,
+            lightClusters);
 
         // Setup haze if current zone has haze
         auto hazeStage = args->_scene->getStage<HazeStage>();
@@ -370,9 +377,15 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
         args->_globalShapeKey = 0;
 
         deferredLightingEffect->unsetLocalLightsBatch(batch,
-                                                      render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT,
-                                                      render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT,
-                                                      render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT);
+            render::ShapePipeline::Slot::LIGHT_ARRAY_BUFFER,
+            render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT,
+            render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT,
+            render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT);
+
+        deferredLightingEffect->unsetKeyLightBatch(batch,
+            render::ShapePipeline::Slot::KEY_LIGHT,
+            render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER,
+            render::ShapePipeline::Slot::LIGHT_AMBIENT_MAP);
     });
 
     config->setNumDrawn((int)inItems.size());
diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp
index 63370109e0..294d8e12f4 100755
--- a/libraries/render-utils/src/RenderForwardTask.cpp
+++ b/libraries/render-utils/src/RenderForwardTask.cpp
@@ -175,7 +175,7 @@ void PrepareForward::run(const RenderContextPointer& renderContext, const Inputs
             batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER, keyAmbiLight->getAmbientSchemaBuffer());
 
             if (keyAmbiLight->getAmbientMap()) {
-                batch.setResourceTexture(render::ShapePipeline::Slot::LIGHT_AMBIENT, keyAmbiLight->getAmbientMap());
+                batch.setResourceTexture(render::ShapePipeline::Slot::LIGHT_AMBIENT_MAP, keyAmbiLight->getAmbientMap());
             }
         }
     });
diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp
index 35cc66315b..7788b14795 100644
--- a/libraries/render/src/render/ShapePipeline.cpp
+++ b/libraries/render/src/render/ShapePipeline.cpp
@@ -89,9 +89,9 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
         slotBindings.insert(gpu::Shader::Binding(std::string("occlusionMap"), Slot::MAP::OCCLUSION));
         slotBindings.insert(gpu::Shader::Binding(std::string("scatteringMap"), Slot::MAP::SCATTERING));
         slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), Slot::BUFFER::KEY_LIGHT));
-        slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), Slot::BUFFER::LIGHT));
+        slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), Slot::BUFFER::LIGHT_ARRAY_BUFFER));
         slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), Slot::BUFFER::LIGHT_AMBIENT_BUFFER));
-        slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), Slot::MAP::LIGHT_AMBIENT));
+        slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), Slot::MAP::LIGHT_AMBIENT_MAP));
         slotBindings.insert(gpu::Shader::Binding(std::string("fadeMaskMap"), Slot::MAP::FADE_MASK));
         slotBindings.insert(gpu::Shader::Binding(std::string("fadeParametersBuffer"), Slot::BUFFER::FADE_PARAMETERS));
         slotBindings.insert(gpu::Shader::Binding(std::string("hazeBuffer"), Slot::BUFFER::HAZE_MODEL));
@@ -123,7 +123,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
     locations->lightAmbientMapUnit = program->getTextures().findLocation("skyboxMap");
     locations->fadeMaskTextureUnit = program->getTextures().findLocation("fadeMaskMap");
     locations->fadeParameterBufferUnit = program->getUniformBuffers().findLocation("fadeParametersBuffer");
-    locations->hazeParameterBufferUnit = program->getUniformBuffers().findLocation("hazeParametersBuffer");
+    locations->hazeParameterBufferUnit = program->getUniformBuffers().findLocation("hazeBuffer");
     if (key.isTranslucent()) {
         locations->lightClusterGridBufferUnit = program->getUniformBuffers().findLocation("clusterGridBuffer");
         locations->lightClusterContentBufferUnit = program->getUniformBuffers().findLocation("clusterContentBuffer");
diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h
index a6bfb4a234..7d87d98deb 100644
--- a/libraries/render/src/render/ShapePipeline.h
+++ b/libraries/render/src/render/ShapePipeline.h
@@ -236,7 +236,7 @@ public:
             TEXMAPARRAY,
             LIGHTING_MODEL,
             KEY_LIGHT,
-            LIGHT,
+            LIGHT_ARRAY_BUFFER,
             LIGHT_AMBIENT_BUFFER,
             HAZE_MODEL,
             FADE_PARAMETERS,
@@ -254,8 +254,9 @@ public:
             ROUGHNESS,
             OCCLUSION,
             SCATTERING,
-            LIGHT_AMBIENT,
             FADE_MASK,
+
+            LIGHT_AMBIENT_MAP = 10,
         };
     };
 
diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml
index 189d23c44f..b2d917475e 100644
--- a/scripts/developer/utilities/render/deferredLighting.qml
+++ b/scripts/developer/utilities/render/deferredLighting.qml
@@ -45,7 +45,8 @@ Rectangle {
                          "Unlit:LightingModel:enableUnlit", 
                          "Emissive:LightingModel:enableEmissive", 
                          "Lightmap:LightingModel:enableLightmap",
-                         "Background:LightingModel:enableBackground",                      
+                         "Background:LightingModel:enableBackground",      
+                         "Haze:LightingModel:enableHaze",                
                          "ssao:AmbientOcclusion:enabled",                      
                          "Textures:LightingModel:enableMaterialTexturing"                     
                     ]

From 21e069c90c1ce459abd08f91259221eb449a42a6 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Wed, 16 May 2018 13:09:55 -0700
Subject: [PATCH 4/5] Adding a toggle button to the developer/Render menu to be
 able to disable taa and fall back to Fxaa

---
 interface/src/Menu.cpp                        | 20 ++++++++++++++++++
 interface/src/Menu.h                          |  1 +
 .../render-utils/src/AntialiasingEffect.h     |  8 +++++--
 .../utilities/render/antialiasing.qml         | 21 ++++++++++---------
 4 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp
index 4384635147..310e873212 100644
--- a/interface/src/Menu.cpp
+++ b/interface/src/Menu.cpp
@@ -47,6 +47,7 @@
 
 #include "AmbientOcclusionEffect.h"
 #include "RenderShadowTask.h"
+#include "AntialiasingEffect.h"
 
 #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
 #include "SpeechRecognizer.h"
@@ -380,6 +381,25 @@ Menu::Menu() {
 
     // Developer > Render >>>
     MenuWrapper* renderOptionsMenu = developerMenu->addMenu("Render");
+
+    action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AntiAliasing, 0, true);
+    connect(action, &QAction::triggered, [action] {
+        auto renderConfig = qApp->getRenderEngine()->getConfiguration();
+        if (renderConfig) {
+            auto mainViewJitterCamConfig = renderConfig->getConfig<JitterSample>("RenderMainView.JitterCam");
+            auto mainViewAntialiasingConfig = renderConfig->getConfig<Antialiasing>("RenderMainView.Antialiasing");
+            if (mainViewJitterCamConfig && mainViewAntialiasingConfig) {
+                if (action->isChecked()) {
+                    mainViewJitterCamConfig->play();
+                    mainViewAntialiasingConfig->debugFXAAX = 1.0;
+                } else {
+                    mainViewJitterCamConfig->none();
+                    mainViewAntialiasingConfig->debugFXAAX = 0.0;
+                }
+            }
+        }
+    });
+
     action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, true);
     connect(action, &QAction::triggered, [action] {
         auto renderConfig = qApp->getRenderEngine()->getConfiguration();
diff --git a/interface/src/Menu.h b/interface/src/Menu.h
index bba70a6a89..92885f0801 100644
--- a/interface/src/Menu.h
+++ b/interface/src/Menu.h
@@ -210,6 +210,7 @@ namespace MenuOption {
     const QString DesktopTabletToToolbar = "Desktop Tablet Becomes Toolbar";
     const QString HMDTabletToToolbar = "HMD Tablet Becomes Toolbar";
     const QString Shadows = "Shadows";
+    const QString AntiAliasing = "Temporal Antialiasing (FXAA if disabled)";
     const QString AmbientOcclusion = "Ambient Occlusion";
 }
 
diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h
index a89666f58b..175f7b41e4 100644
--- a/libraries/render-utils/src/AntialiasingEffect.h
+++ b/libraries/render-utils/src/AntialiasingEffect.h
@@ -62,7 +62,7 @@ public:
     };
 
     using Config = JitterSampleConfig;
-	using Output = glm::vec2;
+    using Output = glm::vec2;
     using JobModel = render::Job::ModelO<JitterSample, Output, Config>;
 
     void configure(const Config& config);
@@ -95,7 +95,7 @@ class AntialiasingConfig : public render::Job::Config {
 
     Q_PROPERTY(bool debug MEMBER debug NOTIFY dirty)
     Q_PROPERTY(float debugX MEMBER debugX NOTIFY dirty)
-    Q_PROPERTY(float debugFXAAX MEMBER debugFXAAX NOTIFY dirty)
+    Q_PROPERTY(bool fxaaOnOff READ debugFXAA WRITE setDebugFXAA NOTIFY dirty)
     Q_PROPERTY(float debugShowVelocityThreshold MEMBER debugShowVelocityThreshold NOTIFY dirty)
     Q_PROPERTY(bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty)
     Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty)
@@ -106,6 +106,10 @@ class AntialiasingConfig : public render::Job::Config {
 public:
     AntialiasingConfig() : render::Job::Config(true) {}
 
+    void setDebugFXAA(bool debug) { debugFXAAX = (debug ? 0.0f : 1.0f); emit dirty();}
+    bool debugFXAA() const { return (debugFXAAX == 0.0f ? true : false); }
+
+
     float blend{ 0.25f };
     float sharpen{ 0.05f };
 
diff --git a/scripts/developer/utilities/render/antialiasing.qml b/scripts/developer/utilities/render/antialiasing.qml
index 8bdd5c6a0d..1a8f9dac2d 100644
--- a/scripts/developer/utilities/render/antialiasing.qml
+++ b/scripts/developer/utilities/render/antialiasing.qml
@@ -38,21 +38,22 @@ Rectangle {
                 id: fxaaOnOff
                 property bool debugFXAA: false
                 HifiControls.Button {
-                    text: {
-                        if (fxaaOnOff.debugFXAA) {
-                            return "FXAA"
-                        } else {
-                            return "TAA"
-                        }
+                    function getTheText() {
+                            if (Render.getConfig("RenderMainView.Antialiasing").fxaaOnOff) {
+                                return "FXAA"
+                            } else {
+                                return "TAA"
+                            }
                         }
+                    text: getTheText()
                     onClicked: {
-                        fxaaOnOff.debugFXAA = !fxaaOnOff.debugFXAA
-                         if (fxaaOnOff.debugFXAA) {
+                        var onOff = !Render.getConfig("RenderMainView.Antialiasing").fxaaOnOff;
+                         if (onOff) {
                             Render.getConfig("RenderMainView.JitterCam").none();
-                            Render.getConfig("RenderMainView.Antialiasing").debugFXAAX = 0;
+                            Render.getConfig("RenderMainView.Antialiasing").fxaaOnOff = true;
                          } else {
                             Render.getConfig("RenderMainView.JitterCam").play();
-                            Render.getConfig("RenderMainView.Antialiasing").debugFXAAX = 1.0;
+                            Render.getConfig("RenderMainView.Antialiasing").fxaaOnOff = false;
                          }
                          
                     }

From ade1d6c0567abed81bff1802a491cd2400adc9ab Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Wed, 16 May 2018 15:37:13 -0700
Subject: [PATCH 5/5] use the correct call to toggle the debugFXAA on the
 AaConfig

---
 interface/src/Menu.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp
index 310e873212..c3ca5feeee 100644
--- a/interface/src/Menu.cpp
+++ b/interface/src/Menu.cpp
@@ -391,10 +391,10 @@ Menu::Menu() {
             if (mainViewJitterCamConfig && mainViewAntialiasingConfig) {
                 if (action->isChecked()) {
                     mainViewJitterCamConfig->play();
-                    mainViewAntialiasingConfig->debugFXAAX = 1.0;
+                    mainViewAntialiasingConfig->setDebugFXAA(false);
                 } else {
                     mainViewJitterCamConfig->none();
-                    mainViewAntialiasingConfig->debugFXAAX = 0.0;
+                    mainViewAntialiasingConfig->setDebugFXAA(true);
                 }
             }
         }