Added FadeManager to centralize some common fade effect data and functions

This commit is contained in:
Olivier Prat 2017-06-06 16:11:12 +02:00
parent e7eca7728f
commit 8af2f75996
8 changed files with 118 additions and 91 deletions

View file

@ -0,0 +1,25 @@
#include "FadeManager.h"
#include "TextureCache.h"
#include <PathUtils.h>
FadeManager::FadeManager() :
_isDebugEnabled{ false },
_debugFadePercent{ 0.f }
{
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
_fadeMaskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
}
render::ShapeKey::Builder FadeManager::getKeyBuilder() const
{
render::ShapeKey::Builder builder;
if (_isDebugEnabled) {
// Force fade for everyone
builder.withFade();
}
return builder;
}

View file

@ -0,0 +1,43 @@
//
// FadeManager.h
// libraries/render-utils/src/
//
// Created by Olivier Prat on 06/06/17.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_FadeManager_h
#define hifi_FadeManager_h
#include <DependencyManager.h>
#include <gpu/Pipeline.h>
#include <render/ShapePipeline.h>
// Centralizes fade effect data and functions
class FadeManager : public Dependency {
SINGLETON_DEPENDENCY
public:
FadeManager();
const gpu::TexturePointer getFadeMaskMap() const { return _fadeMaskMap; }
void setDebugEnabled(bool isEnabled) { _isDebugEnabled = isEnabled; }
bool isDebugEnabled() const { return _isDebugEnabled; }
void setDebugFadePercent(float value) { assert(value >= 0.f && value <= 1.f); _debugFadePercent = value; }
float getDebugFadePercent() const { return _debugFadePercent; }
render::ShapeKey::Builder getKeyBuilder() const;
private:
gpu::TexturePointer _fadeMaskMap;
float _debugFadePercent;
bool _isDebugEnabled;
};
#endif // hifi_FadeManager_h

View file

