Add ssao quality setting

This commit is contained in:
Magnus Norddahl 2016-09-24 19:26:25 +02:00
parent 0397fe185f
commit 3f11c0562c
7 changed files with 76 additions and 33 deletions

View file

@ -99,7 +99,12 @@ CVAR(Float, gl_lens_k, -0.12f, 0)
CVAR(Float, gl_lens_kcube, 0.1f, 0)
CVAR(Float, gl_lens_chromatic, 1.12f, 0)
CVAR(Bool, gl_ssao, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CUSTOM_CVAR(Int, gl_ssao, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0 || self > 3)
self = 0;
}
CVAR(Float, gl_ssao_strength, 0.7, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, gl_ssao_debug, false, 0)
CVAR(Float, gl_ssao_bias, 0.5f, 0)

View file

@ -158,10 +158,11 @@ void FGLRenderer::Set3DViewport(bool mainview)
{
if (mainview && mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height))
{
mBuffers->BindSceneFB(gl_ssao);
bool useSSAO = (gl_ssao != 0);
mBuffers->BindSceneFB(useSSAO);
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers(gl_ssao ? 2 : 1, buffers);
gl_RenderState.SetPassType(gl_ssao ? GBUFFER_PASS : NORMAL_PASS);
glDrawBuffers(useSSAO ? 2 : 1, buffers);
gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
gl_RenderState.Apply();
}
@ -494,7 +495,7 @@ void FGLRenderer::DrawScene(int drawmode)
GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place.
// If SSAO is active, switch to gbuffer shaders and use the gbuffer framebuffer
bool applySSAO = gl_ssao && FGLRenderBuffers::IsEnabled() && drawmode == DM_MAINVIEW;
bool applySSAO = gl_ssao != 0 && FGLRenderBuffers::IsEnabled() && drawmode == DM_MAINVIEW;
if (applySSAO)
{
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };

View file

@ -74,32 +74,47 @@ void FLinearDepthShader::Bind(bool multisample)
void FSSAOShader::Bind()
{
if (!mShader)
auto &shader = mShader[gl_ssao];
if (!shader)
{
const char *defines = R"(
#define USE_RANDOM_TEXTURE
#define RANDOM_TEXTURE_WIDTH 4.0
#define NUM_DIRECTIONS 8.0
#define NUM_STEPS 4.0
)";
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", defines, 330);
mShader.SetFragDataLocation(0, "FragColor");
mShader.Link("shaders/glsl/ssao");
mShader.SetAttribLocation(0, "PositionInProjection");
DepthTexture.Init(mShader, "DepthTexture");
RandomTexture.Init(mShader, "RandomTexture");
UVToViewA.Init(mShader, "UVToViewA");
UVToViewB.Init(mShader, "UVToViewB");
InvFullResolution.Init(mShader, "InvFullResolution");
NDotVBias.Init(mShader, "NDotVBias");
NegInvR2.Init(mShader, "NegInvR2");
RadiusToScreen.Init(mShader, "RadiusToScreen");
AOMultiplier.Init(mShader, "AOMultiplier");
AOStrength.Init(mShader, "AOStrength");
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", GetDefines(gl_ssao), 330);
shader.SetFragDataLocation(0, "FragColor");
shader.Link("shaders/glsl/ssao");
shader.SetAttribLocation(0, "PositionInProjection");
DepthTexture.Init(shader, "DepthTexture");
RandomTexture.Init(shader, "RandomTexture");
UVToViewA.Init(shader, "UVToViewA");
UVToViewB.Init(shader, "UVToViewB");
InvFullResolution.Init(shader, "InvFullResolution");
NDotVBias.Init(shader, "NDotVBias");
NegInvR2.Init(shader, "NegInvR2");
RadiusToScreen.Init(shader, "RadiusToScreen");
AOMultiplier.Init(shader, "AOMultiplier");
AOStrength.Init(shader, "AOStrength");
}
mShader.Bind();
shader.Bind();
}
FString FSSAOShader::GetDefines(int mode)
{
int numDirections, numSteps;
switch (gl_ssao)
{
default:
case LowQuality: numDirections = 2; numSteps = 4; break;
case MediumQuality: numDirections = 4; numSteps = 4; break;
case HighQuality: numDirections = 8; numSteps = 4; break;
}
FString defines;
defines.Format(R"(
#define USE_RANDOM_TEXTURE
#define RANDOM_TEXTURE_WIDTH 4.0
#define NUM_DIRECTIONS %d.0
#define NUM_STEPS %d.0
)", numDirections, numSteps);
return defines;
}
void FDepthBlurShader::Bind(bool vertical)

View file

@ -39,7 +39,18 @@ public:
FBufferedUniform1f AOStrength;
private:
FShaderProgram mShader;
enum Quality
{
Off,
LowQuality,
MediumQuality,
HighQuality,
NumQualityModes
};
FString GetDefines(int mode);
FShaderProgram mShader[NumQualityModes];
};
class FDepthBlurShader

View file

@ -50,7 +50,7 @@ EXTERN_CVAR(Bool, gl_lens)
EXTERN_CVAR(Float, gl_lens_k)
EXTERN_CVAR(Float, gl_lens_kcube)
EXTERN_CVAR(Float, gl_lens_chromatic)
EXTERN_CVAR(Bool, gl_ssao)
EXTERN_CVAR(Int, gl_ssao)
EXTERN_CVAR(Float, gl_ssao_strength)
EXTERN_CVAR(Bool, gl_ssao_debug)
EXTERN_CVAR(Float, gl_ssao_bias)

View file

@ -2167,6 +2167,9 @@ NETMNU_TICBALANCE = "Latency balancing";
// Option Values
OPTVAL_OFF = "Off";
OPTVAL_ON = "On";
OPTVAL_LOW = "Low";
OPTVAL_MEDIUM = "Medium";
OPTVAL_HIGH = "High";
OPTVAL_MALE = "Male";
OPTVAL_FEMALE = "Female";
OPTVAL_OTHER = "Other";
@ -2633,7 +2636,7 @@ GLPREFMNU_MULTISAMPLE = "Multisample";
GLPREFMNU_TONEMAP = "Tonemap Mode";
GLPREFMNU_BLOOM = "Bloom effect";
GLPREFMNU_LENS = "Lens distortion effect";
GLPREFMNU_SSAO = "Ambient occlusion";
GLPREFMNU_SSAO = "Ambient occlusion quality";
// Option Values
OPTVAL_SMART = "Smart";

View file

@ -42,6 +42,14 @@ OptionValue "TonemapModes"
5, "$OPTVAL_PALETTE"
}
OptionValue "SSAOModes"
{
0, "$OPTVAL_OFF"
1, "$OPTVAL_LOW"
2, "$OPTVAL_MEDIUM"
3, "$OPTVAL_HIGH"
}
OptionValue "TextureFormats"
{
0, "$OPTVAL_RGBA8"
@ -226,5 +234,5 @@ OptionMenu "GLPrefOptions"
Option "$GLPREFMNU_TONEMAP", gl_tonemap, "TonemapModes"
Option "$GLPREFMNU_BLOOM", gl_bloom, "OnOff"
Option "$GLPREFMNU_LENS", gl_lens, "OnOff"
Option "$GLPREFMNU_SSAO", gl_ssao, "OnOff"
Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes"
}