- moved postprocessing shader classes to hwrenderer after removing all dependencies on OpenGL.
This commit is contained in:
parent
3401876476
commit
9a7f9bdb4c
23 changed files with 40 additions and 41 deletions
138
src/hwrenderer/postprocessing/hw_ambientshader.cpp
Normal file
138
src/hwrenderer/postprocessing/hw_ambientshader.cpp
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hwrenderer/utility/hw_cvars.h"
|
||||
#include "hw_ambientshader.h"
|
||||
|
||||
void FLinearDepthShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
bool multisample = (gl_multisample > 1);
|
||||
if (mMultisample != multisample)
|
||||
mShader.reset();
|
||||
|
||||
if (!mShader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
if (multisample) prolog += "#define MULTISAMPLE\n";
|
||||
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/lineardepth.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/lineardepth");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
mMultisample = multisample;
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
void FSSAOShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
bool multisample = (gl_multisample > 1);
|
||||
if (mCurrentQuality != gl_ssao || mMultisample != multisample)
|
||||
mShader.reset();
|
||||
|
||||
if (!mShader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
prolog += GetDefines(gl_ssao, multisample);
|
||||
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/ssao.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/ssao");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
mMultisample = multisample;
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
FString FSSAOShader::GetDefines(int mode, bool multisample)
|
||||
{
|
||||
// Must match quality values in FGLRenderBuffers::CreateAmbientOcclusion
|
||||
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);
|
||||
|
||||
if (multisample)
|
||||
defines += "\n#define MULTISAMPLE\n";
|
||||
return defines;
|
||||
}
|
||||
|
||||
void FDepthBlurShader::Bind(IRenderQueue *q, bool vertical)
|
||||
{
|
||||
auto &shader = mShader[vertical];
|
||||
if (!shader)
|
||||
{
|
||||
FString prolog = Uniforms[vertical].CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
if (vertical)
|
||||
prolog += "#define BLUR_VERTICAL\n";
|
||||
else
|
||||
prolog += "#define BLUR_HORIZONTAL\n";
|
||||
|
||||
shader.reset(screen->CreateShaderProgram());
|
||||
shader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
shader->Compile(IShaderProgram::Fragment, "shaders/glsl/depthblur.fp", prolog, 330);
|
||||
shader->Link("shaders/glsl/depthblur");
|
||||
shader->SetUniformBufferLocation(Uniforms[vertical].BindingPoint(), "Uniforms");
|
||||
Uniforms[vertical].Init();
|
||||
}
|
||||
shader->Bind(q);
|
||||
}
|
||||
|
||||
void FSSAOCombineShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
bool multisample = (gl_multisample > 1);
|
||||
if (mMultisample != multisample)
|
||||
mShader.reset();
|
||||
|
||||
if (!mShader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
if (multisample)
|
||||
prolog += "#define MULTISAMPLE\n";
|
||||
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/ssaocombine.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/ssaocombine");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
mMultisample = multisample;
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
168
src/hwrenderer/postprocessing/hw_ambientshader.h
Normal file
168
src/hwrenderer/postprocessing/hw_ambientshader.h
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
#ifndef __GL_AMBIENTSHADER_H
|
||||
#define __GL_AMBIENTSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FLinearDepthShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
int SampleIndex;
|
||||
float LinearizeDepthA;
|
||||
float LinearizeDepthB;
|
||||
float InverseDepthRangeA;
|
||||
float InverseDepthRangeB;
|
||||
float Padding0, Padding1, Padding2;
|
||||
FVector2 Scale;
|
||||
FVector2 Offset;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "SampleIndex", UniformType::Int, offsetof(UniformBlock, SampleIndex) },
|
||||
{ "LinearizeDepthA", UniformType::Float, offsetof(UniformBlock, LinearizeDepthA) },
|
||||
{ "LinearizeDepthB", UniformType::Float, offsetof(UniformBlock, LinearizeDepthB) },
|
||||
{ "InverseDepthRangeA", UniformType::Float, offsetof(UniformBlock, InverseDepthRangeA) },
|
||||
{ "InverseDepthRangeB", UniformType::Float, offsetof(UniformBlock, InverseDepthRangeB) },
|
||||
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||
{ "Padding2", UniformType::Float, offsetof(UniformBlock, Padding2) },
|
||||
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
bool mMultisample = false;
|
||||
};
|
||||
|
||||
class FSSAOShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
FVector2 UVToViewA;
|
||||
FVector2 UVToViewB;
|
||||
FVector2 InvFullResolution;
|
||||
float NDotVBias;
|
||||
float NegInvR2;
|
||||
float RadiusToScreen;
|
||||
float AOMultiplier;
|
||||
float AOStrength;
|
||||
int SampleIndex;
|
||||
float Padding0, Padding1;
|
||||
FVector2 Scale;
|
||||
FVector2 Offset;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "UVToViewA", UniformType::Vec2, offsetof(UniformBlock, UVToViewA) },
|
||||
{ "UVToViewB", UniformType::Vec2, offsetof(UniformBlock, UVToViewB) },
|
||||
{ "InvFullResolution", UniformType::Vec2, offsetof(UniformBlock, InvFullResolution) },
|
||||
{ "NDotVBias", UniformType::Float, offsetof(UniformBlock, NDotVBias) },
|
||||
{ "NegInvR2", UniformType::Float, offsetof(UniformBlock, NegInvR2) },
|
||||
{ "RadiusToScreen", UniformType::Float, offsetof(UniformBlock, RadiusToScreen) },
|
||||
{ "AOMultiplier", UniformType::Float, offsetof(UniformBlock, AOMultiplier) },
|
||||
{ "AOStrength", UniformType::Float, offsetof(UniformBlock, AOStrength) },
|
||||
{ "SampleIndex", UniformType::Int, offsetof(UniformBlock, SampleIndex) },
|
||||
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
enum Quality
|
||||
{
|
||||
Off,
|
||||
LowQuality,
|
||||
MediumQuality,
|
||||
HighQuality,
|
||||
NumQualityModes
|
||||
};
|
||||
|
||||
FString GetDefines(int mode, bool multisample);
|
||||
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
Quality mCurrentQuality = Off;
|
||||
bool mMultisample = false;
|
||||
};
|
||||
|
||||
class FDepthBlurShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q, bool vertical);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
float BlurSharpness;
|
||||
float PowExponent;
|
||||
FVector2 InvFullResolution;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "BlurSharpness", UniformType::Float, offsetof(UniformBlock, BlurSharpness) },
|
||||
{ "PowExponent", UniformType::Float, offsetof(UniformBlock, PowExponent) },
|
||||
{ "InvFullResolution", UniformType::Vec2, offsetof(UniformBlock, InvFullResolution) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms[2];
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader[2];
|
||||
};
|
||||
|
||||
class FSSAOCombineShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
int SampleCount;
|
||||
int Padding0, Padding1, Padding2;
|
||||
FVector2 Scale;
|
||||
FVector2 Offset;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "SampleCount", UniformType::Int, offsetof(UniformBlock, SampleCount) },
|
||||
{ "Padding0", UniformType::Int, offsetof(UniformBlock, Padding0) },
|
||||
{ "Padding1", UniformType::Int, offsetof(UniformBlock, Padding1) },
|
||||
{ "Padding2", UniformType::Int, offsetof(UniformBlock, Padding2) },
|
||||
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
bool mMultisample = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
57
src/hwrenderer/postprocessing/hw_bloomshader.cpp
Normal file
57
src/hwrenderer/postprocessing/hw_bloomshader.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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_bloomshader.cpp
|
||||
** Shaders used to do bloom
|
||||
**
|
||||
*/
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hw_bloomshader.h"
|
||||
|
||||
void FBloomExtractShader::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/bloomextract.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/bloomextract");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
void FBloomCombineShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/bloomcombine.fp", "", 330);
|
||||
mShader->Link("shaders/glsl/bloomcombine");
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
41
src/hwrenderer/postprocessing/hw_bloomshader.h
Normal file
41
src/hwrenderer/postprocessing/hw_bloomshader.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef __GL_BLOOMSHADER_H
|
||||
#define __GL_BLOOMSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FBloomExtractShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
FVector2 Scale;
|
||||
FVector2 Offset;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
class FBloomCombineShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
#endif
|
||||
50
src/hwrenderer/postprocessing/hw_blurshader.cpp
Normal file
50
src/hwrenderer/postprocessing/hw_blurshader.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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_blurshader.cpp
|
||||
** Gaussian blur shader
|
||||
**
|
||||
*/
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hw_blurshader.h"
|
||||
|
||||
void FBlurShader::Bind(IRenderQueue *q, bool vertical)
|
||||
{
|
||||
if (!mShader[vertical])
|
||||
{
|
||||
FString prolog = Uniforms[vertical].CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
if (vertical)
|
||||
prolog += "#define BLUR_VERTICAL\n";
|
||||
else
|
||||
prolog += "#define BLUR_HORIZONTAL\n";
|
||||
|
||||
mShader[vertical].reset(screen->CreateShaderProgram());
|
||||
mShader[vertical]->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader[vertical]->Compile(IShaderProgram::Fragment, "shaders/glsl/blur.fp", prolog, 330);
|
||||
mShader[vertical]->Link("shaders/glsl/blur");
|
||||
mShader[vertical]->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms");
|
||||
Uniforms[vertical].Init();
|
||||
}
|
||||
|
||||
mShader[vertical]->Bind(q);
|
||||
}
|
||||
39
src/hwrenderer/postprocessing/hw_blurshader.h
Normal file
39
src/hwrenderer/postprocessing/hw_blurshader.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FGLRenderer;
|
||||
class PPFrameBuffer;
|
||||
class PPTexture;
|
||||
|
||||
class FBlurShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q, bool vertical);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
float SampleWeights[8];
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "SampleWeights0", UniformType::Float, offsetof(UniformBlock, SampleWeights[0]) },
|
||||
{ "SampleWeights1", UniformType::Float, offsetof(UniformBlock, SampleWeights[1]) },
|
||||
{ "SampleWeights2", UniformType::Float, offsetof(UniformBlock, SampleWeights[2]) },
|
||||
{ "SampleWeights3", UniformType::Float, offsetof(UniformBlock, SampleWeights[3]) },
|
||||
{ "SampleWeights4", UniformType::Float, offsetof(UniformBlock, SampleWeights[4]) },
|
||||
{ "SampleWeights5", UniformType::Float, offsetof(UniformBlock, SampleWeights[5]) },
|
||||
{ "SampleWeights6", UniformType::Float, offsetof(UniformBlock, SampleWeights[6]) },
|
||||
{ "SampleWeights7", UniformType::Float, offsetof(UniformBlock, SampleWeights[7]) },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms[2];
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader[2];
|
||||
};
|
||||
45
src/hwrenderer/postprocessing/hw_colormapshader.cpp
Normal file
45
src/hwrenderer/postprocessing/hw_colormapshader.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2016 Christoph Oelckers
|
||||
// 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_colormapshader.cpp
|
||||
** Applies a fullscreen colormap to the scene
|
||||
**
|
||||
*/
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hw_colormapshader.h"
|
||||
|
||||
void FColormapShader::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/colormap.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/colormap");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
33
src/hwrenderer/postprocessing/hw_colormapshader.h
Normal file
33
src/hwrenderer/postprocessing/hw_colormapshader.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef __GL_COLORMAPSHADER_H
|
||||
#define __GL_COLORMAPSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FColormapShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
FVector4 MapStart;
|
||||
FVector4 MapRange;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "uFixedColormapStart", UniformType::Vec4, offsetof(UniformBlock, MapStart) },
|
||||
{ "uFixedColormapRange", UniformType::Vec4, offsetof(UniformBlock, MapRange) },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
#endif
|
||||
95
src/hwrenderer/postprocessing/hw_fxaashader.cpp
Normal file
95
src/hwrenderer/postprocessing/hw_fxaashader.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
70
src/hwrenderer/postprocessing/hw_fxaashader.h
Normal file
70
src/hwrenderer/postprocessing/hw_fxaashader.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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__
|
||||
45
src/hwrenderer/postprocessing/hw_lensshader.cpp
Normal file
45
src/hwrenderer/postprocessing/hw_lensshader.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
39
src/hwrenderer/postprocessing/hw_lensshader.h
Normal file
39
src/hwrenderer/postprocessing/hw_lensshader.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#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
|
||||
57
src/hwrenderer/postprocessing/hw_present3dRowshader.cpp
Normal file
57
src/hwrenderer/postprocessing/hw_present3dRowshader.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2016 Christopher Bruns
|
||||
// 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_3dRowshader.cpp
|
||||
** Copy rendered texture to back buffer, possibly with gamma correction
|
||||
** while interleaving rows from two independent viewpoint textures,
|
||||
** representing the left-eye and right-eye views.
|
||||
**
|
||||
*/
|
||||
|
||||
#include "hw_present3dRowshader.h"
|
||||
|
||||
void FPresent3DCheckerShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
Init("shaders/glsl/present_checker3d.fp", "shaders/glsl/presentChecker3d");
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
void FPresent3DColumnShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
Init("shaders/glsl/present_column3d.fp", "shaders/glsl/presentColumn3d");
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
void FPresent3DRowShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
Init("shaders/glsl/present_row3d.fp", "shaders/glsl/presentRow3d");
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
53
src/hwrenderer/postprocessing/hw_present3dRowshader.h
Normal file
53
src/hwrenderer/postprocessing/hw_present3dRowshader.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2015 Christopher Bruns
|
||||
// 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_present3dRowshader.h
|
||||
** Final composition and present shader for row-interleaved stereoscopic 3D mode
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef GL_PRESENT3DROWSHADER_H_
|
||||
#define GL_PRESENT3DROWSHADER_H_
|
||||
|
||||
#include "hw_shaderprogram.h"
|
||||
#include "hw_presentshader.h"
|
||||
|
||||
class FPresent3DCheckerShader : public FPresentShaderBase
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q) override;
|
||||
};
|
||||
|
||||
class FPresent3DColumnShader : public FPresentShaderBase
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q) override;
|
||||
};
|
||||
|
||||
class FPresent3DRowShader : public FPresentShaderBase
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q) override;
|
||||
};
|
||||
|
||||
// GL_PRESENT3DROWSHADER_H_
|
||||
#endif
|
||||
50
src/hwrenderer/postprocessing/hw_presentshader.cpp
Normal file
50
src/hwrenderer/postprocessing/hw_presentshader.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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_presentshader.cpp
|
||||
** Copy rendered texture to back buffer, possibly with gamma correction
|
||||
**
|
||||
*/
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hw_presentshader.h"
|
||||
|
||||
void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program_name)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", prolog, 330);
|
||||
mShader->Compile(IShaderProgram::Fragment, vtx_shader_name, prolog, 330);
|
||||
mShader->Link(program_name);
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
|
||||
void FPresentShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
Init("shaders/glsl/present.fp", "shaders/glsl/present");
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
51
src/hwrenderer/postprocessing/hw_presentshader.h
Normal file
51
src/hwrenderer/postprocessing/hw_presentshader.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef __GL_PRESENTSHADER_H
|
||||
#define __GL_PRESENTSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FPresentShaderBase
|
||||
{
|
||||
public:
|
||||
virtual ~FPresentShaderBase() {}
|
||||
virtual void Bind(IRenderQueue *q) = 0;
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
float InvGamma;
|
||||
float Contrast;
|
||||
float Brightness;
|
||||
float Saturation;
|
||||
int GrayFormula;
|
||||
int WindowPositionParity; // top-of-window might not be top-of-screen
|
||||
FVector2 Scale;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "InvGamma", UniformType::Float, offsetof(UniformBlock, InvGamma) },
|
||||
{ "Contrast", UniformType::Float, offsetof(UniformBlock, Contrast) },
|
||||
{ "Brightness", UniformType::Float, offsetof(UniformBlock, Brightness) },
|
||||
{ "Saturation", UniformType::Float, offsetof(UniformBlock, Saturation) },
|
||||
{ "GrayFormula", UniformType::Int, offsetof(UniformBlock, GrayFormula) },
|
||||
{ "WindowPositionParity", UniformType::Int, offsetof(UniformBlock, WindowPositionParity) },
|
||||
{ "UVScale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
protected:
|
||||
virtual void Init(const char * vtx_shader_name, const char * program_name);
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
class FPresentShader : public FPresentShaderBase
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q) override;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
40
src/hwrenderer/postprocessing/hw_shadowmapshader.cpp
Normal file
40
src/hwrenderer/postprocessing/hw_shadowmapshader.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "files.h"
|
||||
#include "hw_shadowmapshader.h"
|
||||
|
||||
void FShadowMapShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", prolog, 430);
|
||||
mShader->Link("shaders/glsl/shadowmap");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
34
src/hwrenderer/postprocessing/hw_shadowmapshader.h
Normal file
34
src/hwrenderer/postprocessing/hw_shadowmapshader.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef __GL_SHADOWMAPSHADER_H
|
||||
#define __GL_SHADOWMAPSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FShadowMapShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
float ShadowmapQuality;
|
||||
float Padding0, Padding1, Padding2;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "ShadowmapQuality", UniformType::Float, offsetof(UniformBlock, ShadowmapQuality) },
|
||||
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||
{ "Padding2", UniformType::Float, offsetof(UniformBlock, Padding2) },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
#endif
|
||||
107
src/hwrenderer/postprocessing/hw_tonemapshader.cpp
Normal file
107
src/hwrenderer/postprocessing/hw_tonemapshader.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// 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_tonemapshader.cpp
|
||||
** Converts a HDR texture to 0-1 range by applying a tonemap operator
|
||||
**
|
||||
*/
|
||||
|
||||
#include "v_video.h"
|
||||
#include "hwrenderer/utility/hw_cvars.h"
|
||||
#include "hw_tonemapshader.h"
|
||||
|
||||
void FTonemapShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
auto &shader = mShader[gl_tonemap];
|
||||
if (!shader)
|
||||
{
|
||||
auto prolog = GetDefines(gl_tonemap);
|
||||
|
||||
shader.reset(screen->CreateShaderProgram());
|
||||
shader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
shader->Compile(IShaderProgram::Fragment, "shaders/glsl/tonemap.fp", prolog, 330);
|
||||
shader->Link("shaders/glsl/tonemap");
|
||||
}
|
||||
shader->Bind(q);
|
||||
}
|
||||
|
||||
bool FTonemapShader::IsPaletteMode()
|
||||
{
|
||||
return gl_tonemap == Palette;
|
||||
}
|
||||
|
||||
const char *FTonemapShader::GetDefines(int mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
case Linear: return "#define LINEAR\n";
|
||||
case Reinhard: return "#define REINHARD\n";
|
||||
case HejlDawson: return "#define HEJLDAWSON\n";
|
||||
case Uncharted2: return "#define UNCHARTED2\n";
|
||||
case Palette: return "#define PALETTE\n";
|
||||
}
|
||||
}
|
||||
|
||||
void FExposureExtractShader::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/exposureextract.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/exposureextract");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
void FExposureAverageShader::Bind(IRenderQueue *q)
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
mShader.reset(screen->CreateShaderProgram());
|
||||
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 400);
|
||||
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/exposureaverage.fp", "", 400);
|
||||
mShader->Link("shaders/glsl/exposureaverage");
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
|
||||
void FExposureCombineShader::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/exposurecombine.fp", prolog, 330);
|
||||
mShader->Link("shaders/glsl/exposurecombine");
|
||||
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
|
||||
Uniforms.Init();
|
||||
}
|
||||
mShader->Bind(q);
|
||||
}
|
||||
95
src/hwrenderer/postprocessing/hw_tonemapshader.h
Normal file
95
src/hwrenderer/postprocessing/hw_tonemapshader.h
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#ifndef __GL_TONEMAPSHADER_H
|
||||
#define __GL_TONEMAPSHADER_H
|
||||
|
||||
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
|
||||
|
||||
class FTonemapShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
static bool IsPaletteMode();
|
||||
|
||||
private:
|
||||
enum TonemapMode
|
||||
{
|
||||
None,
|
||||
Uncharted2,
|
||||
HejlDawson,
|
||||
Reinhard,
|
||||
Linear,
|
||||
Palette,
|
||||
NumTonemapModes
|
||||
};
|
||||
|
||||
static const char *GetDefines(int mode);
|
||||
|
||||
std::unique_ptr<IShaderProgram> mShader[NumTonemapModes];
|
||||
};
|
||||
|
||||
class FExposureExtractShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
FVector2 Scale;
|
||||
FVector2 Offset;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
class FExposureAverageShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
class FExposureCombineShader
|
||||
{
|
||||
public:
|
||||
void Bind(IRenderQueue *q);
|
||||
|
||||
struct UniformBlock
|
||||
{
|
||||
float ExposureBase;
|
||||
float ExposureMin;
|
||||
float ExposureScale;
|
||||
float ExposureSpeed;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "ExposureBase", UniformType::Float, offsetof(UniformBlock, ExposureBase) },
|
||||
{ "ExposureMin", UniformType::Float, offsetof(UniformBlock, ExposureMin) },
|
||||
{ "ExposureScale", UniformType::Float, offsetof(UniformBlock, ExposureScale) },
|
||||
{ "ExposureSpeed", UniformType::Float, offsetof(UniformBlock, ExposureSpeed) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IShaderProgram> mShader;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue