Skip to content

Commit

Permalink
Renderer|LensFX: Added a resizing filter (pixel density)
Browse files Browse the repository at this point in the history
fx::Resize changes the size of the frame buffer to produce a pixelated
appearance, either for performance or aesthetic reasons.

The variables "Config.render.pixelDensity" and
"Config.render.fx.resize.factor" control the amount of resizing. The
former applies globally, however is only shown in Video Settings when
using a HiDPI display mode. The latter is accessible via the Renderer
Appearance editor.

The global pixel density setting replaces video mode resolution
config on OS X (changing the desktop video mode is not supported on
OS X).
  • Loading branch information
skyjake committed Oct 19, 2014
1 parent 5d1b2d6 commit a7e6e3d
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 66 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -276,6 +276,7 @@ DENG_HEADERS += \
include/render/fx/colorfilter.h \
include/render/fx/lensflares.h \
include/render/fx/postprocessing.h \
include/render/fx/resize.h \
include/render/fx/vignette.h \
include/render/huecirclevisual.h \
include/render/ilightsource.h \
Expand Down Expand Up @@ -598,6 +599,7 @@ SOURCES += \
src/render/fx/colorfilter.cpp \
src/render/fx/lensflares.cpp \
src/render/fx/postprocessing.cpp \
src/render/fx/resize.cpp \
src/render/fx/vignette.cpp \
src/render/huecirclevisual.cpp \
src/render/lightdecoration.cpp \
Expand Down
55 changes: 55 additions & 0 deletions doomsday/client/include/render/fx/resize.h
@@ -0,0 +1,55 @@
/** @file fx/resize.h Change the size (pixel density) of the view.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_FX_RESIZE_H
#define DENG_CLIENT_FX_RESIZE_H

#include "render/consoleeffect.h"
#include <de/Time>

namespace fx {

/**
* Post-processing of rendered camera lens frames. Maintains an offscreen
* render target and provides a way to draw it back to the regular target
* with shader effects applied.
*/
class Resize : public ConsoleEffect
{
public:
Resize(int console);

/**
* Determines whether the effect is active. If it isn't, it can be skipped
* altogether when post processing a frame.
*/
bool isActive() const;

void glInit();
void glDeinit();

void beginFrame();
void endFrame();

private:
DENG2_PRIVATE(d)
};

} // namespace fx

#endif // DENG_CLIENT_FX_RESIZE_H
9 changes: 9 additions & 0 deletions doomsday/client/net.dengine.client.pack/modules/appconfig.de
Expand Up @@ -79,6 +79,15 @@ def setDefaults(d)
record d.masterServer
d.masterServer.apiUrl = "www.dengine.net/master.php"

# Renderer settings.
record d.render
d.render.pixelDensity = 1.0 # Overall pixel density.

# LensFx settings.
record d.render.fx
record d.render.fx.resize
d.render.fx.resize.factor = 1.0

# VR/3D settings.
record d.vr
record d.vr.oculusRift
Expand Down
10 changes: 6 additions & 4 deletions doomsday/client/src/render/cameralensfx.cpp
Expand Up @@ -41,11 +41,12 @@
#include "render/cameralensfx.h"
#include "render/rend_main.h"
#include "render/viewports.h"
#include "render/fx/bloom.h"
#include "render/fx/colorfilter.h"
#include "render/fx/lensflares.h"
#include "render/fx/postprocessing.h"
#include "render/fx/resize.h"
#include "render/fx/vignette.h"
#include "render/fx/bloom.h"

#include "ui/clientwindow.h"

Expand Down Expand Up @@ -78,8 +79,8 @@ struct ConsoleEffectStack

static ConsoleEffectStack fxConsole[DDMAXPLAYERS];

#define IDX_LENS_FLARES 2
#define IDX_POST_PROCESSING 4
#define IDX_LENS_FLARES 3
#define IDX_POST_PROCESSING 5

