mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-13 07:57:51 +00:00
Add ssao quality setting
This commit is contained in:
parent
0397fe185f
commit
3f11c0562c
7 changed files with 76 additions and 33 deletions
|
@ -99,7 +99,12 @@ CVAR(Float, gl_lens_k, -0.12f, 0)
|
||||||
CVAR(Float, gl_lens_kcube, 0.1f, 0)
|
CVAR(Float, gl_lens_kcube, 0.1f, 0)
|
||||||
CVAR(Float, gl_lens_chromatic, 1.12f, 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(Float, gl_ssao_strength, 0.7, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
CVAR(Bool, gl_ssao_debug, false, 0)
|
CVAR(Bool, gl_ssao_debug, false, 0)
|
||||||
CVAR(Float, gl_ssao_bias, 0.5f, 0)
|
CVAR(Float, gl_ssao_bias, 0.5f, 0)
|
||||||
|
|
|
@ -158,10 +158,11 @@ void FGLRenderer::Set3DViewport(bool mainview)
|
||||||
{
|
{
|
||||||
if (mainview && mBuffers->Setup(mScreenViewport.width, mScreenViewport.height, mSceneViewport.width, mSceneViewport.height))
|
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 };
|
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||||
glDrawBuffers(gl_ssao ? 2 : 1, buffers);
|
glDrawBuffers(useSSAO ? 2 : 1, buffers);
|
||||||
gl_RenderState.SetPassType(gl_ssao ? GBUFFER_PASS : NORMAL_PASS);
|
gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
||||||
gl_RenderState.Apply();
|
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.
|
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
|
// 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)
|
if (applySSAO)
|
||||||
{
|
{
|
||||||
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||||
|
|
|
@ -74,32 +74,47 @@ void FLinearDepthShader::Bind(bool multisample)
|
||||||
|
|
||||||
void FSSAOShader::Bind()
|
void FSSAOShader::Bind()
|
||||||
{
|
{
|
||||||
if (!mShader)
|
auto &shader = mShader[gl_ssao];
|
||||||
|
if (!shader)
|
||||||
{
|
{
|
||||||
const char *defines = R"(
|
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||||
#define USE_RANDOM_TEXTURE
|
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", GetDefines(gl_ssao), 330);
|
||||||
#define RANDOM_TEXTURE_WIDTH 4.0
|
shader.SetFragDataLocation(0, "FragColor");
|
||||||
#define NUM_DIRECTIONS 8.0
|
shader.Link("shaders/glsl/ssao");
|
||||||
#define NUM_STEPS 4.0
|
shader.SetAttribLocation(0, "PositionInProjection");
|
||||||
)";
|
DepthTexture.Init(shader, "DepthTexture");
|
||||||
|
RandomTexture.Init(shader, "RandomTexture");
|
||||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
UVToViewA.Init(shader, "UVToViewA");
|
||||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", defines, 330);
|
UVToViewB.Init(shader, "UVToViewB");
|
||||||
mShader.SetFragDataLocation(0, "FragColor");
|
InvFullResolution.Init(shader, "InvFullResolution");
|
||||||
mShader.Link("shaders/glsl/ssao");
|
NDotVBias.Init(shader, "NDotVBias");
|
||||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
NegInvR2.Init(shader, "NegInvR2");
|
||||||
DepthTexture.Init(mShader, "DepthTexture");
|
RadiusToScreen.Init(shader, "RadiusToScreen");
|
||||||
RandomTexture.Init(mShader, "RandomTexture");
|
AOMultiplier.Init(shader, "AOMultiplier");
|
||||||
UVToViewA.Init(mShader, "UVToViewA");
|
AOStrength.Init(shader, "AOStrength");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
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)
|
void FDepthBlurShader::Bind(bool vertical)
|
||||||
|
|
|
@ -39,7 +39,18 @@ public:
|
||||||
FBufferedUniform1f AOStrength;
|
FBufferedUniform1f AOStrength;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FShaderProgram mShader;
|
enum Quality
|
||||||
|
{
|
||||||
|
Off,
|
||||||
|
LowQuality,
|
||||||
|
MediumQuality,
|
||||||
|
HighQuality,
|
||||||
|
NumQualityModes
|
||||||
|
};
|
||||||
|
|
||||||
|
FString GetDefines(int mode);
|
||||||
|
|
||||||
|
FShaderProgram mShader[NumQualityModes];
|
||||||
};
|
};
|
||||||
|
|
||||||
class FDepthBlurShader
|
class FDepthBlurShader
|
||||||
|
|
|
@ -50,7 +50,7 @@ EXTERN_CVAR(Bool, gl_lens)
|
||||||
EXTERN_CVAR(Float, gl_lens_k)
|
EXTERN_CVAR(Float, gl_lens_k)
|
||||||
EXTERN_CVAR(Float, gl_lens_kcube)
|
EXTERN_CVAR(Float, gl_lens_kcube)
|
||||||
EXTERN_CVAR(Float, gl_lens_chromatic)
|
EXTERN_CVAR(Float, gl_lens_chromatic)
|
||||||
EXTERN_CVAR(Bool, gl_ssao)
|
EXTERN_CVAR(Int, gl_ssao)
|
||||||
EXTERN_CVAR(Float, gl_ssao_strength)
|
EXTERN_CVAR(Float, gl_ssao_strength)
|
||||||
EXTERN_CVAR(Bool, gl_ssao_debug)
|
EXTERN_CVAR(Bool, gl_ssao_debug)
|
||||||
EXTERN_CVAR(Float, gl_ssao_bias)
|
EXTERN_CVAR(Float, gl_ssao_bias)
|
||||||
|
|
|
@ -2167,6 +2167,9 @@ NETMNU_TICBALANCE = "Latency balancing";
|
||||||
// Option Values
|
// Option Values
|
||||||
OPTVAL_OFF = "Off";
|
OPTVAL_OFF = "Off";
|
||||||
OPTVAL_ON = "On";
|
OPTVAL_ON = "On";
|
||||||
|
OPTVAL_LOW = "Low";
|
||||||
|
OPTVAL_MEDIUM = "Medium";
|
||||||
|
OPTVAL_HIGH = "High";
|
||||||
OPTVAL_MALE = "Male";
|
OPTVAL_MALE = "Male";
|
||||||
OPTVAL_FEMALE = "Female";
|
OPTVAL_FEMALE = "Female";
|
||||||
OPTVAL_OTHER = "Other";
|
OPTVAL_OTHER = "Other";
|
||||||
|
@ -2633,7 +2636,7 @@ GLPREFMNU_MULTISAMPLE = "Multisample";
|
||||||
GLPREFMNU_TONEMAP = "Tonemap Mode";
|
GLPREFMNU_TONEMAP = "Tonemap Mode";
|
||||||
GLPREFMNU_BLOOM = "Bloom effect";
|
GLPREFMNU_BLOOM = "Bloom effect";
|
||||||
GLPREFMNU_LENS = "Lens distortion effect";
|
GLPREFMNU_LENS = "Lens distortion effect";
|
||||||
GLPREFMNU_SSAO = "Ambient occlusion";
|
GLPREFMNU_SSAO = "Ambient occlusion quality";
|
||||||
|
|
||||||
// Option Values
|
// Option Values
|
||||||
OPTVAL_SMART = "Smart";
|
OPTVAL_SMART = "Smart";
|
||||||
|
|
|
@ -42,6 +42,14 @@ OptionValue "TonemapModes"
|
||||||
5, "$OPTVAL_PALETTE"
|
5, "$OPTVAL_PALETTE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OptionValue "SSAOModes"
|
||||||
|
{
|
||||||
|
0, "$OPTVAL_OFF"
|
||||||
|
1, "$OPTVAL_LOW"
|
||||||
|
2, "$OPTVAL_MEDIUM"
|
||||||
|
3, "$OPTVAL_HIGH"
|
||||||
|
}
|
||||||
|
|
||||||
OptionValue "TextureFormats"
|
OptionValue "TextureFormats"
|
||||||
{
|
{
|
||||||
0, "$OPTVAL_RGBA8"
|
0, "$OPTVAL_RGBA8"
|
||||||
|
@ -226,5 +234,5 @@ OptionMenu "GLPrefOptions"
|
||||||
Option "$GLPREFMNU_TONEMAP", gl_tonemap, "TonemapModes"
|
Option "$GLPREFMNU_TONEMAP", gl_tonemap, "TonemapModes"
|
||||||
Option "$GLPREFMNU_BLOOM", gl_bloom, "OnOff"
|
Option "$GLPREFMNU_BLOOM", gl_bloom, "OnOff"
|
||||||
Option "$GLPREFMNU_LENS", gl_lens, "OnOff"
|
Option "$GLPREFMNU_LENS", gl_lens, "OnOff"
|
||||||
Option "$GLPREFMNU_SSAO", gl_ssao, "OnOff"
|
Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue