- write OpenGL backend for hw_postprocess (FGLRenderBuffers::RenderEffect)
- remove old fxaa and lens shader classes - render the fxaa and lens effects
This commit is contained in:
parent
e3997d5f11
commit
151ed22967
13 changed files with 270 additions and 319 deletions
|
|
@ -1,95 +0,0 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2016 Alexey Lysiuk
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// Fast approXimate Anti-Aliasing (FXAA) post-processing
|
||||
//
|
||||
|
||||
#include "hw_fxaashader.h"
|
||||
|
||||
EXTERN_CVAR(Int, gl_fxaa)
|
||||
|
||||
void FFXAALumaShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/fxaa.fp", "#define FXAA_LUMA_PASS\n", 330);
|
||||
mShader->Link("shaders/glsl/fxaa");
|
||||
}
|
||||
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
static int GetMaxVersion()
|
||||
{
|
||||
return screen->glslversion >= 4.f ? 400 : 330;
|
||||
}
|
||||
|
||||
static FString GetDefines()
|
||||
{
|
||||
int quality;
|
||||
|
||||
switch (gl_fxaa)
|
||||
{
|
||||
default:
|
||||
case FFXAAShader::Low: quality = 10; break;
|
||||
case FFXAAShader::Medium: quality = 12; break;
|
||||
case FFXAAShader::High: quality = 29; break;
|
||||
case FFXAAShader::Extreme: quality = 39; break;
|
||||
}
|
||||
|
||||
const int gatherAlpha = GetMaxVersion() >= 400 ? 1 : 0;
|
||||
|
||||
// TODO: enable FXAA_GATHER4_ALPHA on OpenGL earlier than 4.0
|
||||
// when GL_ARB_gpu_shader5/GL_NV_gpu_shader5 extensions are supported
|
||||
|
||||
FString result;
|
||||
result.Format(
|
||||
"#define FXAA_QUALITY__PRESET %i\n"
|
||||
"#define FXAA_GATHER4_ALPHA %i\n",
|
||||
quality, gatherAlpha);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void FFXAAShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
assert(gl_fxaa > 0 && gl_fxaa < Count);
|
||||
auto &shader = mShaders[gl_fxaa];
|
||||
|
||||
if (!shader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()) + GetDefines();
|
||||
const int maxVersion = GetMaxVersion();
|
||||
|
||||
shader.reset(screen->CreateShaderProgram());
|
||||
shader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", maxVersion);
|
||||
shader->Compile(IShaderProgram::Fragment, "shaders/glsl/fxaa.fp", prolog, maxVersion);
|
||||
shader->Link("shaders/glsl/fxaa");
|
||||
shader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
|
||||
shader->Bind(q);
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2016 Alexey Lysiuk
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// Fast approXimate Anti-Aliasing (FXAA) post-processing
|
||||
//
|
||||
|
||||
#ifndef __GL_FXAASHADER_H__
|
||||
#define __GL_FXAASHADER_H__
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
#include "hwrenderer/postprocessing/hw_postprocess_cvars.h"
|
||||
|
||||
class FFXAALumaShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
|
||||
class FFXAAShader : public IFXAAShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
FVector2 ReciprocalResolution;
|
||||
float Padding0, Padding1;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "ReciprocalResolution", UniformType::Vec2, offsetof(UniformBlock, ReciprocalResolution) },
|
||||
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShaders[Count];
|
||||
};
|
||||
|
||||
#endif // __GL_FXAASHADER_H__
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2016 Magnus Norddahl
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
/*
|
||||
** gl_lensshader.cpp
|
||||
** Lens distortion with chromatic aberration shader
|
||||
**
|
||||
*/
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hw_lensshader.h"
|
||||
|
||||
void FLensShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/lensdistortion.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/lensdistortion");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
#ifndef __GL_LENSSHADER_H
|
||||
#define __GL_LENSSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FLensShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
float AspectRatio;
|
||||
float Scale;
|
||||
float Padding0, Padding1;
|
||||
FVector4 LensDistortionCoefficient;
|
||||
FVector4 CubicDistortionValue;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "Aspect", UniformType::Float, offsetof(UniformBlock, AspectRatio) },
|
||||
{ "Scale", UniformType::Float, offsetof(UniformBlock, Scale) },
|
||||
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||
{ "k", UniformType::Vec4, offsetof(UniformBlock, LensDistortionCoefficient) },
|
||||
{ "kcube", UniformType::Vec4, offsetof(UniformBlock, CubicDistortionValue) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -25,19 +25,17 @@ void PPBloom::UpdateTextures(int width, int height)
|
|||
|
||||
for (int i = 0; i < NumBloomLevels; i++)
|
||||
{
|
||||
FString vtexture, htexture;
|
||||
vtexture.Format("Bloom.VTexture.%d", i);
|
||||
htexture.Format("Bloom.HTexture.%d", i);
|
||||
|
||||
auto &level = levels[i];
|
||||
level.VTexture.Format("Bloom.VTexture.%d", i);
|
||||
level.HTexture.Format("Bloom.HTexture.%d", i);
|
||||
level.Viewport.left = 0;
|
||||
level.Viewport.top = 0;
|
||||
level.Viewport.width = (bloomWidth + 1) / 2;
|
||||
level.Viewport.height = (bloomHeight + 1) / 2;
|
||||
|
||||
PPTextureDesc texture = { level.Viewport.width, level.Viewport.height, PixelFormat::Rgba16f };
|
||||
hw_postprocess.Textures[vtexture] = texture;
|
||||
hw_postprocess.Textures[htexture] = texture;
|
||||
hw_postprocess.Textures[level.VTexture] = texture;
|
||||
hw_postprocess.Textures[level.HTexture] = texture;
|
||||
|
||||
bloomWidth = level.Viewport.width;
|
||||
bloomHeight = level.Viewport.height;
|
||||
|
|
@ -65,6 +63,7 @@ void PPBloom::UpdateSteps(int fixedcm)
|
|||
// Extract blooming pixels from scene texture:
|
||||
step.Viewport = level0.Viewport;
|
||||
step.SetInputCurrent(0, PPFilterMode::Linear);
|
||||
step.SetInputTexture(1, "ExposureTexture");
|
||||
step.ShaderName = "BloomExtract";
|
||||
step.Uniforms.Set(extractUniforms);
|
||||
step.SetOutputTexture(level0.VTexture);
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
Data = nullptr;
|
||||
Size = 0;
|
||||
|
||||
Data = new uint8_t[Size];
|
||||
Data = new uint8_t[sizeof(T)];
|
||||
Size = sizeof(T);
|
||||
memcpy(Data, &v, Size);
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ class PPStep
|
|||
public:
|
||||
void SetInputTexture(int index, PPTextureName texture, PPFilterMode filter = PPFilterMode::Nearest)
|
||||
{
|
||||
if ((int)Textures.Size() < index)
|
||||
if ((int)Textures.Size() < index + 1)
|
||||
Textures.Resize(index + 1);
|
||||
auto &tex = Textures[index];
|
||||
tex.Filter = filter;
|
||||
|
|
@ -103,7 +103,7 @@ public:
|
|||
|
||||
void SetInputCurrent(int index, PPFilterMode filter = PPFilterMode::Nearest)
|
||||
{
|
||||
if ((int)Textures.Size() < index)
|
||||
if ((int)Textures.Size() < index + 1)
|
||||
Textures.Resize(index + 1);
|
||||
auto &tex = Textures[index];
|
||||
tex.Filter = filter;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue