Merge pull request #1427 from Penguin-Guru/AntialiasingSetting

Add antialiasing setting.
This commit is contained in:
Kalila 2021-11-02 16:09:15 -04:00 committed by GitHub
commit 61367ffd47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 42 deletions

View file

@ -358,6 +358,68 @@ Item {
}
}
}
ColumnLayout {
Layout.topMargin: 20
Layout.preferredWidth: parent.width
spacing: 0
Item {
Layout.preferredWidth: parent.width
Layout.preferredHeight: 35
HifiStylesUit.RalewayRegular {
id: antialiasingHeader
text: "Anti-aliasing"
anchors.left: parent.left
anchors.top: parent.top
width: 130
height: parent.height
size: 16
color: "#FFFFFF"
}
ListModel {
id: antialiasingModel
// Maintain same order as "AntialiasingConfig::Mode".
ListElement {
text: "None"
}
ListElement {
text: "TAA"
}
ListElement {
text: "FXAA"
}
}
HifiControlsUit.ComboBox {
id: antialiasingDropdown
anchors.left: antialiasingHeader.right
anchors.leftMargin: 20
anchors.top: parent.top
width: 280
height: parent.height
colorScheme: hifi.colorSchemes.dark
model: antialiasingModel
currentIndex: -1
function refreshAntialiasingDropdown() {
antialiasingDropdown.currentIndex = Render.antialiasingMode;
}
Component.onCompleted: {
antialiasingDropdown.refreshAntialiasingDropdown();
}
onCurrentIndexChanged: {
Render.antialiasingMode = currentIndex;
antialiasingDropdown.displayText = model.get(currentIndex).text;
}
}
}
}
}
}
@ -365,5 +427,6 @@ Item {
worldDetailDropdown.refreshWorldDetailDropdown();
renderingEffectsDropdown.refreshRenderingEffectsDropdownDisplay();
refreshRateDropdown.refreshRefreshRateDropdownDisplay();
antialiasingDropdown.refreshAntialiasingDropdown();
}
}

View file

@ -405,9 +405,6 @@ Menu::Menu() {
// Developer > Render >>>
MenuWrapper* renderOptionsMenu = developerMenu->addMenu("Render");
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AntiAliasing, 0, RenderScriptingInterface::getInstance()->getAntialiasingEnabled(),
RenderScriptingInterface::getInstance(), SLOT(setAntialiasingEnabled(bool)));
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, RenderScriptingInterface::getInstance()->getShadowsEnabled(),
RenderScriptingInterface::getInstance(), SLOT(setShadowsEnabled(bool)));

View file

@ -224,7 +224,6 @@ 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";
const QString NotificationSounds = "play_notification_sounds";
const QString NotificationSoundsSnapshot = "play_notification_sounds_snapshot";

View file

