Skip to content

Commit

Permalink
stutter fix: only perform fade transactions when depth == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
HifiExperiments committed Oct 24, 2024
1 parent 43e15c0 commit aaa92df
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 105 deletions.
3 changes: 0 additions & 3 deletions interface/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@
#include <raypick/RayPick.h>
#include <raypick/MouseTransformNode.h>

#include <FadeEffect.h>

#include "ResourceRequestObserver.h"

#include "webbrowser/WebBrowserSuggestionsEngine.h"
Expand Down Expand Up @@ -913,7 +911,6 @@ bool setupEssentials(const QCommandLineParser& parser, bool runningMarkerExisted
DependencyManager::set<SelectionScriptingInterface>();
DependencyManager::set<TTSScriptingInterface>();

DependencyManager::set<FadeEffect>();
DependencyManager::set<ResourceRequestObserver>();
DependencyManager::set<Keyboard>();
DependencyManager::set<KeyboardScriptingInterface>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1748,9 +1748,8 @@ ShapePipelinePointer shapePipelineFactory(const ShapePlumber& plumber, const Sha
if (!std::get<2>(key)) {
_pipelines[std::make_tuple(std::get<0>(key), std::get<1>(key), std::get<2>(key), wireframe)] = std::make_shared<render::ShapePipeline>(pipeline, nullptr, nullptr, nullptr);
} else {
const auto& fadeEffect = DependencyManager::get<FadeEffect>();
_pipelines[std::make_tuple(std::get<0>(key), std::get<1>(key), std::get<2>(key), wireframe)] = std::make_shared<render::ShapePipeline>(pipeline, nullptr,
fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter());
FadeEffect::getBatchSetter(), FadeEffect::getItemUniformSetter());
}
}
}
Expand Down
59 changes: 13 additions & 46 deletions libraries/render-utils/src/FadeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@
#include "render-utils/ShaderConstants.h"
#include <PathUtils.h>

gpu::TexturePointer FadeEffect::_maskMap;

FadeEffect::FadeEffect() {
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
_maskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
std::once_flag once;
std::call_once(once, [] {
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
_maskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
});
}

void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& editableItems) {
void FadeEffect::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) {
auto editedFadeCategory = task.addJob<FadeJob>("Fade");
auto& fadeJob = task._jobs.back();
_configurations = fadeJob.get<FadeJob>().getConfigurationBuffer();

const auto fadeEditInput = FadeEditJob::Input(editableItems, editedFadeCategory).asVarying();
const auto fadeEditInput = FadeEditJob::Input(inputs, editedFadeCategory).asVarying();
task.addJob<FadeEditJob>("FadeEdit", fadeEditInput);
}