D_CMD(PostFx)
{
Expand Down Expand Up @@ -116,7 +117,7 @@ D_CMD(PostFx)

void LensFx_Register()
{
C_CMD("postfx", "is", PostFx);
C_CMD("postfx", "is", PostFx);
C_CMD("postfx", "isf", PostFx);
}

Expand All @@ -126,6 +127,7 @@ void LensFx_Init()
{
ConsoleEffectStack &stack = fxConsole[i];
stack.effects
<< new fx::Resize(i)
<< new fx::Bloom(i)
<< new fx::Vignette(i)
<< new fx::LensFlares(i) // IDX_LENS_FLARES
Expand Down
195 changes: 195 additions & 0 deletions doomsday/client/src/render/fx/resize.cpp
@@ -0,0 +1,195 @@
/** @file fx/resize.cpp Change the size (pixel density) of the view.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "render/fx/resize.h"
#include "ui/clientwindow.h"
#include "clientapp.h"

#include <de/VRConfig>
#include <de/Drawable>
#include <de/GLFramebuffer>
#include <de/Variable>

#include <QList>

using namespace de;

namespace fx {

static ddouble const MIN_FACTOR = 1.0 / 16.0;

DENG2_PIMPL(Resize)
{
Variable const &pixelDensity;
Variable const &resizeFactor;

GLFramebuffer framebuf;
Drawable frame;
GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };
GLUniform uFrame { "uTex", GLUniform::Sampler2D };

typedef GLBufferT<Vertex2Tex> VBuf;

Instance(Public *i)
: Base(i)
, pixelDensity { App::config("render.pixelDensity") }
, resizeFactor { App::config("render.fx.resize.factor") }
{}

GuiRootWidget &root() const
{
return ClientWindow::main().game().root();
}

float factor() const
{
return max(MIN_FACTOR, pixelDensity * resizeFactor);
}

/// Determines if the post-processing shader will be applied.
bool isActive() const
{
// This kind of scaling is not compatible with Oculus Rift -- LibOVR does its
// own pixel density scaling.
if(ClientApp::vr().mode() == VRConfig::OculusRift) return false;

return !fequal(factor(), 1.f);
}

void glInit()
{
framebuf.glInit();

uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);
uFrame = framebuf.colorTexture();

// Drawable for drawing stuff back to the original target.
VBuf *buf = new VBuf;
buf->setVertices(gl::TriangleStrip,
VBuf::Builder().makeQuad(Rectanglef(0, 0, 1, 1),
Rectanglef(0, 1, 1, -1)),
gl::Static);
frame.addBuffer(buf);

ClientApp::shaders().build(frame.program(), "generic.texture")
<< uMvpMatrix << uFrame;
}

void glDeinit()
{
LOGDEV_GL_XVERBOSE("Releasing GL resources");
framebuf.glDeinit();
frame.clear();
}

void update()
{
framebuf.resize(GLState::current().target().rectInUse().size() * factor());
framebuf.setSampleCount(GLFramebuffer::defaultMultisampling());
}

void begin()
{
if(!isActive()) return;

update();

GLState::push()
.setTarget(framebuf.target())
.setViewport(Rectangleui::fromSize(framebuf.size()))
.setColorMask(gl::WriteAll)
.apply();
framebuf.target().clear(GLTarget::ColorDepthStencil);
}

void end()
{
if(!isActive()) return;

GLState::pop().apply();
}

void draw()
{
if(!isActive()) return;

glEnable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);

GLState::push()
.setBlend(false)
.setDepthTest(false)
.setViewport(Rectangleui::fromSize(GLState::current().target().size()))
.apply();

frame.draw();

GLState::pop().apply();

glEnable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
}
};

Resize::Resize(int console)
: ConsoleEffect(console), d(new Instance(this))
{}

bool Resize::isActive() const
{
return d->isActive();
}

void Resize::glInit()
{
if(!d->isActive()) return;

LOG_AS("fx::Resize");

ConsoleEffect::glInit();
d->glInit();
}

void Resize::glDeinit()
{
LOG_AS("fx::Resize");

d->glDeinit();
ConsoleEffect::glDeinit();
}

void Resize::beginFrame()
{
d->begin();
}

void Resize::endFrame()
{
LOG_AS("fx::Resize");

d->end();
d->draw();

if(!d->isActive() && isInited())
{
glDeinit();
}
}

} // namespace fx
2 changes: 2 additions & 0 deletions doomsday/client/src/render/rendersystem.cpp
Expand Up @@ -170,6 +170,8 @@ DENG2_PIMPL(RenderSystem)
.define(SReg::FloatCVar, "rend-glow-scale", 3)
.define(SReg::IntCVar, "rend-glow-wall", 1)

.define(SReg::ConfigVariable, "render.fx.resize.factor")

.define(SReg::IntCVar, "rend-bloom", 1)
.define(SReg::FloatCVar, "rend-bloom-intensity", .65f)
.define(SReg::FloatCVar, "rend-bloom-threshold", .35f)
Expand Down
5 changes: 3 additions & 2 deletions doomsday/client/src/ui/clientwindowsystem.cpp
Expand Up @@ -41,8 +41,9 @@ DENG2_PIMPL(ClientWindowSystem)
self.style().load(App::packageLoader().load("net.dengine.client.defaultstyle"));

settings.define(SettingsRegister::ConfigVariable, "window.main.showFps")
.define(SettingsRegister::IntCVar, "vid-fsaa", 1)
.define(SettingsRegister::IntCVar, "vid-vsync", 1);
.define(SettingsRegister::IntCVar, "vid-fsaa", 0)
.define(SettingsRegister::IntCVar, "vid-vsync", 1)
.define(SettingsRegister::ConfigVariable, "render.pixelDensity");
}
};

Expand Down

0 comments on commit a7e6e3d

Please sign in to comment.