@ -8,7 +8,6 @@
#include "RenderScriptingInterface.h"
#include "LightingModel.h"
#include "AntialiasingEffect.h"
RenderScriptingInterface* RenderScriptingInterface::getInstance() {
@ -29,13 +28,14 @@ void RenderScriptingInterface::loadSettings() {
_renderMethod = (_renderMethodSetting.get());
_shadowsEnabled = (_shadowsEnabledSetting.get());
_ambientOcclusionEnabled = (_ambientOcclusionEnabledSetting.get());
_antialiasingEnabled = (_antialiasingEnabledSetting.get());
//_antialiasingMode = (_antialiasingModeSetting.get());
_antialiasingMode = static_cast<AntialiasingConfig::Mode>(_antialiasingModeSetting.get());
_viewportResolutionScale = (_viewportResolutionScaleSetting.get());
});
forceRenderMethod((RenderMethod)_renderMethod);
forceShadowsEnabled(_shadowsEnabled);
forceAmbientOcclusionEnabled(_ambientOcclusionEnabled);
forceAntialiasingEnabled(_antialiasingEnabled);
forceAntialiasingMode(_antialiasingMode);
forceViewportResolutionScale(_viewportResolutionScale);
}
@ -121,35 +121,50 @@ void RenderScriptingInterface::forceAmbientOcclusionEnabled(bool enabled) {
});
}
bool RenderScriptingInterface::getAntialiasingEnabled() const {
return _antialiasingEnabled;
AntialiasingConfig::Mode RenderScriptingInterface::getAntialiasingMode() const {
return _antialiasingMode;
}
void RenderScriptingInterface::setAntialiasingEnabled(bool enabled) {
if (_antialiasingEnabled != enabled) {
forceAntialiasingEnabled(enabled);
void RenderScriptingInterface::setAntialiasingMode(AntialiasingConfig::Mode mode) {
if (_antialiasingMode != mode) {
forceAntialiasingMode(mode);
emit settingsChanged();
}
}
void RenderScriptingInterface::forceAntialiasingEnabled(bool enabled) {
void RenderScriptingInterface::forceAntialiasingMode(AntialiasingConfig::Mode mode) {
_renderSettingLock.withWriteLock([&] {
_antialiasingEnabled = (enabled);
_antialiasingEnabledSetting.set(enabled);
_antialiasingMode = mode;
auto mainViewJitterCamConfig = qApp->getRenderEngine()->getConfiguration()->getConfig<JitterSample>("RenderMainView.JitterCam");
auto mainViewAntialiasingConfig = qApp->getRenderEngine()->getConfiguration()->getConfig<Antialiasing>("RenderMainView.Antialiasing");
if (mainViewJitterCamConfig && mainViewAntialiasingConfig) {
Menu::getInstance()->setIsOptionChecked(MenuOption::AntiAliasing, enabled);
if (enabled) {
mainViewJitterCamConfig->play();
mainViewAntialiasingConfig->setDebugFXAA(false);
}
else {
mainViewJitterCamConfig->none();
mainViewAntialiasingConfig->setDebugFXAA(true);
switch (mode) {
case AntialiasingConfig::Mode::NONE:
mainViewJitterCamConfig->none();
mainViewAntialiasingConfig->blend = 1;
mainViewAntialiasingConfig->setDebugFXAA(false);
break;
case AntialiasingConfig::Mode::TAA:
mainViewJitterCamConfig->play();
mainViewAntialiasingConfig->blend = 0.25;
mainViewAntialiasingConfig->setDebugFXAA(false);
break;
case AntialiasingConfig::Mode::FXAA:
mainViewJitterCamConfig->none();
mainViewAntialiasingConfig->blend = 0.25;
mainViewAntialiasingConfig->setDebugFXAA(true);
break;
default:
_antialiasingMode = AntialiasingConfig::Mode::NONE;
mainViewJitterCamConfig->none();
mainViewAntialiasingConfig->blend = 1;
mainViewAntialiasingConfig->setDebugFXAA(false);
break;
}
}
_antialiasingModeSetting.set(_antialiasingMode);
});
}

View file

@ -13,6 +13,8 @@
#include "Application.h"
#include "RenderForward.h"
#include "AntialiasingEffect.h"
/*@jsdoc
* The <code>Render</code> API enables you to configure the graphics engine.
@ -27,7 +29,7 @@
* @property {boolean} shadowsEnabled - <code>true</code> if shadows are enabled, <code>false</code> if they're disabled.
* @property {boolean} ambientOcclusionEnabled - <code>true</code> if ambient occlusion is enabled, <code>false</code> if it's
* disabled.
* @property {boolean} antialiasingEnabled - <code>true</code> if anti-aliasing is enabled, <code>false</code> if it's disabled.
* @property {integer} antialiasingMode - The active anti-aliasing mode.
* @property {number} viewportResolutionScale - The view port resolution scale, <code>&gt; 0.0</code>.
*/
class RenderScriptingInterface : public QObject {
@ -35,7 +37,7 @@ class RenderScriptingInterface : public QObject {
Q_PROPERTY(RenderMethod renderMethod READ getRenderMethod WRITE setRenderMethod NOTIFY settingsChanged)
Q_PROPERTY(bool shadowsEnabled READ getShadowsEnabled WRITE setShadowsEnabled NOTIFY settingsChanged)
Q_PROPERTY(bool ambientOcclusionEnabled READ getAmbientOcclusionEnabled WRITE setAmbientOcclusionEnabled NOTIFY settingsChanged)
Q_PROPERTY(bool antialiasingEnabled READ getAntialiasingEnabled WRITE setAntialiasingEnabled NOTIFY settingsChanged)
Q_PROPERTY(AntialiasingConfig::Mode antialiasingMode READ getAntialiasingMode WRITE setAntialiasingMode NOTIFY settingsChanged)
Q_PROPERTY(float viewportResolutionScale READ getViewportResolutionScale WRITE setViewportResolutionScale NOTIFY settingsChanged)
public:
@ -143,18 +145,18 @@ public slots:
void setAmbientOcclusionEnabled(bool enabled);
/*@jsdoc
* Gets whether or not anti-aliasing is enabled.
* @function Render.getAntialiasingEnabled
* @returns {boolean} <code>true</code> if anti-aliasing is enabled, <code>false</code> if it's disabled.
* Gets the active anti-aliasing mode.
* @function Render.getAntialiasingMode
* @returns {integer} the active anti-aliasing mode.
*/
bool getAntialiasingEnabled() const;
AntialiasingConfig::Mode getAntialiasingMode() const;
/*@jsdoc
* Sets whether or not anti-aliasing is enabled.
* @function Render.setAntialiasingEnabled
* @param {boolean} enabled - <code>true</code> to enable anti-aliasing, <code>false</code> to disable.
* Sets the active anti-aliasing mode.
* @function Render.setAntialiasingMode
* @param {integer} the active anti-aliasing mode.
*/
void setAntialiasingEnabled(bool enabled);
void setAntialiasingMode(AntialiasingConfig::Mode mode);
/*@jsdoc
* Gets the view port resolution scale.
@ -192,21 +194,22 @@ private:
int _renderMethod{ RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED };
bool _shadowsEnabled{ true };
bool _ambientOcclusionEnabled{ false };
bool _antialiasingEnabled{ true };
AntialiasingConfig::Mode _antialiasingMode{ AntialiasingConfig::Mode::TAA };
float _viewportResolutionScale{ 1.0f };
// Actual settings saved on disk
Setting::Handle<int> _renderMethodSetting { "renderMethod", RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED };
Setting::Handle<bool> _shadowsEnabledSetting { "shadowsEnabled", true };
Setting::Handle<bool> _ambientOcclusionEnabledSetting { "ambientOcclusionEnabled", false };
Setting::Handle<bool> _antialiasingEnabledSetting { "antialiasingEnabled", true };
//Setting::Handle<AntialiasingConfig::Mode> _antialiasingModeSetting { "antialiasingMode", AntialiasingConfig::Mode::TAA };
Setting::Handle<int> _antialiasingModeSetting { "antialiasingMode", AntialiasingConfig::Mode::TAA };
Setting::Handle<float> _viewportResolutionScaleSetting { "viewportResolutionScale", 1.0f };
// Force assign both setting AND runtime value to the parameter value
void forceRenderMethod(RenderMethod renderMethod);
void forceShadowsEnabled(bool enabled);
void forceAmbientOcclusionEnabled(bool enabled);
void forceAntialiasingEnabled(bool enabled);
void forceAntialiasingMode(AntialiasingConfig::Mode mode);
void forceViewportResolutionScale(float scale);
static std::once_flag registry_flag;

View file

@ -140,7 +140,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
#else
void AntialiasingConfig::setAAMode(int mode) {
_mode = std::min((int)AntialiasingConfig::MODE_COUNT, std::max(0, mode));
_mode = std::min((int)AntialiasingConfig::MODE_COUNT, std::max(0, mode)); // Just use unsigned?
emit dirty();
}

View file

@ -110,11 +110,12 @@ public:
AntialiasingConfig() : render::Job::Config(true) {}
enum Mode {
OFF = 0,
NONE = 0,
TAA,
FXAA,
MODE_COUNT
};
Q_ENUM(Mode) // Stored as signed int.
void setAAMode(int mode);
int getAAMode() const { return _mode; }
@ -122,7 +123,7 @@ public:
void setDebugFXAA(bool debug) { debugFXAAX = (debug ? 0.0f : 1.0f); emit dirty();}
bool debugFXAA() const { return (debugFXAAX == 0.0f ? true : false); }
int _mode{ TAA };
int _mode{ TAA }; // '_' prefix but not private?
float blend{ 0.25f };
float sharpen{ 0.05f };
@ -216,8 +217,8 @@ private:
};
#else
class AntiAliasingConfig : public render::Job::Config {
#else // User setting for antialias mode will probably be broken.
class AntiAliasingConfig : public render::Job::Config { // Not to be confused with AntialiasingConfig...
Q_OBJECT
Q_PROPERTY(bool enabled MEMBER enabled)
public:
@ -236,7 +237,7 @@ public:
const gpu::PipelinePointer& getAntialiasingPipeline();
const gpu::PipelinePointer& getBlendPipeline();
private:
gpu::FramebufferPointer _antialiasingBuffer;