@ -15,6 +15,7 @@
#include "DeferredLightingEffect.h"
#include "EntityItem.h"
#include "FadeManager.h"
using namespace render;
@ -550,8 +551,8 @@ float ModelMeshPartPayload::computeFadePercent() const {
return fadeAlpha;
}
void ModelMeshPartPayload::bindFade(gpu::Batch& batch, const RenderArgs* args) const {
const bool isDebugEnabled = (args->_debugFlags & RenderArgs::RENDER_DEBUG_FADE) != 0;
void ModelMeshPartPayload::bindFade(gpu::Batch& batch) const {
const bool isDebugEnabled = DependencyManager::get<FadeManager>()->isDebugEnabled();
if (_fadeState != FADE_COMPLETE || isDebugEnabled) {
auto& fade = _fadeBuffer.edit<Fade>();
@ -562,7 +563,7 @@ void ModelMeshPartPayload::bindFade(gpu::Batch& batch, const RenderArgs* args) c
fade._percent = computeFadePercent();
}
else {
fade._percent = args->_debugFadePercent;
fade._percent = DependencyManager::get<FadeManager>()->getDebugFadePercent();
}
fade._offset = offset;
@ -617,7 +618,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) {
bindMaterial(batch, locations, args->_enableTexturing);
// Apply fade effect
bindFade(batch, args);
bindFade(batch);
args->_details._materialSwitches++;

View file

@ -106,7 +106,7 @@ public:
// ModelMeshPartPayload functions to perform render
void bindMesh(gpu::Batch& batch) override;
void bindTransform(gpu::Batch& batch, const render::ShapePipeline::LocationsPointer locations, RenderArgs::RenderMode renderMode) const override;
void bindFade(gpu::Batch& batch, const RenderArgs* args) const;
void bindFade(gpu::Batch& batch) const;
void initCache();

View file

@ -35,6 +35,7 @@
#include "HitEffect.h"
#include "TextureCache.h"
#include "ZoneRenderer.h"
#include "FadeManager.h"
#include "AmbientOcclusionEffect.h"
#include "AntialiasingEffect.h"
@ -50,6 +51,12 @@ using namespace render;
extern void initOverlay3DPipelines(render::ShapePlumber& plumber);
extern void initDeferredPipelines(render::ShapePlumber& plumber);
void RenderDeferredTask::configure(const Config& config)
{
DependencyManager::get<FadeManager>()->setDebugEnabled(config.debugFade);
DependencyManager::get<FadeManager>()->setDebugFadePercent(config.debugFadePercent);
}
void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output) {
auto items = input.get<Input>();
@ -85,13 +92,11 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
const auto deferredFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(0);
const auto lightingFramebuffer = prepareDeferredOutputs.getN<PrepareDeferred::Outputs>(1);
// Fade texture mask
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
auto fadeMaskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
DependencyManager::set<FadeManager>();
// Render opaque objects in DeferredBuffer
const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).hasVarying();
task.addJob<DrawStateSortDeferred>("DrawOpaqueDeferred", opaqueInputs, shapePlumber, fadeMaskMap);
task.addJob<DrawStateSortDeferred>("DrawOpaqueDeferred", opaqueInputs, shapePlumber);
// Once opaque is all rendered create stencil background
task.addJob<DrawStencilDeferred>("DrawOpaqueStencil", deferredFramebuffer);
@ -147,7 +152,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
// Render transparent objects forward in LightingBuffer
const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).hasVarying();
task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber, fadeMaskMap);
task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber);
// LIght Cluster Grid Debuging job
{
@ -252,15 +257,8 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
const auto& lightingModel = inputs.get1();
RenderArgs* args = renderContext->args;
ShapeKey::Builder defaultKeyBuilder;
if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone
defaultKeyBuilder.withFade();
}
ShapeKey::Builder defaultKeyBuilder = DependencyManager::get<FadeManager>()->getKeyBuilder();
gpu::TexturePointer fadeMaskMap = DependencyManager::get<FadeManager>()->getFadeMaskMap();
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
args->_batch = &batch;
@ -285,8 +283,9 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
if (lightingModel->isWireframeEnabled()) {
keyBuilder.withWireframe();
}
// Prepare fade effect
batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap);
batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, fadeMaskMap);
ShapeKey globalKey = keyBuilder.build();
args->_globalShapeKey = globalKey._flags.to_ulong();
@ -297,13 +296,6 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
args->_globalShapeKey = 0;
});
// Not sure this is really needed...
if (_debugFade) {
// Turn off fade debug
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags &
~static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
}
config->setNumDrawn((int)inItems.size());
}
@ -317,15 +309,8 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
const auto& lightingModel = inputs.get1();
RenderArgs* args = renderContext->args;
ShapeKey::Builder defaultKeyBuilder;
if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone
defaultKeyBuilder.withFade();
}
ShapeKey::Builder defaultKeyBuilder = DependencyManager::get<FadeManager>()->getKeyBuilder();
gpu::TexturePointer fadeMaskMap = DependencyManager::get<FadeManager>()->getFadeMaskMap();
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
args->_batch = &batch;
@ -352,7 +337,7 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
}
// Prepare fade effect
batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap);
batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, fadeMaskMap);
ShapeKey globalKey = keyBuilder.build();
args->_globalShapeKey = globalKey._flags.to_ulong();
@ -366,13 +351,6 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
args->_globalShapeKey = 0;
});
// Not sure this is really needed...
if (_debugFade) {
// Turn off fade debug
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags &
~static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
}
config->setNumDrawn((int)inItems.size());
}

View file

