Make sure we never pass a negative value to pow, and optimize gamma uniform

This commit is contained in:
Magnus Norddahl 2016-08-16 00:01:18 +02:00
parent a03b2ff48b
commit a8d1197ea7
4 changed files with 7 additions and 7 deletions

View file

@ -306,13 +306,13 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
mPresentShader->InputTexture.Set(0);
if (!applyGamma || framebuffer->IsHWGammaActive())
{
mPresentShader->Gamma.Set(1.0f);
mPresentShader->InvGamma.Set(1.0f);
mPresentShader->Contrast.Set(1.0f);
mPresentShader->Brightness.Set(0.0f);
}
else
{
mPresentShader->Gamma.Set(clamp<float>(Gamma, 0.1f, 4.f));
mPresentShader->InvGamma.Set(1.0f / clamp<float>(Gamma, 0.1f, 4.f));
mPresentShader->Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
}

View file

@ -60,7 +60,7 @@ void FPresentShader::Bind()
mShader.SetAttribLocation(0, "PositionInProjection");
mShader.SetAttribLocation(1, "UV");
InputTexture.Init(mShader, "InputTexture");
Gamma.Init(mShader, "Gamma");
InvGamma.Init(mShader, "InvGamma");
Contrast.Init(mShader, "Contrast");
Brightness.Init(mShader, "Brightness");
Scale.Init(mShader, "UVScale");

View file

@ -9,7 +9,7 @@ public:
void Bind();
FBufferedUniform1i InputTexture;
FBufferedUniform1f Gamma;
FBufferedUniform1f InvGamma;
FBufferedUniform1f Contrast;
FBufferedUniform1f Brightness;
FBufferedUniform2f Scale;

View file

@ -3,14 +3,14 @@ in vec2 TexCoord;
out vec4 FragColor;
uniform sampler2D InputTexture;
uniform float Gamma;
uniform float InvGamma;
uniform float Contrast;
uniform float Brightness;
vec4 ApplyGamma(vec4 c)
{
vec3 val = c.rgb * Contrast - (Contrast - 1.0) * 0.5;
val = pow(val, vec3(1.0 / Gamma));
vec3 val = max(c.rgb * Contrast - (Contrast - 1.0) * 0.5, vec3(0.0));
val = pow(val, vec3(InvGamma));
val += Brightness * 0.5;
return vec4(val, c.a);
}