Turn fade-in value into a property and move away from dedicated fadeIn, fadeOut methods (closes #869)

This commit is contained in:
Alexander Bock
2019-05-22 22:08:54 -06:00
parent cdeaae5068
commit a894e2cf5a
5 changed files with 11 additions and 128 deletions

View File

@@ -76,7 +76,7 @@ local Keybindings = {
{
Key = "w",
Name = "Fade to/from black",
Command = "openspace.toggleFade(3)",
Command = "if openspace.getPropertyValue('RenderEngine.BlackoutFactor') > 0.5 then openspace.setPropertyValueSingle('RenderEngine.BlackoutFactor', 0.0, 3) else openspace.setPropertyValueSingle('RenderEngine.BlackoutFactor', 1.0, 3) end",
Documentation = "Toggles the fade to black within 3 seconds or shows the rendering after 3 seconds.",
GuiPath = "/Rendering",
Local = false

View File

@@ -78,7 +78,6 @@ public:
RendererImplementation rendererImplementation() const;
void updateShaderPrograms();
void updateFade();
void updateRenderer();
void updateScreenSpaceRenderables();
void render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix,
@@ -145,9 +144,6 @@ public:
*/
static scripting::LuaLibrary luaLibrary();
// Temporary fade functionality
void startFading(int direction, float fadeDuration);
glm::ivec2 renderingResolution() const;
glm::ivec2 fontResolution() const;
@@ -187,10 +183,7 @@ private:
properties::BoolProperty _showFrameNumber;
properties::BoolProperty _disableMasterRendering;
float _globalBlackOutFactor = 1.f;
float _fadeDuration = 2.f;
float _currentFadeTime = 0.f;
int _fadeDirection = 0;
properties::FloatProperty _globalBlackOutFactor;
properties::IntProperty _nAaSamples;
properties::FloatProperty _hdrExposure;
properties::FloatProperty _hdrBackground;

View File

@@ -760,9 +760,6 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
global::renderEngine.updateScene();
global::renderEngine.setGlobalBlackOutFactor(0.f);
global::renderEngine.startFading(1, 3.f);
global::syncEngine.addSyncables(global::timeManager.getSyncables());
if (_scene && _scene->camera()) {
global::syncEngine.addSyncables(_scene->camera()->getSyncables());
@@ -1043,7 +1040,6 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
}
global::renderEngine.updateScene();
global::renderEngine.updateFade();
global::renderEngine.updateRenderer();
global::renderEngine.updateScreenSpaceRenderables();
global::renderEngine.updateShaderPrograms();

View File

@@ -218,6 +218,13 @@ namespace {
"view will be automatically adjusted to match, according to the current "
"aspect ratio."
};
constexpr openspace::properties::Property::PropertyInfo GlobalBlackoutFactorInfo = {
"BlackoutFactor",
"Blackout Factor",
"The blackout factor of the rendering. This can be used for fading in or out the "
"rendering window"
};
} // namespace
@@ -234,6 +241,7 @@ RenderEngine::RenderEngine()
, _applyWarping(ApplyWarpingInfo, false)
, _showFrameNumber(ShowFrameNumberInfo, false)
, _disableMasterRendering(DisableMasterInfo, false)
, _globalBlackOutFactor(GlobalBlackoutFactorInfo, 1.f, 0.f, 1.f)
, _nAaSamples(AaSamplesInfo, 4, 1, 8)
, _hdrExposure(HDRExposureInfo, 0.4f, 0.01f, 10.0f)
, _hdrBackground(BackgroundExposureInfo, 2.8f, 0.01f, 10.0f)
@@ -296,6 +304,7 @@ RenderEngine::RenderEngine()
});
addProperty(_gamma);
addProperty(_globalBlackOutFactor);
addProperty(_applyWarping);
_horizFieldOfView.onChange([this]() {
@@ -540,44 +549,6 @@ glm::mat4 RenderEngine::nodeRotation() const {
return glm::mat4_cast(glm::normalize(pitch * yaw * roll));
}
void RenderEngine::updateFade() {
// Temporary fade funtionality
constexpr const float FadedIn = 1.0;
constexpr const float FadedOut = 0.0;
// Don't restart the fade if you've already done it in that direction
const bool isFadedIn = (_fadeDirection > 0 && _globalBlackOutFactor == FadedIn);
const bool isFadedOut = (_fadeDirection < 0 && _globalBlackOutFactor == FadedOut);
if (isFadedIn || isFadedOut) {
_fadeDirection = 0;
}
if (_fadeDirection != 0) {
if (_currentFadeTime > _fadeDuration) {
_globalBlackOutFactor = _fadeDirection > 0 ? FadedIn : FadedOut;
_fadeDirection = 0;
}
else {
if (_fadeDirection < 0) {
_globalBlackOutFactor = glm::smoothstep(
1.f,
0.f,
_currentFadeTime / _fadeDuration
);
}
else {
_globalBlackOutFactor = glm::smoothstep(
0.f,
1.f,
_currentFadeTime / _fadeDuration
);
}
_currentFadeTime += static_cast<float>(
global::windowDelegate.averageDeltaTime()
);
}
}
}
void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix,
const glm::mat4& projectionMatrix)
{
@@ -849,12 +820,6 @@ void RenderEngine::setGlobalBlackOutFactor(float opacity) {
_globalBlackOutFactor = opacity;
}
void RenderEngine::startFading(int direction, float fadeDuration) {
_fadeDirection = direction;
_fadeDuration = fadeDuration;
_currentFadeTime = 0.f;
}
/**
* Build a program object for rendering with the used renderer
*/
@@ -1004,27 +969,6 @@ scripting::LuaLibrary RenderEngine::luaLibrary() {
"string",
"Sets the renderer (ABuffer or FrameBuffer)"
},
{
"toggleFade",
&luascriptfunctions::toggleFade,
{},
"number",
"Toggles fading in or out"
},
{
"fadeIn",
&luascriptfunctions::fadeIn,
{},
"number",
""
},
{
"fadeOut",
&luascriptfunctions::fadeOut,
{},
"number",
""
},
{
"addScreenSpaceRenderable",
&luascriptfunctions::addScreenSpaceRenderable,

View File

@@ -50,56 +50,6 @@ int setRenderer(lua_State* L) {
return 0;
}
/**
* \ingroup LuaScripts
* toggleFade(float):
* Toggle a global fade over (float) seconds
*/
int toggleFade(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::toggleFade");
const float t = ghoul::lua::value<float>(L, 1, ghoul::lua::PopValue::Yes);
constexpr const float fadedIn = 1.f;
const int direction = global::renderEngine.globalBlackOutFactor() == fadedIn ? -1 : 1;
global::renderEngine.startFading(direction, static_cast<float>(t));
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
/**
* \ingroup LuaScripts
* fadeIn(float):
* start a global fadein over (float) seconds
*/
int fadeIn(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fadeIn");
const float t = ghoul::lua::value<float>(L, 1, ghoul::lua::PopValue::Yes);
global::renderEngine.startFading(1, t);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
/**
* \ingroup LuaScripts
* fadeIn(float):
* start a global fadeout over (float) seconds
*/
int fadeOut(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fadeOut");
float t = ghoul::lua::value<float>(L, 1, ghoul::lua::PopValue::Yes);
global::renderEngine.startFading(-1, t);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
int addScreenSpaceRenderable(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::addScreenSpaceRenderable");