@ -44,22 +44,10 @@ public:
protected:
};
class DrawFadableDeferred {
protected:
DrawFadableDeferred(gpu::TexturePointer fadeMaskMap) : _fadeMaskMap{ fadeMaskMap } {}
gpu::TexturePointer _fadeMaskMap;
float _debugFadePercent;
bool _debugFade;
};
class DrawConfig : public render::Job::Config {
Q_OBJECT
Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY newStats)
Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
Q_PROPERTY(bool debugFade MEMBER debugFade NOTIFY dirty)
Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty)
public:
@ -67,8 +55,6 @@ public:
void setNumDrawn(int numDrawn) { _numDrawn = numDrawn; emit newStats(); }
int maxDrawn{ -1 };
float debugFadePercent{ 0.f };
bool debugFade{ false };
signals:
void newStats();
@ -78,15 +64,15 @@ protected:
int _numDrawn{ 0 };
};
class DrawDeferred : public DrawFadableDeferred {
class DrawDeferred {
public:
using Inputs = render::VaryingSet2 <render::ItemBounds, LightingModelPointer>;
using Config = DrawConfig;
using JobModel = render::Job::ModelI<DrawDeferred, Inputs, Config>;
DrawDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, DrawFadableDeferred{ fadeMaskMap } {}
DrawDeferred(render::ShapePlumberPointer shapePlumber) : _shapePlumber{ shapePlumber } {}
void configure(const Config& config) { _maxDrawn = config.maxDrawn; _debugFadePercent = config.debugFadePercent; _debugFade = config.debugFade; }
void configure(const Config& config) { _maxDrawn = config.maxDrawn; }
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
protected:
@ -99,8 +85,6 @@ class DrawStateSortConfig : public render::Job::Config {
Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY numDrawnChanged)
Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
Q_PROPERTY(bool stateSort MEMBER stateSort NOTIFY dirty)
Q_PROPERTY(bool debugFade MEMBER debugFade NOTIFY dirty)
Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty)
public:
int getNumDrawn() { return numDrawn; }
@ -108,8 +92,6 @@ public:
int maxDrawn{ -1 };
bool stateSort{ true };
float debugFadePercent{ 0.f };
bool debugFade{ false };
signals:
void numDrawnChanged();
@ -119,16 +101,16 @@ protected:
int numDrawn{ 0 };
};
class DrawStateSortDeferred : public DrawFadableDeferred {
class DrawStateSortDeferred {
public:
using Inputs = render::VaryingSet2 <render::ItemBounds, LightingModelPointer>;
using Config = DrawStateSortConfig;
using JobModel = render::Job::ModelI<DrawStateSortDeferred, Inputs, Config>;
DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, DrawFadableDeferred{ fadeMaskMap } {}
DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber) : _shapePlumber{ shapePlumber } {}
void configure(const Config& config) { _maxDrawn = config.maxDrawn; _stateSort = config.stateSort; _debugFadePercent = config.debugFadePercent; _debugFade = config.debugFade; }
void configure(const Config& config) { _maxDrawn = config.maxDrawn; _stateSort = config.stateSort; }
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
protected:
@ -209,13 +191,28 @@ public:
void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer);
};
class RenderDeferredTaskConfig : public render::Task::Config {
Q_OBJECT
Q_PROPERTY(bool debugFade MEMBER debugFade NOTIFY dirty)
Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty)
public:
float debugFadePercent{ 0.f };
bool debugFade{ false };
signals:
void dirty();
};
class RenderDeferredTask {
public:
using Input = RenderFetchCullSortTask::Output;
using JobModel = render::Task::ModelI<RenderDeferredTask, Input>;
using Config = RenderDeferredTaskConfig;
using JobModel = render::Task::ModelI<RenderDeferredTask, Input, Config>;
RenderDeferredTask() {}
void configure(const Config& config);
void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs);
};

View file

@ -80,7 +80,6 @@ public:
enum DebugFlags {
RENDER_DEBUG_NONE = 0,
RENDER_DEBUG_HULLS = 1,
RENDER_DEBUG_FADE = 2,
};
RenderArgs(std::shared_ptr<gpu::Context> context = nullptr,
@ -133,7 +132,6 @@ public:
RenderDetails _details;
render::ScenePointer _scene; // HACK
int8_t _cameraMode { -1 }; // HACK
float _debugFadePercent{ 0.f }; // HACK too
};
#endif // hifi_RenderArgs_h

View file

@ -13,21 +13,15 @@ import QtQuick.Controls 1.4
import "configSlider"
Row {
property var drawOpaqueConfig: Render.getConfig("DrawOpaqueDeferred");
property var drawTransparentConfig: Render.getConfig("DrawTransparentDeferred");
property var taskConfig: Render.getConfig("RenderDeferredTask");
spacing: 4
Column {
spacing: 8
CheckBox {
text: "Force Fade Opaque"
checked: drawOpaqueConfig["debugFade"]
onCheckedChanged: { drawOpaqueConfig["debugFade"] = checked }
}
CheckBox {
text: "Force Fade Transparent"
checked: drawTransparentConfig["debugFade"]
onCheckedChanged: { drawTransparentConfig["debugFade"] = checked }
text: "Force Fade"
checked: taskConfig["debugFade"]
onCheckedChanged: { taskConfig["debugFade"] = checked }
}
}
Column {
@ -36,16 +30,7 @@ Row {
ConfigSlider {
label: "Percent"
integral: false
config: drawOpaqueConfig
property: "debugFadePercent"
max: 1.0
min: 0.0
width: 250
}
ConfigSlider {
label: "Percent"
integral: false
config: drawTransparentConfig
config: taskConfig
property: "debugFadePercent"
max: 1.0
min: 0.0