render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() const {
return [this](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args*) {
render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() {
return [](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args*) {
batch.setResourceTexture(render_utils::slot::texture::FadeMask, _maskMap);
batch.setUniformBuffer(render_utils::slot::buffer::FadeParameters, _configurations);
batch.setUniformBuffer(render_utils::slot::buffer::FadeParameters, FadeJob::getConfigurationBuffer());
};
}

render::ShapePipeline::ItemSetter FadeEffect::getItemUniformSetter() const {
render::ShapePipeline::ItemSetter FadeEffect::getItemUniformSetter() {
return [](const render::ShapePipeline& shapePipeline, render::Args* args, const render::Item& item) {
if (!render::TransitionStage::isIndexInvalid(item.getTransitionId())) {
const auto& scene = args->_scene;
Expand Down Expand Up @@ -71,39 +74,3 @@ render::ShapePipeline::ItemSetter FadeEffect::getItemUniformSetter() const {
}
};
}

render::ShapePipeline::ItemSetter FadeEffect::getItemStoredSetter() {
return [this](const render::ShapePipeline& shapePipeline, render::Args* args, const render::Item& item) {
if (!render::TransitionStage::isIndexInvalid(item.getTransitionId())) {
auto scene = args->_scene;
auto transitionStage = scene->getStage<render::TransitionStage>();
auto& transitionState = transitionStage->getTransition(item.getTransitionId());
const auto fadeCategory = FadeJob::transitionToCategory[transitionState.eventType];

_lastCategory = fadeCategory;
_lastThreshold = transitionState.threshold;
_lastNoiseOffset = transitionState.noiseOffset;
_lastBaseOffset = transitionState.baseOffset;
_lastBaseInvSize = transitionState.baseInvSize;
}
};
}

void FadeEffect::packToAttributes(const int category, const float threshold, const glm::vec3& noiseOffset,
const glm::vec3& baseOffset, const glm::vec3& baseInvSize,
glm::vec4& packedData1, glm::vec4& packedData2, glm::vec4& packedData3) {
packedData1.x = noiseOffset.x;
packedData1.y = noiseOffset.y;
packedData1.z = noiseOffset.z;
packedData1.w = (float)(category+0.1f); // GLSL hack so that casting back from float to int in fragment shader returns the correct value.

packedData2.x = baseOffset.x;
packedData2.y = baseOffset.y;
packedData2.z = baseOffset.z;
packedData2.w = threshold;

packedData3.x = baseInvSize.x;
packedData3.y = baseInvSize.y;
packedData3.z = baseInvSize.z;
packedData3.w = 0.f;
}
40 changes: 9 additions & 31 deletions libraries/render-utils/src/FadeEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,22 @@
#ifndef hifi_render_utils_FadeEffect_h
#define hifi_render_utils_FadeEffect_h

#include <DependencyManager.h>
#include <render/Engine.h>

class FadeEffect : public Dependency {
SINGLETON_DEPENDENCY;

class FadeEffect {
public:
using Input = render::ItemBounds;
using JobModel = render::Task::ModelI<FadeEffect, render::ItemBounds>;

void build(render::Task::TaskConcept& task, const task::Varying& editableItems);

render::ShapePipeline::BatchSetter getBatchSetter() const;
render::ShapePipeline::ItemSetter getItemUniformSetter() const;
render::ShapePipeline::ItemSetter getItemStoredSetter();
FadeEffect();

int getLastCategory() const { return _lastCategory; }
float getLastThreshold() const { return _lastThreshold; }
const glm::vec3& getLastNoiseOffset() const { return _lastNoiseOffset; }
const glm::vec3& getLastBaseOffset() const { return _lastBaseOffset; }
const glm::vec3& getLastBaseInvSize() const { return _lastBaseInvSize; }
void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs);

static void packToAttributes(const int category, const float threshold, const glm::vec3& noiseOffset,
const glm::vec3& baseOffset, const glm::vec3& baseInvSize,
glm::vec4& packedData1, glm::vec4& packedData2, glm::vec4& packedData3);
static render::ShapePipeline::BatchSetter getBatchSetter();
static render::ShapePipeline::ItemSetter getItemUniformSetter();

private:

gpu::BufferView _configurations;
gpu::TexturePointer _maskMap;

// The last fade set through the stored item setter
int _lastCategory { 0 };
float _lastThreshold { 0.f };
glm::vec3 _lastNoiseOffset { 0.f, 0.f, 0.f };
glm::vec3 _lastBaseOffset { 0.f, 0.f, 0.f };
glm::vec3 _lastBaseInvSize { 1.f, 1.f, 1.f };

explicit FadeEffect();
virtual ~FadeEffect() { }

static gpu::TexturePointer _maskMap;
};

#endif // hifi_render_utils_FadeEffect_h
6 changes: 4 additions & 2 deletions libraries/render-utils/src/FadeEffectJobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ void FadeConfig::load(const QString& configFilePath) {
}
}

FadeJob::FadeConfigurationBuffer FadeJob::_configurations;

FadeJob::FadeJob() {
_previousTime = usecTimestampNow();
}
Expand Down Expand Up @@ -558,15 +560,15 @@ void FadeJob::configure(const Config& config) {

void FadeJob::run(const render::RenderContextPointer& renderContext, FadeJob::Output& output) {
Config* jobConfig = static_cast<Config*>(renderContext->jobConfig.get());
output = (FadeCategory)jobConfig->editedCategory;

auto scene = renderContext->args->_scene;
auto transitionStage = scene->getStage<render::TransitionStage>();
uint64_t now = usecTimestampNow();
const double deltaTime = (int64_t(now) - int64_t(_previousTime)) / double(USECS_PER_SECOND);
render::Transaction transaction;
bool isFirstItem = true;
bool hasTransaction = false;

output = (FadeCategory) jobConfig->editedCategory;

// And now update fade effect
for (auto transitionId : *transitionStage) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/render-utils/src/FadeEffectJobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class FadeJob {
void configure(const Config& config);
void run(const render::RenderContextPointer& renderContext, FadeJob::Output& output);

gpu::BufferView getConfigurationBuffer() const { return _configurations; }
static gpu::BufferView getConfigurationBuffer() { return _configurations; }

private:

Expand All @@ -219,7 +219,7 @@ class FadeJob {
};
using FadeConfigurationBuffer = gpu::StructBuffer<FadeConfiguration>;

FadeConfigurationBuffer _configurations;
static FadeConfigurationBuffer _configurations;
float _thresholdScale[FADE_CATEGORY_COUNT];
uint64_t _previousTime{ 0 };

Expand Down
5 changes: 2 additions & 3 deletions libraries/render-utils/src/GeometryCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,8 @@ render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool

render::ShapePipelinePointer GeometryCache::getFadingShapePipeline(bool textured, bool transparent, bool unlit, bool depthBias, bool forward,
graphics::MaterialKey::CullFaceMode cullFaceMode) {
auto fadeEffect = DependencyManager::get<FadeEffect>();
auto fadeBatchSetter = fadeEffect->getBatchSetter();
auto fadeItemSetter = fadeEffect->getItemUniformSetter();
auto fadeBatchSetter = FadeEffect::getBatchSetter();
auto fadeItemSetter = FadeEffect::getItemUniformSetter();
return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, unlit, depthBias, true, true, forward, cullFaceMode), nullptr,
[fadeBatchSetter, fadeItemSetter](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args* args) {
batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture());
Expand Down
3 changes: 1 addition & 2 deletions libraries/render-utils/src/HighlightEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ void DrawHighlightTask::build(JobModel& task, const render::Varying& inputs, ren
std::call_once(once, [] {
auto state = std::make_shared<gpu::State>();
state->setColorWriteMask(false, false, false, false);
auto fadeEffect = DependencyManager::get<FadeEffect>();
initZPassPipelines(*shapePlumber, state, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter());
initZPassPipelines(*shapePlumber, state, FadeEffect::getBatchSetter(), FadeEffect::getItemUniformSetter());
});
auto sharedParameters = std::make_shared<HighlightSharedParameters>();

Expand Down
5 changes: 2 additions & 3 deletions libraries/render-utils/src/RenderCommonTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,8 @@ class DrawMirrorTask {
state->setDepthTest(true, true, gpu::LESS_EQUAL);
PrepareStencil::testMaskDrawShape(*state);

auto fadeEffect = DependencyManager::get<FadeEffect>();
initMirrorPipelines(*_forwardPipelines, state, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter(), true);
initMirrorPipelines(*_deferredPipelines, state, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter(), false);
initMirrorPipelines(*_forwardPipelines, state, FadeEffect::getBatchSetter(), FadeEffect::getItemUniformSetter(), true);
initMirrorPipelines(*_deferredPipelines, state, FadeEffect::getBatchSetter(), FadeEffect::getItemUniformSetter(), false);
});
}

Expand Down
7 changes: 4 additions & 3 deletions libraries/render-utils/src/RenderDeferredTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ void RenderDeferredTask::configure(const Config& config) {
}

void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, size_t depth) {
static auto fadeEffect = DependencyManager::get<FadeEffect>();
// Prepare the ShapePipelines
static ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>();
static std::once_flag once;
std::call_once(once, [] {
initDeferredPipelines(*shapePlumber, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter());
initDeferredPipelines(*shapePlumber, FadeEffect::getBatchSetter(), FadeEffect::getItemUniformSetter());
});

const auto& inputs = input.get<Input>();
Expand Down Expand Up @@ -146,7 +145,9 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
// Shadow Stage Frame
const auto shadowFrame = shadowTaskOutputs[1];

fadeEffect->build(task, opaques);
if (depth == 0) {
task.addJob<FadeEffect>("FadeEffect", opaques);
}

const auto jitter = task.addJob<JitterSample>("JitterCam");

Expand Down
5 changes: 0 additions & 5 deletions libraries/render-utils/src/RenderForwardTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "render-utils/ShaderConstants.h"
#include "StencilMaskPass.h"
#include "ZoneRenderer.h"
#include "FadeEffect.h"
#include "ToneMapAndResampleTask.h"
#include "BackgroundStage.h"
#include "FramebufferCache.h"
Expand Down Expand Up @@ -72,7 +71,6 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
task.addJob<SetRenderMethod>("SetRenderMethodTask", render::Args::FORWARD);

// Prepare the ShapePipelines
auto fadeEffect = DependencyManager::get<FadeEffect>();
static ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>();
static std::once_flag once;
std::call_once(once, [] {
Expand Down Expand Up @@ -112,9 +110,6 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend

const auto& zones = lightingStageInputs[1];

// First job, alter faded
fadeEffect->build(task, opaques);

// GPU jobs: Start preparing the main framebuffer
const auto scaledPrimaryFramebuffer = task.addJob<PreparePrimaryFramebufferMSAA>("PreparePrimaryBufferForward");

Expand Down
3 changes: 1 addition & 2 deletions libraries/render-utils/src/RenderShadowTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
static ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>();
static std::once_flag once;
std::call_once(once, [] {
auto fadeEffect = DependencyManager::get<FadeEffect>();
initZPassPipelines(*shapePlumber, std::make_shared<gpu::State>(), fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter());
initZPassPipelines(*shapePlumber, std::make_shared<gpu::State>(), FadeEffect::getBatchSetter(), FadeEffect::getItemUniformSetter());
});

const auto setupOutput = task.addJob<RenderShadowSetup>("ShadowSetup", input);
Expand Down
5 changes: 4 additions & 1 deletion libraries/render/src/render/DrawSceneOctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ gpu::PipelinePointer DrawSceneOctree::_drawItemBoundPipeline;
gpu::Stream::FormatPointer DrawSceneOctree::_cellBoundsFormat = std::make_shared<gpu::Stream::Format>();

DrawSceneOctree::DrawSceneOctree() {
_cellBoundsFormat->setAttribute(0, 0, gpu::Element(gpu::VEC4, gpu::INT32, gpu::XYZW), 0, gpu::Stream::PER_INSTANCE);
std::once_flag once;
std::call_once(once, [] {
_cellBoundsFormat->setAttribute(0, 0, gpu::Element(gpu::VEC4, gpu::INT32, gpu::XYZW), 0, gpu::Stream::PER_INSTANCE);
});
}

const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
Expand Down

0 comments on commit aaa92df

Please sign in to comment.