mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
- uniform buffers for the fxaa, blur and bloom shaders
This commit is contained in:
parent
48f753061a
commit
49073489e5
8 changed files with 47 additions and 24 deletions
|
@ -302,8 +302,9 @@ void FGLRenderer::BloomScene(int fixedcm)
|
|||
mBloomExtractShader->Bind();
|
||||
mBloomExtractShader->SceneTexture.Set(0);
|
||||
mBloomExtractShader->ExposureTexture.Set(1);
|
||||
mBloomExtractShader->Scale.Set(mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height);
|
||||
mBloomExtractShader->Offset.Set(mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height);
|
||||
mBloomExtractShader->Uniforms->Scale = { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height };
|
||||
mBloomExtractShader->Uniforms->Offset = { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height };
|
||||
mBloomExtractShader->Uniforms.Set();
|
||||
RenderScreenQuad();
|
||||
|
||||
// Blur and downscale:
|
||||
|
@ -611,12 +612,6 @@ void FGLRenderer::ApplyFXAA()
|
|||
|
||||
FGLDebug::PushGroup("ApplyFXAA");
|
||||
|
||||
const GLfloat rpcRes[2] =
|
||||
{
|
||||
1.0f / mBuffers->GetWidth(),
|
||||
1.0f / mBuffers->GetHeight()
|
||||
};
|
||||
|
||||
FGLPostProcessState savedState;
|
||||
|
||||
mBuffers->BindNextFB();
|
||||
|
@ -630,7 +625,8 @@ void FGLRenderer::ApplyFXAA()
|
|||
mBuffers->BindCurrentTexture(0, GL_LINEAR);
|
||||
mFXAAShader->Bind();
|
||||
mFXAAShader->InputTexture.Set(0);
|
||||
mFXAAShader->ReciprocalResolution.Set(rpcRes);
|
||||
mFXAAShader->Uniforms->ReciprocalResolution = { 1.0f / mBuffers->GetWidth(), 1.0f / mBuffers->GetHeight() };
|
||||
mFXAAShader->Uniforms.Set();
|
||||
RenderScreenQuad();
|
||||
mBuffers->NextTexture();
|
||||
|
||||
|
|
|
@ -33,15 +33,16 @@ void FBloomExtractShader::Bind()
|
|||
{
|
||||
if (!mShader)
|
||||
{
|
||||
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||
|
||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/bloomextract.fp", "", 330);
|
||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/bloomextract.fp", prolog, 330);
|
||||
mShader.SetFragDataLocation(0, "FragColor");
|
||||
mShader.Link("shaders/glsl/bloomextract");
|
||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||
SceneTexture.Init(mShader, "SceneTexture");
|
||||
ExposureTexture.Init(mShader, "ExposureTexture");
|
||||
Scale.Init(mShader, "Scale");
|
||||
Offset.Init(mShader, "Offset");
|
||||
Uniforms.Init(mShader);
|
||||
}
|
||||
mShader.Bind();
|
||||
}
|
||||
|
|
|
@ -10,8 +10,23 @@ public:
|
|||
|
||||
FBufferedUniformSampler SceneTexture;
|
||||
FBufferedUniformSampler ExposureTexture;
|
||||
FBufferedUniform2f Scale;
|
||||
FBufferedUniform2f Offset;
|
||||
|
||||
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> Uniforms;
|
||||
|
||||
private:
|
||||
FShaderProgram mShader;
|
||||
|
|
|
@ -25,8 +25,6 @@ private:
|
|||
int sampleCount;
|
||||
std::shared_ptr<FShaderProgram> VerticalShader;
|
||||
std::shared_ptr<FShaderProgram> HorizontalShader;
|
||||
FBufferedUniform1f VerticalScaleX, VerticalScaleY;
|
||||
FBufferedUniform1f HorizontalScaleX, HorizontalScaleY;
|
||||
};
|
||||
|
||||
BlurSetup *GetSetup(float blurAmount, int sampleCount);
|
||||
|
|
|
@ -83,16 +83,16 @@ void FFXAAShader::Bind()
|
|||
|
||||
if (!shader)
|
||||
{
|
||||
const FString defines = GetDefines();
|
||||
const FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()) + GetDefines();
|
||||
const int maxVersion = GetMaxVersion();
|
||||
|
||||
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/fxaa.fp", defines, maxVersion);
|
||||
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/fxaa.fp", prolog, maxVersion);
|
||||
shader.SetFragDataLocation(0, "FragColor");
|
||||
shader.Link("shaders/glsl/fxaa");
|
||||
shader.SetAttribLocation(0, "PositionInProjection");
|
||||
InputTexture.Init(shader, "InputTexture");
|
||||
ReciprocalResolution.Init(shader, "ReciprocalResolution");
|
||||
Uniforms.Init(shader);
|
||||
}
|
||||
|
||||
shader.Bind();
|
||||
|
|
|
@ -48,7 +48,24 @@ public:
|
|||
void Bind();
|
||||
|
||||
FBufferedUniform1i InputTexture;
|
||||
FBufferedUniform2f ReciprocalResolution;
|
||||
|
||||
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> Uniforms;
|
||||
|
||||
private:
|
||||
FShaderProgram mShaders[Count];
|
||||
|
|
|
@ -4,8 +4,6 @@ out vec4 FragColor;
|
|||
|
||||
uniform sampler2D SceneTexture;
|
||||
uniform sampler2D ExposureTexture;
|
||||
uniform vec2 Scale;
|
||||
uniform vec2 Offset;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -605,8 +605,6 @@ FxaaFloat4 FxaaPixelShader(FxaaFloat2 pos, FxaaTex tex, FxaaFloat2 fxaaQualityRc
|
|||
#endif
|
||||
}
|
||||
|
||||
uniform vec2 ReciprocalResolution;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = FxaaPixelShader(TexCoord, InputTexture, ReciprocalResolution, 0.75f, 0.166f, 0.0833f);
|
||||
|
|
Loading…
Reference in a new issue