diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index a47b1becc..06ac1cae3 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -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(); diff --git a/src/gl/shaders/gl_bloomshader.cpp b/src/gl/shaders/gl_bloomshader.cpp index 94a84b8c1..920a140c1 100644 --- a/src/gl/shaders/gl_bloomshader.cpp +++ b/src/gl/shaders/gl_bloomshader.cpp @@ -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(); } diff --git a/src/gl/shaders/gl_bloomshader.h b/src/gl/shaders/gl_bloomshader.h index 8b34bb479..e3473babb 100644 --- a/src/gl/shaders/gl_bloomshader.h +++ b/src/gl/shaders/gl_bloomshader.h @@ -10,8 +10,23 @@ public: FBufferedUniformSampler SceneTexture; FBufferedUniformSampler ExposureTexture; - FBufferedUniform2f Scale; - FBufferedUniform2f Offset; + + struct UniformBlock + { + FVector2 Scale; + FVector2 Offset; + + static std::vector Desc() + { + return + { + { "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) }, + { "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) } + }; + } + }; + + ShaderUniforms Uniforms; private: FShaderProgram mShader; diff --git a/src/gl/shaders/gl_blurshader.h b/src/gl/shaders/gl_blurshader.h index 0ffd6a4e7..b143c22f1 100644 --- a/src/gl/shaders/gl_blurshader.h +++ b/src/gl/shaders/gl_blurshader.h @@ -25,8 +25,6 @@ private: int sampleCount; std::shared_ptr VerticalShader; std::shared_ptr HorizontalShader; - FBufferedUniform1f VerticalScaleX, VerticalScaleY; - FBufferedUniform1f HorizontalScaleX, HorizontalScaleY; }; BlurSetup *GetSetup(float blurAmount, int sampleCount); diff --git a/src/gl/shaders/gl_fxaashader.cpp b/src/gl/shaders/gl_fxaashader.cpp index b5550bcf3..844f803f1 100644 --- a/src/gl/shaders/gl_fxaashader.cpp +++ b/src/gl/shaders/gl_fxaashader.cpp @@ -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(); diff --git a/src/gl/shaders/gl_fxaashader.h b/src/gl/shaders/gl_fxaashader.h index fc1567d93..126f0da79 100644 --- a/src/gl/shaders/gl_fxaashader.h +++ b/src/gl/shaders/gl_fxaashader.h @@ -48,7 +48,24 @@ public: void Bind(); FBufferedUniform1i InputTexture; - FBufferedUniform2f ReciprocalResolution; + + struct UniformBlock + { + FVector2 ReciprocalResolution; + float Padding0, Padding1; + + static std::vector Desc() + { + return + { + { "ReciprocalResolution", UniformType::Vec2, offsetof(UniformBlock, ReciprocalResolution) }, + { "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) }, + { "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) } + }; + } + }; + + ShaderUniforms Uniforms; private: FShaderProgram mShaders[Count]; diff --git a/wadsrc/static/shaders/glsl/bloomextract.fp b/wadsrc/static/shaders/glsl/bloomextract.fp index 9c5aa0bea..ca295500c 100644 --- a/wadsrc/static/shaders/glsl/bloomextract.fp +++ b/wadsrc/static/shaders/glsl/bloomextract.fp @@ -4,8 +4,6 @@ out vec4 FragColor; uniform sampler2D SceneTexture; uniform sampler2D ExposureTexture; -uniform vec2 Scale; -uniform vec2 Offset; void main() { diff --git a/wadsrc/static/shaders/glsl/fxaa.fp b/wadsrc/static/shaders/glsl/fxaa.fp index 7fcdf8c81..415260802 100644 --- a/wadsrc/static/shaders/glsl/fxaa.fp +++ b/wadsrc/static/shaders/glsl/fxaa.fp @@ -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);